OTel trace context not added to stdlib log events

Open Beginner friendly
#198 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
python

Research direction

Read setup_logging() in common/core/logging.py, focusing on the foreign_pre_chain passed to ProcessorFormatter. Confirm how stdlib logging records are processed, then add the trace-context processor there and verify that stdlib and structlog events emitted within an active OTel span contain trace_id and span_id.

Written by the indexing model from the issue text.

Description

The add_otel_trace_context structlog processor currently only lives in the structlog.configure() pipeline, not in the foreign_pre_chain used by ProcessorFormatter for standard library logging events.

This means any module using logging.getLogger(__name__) (e.g. task_processor.processor) does not get trace_id / span_id injected into its log output — even when an active OTel span exists.

How to reproduce
  1. Run the API + task processor with OTEL_EXPORTER_OTLP_ENDPOINT set and LOG_FORMAT=json.
  2. Trigger a request that enqueues a task.
  3. Observe that task processor log events (e.g. "Failed to execute task") lack trace_id and span_id fields.
Expected

All log events emitted while an OTel span is active — regardless of whether they originate from structlog or stdlib logging — should include trace_id and span_id.

Fix

Add add_otel_trace_context to the foreign_pre_chain in setup_logging() (common/core/logging.py), so that ProcessorFormatter also injects trace context into stdlib log records.

Found while testing #197.

Dominant language
Python
Stars
2
Forks
4
Avg merge
2d 9h
Merged PRs (30d)
10

Contributor guide

No contributing guide indexed for this repository

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.

More from Flagsmith/flagsmith-common

All issues in Flagsmith/flagsmith-common

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.