From 59459ae5fe16ce0aa39490a5c160c29172805dce Mon Sep 17 00:00:00 2001 From: surbhigarg92 Date: Fri, 3 Jan 2025 12:40:22 +0530 Subject: [PATCH] Refactor Header Interceptor and modified the server timing header logic --- .../BuiltInOpenTelemetryMetricsProvider.java | 109 +++++++++------- .../BuiltInOpenTelemetryMetricsRecorder.java | 5 +- .../google/cloud/spanner/SpannerOptions.java | 28 +++-- .../cloud/spanner/spi/v1/GapicSpannerRpc.java | 4 +- .../spanner/spi/v1/HeaderInterceptor.java | 116 ++++++++++-------- .../spi/v1/SpannerInterceptorProvider.java | 17 ++- ...OpenTelemetryBuiltInMetricsTracerTest.java | 4 +- 7 files changed, 164 insertions(+), 119 deletions(-) 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 db343665e1c..e7879586917 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 @@ -28,6 +28,7 @@ import com.google.cloud.opentelemetry.detection.AttributeKeys; import com.google.cloud.opentelemetry.detection.DetectedPlatform; import com.google.cloud.opentelemetry.detection.GCPPlatformDetector; +import com.google.common.annotations.VisibleForTesting; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import com.google.common.hash.HashFunction; @@ -44,72 +45,96 @@ import java.util.HashMap; import java.util.Map; import java.util.UUID; -import java.util.concurrent.ExecutionException; import java.util.logging.Level; import java.util.logging.Logger; import javax.annotation.Nullable; final class BuiltInOpenTelemetryMetricsProvider { - static BuiltInOpenTelemetryMetricsProvider INSTANCE = new BuiltInOpenTelemetryMetricsProvider(); + public static BuiltInOpenTelemetryMetricsProvider INSTANCE = + new BuiltInOpenTelemetryMetricsProvider(); private static final Logger logger = Logger.getLogger(BuiltInOpenTelemetryMetricsProvider.class.getName()); + private final Cache> clientAttributesCache = + CacheBuilder.newBuilder().maximumSize(1000).build(); + private static String taskId; private OpenTelemetry openTelemetry; - private final Cache> clientAttributesCache = - CacheBuilder.newBuilder().maximumSize(1000).build(); + private Map clientAttributes; + + private boolean isInitialized; - private BuiltInOpenTelemetryMetricsProvider() {} + private BuiltInOpenTelemetryMetricsRecorder builtInOpenTelemetryMetricsRecorder; + + private BuiltInOpenTelemetryMetricsProvider() {}; + + void initialize( + String projectId, + String client_name, + @Nullable Credentials credentials, + @Nullable String monitoringHost) { - OpenTelemetry getOrCreateOpenTelemetry( - String projectId, @Nullable Credentials credentials, @Nullable String monitoringHost) { try { - if (this.openTelemetry == null) { - SdkMeterProviderBuilder sdkMeterProviderBuilder = SdkMeterProvider.builder(); - BuiltInOpenTelemetryMetricsView.registerBuiltinMetrics( - SpannerCloudMonitoringExporter.create(projectId, credentials, monitoringHost), - sdkMeterProviderBuilder); - SdkMeterProvider sdkMeterProvider = sdkMeterProviderBuilder.build(); - this.openTelemetry = OpenTelemetrySdk.builder().setMeterProvider(sdkMeterProvider).build(); - Runtime.getRuntime().addShutdownHook(new Thread(sdkMeterProvider::close)); + if (!isInitialized) { + this.openTelemetry = createOpenTelemetry(projectId, credentials, monitoringHost); + this.clientAttributes = createClientAttributes(projectId, client_name); + this.builtInOpenTelemetryMetricsRecorder = + new BuiltInOpenTelemetryMetricsRecorder(openTelemetry, clientAttributes); + isInitialized = true; } - return this.openTelemetry; - } catch (IOException ex) { + } catch (Exception ex) { logger.log( Level.WARNING, - "Unable to get OpenTelemetry object for client side metrics, will skip exporting client side metrics", + "Unable to initialize OpenTelemetry object or attributes for client side metrics, will skip exporting client side metrics", ex); - return null; } } - Map createOrGetClientAttributes(String projectId, String client_name) { - try { - String key = projectId + client_name; - return clientAttributesCache.get( - key, - () -> { - Map clientAttributes = new HashMap<>(); - clientAttributes.put(LOCATION_ID_KEY.getKey(), detectClientLocation()); - clientAttributes.put(PROJECT_ID_KEY.getKey(), projectId); - clientAttributes.put(INSTANCE_CONFIG_ID_KEY.getKey(), "unknown"); - clientAttributes.put(CLIENT_NAME_KEY.getKey(), client_name); - String clientUid = getDefaultTaskValue(); - clientAttributes.put(CLIENT_UID_KEY.getKey(), clientUid); - clientAttributes.put(CLIENT_HASH_KEY.getKey(), generateClientHash(clientUid)); - return clientAttributes; - }); - } catch (ExecutionException executionException) { - logger.log( - Level.WARNING, - "Unable to get Client Attributes for client side metrics, will skip exporting client side metrics", - executionException); - return null; - } + OpenTelemetry getOpenTelemetry() { + return this.openTelemetry; + } + + Map getClientAttributes() { + return this.clientAttributes; + } + + BuiltInOpenTelemetryMetricsRecorder getBuiltInOpenTelemetryMetricsRecorder() { + return this.builtInOpenTelemetryMetricsRecorder; + } + + @VisibleForTesting + void reset() { + isInitialized = false; + } + + private 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); + clientAttributes.put(INSTANCE_CONFIG_ID_KEY.getKey(), "unknown"); + clientAttributes.put(CLIENT_NAME_KEY.getKey(), client_name); + String clientUid = getDefaultTaskValue(); + clientAttributes.put(CLIENT_UID_KEY.getKey(), clientUid); + clientAttributes.put(CLIENT_HASH_KEY.getKey(), generateClientHash(clientUid)); + return clientAttributes; + } + + private OpenTelemetry createOpenTelemetry( + String projectId, @Nullable Credentials credentials, @Nullable String monitoringHost) + throws IOException { + OpenTelemetry openTelemetry; + SdkMeterProviderBuilder sdkMeterProviderBuilder = SdkMeterProvider.builder(); + BuiltInOpenTelemetryMetricsView.registerBuiltinMetrics( + SpannerCloudMonitoringExporter.create(projectId, credentials, monitoringHost), + sdkMeterProviderBuilder); + SdkMeterProvider sdkMeterProvider = sdkMeterProviderBuilder.build(); + openTelemetry = OpenTelemetrySdk.builder().setMeterProvider(sdkMeterProvider).build(); + Runtime.getRuntime().addShutdownHook(new Thread(sdkMeterProvider::close)); + return openTelemetry; } /** diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/BuiltInOpenTelemetryMetricsRecorder.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/BuiltInOpenTelemetryMetricsRecorder.java index d5c72506da9..416dbc3a639 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/BuiltInOpenTelemetryMetricsRecorder.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/BuiltInOpenTelemetryMetricsRecorder.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Google LLC + * Copyright 2025 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,10 +44,11 @@ public class BuiltInOpenTelemetryMetricsRecorder { */ public BuiltInOpenTelemetryMetricsRecorder( OpenTelemetry openTelemetry, Map clientAttributes) { - if (openTelemetry != null && clientAttributes != null) { + if (openTelemetry == null || clientAttributes == null) { gfeLatencyRecorder = null; return; } + Meter meter = openTelemetry .meterBuilder(BuiltInMetricsConstant.SPANNER_METER_NAME) 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 5e917ba1767..6e96828b495 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 @@ -1825,16 +1825,21 @@ public OpenTelemetry getOpenTelemetry() { } } - /** Returns an instance of OpenTelemetry object for Built-in Client metrics. */ - public OpenTelemetry getBuiltInMetricsOpenTelemetry() { - return this.builtInOpenTelemetryMetricsProvider.getOrCreateOpenTelemetry( - this.getProjectId(), getCredentials()); + /** + * Returns an instance of Built-In MetricsRecorder object. initializeBuiltInMetrics should be + * called first before this recorder can be fetched + */ + public BuiltInOpenTelemetryMetricsRecorder getBuiltInMetricsRecorder() { + return this.builtInOpenTelemetryMetricsProvider.getBuiltInOpenTelemetryMetricsRecorder(); } - /** Returns attributes for an instance of Built-in Client metrics. */ - public Map getBuiltInMetricsClientAttributes() { - return builtInOpenTelemetryMetricsProvider.createOrGetClientAttributes( - this.getProjectId(), "spanner-java/" + GaxProperties.getLibraryVersion(getClass())); + /** Initialize the built-in metrics provider */ + public void initializeBuiltInMetrics() { + this.builtInOpenTelemetryMetricsProvider.initialize( + this.getProjectId(), + "spanner-java/" + GaxProperties.getLibraryVersion(getClass()), + getCredentials(), + this.getMonitoringHost()); } @Override @@ -1882,13 +1887,10 @@ private ApiTracerFactory getDefaultApiTracerFactory() { } private ApiTracerFactory createMetricsApiTracerFactory() { - OpenTelemetry openTelemetry = - this.builtInOpenTelemetryMetricsProvider.getOrCreateOpenTelemetry( - this.getProjectId(), getCredentials(), this.monitoringHost); + OpenTelemetry openTelemetry = this.builtInOpenTelemetryMetricsProvider.getOpenTelemetry(); Map clientAttributes = - builtInOpenTelemetryMetricsProvider.createOrGetClientAttributes( - this.getProjectId(), "spanner-java/" + GaxProperties.getLibraryVersion(getClass())); + builtInOpenTelemetryMetricsProvider.getClientAttributes(); return openTelemetry != null && clientAttributes != null ? new MetricsTracerFactory( new OpenTelemetryMetricsRecorder(openTelemetry, BuiltInMetricsConstant.METER_NAME), 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 edd885d3c8e..83955fcfbf9 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 @@ -333,6 +333,7 @@ public GapicSpannerRpc(final SpannerOptions options) { this.endToEndTracingEnabled = options.isEndToEndTracingEnabled(); this.numChannels = options.getNumChannels(); this.isGrpcGcpExtensionEnabled = options.isGrpcGcpExtensionEnabled(); + options.initializeBuiltInMetrics(); if (initializeStubs) { // First check if SpannerOptions provides a TransportChannelProvider. Create one @@ -357,8 +358,7 @@ public GapicSpannerRpc(final SpannerOptions options) { options.getInterceptorProvider(), SpannerInterceptorProvider.createDefault( options.getOpenTelemetry(), - options.getBuiltInMetricsOpenTelemetry(), - options.getBuiltInMetricsClientAttributes(), + options.getBuiltInMetricsRecorder(), (() -> directPathEnabledSupplier.get())))) // This sets the trace context headers. .withTraceContext(endToEndTracingEnabled, options.getOpenTelemetry()) diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/HeaderInterceptor.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/HeaderInterceptor.java index de5a042ff75..9d7c1140920 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/HeaderInterceptor.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/HeaderInterceptor.java @@ -72,9 +72,11 @@ class HeaderInterceptor implements ClientInterceptor { DatabaseName.of("undefined-project", "undefined-instance", "undefined-database"); private static final Metadata.Key SERVER_TIMING_HEADER_KEY = Metadata.Key.of("server-timing", Metadata.ASCII_STRING_MARSHALLER); - private static final String SERVER_TIMING_HEADER_PREFIX = "gfet4t7; dur="; + private static final String GFE_TIMING_HEADER = "gfet4t7"; private static final Metadata.Key GOOGLE_CLOUD_RESOURCE_PREFIX_KEY = Metadata.Key.of("google-cloud-resource-prefix", Metadata.ASCII_STRING_MARSHALLER); + private static final Pattern SERVER_TIMING_PATTERN = + Pattern.compile("(?[a-zA-Z0-9_-]+);\\s*dur=(?\\d+)"); private static final Pattern GOOGLE_CLOUD_RESOURCE_PREFIX_PATTERN = Pattern.compile( ".*projects/(?\\p{ASCII}[^/]*)(/instances/(?\\p{ASCII}[^/]*))?(/databases/(?\\p{ASCII}[^/]*))?"); @@ -121,25 +123,31 @@ public void start(Listener responseListener, Metadata headers) { Span span = Span.current(); DatabaseName databaseName = extractDatabaseName(headers); String key = databaseName + method.getFullMethodName(); - TagContext tagContext = getTagContext(key, method.getFullMethodName(), databaseName); - Attributes attributes = - getMetricAttributes(key, method.getFullMethodName(), databaseName); - Map commonBuiltInMetricAttributes = - getCommonBuiltInMetricAttributes(key, databaseName); + + TagContext openCensusTagContext = + getOpenCensusTagContext(key, method.getFullMethodName(), databaseName); + Attributes customMetricAttributes = + buildCustomMetricAttributes(key, method.getFullMethodName(), databaseName); + Map builtInMetricAttributes = + buildBuiltInMetricAttributes(key, databaseName); super.start( new SimpleForwardingClientCallListener(responseListener) { @Override public void onHeaders(Metadata metadata) { - Boolean isDirectPathUsed = - isDirectPathUsed(getAttributes().get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR)); - addBuiltInMetricAttributes( - compositeTracer, commonBuiltInMetricAttributes, isDirectPathUsed); - processHeader( + if (compositeTracer != null) { + builtInMetricAttributes.put( + BuiltInMetricsConstant.DIRECT_PATH_USED_KEY.getKey(), + Boolean.toString( + isDirectPathUsed( + getAttributes().get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR)))); + compositeTracer.addAttributes(builtInMetricAttributes); + } + processServerTimingHeader( metadata, - tagContext, - attributes, + openCensusTagContext, + customMetricAttributes, span, - getBuiltInMetricAttributes(commonBuiltInMetricAttributes, isDirectPathUsed)); + builtInMetricAttributes); super.onHeaders(metadata); } }, @@ -152,7 +160,7 @@ public void onHeaders(Metadata metadata) { }; } - private void processHeader( + private void processServerTimingHeader( Metadata metadata, TagContext tagContext, Attributes attributes, @@ -160,29 +168,55 @@ private void processHeader( Map builtInMetricsAttributes) { MeasureMap measureMap = STATS_RECORDER.newMeasureMap(); String serverTiming = metadata.get(SERVER_TIMING_HEADER_KEY); - if (serverTiming != null && serverTiming.startsWith(SERVER_TIMING_HEADER_PREFIX)) { - try { - long latency = Long.parseLong(serverTiming.substring(SERVER_TIMING_HEADER_PREFIX.length())); - measureMap.put(SPANNER_GFE_LATENCY, latency); + try { + // Previous implementation parsed the GFE latency directly using: + // long latency = Long.parseLong(serverTiming.substring("gfet4t7; dur=".length())); + // This approach assumed the serverTiming header contained exactly one metric "gfet4t7". + // If additional metrics were introduced in the header, older versions of the library + // would fail to parse it correctly. To make the parsing more robust, the logic has been + // updated to handle multiple metrics gracefully. + + Map serverTimingMetrics = parseServerTimingHeader(serverTiming); + if (serverTimingMetrics.containsKey(GFE_TIMING_HEADER)) { + long gfeLatency = serverTimingMetrics.get(GFE_TIMING_HEADER); + + measureMap.put(SPANNER_GFE_LATENCY, gfeLatency); measureMap.put(SPANNER_GFE_HEADER_MISSING_COUNT, 0L); measureMap.record(tagContext); - spannerRpcMetrics.recordGfeLatency(latency, attributes); + spannerRpcMetrics.recordGfeLatency(gfeLatency, attributes); spannerRpcMetrics.recordGfeHeaderMissingCount(0L, attributes); - builtInOpenTelemetryMetricsRecorder.recordGFELatency(latency, builtInMetricsAttributes); + + builtInOpenTelemetryMetricsRecorder.recordGFELatency(gfeLatency, builtInMetricsAttributes); if (span != null) { - span.setAttribute("gfe_latency", String.valueOf(latency)); + span.setAttribute("gfe_latency", String.valueOf(gfeLatency)); } - } catch (NumberFormatException e) { - LOGGER.log(LEVEL, "Invalid server-timing object in header: {}", serverTiming); + } else { + measureMap.put(SPANNER_GFE_HEADER_MISSING_COUNT, 1L).record(tagContext); + spannerRpcMetrics.recordGfeHeaderMissingCount(1L, attributes); } - } else { - spannerRpcMetrics.recordGfeHeaderMissingCount(1L, attributes); - measureMap.put(SPANNER_GFE_HEADER_MISSING_COUNT, 1L).record(tagContext); + } catch (NumberFormatException e) { + LOGGER.log(LEVEL, "Invalid server-timing object in header: {}", serverTiming); } } + private Map parseServerTimingHeader(String serverTiming) { + Map serverTimingMetrics = new HashMap<>(); + if (serverTiming != null) { + Matcher matcher = SERVER_TIMING_PATTERN.matcher(serverTiming); + while (matcher.find()) { + String metricName = matcher.group("metricName"); + String durationStr = matcher.group("duration"); + + if (metricName != null && durationStr != null) { + serverTimingMetrics.put(metricName, Long.valueOf(durationStr)); + } + } + } + return serverTimingMetrics; + } + private DatabaseName extractDatabaseName(Metadata headers) throws ExecutionException { String googleResourcePrefix = headers.get(GOOGLE_CLOUD_RESOURCE_PREFIX_KEY); if (googleResourcePrefix != null) { @@ -211,7 +245,7 @@ private DatabaseName extractDatabaseName(Metadata headers) throws ExecutionExcep return UNDEFINED_DATABASE_NAME; } - private TagContext getTagContext(String key, String method, DatabaseName databaseName) + private TagContext getOpenCensusTagContext(String key, String method, DatabaseName databaseName) throws ExecutionException { return tagsCache.get( key, @@ -225,8 +259,8 @@ private TagContext getTagContext(String key, String method, DatabaseName databas .build()); } - private Attributes getMetricAttributes(String key, String method, DatabaseName databaseName) - throws ExecutionException { + private Attributes buildCustomMetricAttributes( + String key, String method, DatabaseName databaseName) throws ExecutionException { return attributesCache.get( key, () -> { @@ -240,8 +274,8 @@ private Attributes getMetricAttributes(String key, String method, DatabaseName d }); } - private Map getCommonBuiltInMetricAttributes( - String key, DatabaseName databaseName) throws ExecutionException { + private Map buildBuiltInMetricAttributes(String key, DatabaseName databaseName) + throws ExecutionException { return builtInAttributesCache.get( key, () -> { @@ -256,24 +290,6 @@ private Map getCommonBuiltInMetricAttributes( }); } - private Map getBuiltInMetricAttributes( - Map commonBuiltInMetricsAttributes, Boolean isDirectPathUsed) { - Map builtInMetricAttributes = new HashMap<>(commonBuiltInMetricsAttributes); - builtInMetricAttributes.put( - BuiltInMetricsConstant.DIRECT_PATH_USED_KEY.getKey(), Boolean.toString(isDirectPathUsed)); - return builtInMetricAttributes; - } - - private void addBuiltInMetricAttributes( - CompositeTracer compositeTracer, - Map commonBuiltInMetricsAttributes, - Boolean isDirectPathUsed) { - if (compositeTracer != null) { - compositeTracer.addAttributes( - getBuiltInMetricAttributes(commonBuiltInMetricsAttributes, isDirectPathUsed)); - } - } - private Boolean isDirectPathUsed(SocketAddress remoteAddr) { if (remoteAddr instanceof InetSocketAddress) { InetAddress inetAddress = ((InetSocketAddress) remoteAddr).getAddress(); diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/SpannerInterceptorProvider.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/SpannerInterceptorProvider.java index cbb9b62bdd2..6f43954bf32 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/SpannerInterceptorProvider.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/SpannerInterceptorProvider.java @@ -29,7 +29,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; @@ -47,15 +46,17 @@ private SpannerInterceptorProvider(List clientInterceptors) { @ObsoleteApi("This method always uses Global OpenTelemetry") public static SpannerInterceptorProvider createDefault() { - return createDefault(GlobalOpenTelemetry.get(), GlobalOpenTelemetry.get()); + return createDefault( + GlobalOpenTelemetry.get(), + new BuiltInOpenTelemetryMetricsRecorder(GlobalOpenTelemetry.get(), new HashMap<>())); } public static SpannerInterceptorProvider createDefault( - OpenTelemetry openTelemetry, OpenTelemetry builtInMetricsopenTelemetry) { + OpenTelemetry openTelemetry, + BuiltInOpenTelemetryMetricsRecorder builtInOpenTelemetryMetricsRecorder) { return createDefault( openTelemetry, - builtInMetricsopenTelemetry, - new HashMap<>(), + builtInOpenTelemetryMetricsRecorder, Suppliers.memoize( () -> { return false; @@ -64,8 +65,7 @@ public static SpannerInterceptorProvider createDefault( public static SpannerInterceptorProvider createDefault( OpenTelemetry openTelemetry, - OpenTelemetry builtInMetricsopenTelemetry, - Map builtInMetricsClientAttributes, + BuiltInOpenTelemetryMetricsRecorder builtInOpenTelemetryMetricsRecorder, Supplier directPathEnabledSupplier) { List defaultInterceptorList = new ArrayList<>(); defaultInterceptorList.add(new SpannerErrorInterceptor()); @@ -74,8 +74,7 @@ public static SpannerInterceptorProvider createDefault( defaultInterceptorList.add( new HeaderInterceptor( new SpannerRpcMetrics(openTelemetry), - new BuiltInOpenTelemetryMetricsRecorder( - builtInMetricsopenTelemetry, builtInMetricsClientAttributes), + builtInOpenTelemetryMetricsRecorder, directPathEnabledSupplier)); return new SpannerInterceptorProvider(ImmutableList.copyOf(defaultInterceptorList)); } 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 0b30e893c0e..4b593b06556 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,7 +88,9 @@ public static void setup() { String client_name = "spanner-java/"; openTelemetry = OpenTelemetrySdk.builder().setMeterProvider(meterProvider.build()).build(); - attributes = provider.createOrGetClientAttributes("test-project", client_name); + provider.reset(); + provider.initialize("test-project", client_name, null, null); + attributes = provider.getClientAttributes(); expectedBaseAttributes = Attributes.builder()