Use spec-compatible logging trace context fields - #4914
Open
saisharan0103 wants to merge 1 commit into
Open
Conversation
…ing JSON Formatter compatibility with spec Closes open-telemetry#4643
|
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.
Fixes #4643.
The logging instrumentor was injecting trace context into
LogRecordinstances with OpenTelemetry-specific camelCase names:otelTraceID,otelSpanID, andotelTraceSampled. JSON formatters commonly serialize the raw record attributes, which meant the emitted fields did not match OpenTelemetry logging trace-context compatibility guidance.This updates injection to populate
record.trace_id,record.span_id, andrecord.trace_flagswith lowercase hex IDs and W3C traceflags formatting. When no sampled span is active,trace_flagsis set to00; when a span context is present, it uses that context's W3C traceflags string.DEFAULT_LOGGING_FORMATand logging instrumentation docs now reference the snake_case record fields, while the default visible text output remains semantically equivalent except for reportingtrace_flagsinstead oftrace_sampled.The logging tests were adjusted for the new attributes, with a regression assertion that a raw
LogRecorddictionary exposes the spec-compatible JSON field names.ruff check instrumentation/opentelemetry-instrumentation-logging/src/opentelemetry/instrumentation/logging/__init__.py instrumentation/opentelemetry-instrumentation-logging/src/opentelemetry/instrumentation/logging/constants.py instrumentation/opentelemetry-instrumentation-logging/tests/test_logging.pyreports no new findings on the changed files.Ran
pytest -xlocally with no new failures.