Skip to content

OTel trace context not added to stdlib log events #198

@khvn26

Description

@khvn26

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions