feat: add trace_flags to JSON log records

SH
4d ago
+55-5

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

New Feature Submission:

  • Does your submission pass the tests?
  • Have you linted your code locally prior to submission?

Description

Closes #7729.

otel.trace_fields() now also returns trace_flags, the span's W3C trace flags as two hex digits, so JSON log records carry it next to trace_id and span_id.

One difference from the issue: the values aren't always "01"/"00". opentelemetry-sdk 1.45 also sets the W3C Level 2 random-trace-id flag (0x02) when it starts a trace itself, so a span that starts a new trace on the backend gives "03" (sampled) or "02" (not). Under a client traceparent, the flags come from the client, so a client sending 01/00 gives "01"/"00". I kept the full byte, since that's what the OpenTelemetry non-OTLP log format defines for trace_flags, and the observability docs now say to read the lowest bit.

Tests cover a span, an ALWAYS_OFF sampler, and a client traceparent with 01 and 00, which must come back unchanged. The JSON log tests check the field inside a span and its absence outside one.