diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/BuiltInOpenTelemetryMetricsProvider.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/BuiltInOpenTelemetryMetricsProvider.java index 58f98db22c7..a980204950a 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/BuiltInOpenTelemetryMetricsProvider.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/BuiltInOpenTelemetryMetricsProvider.java @@ -19,7 +19,6 @@ import static com.google.cloud.opentelemetry.detection.GCPPlatformDetector.SupportedPlatform.GOOGLE_KUBERNETES_ENGINE; import static com.google.cloud.spanner.BuiltInMetricsConstant.CLIENT_NAME_KEY; import static com.google.cloud.spanner.BuiltInMetricsConstant.CLIENT_UID_KEY; -import static com.google.cloud.spanner.BuiltInMetricsConstant.DIRECT_PATH_ENABLED_KEY; import static com.google.cloud.spanner.BuiltInMetricsConstant.INSTANCE_CONFIG_ID_KEY; import static com.google.cloud.spanner.BuiltInMetricsConstant.LOCATION_ID_KEY; import static com.google.cloud.spanner.BuiltInMetricsConstant.PROJECT_ID_KEY; @@ -76,15 +75,12 @@ OpenTelemetry getOrCreateOpenTelemetry(String projectId, @Nullable Credentials c } } - Map createClientAttributes( - String projectId, boolean isDirectPathChannelCreated, String client_name) { + Map createClientAttributes(String projectId, String client_name) { Map clientAttributes = new HashMap<>(); clientAttributes.put(LOCATION_ID_KEY.getKey(), detectClientLocation()); clientAttributes.put(PROJECT_ID_KEY.getKey(), projectId); // TODO: Replace this with real value. clientAttributes.put(INSTANCE_CONFIG_ID_KEY.getKey(), "unknown"); - clientAttributes.put( - DIRECT_PATH_ENABLED_KEY.getKey(), String.valueOf(isDirectPathChannelCreated)); clientAttributes.put(CLIENT_NAME_KEY.getKey(), client_name); clientAttributes.put(CLIENT_UID_KEY.getKey(), getDefaultTaskValue()); return clientAttributes; diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java index 8968b7ecde4..1a9f2c49a42 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java @@ -1652,16 +1652,15 @@ public OpenTelemetry getOpenTelemetry() { @Override public ApiTracerFactory getApiTracerFactory() { - return createApiTracerFactory(false, false, false); + return createApiTracerFactory(false, false); } - public ApiTracerFactory getApiTracerFactory( - boolean isDirectPathChannelCreated, boolean isAdminClient, boolean isEmulatorEnabled) { - return createApiTracerFactory(isDirectPathChannelCreated, isAdminClient, isEmulatorEnabled); + public ApiTracerFactory getApiTracerFactory(boolean isAdminClient, boolean isEmulatorEnabled) { + return createApiTracerFactory(isAdminClient, isEmulatorEnabled); } private ApiTracerFactory createApiTracerFactory( - boolean isDirectPathChannelCreated, boolean isAdminClient, boolean isEmulatorEnabled) { + boolean isAdminClient, boolean isEmulatorEnabled) { List apiTracerFactories = new ArrayList<>(); // Prefer any direct ApiTracerFactory that might have been set on the builder. apiTracerFactories.add( @@ -1670,8 +1669,7 @@ private ApiTracerFactory createApiTracerFactory( // Add Metrics Tracer factory if built in metrics are enabled and if the client is data client // and if emulator is not enabled. if (isEnableBuiltInMetrics() && !isAdminClient && !isEmulatorEnabled) { - ApiTracerFactory metricsTracerFactory = - createMetricsApiTracerFactory(isDirectPathChannelCreated); + ApiTracerFactory metricsTracerFactory = createMetricsApiTracerFactory(); if (metricsTracerFactory != null) { apiTracerFactories.add(metricsTracerFactory); } @@ -1696,7 +1694,7 @@ private ApiTracerFactory getDefaultApiTracerFactory() { return BaseApiTracerFactory.getInstance(); } - private ApiTracerFactory createMetricsApiTracerFactory(boolean isDirectPathChannelCreated) { + private ApiTracerFactory createMetricsApiTracerFactory() { OpenTelemetry openTelemetry = this.builtInOpenTelemetryMetricsProvider.getOrCreateOpenTelemetry( getDefaultProjectId(), getCredentials()); @@ -1706,7 +1704,6 @@ private ApiTracerFactory createMetricsApiTracerFactory(boolean isDirectPathChann new OpenTelemetryMetricsRecorder(openTelemetry, BuiltInMetricsConstant.METER_NAME), builtInOpenTelemetryMetricsProvider.createClientAttributes( getDefaultProjectId(), - isDirectPathChannelCreated, "spanner-java/" + GaxProperties.getLibraryVersion(getClass()))) : null; } diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java index d4779ba956f..b389ea6a31a 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java @@ -370,18 +370,9 @@ public GapicSpannerRpc(final SpannerOptions options) { // If it is enabled in options uses the channel pool provided by the gRPC-GCP extension. maybeEnableGrpcGcpExtension(defaultChannelProviderBuilder, options); - InstantiatingGrpcChannelProvider defaultChannelProvider = null; - boolean isDirectPathChannelCreated = false; - - if (options.getChannelProvider() == null) { - defaultChannelProvider = defaultChannelProviderBuilder.build(); - isDirectPathChannelCreated = - defaultChannelProvider.canUseDirectPath() - && defaultChannelProvider.isDirectPathXdsEnabled(); - } - TransportChannelProvider channelProvider = - MoreObjects.firstNonNull(options.getChannelProvider(), defaultChannelProvider); + MoreObjects.firstNonNull( + options.getChannelProvider(), defaultChannelProviderBuilder.build()); CredentialsProvider credentialsProvider = GrpcTransportOptions.setUpCredentialsProvider(options); @@ -411,9 +402,7 @@ public GapicSpannerRpc(final SpannerOptions options) { .setStreamWatchdogProvider(watchdogProvider) .setTracerFactory( options.getApiTracerFactory( - isDirectPathChannelCreated, - /* isAdminClient = */ false, - isEmulatorEnabled(options, emulatorHost))) + /* isAdminClient = */ false, isEmulatorEnabled(options, emulatorHost))) .build()); this.readRetrySettings = options.getSpannerStubSettings().streamingReadSettings().getRetrySettings(); @@ -443,9 +432,7 @@ public GapicSpannerRpc(final SpannerOptions options) { .setStreamWatchdogProvider(watchdogProvider) .setTracerFactory( options.getApiTracerFactory( - isDirectPathChannelCreated, - /* isAdminClient = */ false, - isEmulatorEnabled(options, emulatorHost))) + /* isAdminClient = */ false, isEmulatorEnabled(options, emulatorHost))) .executeSqlSettings() .setRetrySettings(partitionedDmlRetrySettings); pdmlSettings.executeStreamingSqlSettings().setRetrySettings(partitionedDmlRetrySettings); @@ -474,9 +461,7 @@ public GapicSpannerRpc(final SpannerOptions options) { .setStreamWatchdogProvider(watchdogProvider) .setTracerFactory( options.getApiTracerFactory( - isDirectPathChannelCreated, - /* isAdminClient = */ true, - isEmulatorEnabled(options, emulatorHost))) + /* isAdminClient = */ true, isEmulatorEnabled(options, emulatorHost))) .build(); this.instanceAdminStub = GrpcInstanceAdminStub.create(instanceAdminStubSettings); @@ -489,9 +474,7 @@ public GapicSpannerRpc(final SpannerOptions options) { .setStreamWatchdogProvider(watchdogProvider) .setTracerFactory( options.getApiTracerFactory( - isDirectPathChannelCreated, - /* isAdminClient = */ true, - isEmulatorEnabled(options, emulatorHost))) + /* isAdminClient = */ true, isEmulatorEnabled(options, emulatorHost))) .build(); // Automatically retry RESOURCE_EXHAUSTED for GetOperation if auto-throttling of diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenTelemetryBuiltInMetricsTracerTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenTelemetryBuiltInMetricsTracerTest.java index 7bfdb99ca90..51d334c1726 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenTelemetryBuiltInMetricsTracerTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenTelemetryBuiltInMetricsTracerTest.java @@ -88,13 +88,12 @@ public static void setup() { String client_name = "spanner-java/"; openTelemetry = OpenTelemetrySdk.builder().setMeterProvider(meterProvider.build()).build(); - attributes = provider.createClientAttributes("test-project", true, client_name); + attributes = provider.createClientAttributes("test-project", client_name); expectedBaseAttributes = Attributes.builder() .put(BuiltInMetricsConstant.PROJECT_ID_KEY, "test-project") .put(BuiltInMetricsConstant.INSTANCE_CONFIG_ID_KEY, "unknown") - .put(BuiltInMetricsConstant.DIRECT_PATH_ENABLED_KEY, "true") .put( BuiltInMetricsConstant.LOCATION_ID_KEY, BuiltInOpenTelemetryMetricsProvider.detectClientLocation())