Skip to content

feat(gax): Implement trace context extraction and injection interceptors#12310

Open
westarle wants to merge 1 commit intogoogleapis:mainfrom
westarle:trace-propagation-interceptors
Open

feat(gax): Implement trace context extraction and injection interceptors#12310
westarle wants to merge 1 commit intogoogleapis:mainfrom
westarle:trace-propagation-interceptors

Conversation

@westarle
Copy link
Copy Markdown
Contributor

@westarle westarle commented Mar 30, 2026

@westarle westarle requested a review from a team as a code owner March 30, 2026 15:56
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 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.

Comment on lines +63 to +65
// OpenTelemetry API is not available
isOpentelemetryAvailable = false;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Catching ClassNotFoundException and silently ignoring it can make debugging difficult if OpenTelemetry is expected to be available but isn't. Consider logging this exception at a debug level to provide more insight into why OpenTelemetry might not be found.

Comment on lines +103 to +105
} catch (NoSuchMethodError e) {
// Silently ignore if incompatible OpenTelemetry version
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Similar to the ClassNotFoundException, silently ignoring NoSuchMethodError can obscure issues related to incompatible OpenTelemetry versions. Logging this at a debug level would be helpful for diagnosing potential runtime problems.

Comment on lines +58 to +60
isOpentelemetryAvailable = true;
} catch (ClassNotFoundException e) {
// OpenTelemetry API is not available
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Catching ClassNotFoundException and silently ignoring it can make debugging difficult if OpenTelemetry is expected to be available but isn't. Consider logging this exception at a debug level to provide more insight into why OpenTelemetry might not be found.

Comment on lines +107 to +109
} catch (NoSuchMethodError e) {
// Silently ignore if incompatible OpenTelemetry version
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Similar to the ClassNotFoundException, silently ignoring NoSuchMethodError can obscure issues related to incompatible OpenTelemetry versions. Logging this at a debug level would be helpful for diagnosing potential runtime problems.

@westarle westarle force-pushed the trace-propagation-interceptors branch from 7dfaa9f to 65a795f Compare March 30, 2026 18:23
@Override
public void start(ClientCall.Listener<RespT> responseListener, Metadata headers) {
try {
TextMapPropagator propagator = W3CTraceContextPropagator.getInstance();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

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