gRPC frontend reads the `traceparent` metadata past its end, so OpenTelemetry drops some valid trace contexts
Description
With OpenTelemetry tracing, the gRPC frontend sometimes ignores a valid traceparent. The request then gets no trace, or a new trace that is not a child of the caller's trace.
The cause is GrpcServerCarrier::Get in src/grpc/infer_handler.h:
it->second is a grpc::string_ref, and its data does not end with a null byte. return it->second.data(); builds the nostd::string_view from a const char*, so the length comes from strlen. strlen reads past the end of the metadata value. For a version 00 header, HttpTraceContext accepts only a value of exactly 55 characters. When the byte after the value is not a null byte, the length is more than 55, and the parser returns an invalid context.
The result depends on the memory that follows the value, so the drop is random. We see it on 3% to 10% of calls, at any load.
Proposed fix, one line:
return {it->second.data(), it->second.size()};Triton Information
- 26.08. The same code is on
main. - Container: a Chainguard build of Triton 26.08 with the PyTorch backend. The defect is in the frontend and does not depend on the backend.
- Tracing flags:
--trace-config mode=opentelemetry --trace-config rate=0. Withrate=0, Triton traces a request only when the request brings a valid context, so each rejected context makes a request with no trace.
To Reproduce
- Start Triton with the tracing flags above and an OTLP collector.
- Send 200 gRPC
ModelInfercalls, one at a time. Give each call a new validtraceparentmetadata value, for example00-<32 hex>-<16 hex>-01. Any model shows the defect. - Count the traces that the collector receives, by trace id.
In four runs of 200 calls, Triton did not trace 5, 5, 8 and 21 calls. The lost calls were not in runs. Each call that Triton traced had all of its spans. The collector refused or dropped no spans.
Expected behavior
Triton traces every call that brings a valid traceparent, and its spans are children of the caller's span.
Source: triton-inference-server/server