Skip to content

fix: Preserve gRPC trace metadata length - #8987

Open
amarrtech wants to merge 2 commits into
triton-inference-server:mainfrom
amarrtech:fix/grpc-trace-context-length
Open

amarrtech wants to merge 2 commits into
triton-inference-server:mainfrom
amarrtech:fix/grpc-trace-context-length

Conversation

@amarrtech

@amarrtech amarrtech commented Sep 29, 2026 •

Copy link
Copy Markdown

What does the PR do?

Preserves the exact byte length of gRPC metadata when GrpcServerCarrier returns a value to the OpenTelemetry propagator.

grpc::string_ref values are not null-terminated. Constructing the returned nostd::string_view from data() alone invokes the pointer constructor, which scans past the metadata boundary. For a 55-byte W3C traceparent, trailing bytes can make the value appear longer and cause HttpTraceContext to reject an otherwise valid parent context.

This change constructs the view from both data() and size(), so extraction sees exactly the bytes supplied by gRPC. It also adds a focused unit test for the exact-length boundary.

Checklist

  • I have read the Contribution guidelines and signed the Contributor License Agreement
  • PR title reflects the change and is of format <commit_type>: <Title>
  • Changes are described in the pull request.
  • Related issues are referenced.
  • Populated github labels field
  • Added test plan and verified the available tests pass.
  • Verified that the PR passes existing CI.
  • I ran pre-commit locally (pre-commit install, pre-commit run --all); see Caveats.
  • Verified copyright is correct on all changed files.
  • Added succinct git squash message before merging ref.
  • All template sections are filled out.
  • Optional: Additional screenshots for behavior/output changes with before/after. (Not applicable.)

Commit Type:

  • build
  • ci
  • docs
  • feat
  • fix
  • perf
  • refactor
  • revert
  • style
  • test

Related PRs:

None.

Where should the reviewer start?

  • src/grpc/infer_handler.h, in GrpcServerCarrier::Get and GrpcMetadataValueView.
  • src/test/grpc_carrier_test.cc, for the non-null trailing-byte regression.

Test plan:

  • Added GrpcServerCarrierTest.PreservesMetadataValueLength, built when gRPC and tracing are enabled. It backs a 55-byte grpc::string_ref with a non-null sentinel byte followed by a terminator and asserts the OpenTelemetry view remains exactly 55 bytes.
  • uvx --from pre-commit pre-commit run --files src/grpc/infer_handler.h src/test/CMakeLists.txt src/test/grpc_carrier_test.cc — passed every applicable hook, including clang-format, codespell, secret scan, whitespace, and copyright.
  • git diff --check — passed.
  • Existing mapped integration coverage: OpenTelemetryTest.test_grpc_trace_simple_model_context_propagation in qa/L0_trace/opentelemetry_unittest.py verifies that gRPC trace metadata is extracted as the expected parent context.

Caveats:

This host does not have CMake, a packaged Linux Triton server, or the GPU test stack needed to build the new C++ target and run qa/L0_trace; CI/reviewer infrastructure must run those. A repository-wide pre-commit run was attempted, but untouched main currently reports existing repo-wide flake8 violations and the copyright hook proposes broad unrelated header updates. All changed files pass the complete configured hook set in isolation.

The NVIDIA CLA still needs to be confirmed by the contributor. The fix label exists, but GitHub does not grant external contributors permission to apply it; no label was added.

Squash message: fix: preserve gRPC trace metadata length

Background

Operators reported valid gRPC traceparent metadata being dropped nondeterministically because bytes beyond the grpc::string_ref value affected its apparent length. This makes inference spans disappear or detach from the caller trace.

Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)

Assisted-by: OpenAI Codex
Signed-off-by: Amrinder Randhawa <272048731+amarrtech@users.noreply.github.com>
@amarrtech amarrtech mentioned this pull request Sep 29, 2026
10 of 13 tasks
@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Fixes trace metadata handling in gRPC carrier.

The PR appears safe to merge based on the reviewed changes.

Summary

The PR preserves the gRPC metadata value’s exact byte length during trace-context extraction and adds a focused boundary test.

  • The carrier now constructs its view from both the metadata pointer and size.
  • A new test target checks a 55-byte traceparent followed by a non-null byte.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[gRPC client metadata] --> B[GrpcServerCarrier::Get]
  B --> C[View bounded by data and size]
  C --> D[OpenTelemetry context extraction]
Loading

Reviews (2) · Last reviewed commit: "test: cover gRPC metadata value boundary"

Comment thread src/grpc/infer_handler.h Outdated
Assisted-by: OpenAI Codex
Signed-off-by: Amrinder Randhawa <272048731+amarrtech@users.noreply.github.com>

This branch has not been deployed

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant