Skip to content

Use spec-compatible logging trace context fields - #4914

Open
saisharan0103 wants to merge 1 commit into
open-telemetry:mainfrom
saisharan0103:mergepath/issue-4643-opentelemetry-instrumentation-logging-js
Open

Use spec-compatible logging trace context fields#4914
saisharan0103 wants to merge 1 commit into
open-telemetry:mainfrom
saisharan0103:mergepath/issue-4643-opentelemetry-instrumentation-logging-js

Conversation

@saisharan0103

Copy link
Copy Markdown

Fixes #4643.

The logging instrumentor was injecting trace context into LogRecord instances with OpenTelemetry-specific camelCase names: otelTraceID, otelSpanID, and otelTraceSampled. 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, and record.trace_flags with lowercase hex IDs and W3C traceflags formatting. When no sampled span is active, trace_flags is set to 00; when a span context is present, it uses that context's W3C traceflags string.

DEFAULT_LOGGING_FORMAT and logging instrumentation docs now reference the snake_case record fields, while the default visible text output remains semantically equivalent except for reporting trace_flags instead of trace_sampled.

The logging tests were adjusted for the new attributes, with a regression assertion that a raw LogRecord dictionary 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.py reports no new findings on the changed files.
Ran pytest -x locally with no new failures.

@linux-foundation-easycla

Copy link
Copy Markdown

CLA Missing ID

  • ❌ The email address for the commit (d4bcb55) is not linked to the GitHub account, preventing the EasyCLA check. Consult this Help Article and GitHub Help to resolve. (To view the commit's email address, add .patch at the end of this PR page's URL.) For further assistance with EasyCLA, please visit our EasyCLA portal and chat with our support bot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

opentelemetry-instrumentation-logging JSON Formatter compatibility with spec

1 participant