Flagsmith / Flagsmith/flagsmith-common
OTel trace context not added to stdlib log events
- Dominant language
- Python
- Stars
- 2
- Forks
- 4
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 10
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.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.