Skip to content

feat(gax): Implement trace context extraction and injection with integration test#12625

Open
westarle wants to merge 1 commit intogoogleapis:mainfrom
westarle:trace-propagation-integration-test-pr5
Open

feat(gax): Implement trace context extraction and injection with integration test#12625
westarle wants to merge 1 commit intogoogleapis:mainfrom
westarle:trace-propagation-integration-test-pr5

Conversation

@westarle
Copy link
Copy Markdown
Contributor

@westarle westarle commented Apr 2, 2026

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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@westarle westarle force-pushed the trace-propagation-integration-test-pr5 branch 3 times, most recently from b4d51dd to 230ffac Compare April 2, 2026 20:52
@westarle westarle marked this pull request as ready for review April 2, 2026 20:54
@westarle westarle requested a review from a team as a code owner April 2, 2026 20:54
@westarle westarle force-pushed the trace-propagation-integration-test-pr5 branch from abeec06 to 77e7d91 Compare April 2, 2026 21:30
@westarle westarle force-pushed the trace-propagation-integration-test-pr5 branch from 77e7d91 to 65f414f Compare April 3, 2026 03:35
@westarle westarle requested a review from a team as a code owner April 3, 2026 03:35
@westarle westarle force-pushed the trace-propagation-integration-test-pr5 branch from 65f414f to d80c40e Compare April 3, 2026 03:39
@westarle westarle force-pushed the trace-propagation-integration-test-pr5 branch from d80c40e to 36746c6 Compare April 3, 2026 04:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants