open-telemetry / open-telemetry/opentelemetry-python-contrib

OTEL_PYTHON_LOG_CORRELATION is mentioned in doc, but does not seem to work.

Open
#2,346 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
1.1k
Forks
1.1k
Avg merge
4d 15h
Merged PRs (30d)
16

Description

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.

  1. Write a simple python app (e.g. flask application), and use python's logging and generate a log.
  2. 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
...
  1. 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

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 linked Python automatic-configuration documentation and search the repository for OTEL_PYTHON_LOG_CORRELATION and related logging auto-instrumentation entry points. Reproduce the report with a Flask application using Python logging and the listed requirements, then determine why the emitted trace_id and span_id remain zero. Done means the documented environment settings produce populated IDs in the OTLP log payload.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
observability-sre
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.