opentelemetry-python icon indicating copy to clipboard operation
opentelemetry-python copied to clipboard

can you attach a LogRecordProcessor to default logger provider?

Open ty-elastic opened this issue 1 year ago • 0 comments

Is your feature request related to a problem?

Hi, I want to write a custom LogRecordProcessor that will attach baggage attributes (on the current context) to the log record. I've written it, and I'd like to attach it to the default logger provider OTel sets up when you set OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED="true".

I can do that like this:

log_provider = logs.get_logger_provider()
log_provider.add_log_record_processor(BaggageLogRecordProcessor())

and the emit() gets called as expected. I can set stuff, but then I realized that once I do that, log records are no longer being emitted to the OTLP exporter.

Can I hook the existing auto-instrumentation otel logging exporter like this, modify records, and still have them emit to the OTLP exporter without further config?

That seems possible with span processors... like:

tracer_provider = trace.get_tracer_provider()
tracer_provider.add_span_processor(...)

but with the log record processors, it seems the expectation is that they manually emit the record to something... in some examples, i've seen an exporter passed in, and then the processor manually exports to that exporter... to make that work, i would then have to basically construct my own logger_provider stack (adding my processor, then a manually configured otlp exporter). is there a way to create a "pass through" processor, like span processors?

Describe the solution you'd like

ideally a "pass through" processor for log records, like span processors

Describe alternatives you've considered

No response

Additional Context

No response

Would you like to implement a fix?

No

ty-elastic avatar Sep 25 '24 18:09 ty-elastic