Correlate Python logs to active OTel span + bridge to stdlib logging#169
Open
brentrager wants to merge 1 commit into
Open
Correlate Python logs to active OTel span + bridge to stdlib logging#169brentrager wants to merge 1 commit into
brentrager wants to merge 1 commit into
Conversation
Replaces the fabricated uuid trace id with the ACTIVE OTel span's real W3C trace_id/span_id when a span is active (get_current_span().get_span_context()), falling back to the prior uuid behavior only when no span is active. Adds a spanId field to the record. Also bridges every emitted line through a dedicated stdlib `logging` logger (smooai_logger) so an installed @smooai/observability LoggingHandler on the root logger turns each line into an OTLP log record — correlated to the active span, which that handler reads. NullHandler keeps it a true no-op when observability isn't installed. The file-rotation logger no longer propagates its pretty ANSI blob to root (would otherwise leak into the OTLP bridge). Depends on opentelemetry-api ONLY — never on @smooai/observability (circular). Verified with an api-only NonRecordingSpan: a log inside the span carries that span's ids; no span → uuid fallback; the bridged line reaches root within the span context. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S2bM94GAnVjYSSv1x7HKRB
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Python logger fabricated a uuid trace id per context, so its logs never correlated to real OTel traces. And its lines never flowed through the stdlib
loggingfacade, so an installed@smooai/observabilityLoggingHandlernever saw them. (Pearl th-de3805; matches ADR-100.)Solution
_build_recordnow replaces the fabricated uuid with the active OTel span's real W3Ctrace_id/span_id(get_current_span().get_span_context()), adding aspanIdfield. Falls back to the prior uuid behavior only when no span is active.smooai_logger) so an observabilityLoggingHandleron root turns it into an OTLP log record — correlated to the active span, which that handler reads. ANullHandlerkeeps it a true no-op when observability isn't installed. The file-rotation logger no longer propagates its pretty ANSI blob to root (would otherwise leak into the bridge).opentelemetry-apionly — never on@smooai/observability(circular).Tests (verified, not just compiled)
python/tests/test_otel_correlation.py, api-onlyNonRecordingSpan:trace_id/span_idspanIdFull Python suite: 58 passed, ruff lint + format clean, basedpyright 0 errors.
🤖 Generated with Claude Code