Skip to content

[instrumentation] write auto-instrumentation loader messages to stderr when OTEL_LOG_LEVEL=debug #4540

@pmcollins

Description

@pmcollins

Write auto-instrumentation debug messages to stderr when OTEL_LOG_LEVEL=debug

What problem do you want to solve?

When Python auto-instrumentation runs, it is hard to tell which instrumentors were loaded. These messages are logged, but they are usually not visible when opentelemetry-instrument runs even though OTEL_LOG_LEVEL=debug may have been set. This is because auto-instrumentation runs from sitecustomize, before the application has had a chance to configure logging.

Writing these messages to stderr would be especially useful in k8s/operator-based deployments, where many instrumentation packages may be present in the auto-instrumentation image and users need to understand what happened at startup.

Expected behavior

When the user explicitly sets OTEL_LOG_LEVEL=debug or OTEL_LOG_LEVEL=trace, auto-instrumentation should write minimal startup messages to stderr.

For example:

DEBUG:opentelemetry.instrumentation.auto_instrumentation._load:Distribution 'distro' will be configured
DEBUG:opentelemetry.instrumentation.auto_instrumentation._load:Instrumented 'requests'

Proposed solution

Write auto-instrumentation startup messages to stderr when auto-instrumentation runs and OTEL_LOG_LEVEL=debug or OTEL_LOG_LEVEL=trace is set. Don't attempt to configure application logging. In the unlikely event that the application has already set up logging and then makes an explicit call to auto_instrumentation.initialize(), suppress this new output channel to prevent double logging.

Would you like to implement a fix?

Yes.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions