open-telemetry / open-telemetry/opentelemetry-python

can you attach a LogRecordProcessor to default logger provider?

Open
#4,201 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature-request logging
Dominant language
Python
Stars
2.6k
Forks
1k
Avg merge
4d 15h
Merged PRs (30d)
19

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the logging APIs around logs.get_logger_provider(), add_log_record_processor(), and the OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED path. Trace how the default provider connects to the OTLP exporter and compare that behavior with span processors. Done means the requested pass-through behavior is clearly designed and verified without requiring users to rebuild the logger provider stack.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
observability
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.