Trace ID Canonicalization#
Multiple subsystems in Jaeger โ the anonymizer and the MCP tool handlers โ compare or filter spans using user-supplied trace/span ID strings. Both subsystems emit IDs in a specific canonical lowercase hex form; if the caller supplies a non-canonical spelling (wrong length, mixed case, all-zero value), the comparison silently misses and no spans are returned.
Canonical Forms#
| ID type | Byte width | Canonical hex chars | Example |
|---|---|---|---|
| TraceID (128-bit) | 16 bytes | 32 | 4bf92f3577b34da6a3ce929d0e0e4736 |
| SpanID (8-byte) | 8 bytes | 16 | 00f067aa0ba902b7 |
jaeger-idl model v1 (model/v1/ids.go) defines the canonical rules for the legacy model types :
TraceID.String()emits 32 hex chars whenHigh != 0, or 16 chars for 64-bit-only IDs.SpanID.String()always emits exactly 16 hex chars.TraceIDFromString/SpanIDFromStringparse strings up to 32 / 16 chars respectively, accepting shorter inputs (64-bit trace IDs).
MCP handlers use the OpenTelemetry pcommon types instead, where both pcommon.TraceID.String() and pcommon.SpanID.String() produce fixed-width lowercase hex (32 and 16 chars respectively). The canonical form is what span.SpanID().String() and span.TraceID().String() emit when iterating a stored trace .
Where Canonicalization Happens#
MCP Handlers (get_span_details.go)#
The buildQuery method in get_span_details.go does two canonicalization steps:
parseTraceIDโ validates the input is exactly 32 hex characters, hex-decodes it into apcommon.TraceID, and (after PR #9325) rejects all-zero values viaIsEmpty().parseSpanIDโ validates exactly 16 hex characters, hex-decodes intopcommon.SpanID, and rejects all-zero span IDs (added in PR #8845).
After parsing, each span ID is stored in its canonical form via spanID.String() , building a lookup set spanIDSet. Spans from the trace iterator are matched by span.SpanID().String() . Because both sides go through .String(), case-insensitive input still matches โ but only if the input passes the 16-char / 32-char length check first.
The same parseTraceID helper is reused across all MCP handlers in the same package: get_critical_path.go, get_trace_topology.go, and get_trace_errors.go.
Anonymizer (uiconv/extractor.go)#
The extractor compares spans using a raw string equality check:
if string(span.TraceID) == e.traceID { ... }
span.TraceID is a uimodel.TraceID (string alias) serialized from the backend, which will always be in canonical hex. If e.traceID โ the user-supplied value โ uses a different case or a shorter form (e.g., dropping leading zeros), the equality check fails silently and zero spans are written to the output file. There is no normalization step before the comparison.
Silent Failure Modes#
| Subsystem | Non-canonical input | Failure mode |
|---|---|---|
MCP parseTraceID | Not 32 hex chars | Returns error immediately (fast-fail) |
MCP parseSpanID | Not 16 hex chars or non-hex | Returns error immediately (fast-fail) |
MCP parseSpanID | All-zero (0000000000000000) | Returns error (after PR #8845) |
MCP parseTraceID | All-zero (00000000000000000000000000000000) | Returns error (after PR #9325); previously wasted a backend query with "trace not found" |
| Anonymizer extractor | Wrong case or non-canonical length | Silent empty output โ no error, no spans extracted |
The all-zero ID issues in MCP were previously subtle: pcommon.SpanID.String() returns "" for the zero value , so an all-zero span ID would never match any real span, returning an empty result with no diagnostic.
Key Files#
| File | Role |
|---|---|
cmd/jaeger/internal/extension/jaegerquery/internal/mcptools/internal/handlers/get_span_details.go | parseTraceID, parseSpanID, canonicalization logic |
cmd/anonymizer/app/uiconv/extractor.go | Raw string comparison โ no normalization |
cmd/anonymizer/app/query/query.go | Uses model.TraceIDFromString to parse before querying gRPC |
jaeger-idl/model/v1/ids.go | Defines TraceIDFromString, SpanIDFromString, canonical .String() rules |
What to Do When Adding New ID Lookups#
- Always canonicalize before comparing. Call
parseTraceID/parseSpanID(MCP) ormodel.TraceIDFromString/model.SpanIDFromString(legacy model) on user input, then use.String()on both sides of any equality check. - Reject all-zero IDs early. Check
.IsEmpty()(pcommon types) immediately after parsing. - Don't store raw user input for later comparison. Store the canonical form returned by
.String()after a successful parse. - For the anonymizer extractor, normalize
e.traceIDat construction time (e.g., viamodel.TraceIDFromStringthen.String()) to make it immune to case and length variation.