Problem Statement
As mentioned in https://opentelemetry.io/docs/languages/python/automatic/configuration/, there is a mention of OTEL_PYTHON_LOG_CORRELATION which when set to true, will automatically inject trace id and span id in context to python's logs:
export OTEL_PYTHON_LOG_CORRELATION=true
export OTEL_PYTHON_LOG_FORMAT="%(msg)s [span_id=%(span_id)s]"
export OTEL_PYTHON_LOG_LEVEL=debug
export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true
However, setting the environment does NOT inject the trace_id and span_id, and the generated span has 0x0 as their values. In fact, when I tried to find the OTEL_PYTHON_LOG_CORRELATION in Otel python repo in github, I couldn't find any mention of it in the codebase.
Steps to reproduce
Describe exactly how to reproduce the error. Include a code sample if applicable.
- Write a simple python app (e.g. flask application), and use python's
logging and generate a log.
- define the following env:
...
- OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
- OTEL_LOGS_EXPORTER=console,otlp_proto_http
- OTEL_PYTHON_LOG_CORRELATION=true
- OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true
...
- run the application, with
What is the expected behavior?
OTEL log payload should have trace_id and span_id correctly populated
What is the actual behavior?
The console output has 0x00.. values for trace_id and span_id.
"timestamp": "2024-03-13T04:25:59.888144Z",
"observed_timestamp": "2024-03-13T04:25:59.889081Z",
"trace_id": "0x00000000000000000000000000000000",
"span_id": "0x0000000000000000",
"trace_flags": 0,
Additional context
The following dependencies were added to requirements.txt:
- opentelemetry-distro
- opentelemetry-exporter-otlp