Skip to content

opentelemetry-instrumentation-logging JSON Formatter compatibility with spec #4643

@tailg8nj

Description

@tailg8nj

The spec for log formatting, specifically JSON has an example:

https://opentelemetry.io/docs/specs/otel/compatibility/logging_trace_context/#json-formats

Which seems to reinforce the overview of logging Trace ID and Span ID in legacy log formats:

To summarize, the following field names should be used in legacy formats:

“trace_id” for TraceId, lowercase and hex-encoded.
“span_id” for SpanId, lowercase and hex-encoded.
“trace_flags” for trace flags, formatted according to W3C traceflags format.

However, the log record that is created with the opentelemetry-instrumentation-logging has fields named otelTraceID and otelSpanID, etc.:

record.otelSpanID = format(ctx.span_id, "016x")
record.otelTraceID = format(ctx.trace_id, "032x")
record.otelTraceSampled = ctx.trace_flags.sampled

This doesn't rear it's head with standard text formatters as the default logging format pulls the appropriate log record attributes out explicitly:

DEFAULT_LOGGING_FORMAT = "%(asctime)s %(levelname)s [%(name)s] [%(filename)s:%(lineno)d] [trace_id=%(otelTraceID)s span_id=%(otelSpanID)s resource.service.name=%(otelServiceName)s trace_sampled=%(otelTraceSampled)s] - %(message)s"

JSON formatters traditionally just take what they are given and spit them out, see reference implementation: python-json-logger.

I believe the attributes placed onto the log record should change to snake case, and the default text format changed to leverage them appropriately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions