﻿# OTLP JSON trace IDs: generic protobuf byte encoding can break correlation

A practical investigation of oTLP JSON trace IDs: generic protobuf byte encoding can break correlation, with explicit observations, control cases and evidence limits.

Author: Retrivium team
Updated: 2026-11-06
Canonical URL: https://retrivium.ai/journal/field-observe-otlp-json-trace-id-hex/
Language: en

## The diagnostic situation

A diagnostic gateway converts binary telemetry into JSON with a generic protobuf mapping. Requests reach the receiver, but links between spans and logs disappear. The original identifier bytes may be intact while their JSON representation violates OTLP-specific rules. Retrying the same payload or changing trace sampling cannot repair a serialization mismatch at that boundary.

## Why the observation changes meaning

The OTLP JSON encoding specifies hexadecimal strings for traceId and spanId rather than the ordinary protobuf JSON base64 treatment of byte arrays. The rule applies across span, link and log record fields. A syntactically valid JSON string is therefore not sufficient. The receiver must interpret the same identifier bytes, not merely accept an arbitrary printable value.

## Define the instrumentation contract

Document the binary-to-JSON conversion library and any OTLP-specific adaptation. Treat identifier representation separately from user-visible request IDs and display shortening. Preserve the same safe synthetic identity through spans, links and correlated logs. Do not repair unknown input by guessing an encoding from appearance alone: arbitrary strings can resemble several encodings while referring to different byte sequences.

## A bounded verification procedure

Create a synthetic trace with a parent, a linked span and a log carrying the corresponding context. Capture the binary reference and the produced JSON. Compare decoded identifiers at each field location against the expected bytes. Add a deliberately generic base64 conversion as an invalid control. Verify correlation at the receiver rather than considering a successful HTTP exchange sufficient acceptance.

## Evidence required for acceptance

Acceptance evidence includes the source identifier inventory, conversion settings, serialized fixture and receiver associations. Check that case variation accepted by the hexadecimal rule does not create a new identity in the tested path. Keep malformed values visible as parse or validation failures. A fallback that clears invalid IDs can preserve data ingestion while silently destroying the relationships needed for incident diagnosis.

## Failure cases and limits

This check concerns OTLP JSON, not every JSON API carrying a trace-like field. Native binary transport has different serialization responsibilities, and external request identifiers may follow another contract entirely. Correct encoding also does not guarantee sampling, export delivery or trace retention. The protocol proves representation-preserving correlation for the fixture, without claiming that missing production relationships have only one possible cause.

## Primary references and related reading

OTLP JSON uses hexadecimal trace and span identifiers; generic byte-to-base64 conversion is not equivalent. [OpenTelemetry Protocol specification](https://opentelemetry.io/docs/specs/otlp/); [OpenTelemetry tracing API specification](https://opentelemetry.io/docs/specs/otel/trace/api/).

The proposed investigation of otlp json trace id hex is not an executed deployment benchmark. Related reading: [Request IDs and trace context across gateway, API and engine](/journal/provider-request-id-trace-context/); [From a slow histogram bucket to a trace through an exemplar](/journal/provider-metric-exemplar-trace-link/).
