@@ -280,6 +280,8 @@ public class GapicSpannerRpc implements SpannerRpc {
280
280
281
281
private Supplier <Boolean > directPathEnabledSupplier = () -> false ;
282
282
283
+ private final GrpcCallContext baseGrpcCallContext ;
284
+
283
285
public static GapicSpannerRpc create (SpannerOptions options ) {
284
286
return new GapicSpannerRpc (options );
285
287
}
@@ -333,6 +335,7 @@ public GapicSpannerRpc(final SpannerOptions options) {
333
335
this .endToEndTracingEnabled = options .isEndToEndTracingEnabled ();
334
336
this .numChannels = options .getNumChannels ();
335
337
this .isGrpcGcpExtensionEnabled = options .isGrpcGcpExtensionEnabled ();
338
+ this .baseGrpcCallContext = createBaseCallContext ();
336
339
337
340
if (initializeStubs ) {
338
341
// First check if SpannerOptions provides a TransportChannelProvider. Create one
@@ -1978,6 +1981,20 @@ private static <T> T get(final Future<T> future) throws SpannerException {
1978
1981
}
1979
1982
}
1980
1983
1984
+ private GrpcCallContext createBaseCallContext () {
1985
+ GrpcCallContext context = GrpcCallContext .createDefault ();
1986
+ if (compressorName != null ) {
1987
+ // This sets the compressor for Client -> Server.
1988
+ context = context .withCallOptions (context .getCallOptions ().withCompression (compressorName ));
1989
+ }
1990
+ if (endToEndTracingEnabled ) {
1991
+ context = context .withExtraHeaders (metadataProvider .newEndToEndTracingHeader ());
1992
+ }
1993
+ return context
1994
+ .withStreamWaitTimeoutDuration (waitTimeout )
1995
+ .withStreamIdleTimeoutDuration (idleTimeout );
1996
+ }
1997
+
1981
1998
// Before removing this method, please verify with a code owner that it is not used
1982
1999
// in any internal testing infrastructure.
1983
2000
@ VisibleForTesting
@@ -2002,7 +2019,7 @@ <ReqT, RespT> GrpcCallContext newCallContext(
2002
2019
ReqT request ,
2003
2020
MethodDescriptor <ReqT , RespT > method ,
2004
2021
boolean routeToLeader ) {
2005
- GrpcCallContext context = GrpcCallContext . createDefault () ;
2022
+ GrpcCallContext context = this . baseGrpcCallContext ;
2006
2023
if (options != null ) {
2007
2024
if (this .isGrpcGcpExtensionEnabled ) {
2008
2025
// Set channel affinity in gRPC-GCP.
@@ -2019,28 +2036,17 @@ <ReqT, RespT> GrpcCallContext newCallContext(
2019
2036
context = context .withChannelAffinity (Option .CHANNEL_HINT .getLong (options ).intValue ());
2020
2037
}
2021
2038
}
2022
- if (compressorName != null ) {
2023
- // This sets the compressor for Client -> Server.
2024
- context = context .withCallOptions (context .getCallOptions ().withCompression (compressorName ));
2025
- }
2026
2039
context = context .withExtraHeaders (metadataProvider .newExtraHeaders (resource , projectName ));
2027
2040
if (routeToLeader && leaderAwareRoutingEnabled ) {
2028
2041
context = context .withExtraHeaders (metadataProvider .newRouteToLeaderHeader ());
2029
2042
}
2030
- if (endToEndTracingEnabled ) {
2031
- context = context .withExtraHeaders (metadataProvider .newEndToEndTracingHeader ());
2032
- }
2033
2043
if (callCredentialsProvider != null ) {
2034
2044
CallCredentials callCredentials = callCredentialsProvider .getCallCredentials ();
2035
2045
if (callCredentials != null ) {
2036
2046
context =
2037
2047
context .withCallOptions (context .getCallOptions ().withCallCredentials (callCredentials ));
2038
2048
}
2039
2049
}
2040
- context =
2041
- context
2042
- .withStreamWaitTimeoutDuration (waitTimeout )
2043
- .withStreamIdleTimeoutDuration (idleTimeout );
2044
2050
CallContextConfigurator configurator = SpannerOptions .CALL_CONTEXT_CONFIGURATOR_KEY .get ();
2045
2051
ApiCallContext apiCallContextFromContext = null ;
2046
2052
if (configurator != null ) {
0 commit comments