feat(gax): Implement trace context extraction and injection interceptors#12310
feat(gax): Implement trace context extraction and injection interceptors#12310westarle wants to merge 1 commit intogoogleapis:mainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces OpenTelemetry trace propagation for both gRPC and HTTP/JSON callables. It adds new interceptors, GrpcTracePropagationInterceptor and HttpJsonTracePropagationInterceptor, which inject W3C trace context into request headers when OpenTelemetry is detected on the classpath. The PR also updates various callable implementations to wrap call executions within an ApiTracer.Scope and provides a concrete implementation of the inScope method in SpanTracer. Review feedback suggests adding debug-level logging when OpenTelemetry classes or methods are unavailable to improve observability during troubleshooting.
| // OpenTelemetry API is not available | ||
| isOpentelemetryAvailable = false; | ||
| } |
| } catch (NoSuchMethodError e) { | ||
| // Silently ignore if incompatible OpenTelemetry version | ||
| } |
| isOpentelemetryAvailable = true; | ||
| } catch (ClassNotFoundException e) { | ||
| // OpenTelemetry API is not available |
| } catch (NoSuchMethodError e) { | ||
| // Silently ignore if incompatible OpenTelemetry version | ||
| } |
7dfaa9f to
65a795f
Compare
| @Override | ||
| public void start(ClientCall.Listener<RespT> responseListener, Metadata headers) { | ||
| try { | ||
| TextMapPropagator propagator = W3CTraceContextPropagator.getInstance(); |
There was a problem hiding this comment.
I think we can extract this logic to a common place such as SpanTracer.injectTracerId(). Call it in GrpcClientCalls and HttpJsonClientCallImpl where we have access to both ApiTracer and request headers.
This avoids creating interceptors for both transports and reuse similar logics.
See main...westarle:google-cloud-java:trace-propagation-integration-test for the end-to-end integration test.