open-telemetry / open-telemetry/opentelemetry-python-contrib
opentelemetry-instrumentation-logging JSON Formatter compatibility with spec
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.1k
- Forks
- 1.1k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 16
Description
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.:
This doesn't rear it's head with standard text formatters as the default logging format pulls the appropriate log record attributes out explicitly: https://github.com/open-telemetry/opentelemetry-python-contrib/blob/26c975f2aea142ef198c1a4b377d7cb71bbbbd57/instrumentation/opentelemetry-instrumentation-logging/src/opentelemetry/instrumentation/logging/constants.py#L4
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in instrumentation/opentelemetry-instrumentation-logging/src/opentelemetry/instrumentation/logging/init.py around the log-record attributes and in constants.py around the default text format. Compare those names and formatting rules with the linked OpenTelemetry JSON specification and python-json-logger behavior. Done means the instrumentation is compatible with the specified JSON field names while the default text format still emits the expected values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- observability
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100