|
29 | 29 | import com.google.api.gax.grpc.GrpcCallContext; |
30 | 30 | import com.google.api.gax.grpc.GrpcCallSettings; |
31 | 31 | import com.google.api.gax.grpc.GrpcStubCallableFactory; |
| 32 | +import com.google.api.gax.grpc.GrpcTransportChannel; |
32 | 33 | import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; |
33 | 34 | import com.google.api.gax.longrunning.OperationFuture; |
34 | 35 | import com.google.api.gax.retrying.ResultRetryAlgorithm; |
|
63 | 64 | import com.google.cloud.grpc.GrpcTransportOptions; |
64 | 65 | import com.google.cloud.spanner.AdminRequestsPerMinuteExceededException; |
65 | 66 | import com.google.cloud.spanner.BackupId; |
| 67 | +import com.google.cloud.spanner.BuiltInMetricsConstant; |
66 | 68 | import com.google.cloud.spanner.ErrorCode; |
67 | 69 | import com.google.cloud.spanner.Restore; |
68 | 70 | import com.google.cloud.spanner.SpannerException; |
@@ -396,18 +398,22 @@ public GapicSpannerRpc(final SpannerOptions options) { |
396 | 398 | final String emulatorHost = System.getenv("SPANNER_EMULATOR_HOST"); |
397 | 399 |
|
398 | 400 | try { |
399 | | - this.spannerStub = |
400 | | - GrpcSpannerStub.create( |
401 | | - options |
402 | | - .getSpannerStubSettings() |
403 | | - .toBuilder() |
404 | | - .setTransportChannelProvider(channelProvider) |
405 | | - .setCredentialsProvider(credentialsProvider) |
406 | | - .setStreamWatchdogProvider(watchdogProvider) |
407 | | - .setTracerFactory( |
408 | | - options.getApiTracerFactory( |
409 | | - /* isAdminClient = */ false, isEmulatorEnabled(options, emulatorHost))) |
410 | | - .build()); |
| 401 | + SpannerStubSettings spannerStubSettings = |
| 402 | + options |
| 403 | + .getSpannerStubSettings() |
| 404 | + .toBuilder() |
| 405 | + .setTransportChannelProvider(channelProvider) |
| 406 | + .setCredentialsProvider(credentialsProvider) |
| 407 | + .setStreamWatchdogProvider(watchdogProvider) |
| 408 | + .setTracerFactory( |
| 409 | + options.getApiTracerFactory( |
| 410 | + /* isAdminClient = */ false, isEmulatorEnabled(options, emulatorHost))) |
| 411 | + .build(); |
| 412 | + ClientContext clientContext = ClientContext.create(spannerStubSettings); |
| 413 | + this.spannerStub = GrpcSpannerStub.create((clientContext)); |
| 414 | + BuiltInMetricsConstant.DIRECT_PATH_ENABLED = |
| 415 | + ((GrpcTransportChannel) clientContext.getTransportChannel()).isDirectPath() |
| 416 | + && isAttemptDirectPathXds; |
411 | 417 | this.readRetrySettings = |
412 | 418 | options.getSpannerStubSettings().streamingReadSettings().getRetrySettings(); |
413 | 419 | this.readRetryableCodes = |
|
0 commit comments