Skip to content

Commit 6a88800

Browse files
committed
feat: Register trace propagation interceptors by default
1 parent 374f2a6 commit 6a88800

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

sdk-platform-java/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,7 @@ public ManagedChannelBuilder<?> createDecoratedChannelBuilder() throws IOExcepti
790790
.intercept(new GrpcChannelUUIDInterceptor())
791791
.intercept(new GrpcLoggingInterceptor())
792792
.intercept(headerInterceptor)
793+
.intercept(new GrpcTracePropagationInterceptor())
793794
.intercept(metadataHandlerInterceptor)
794795
.userAgent(headerInterceptor.getUserAgentHeader())
795796
.executor(executor);

sdk-platform-java/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/InstantiatingHttpJsonChannelProvider.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ private HttpJsonTransportChannel createChannel() throws IOException, GeneralSecu
217217

218218
channel = new ManagedHttpJsonInterceptorChannel(channel, new HttpJsonLoggingInterceptor());
219219
channel = new ManagedHttpJsonInterceptorChannel(channel, headerInterceptor);
220+
channel = new ManagedHttpJsonInterceptorChannel(channel, new HttpJsonTracePropagationInterceptor());
220221
if (interceptorProvider != null && interceptorProvider.getInterceptors() != null) {
221222
for (HttpJsonClientInterceptor interceptor : interceptorProvider.getInterceptors()) {
222223
channel = new ManagedHttpJsonInterceptorChannel(channel, interceptor);

sdk-platform-java/gax-java/gax-httpjson/src/test/java/com/google/api/gax/httpjson/InstantiatingHttpJsonChannelProviderTest.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,7 @@ void managedChannelUsesDefaultChannelExecutor() throws IOException {
131131
HttpJsonTransportChannel httpJsonTransportChannel =
132132
instantiatingHttpJsonChannelProvider.getTransportChannel();
133133

134-
// By default, the channel will be wrapped with ManagedHttpJsonInterceptorChannel
135-
ManagedHttpJsonInterceptorChannel interceptorChannel =
136-
(ManagedHttpJsonInterceptorChannel) httpJsonTransportChannel.getManagedChannel();
137-
// call getChannel() twice because interceptors are chained in layers by recursive construction
138-
// inside com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider.createChannel
139-
ManagedHttpJsonInterceptorChannel managedHttpJsonChannel =
140-
(ManagedHttpJsonInterceptorChannel) interceptorChannel.getChannel();
141-
ManagedHttpJsonChannel channel = managedHttpJsonChannel.getChannel();
134+
ManagedHttpJsonChannel channel = unwrapChannel(httpJsonTransportChannel.getManagedChannel());
142135
assertThat(channel.getExecutor()).isNotNull();
143136

144137
// Clean up the resources (executor, deadlineScheduler, httpTransport)
@@ -164,14 +157,7 @@ void managedChannelUsesCustomExecutor() throws IOException {
164157
HttpJsonTransportChannel httpJsonTransportChannel =
165158
instantiatingHttpJsonChannelProvider.getTransportChannel();
166159

167-
// By default, the channel will be wrapped with ManagedHttpJsonInterceptorChannel
168-
ManagedHttpJsonInterceptorChannel interceptorChannel =
169-
(ManagedHttpJsonInterceptorChannel) httpJsonTransportChannel.getManagedChannel();
170-
// call getChannel() twice because interceptors are chained in layers by recursive construction
171-
// inside com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider.createChannel
172-
ManagedHttpJsonInterceptorChannel managedHttpJsonChannel =
173-
(ManagedHttpJsonInterceptorChannel) interceptorChannel.getChannel();
174-
ManagedHttpJsonChannel channel = managedHttpJsonChannel.getChannel();
160+
ManagedHttpJsonChannel channel = unwrapChannel(httpJsonTransportChannel.getManagedChannel());
175161

176162
assertThat(channel.getExecutor()).isNotNull();
177163
assertThat(channel.getExecutor()).isEqualTo(executor);
@@ -180,6 +166,13 @@ void managedChannelUsesCustomExecutor() throws IOException {
180166
instantiatingHttpJsonChannelProvider.getTransportChannel().shutdownNow();
181167
}
182168

169+
private ManagedHttpJsonChannel unwrapChannel(HttpJsonChannel channel) {
170+
while (channel instanceof ManagedHttpJsonInterceptorChannel) {
171+
channel = ((ManagedHttpJsonInterceptorChannel) channel).getChannel();
172+
}
173+
return (ManagedHttpJsonChannel) channel;
174+
}
175+
183176
@Override
184177
protected Object getMtlsObjectFromTransportChannel(
185178
MtlsProvider provider, CertificateBasedAccess certificateBasedAccess)

0 commit comments

Comments
 (0)