feat(gax): Implement trace context extraction and injection with integration test#12625
Open
westarle wants to merge 1 commit intogoogleapis:mainfrom
Open
feat(gax): Implement trace context extraction and injection with integration test#12625westarle wants to merge 1 commit intogoogleapis:mainfrom
westarle wants to merge 1 commit intogoogleapis:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request implements OpenTelemetry trace context propagation for gRPC and HTTP/JSON transports by adding an injectTraceContext method to the ApiTracer interface and implementing it in SpanTracer. The GrpcClientCalls and HttpJsonClientCalls classes were updated to inject trace headers into outgoing requests. A review comment identifies a potential issue in the gRPC implementation where direct mutation of the metadata object could lead to side effects during retries, suggesting the creation of a new metadata instance instead.
sdk-platform-java/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcClientCalls.java
Outdated
Show resolved
Hide resolved
b4d51dd to
230ffac
Compare
abeec06 to
77e7d91
Compare
blakeli0
reviewed
Apr 3, 2026
sdk-platform-java/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcClientCalls.java
Outdated
Show resolved
Hide resolved
77e7d91 to
65f414f
Compare
65f414f to
d80c40e
Compare
d80c40e to
36746c6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements native trace context propagation for Google Cloud Java clients, enabling App Centric Observability by linking client-side telemetry with server-side resources.
It introduces a new injectTraceContext method to the ApiTracer interface and implements it in SpanTracer using the OpenTelemetry W3CTraceContextPropagator. The extracted trace context is then
dynamically injected into the outgoing request metadata natively within GrpcClientCalls and HttpJsonClientCalls for unary requests. CompositeTracer has also been updated to delegate this new
method to its child tracers.
By pushing this logic down into the ApiTracer and core call factories, we ensure that trace headers (e.g., traceparent) are automatically propagated whenever tracing is enabled, without requiring users to configure separate transport-specific interceptors or rely on external OpenTelemetry instrumentation agents.
Finally, this PR includes an end-to-end integration test (ITOtelTracePropagation) in the java-showcase module, which verifies the successful round-trip of W3C trace headers against the gapic-showcase server.