Skip to content

fix: encode OTLP trace identifiers as hex - #54

Open
incidere wants to merge 1 commit into
open-telemetry:mainfrom
incidere:fix/otlp-json-identifiers
Open

fix: encode OTLP trace identifiers as hex#54
incidere wants to merge 1 commit into
open-telemetry:mainfrom
incidere:fix/otlp-json-identifiers

Conversation

@incidere

Copy link
Copy Markdown

Fixes #50.

OTLP's JSON mapping represents trace and span identifiers as hexadecimal strings instead of protobuf's default base64.

This change:

  • converts traceId, spanId, and parentSpanId after protobuf JSON encoding;
  • preserves standard base64 encoding for unrelated bytes fields;
  • adds a regression test covering Span, Link, a parent span, and an unrelated bytes attribute.

Tests:

  • zig build sdk-test -Dtarget=x86_64-linux-musl — 290 tests passed
  • zig fmt --check opentelemetry-sdk/src/otlp.zig

@incidere
incidere requested a review from a team as a code owner August 10, 2026 19:54
@linux-foundation-easycla

linux-foundation-easycla Bot commented Aug 10, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: incidere / name: Incidere (a62f851)

@agagniere

Copy link
Copy Markdown
Member

I would prefer to wait for Arwalk/zig-protobuf#176 to do it cleanly

@inge4pres inge4pres left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sending this PR @incidere 🙏🏼

I agree with @agagniere that the proposed approach, while functionally working, can be better addressed at a lower level in the protobuf JSON decoder (real fix is in Jacob's PR Arwalk/zig-protobuf#176).

I liked that you added tests, would love to see them added also for LogRecord (and also Exemplars once implemented), but only after we have bumped our zig-protobuf depedency.

return next;
}

fn encodeOtlpIdsAsHex(json: []const u8, allocator: std.mem.Allocator) ![]u8 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zig 0.16.0 has a std.Io.Writer.printHex function that converts to Hex digits for us
https://ziglang.org/documentation/0.16.0/std/#std.Io.Writer.printHex

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OTLP json object's trace id should be treated as a hex

3 participants