Closed avramdjo closed 2 days ago
I've found 2 workarounds
logger_provider.force_flush()
at the end of my forked functionBatchLogRecordProcessor
schedule_delay_millis
to a very low value like 10 miliseconds, which so far works, but it sounds like a race condition waiting to happen.I think this indicates that there isn't some fundamental lack of support for multiprocessing, or at least not an unsolvable one.
I obviously prefer the first solution, i just need to know if it's good. It also introduces some latency for every request. It seems to me like the problem is messages not being recorded in the batch accumulator, not necessarily that they're not being emitted to the exporter. I wish there was a functionality that safely "flushed" everything to the batch accumulator (before the fork exits, which happens in under a second) without pushing it through the exporter which is IO heavy.
I've ditched the SimpleLogRecordProcessor
solution since it both introduces significant overhead + I've been seeing some Envelopes could not be exported and are not retryable
errors.
I also could completely be missing the mark on this one, waiting for someone to reply.
The issue was the azure monitor exporter not being fork-safe.
Describe your environment
OS: Ubuntu Python version: Python 3.11.9 SDK version: 1.25.0 API version: 1.25.0
What happened?
The
BatchLogRecordProcessor
exporter set up to aLoggerProvider
set withset_logger_provider
doesn't seem to export logs from within a forked or spawned subprocess using aPoolProcessExecutor
.Funnily enough, it does work with SimpleLogRecordProcessor, but it slows my application down significantly.
Steps to Reproduce
Expected Result
both messages exported to azure application insights
Actual Result
only
"This log gets exported correctly"
is exportedAdditional context
This is a uvicorn fastapi application running with 1 worker without async. All the logs get exported correctly, ones before
uvicorn.run
, the ones insidefastapi
, except the ones in functions run fromPoolProcessExecutor
.Please excuse the pseudo-code in the
Steps to Reproduce
section.Would you like to implement a fix?
None