@@ -227,6 +227,7 @@ public static GcpChannelPoolOptions createDefaultDynamicChannelPoolOptions() {
227227 private final boolean autoThrottleAdministrativeRequests ;
228228 private final RetrySettings retryAdministrativeRequestsSettings ;
229229 private final boolean trackTransactionStarter ;
230+ private final boolean enableGrpcGcpOtelMetrics ;
230231 private final BuiltInMetricsProvider builtInMetricsProvider = BuiltInMetricsProvider .INSTANCE ;
231232
232233 /**
@@ -895,6 +896,7 @@ protected SpannerOptions(Builder builder) {
895896 autoThrottleAdministrativeRequests = builder .autoThrottleAdministrativeRequests ;
896897 retryAdministrativeRequestsSettings = builder .retryAdministrativeRequestsSettings ;
897898 trackTransactionStarter = builder .trackTransactionStarter ;
899+ enableGrpcGcpOtelMetrics = builder .enableGrpcGcpOtelMetrics ;
898900 defaultQueryOptions = builder .defaultQueryOptions ;
899901 envQueryOptions = builder .getEnvironmentQueryOptions ();
900902 if (envQueryOptions .equals (QueryOptions .getDefaultInstance ())) {
@@ -975,6 +977,10 @@ default boolean isEnableGRPCBuiltInMetrics() {
975977 return false ;
976978 }
977979
980+ default boolean isEnableGrpcGcpOtelMetrics () {
981+ return true ;
982+ }
983+
978984 default boolean isEnableEndToEndTracing () {
979985 return false ;
980986 }
@@ -1013,6 +1019,8 @@ private static class SpannerEnvironmentImpl implements SpannerEnvironment {
10131019 private static final String SPANNER_DISABLE_BUILTIN_METRICS = "SPANNER_DISABLE_BUILTIN_METRICS" ;
10141020 private static final String SPANNER_DISABLE_DIRECT_ACCESS_GRPC_BUILTIN_METRICS =
10151021 "SPANNER_DISABLE_DIRECT_ACCESS_GRPC_BUILTIN_METRICS" ;
1022+ private static final String SPANNER_DISABLE_GRPC_GCP_OTEL_METRICS =
1023+ "SPANNER_DISABLE_GRPC_GCP_OTEL_METRICS" ;
10161024 private static final String SPANNER_MONITORING_HOST = "SPANNER_MONITORING_HOST" ;
10171025
10181026 private SpannerEnvironmentImpl () {}
@@ -1058,6 +1066,11 @@ public boolean isEnableGRPCBuiltInMetrics() {
10581066 System .getenv (SPANNER_DISABLE_DIRECT_ACCESS_GRPC_BUILTIN_METRICS ));
10591067 }
10601068
1069+ @ Override
1070+ public boolean isEnableGrpcGcpOtelMetrics () {
1071+ return !Boolean .parseBoolean (System .getenv (SPANNER_DISABLE_GRPC_GCP_OTEL_METRICS ));
1072+ }
1073+
10611074 @ Override
10621075 public boolean isEnableEndToEndTracing () {
10631076 return Boolean .parseBoolean (System .getenv (SPANNER_ENABLE_END_TO_END_TRACING ));
@@ -1128,6 +1141,8 @@ public static class Builder
11281141 private boolean autoThrottleAdministrativeRequests = false ;
11291142 private boolean trackTransactionStarter = false ;
11301143 private Map <DatabaseId , QueryOptions > defaultQueryOptions = new HashMap <>();
1144+ private boolean enableGrpcGcpOtelMetrics =
1145+ SpannerOptions .environment .isEnableGrpcGcpOtelMetrics ();
11311146 private CallCredentialsProvider callCredentialsProvider ;
11321147 private CloseableExecutorProvider asyncExecutorProvider ;
11331148 private String compressorName ;
@@ -1231,6 +1246,7 @@ protected Builder() {
12311246 this .autoThrottleAdministrativeRequests = options .autoThrottleAdministrativeRequests ;
12321247 this .retryAdministrativeRequestsSettings = options .retryAdministrativeRequestsSettings ;
12331248 this .trackTransactionStarter = options .trackTransactionStarter ;
1249+ this .enableGrpcGcpOtelMetrics = options .enableGrpcGcpOtelMetrics ;
12341250 this .defaultQueryOptions = options .defaultQueryOptions ;
12351251 this .callCredentialsProvider = options .callCredentialsProvider ;
12361252 this .asyncExecutorProvider = options .asyncExecutorProvider ;
@@ -1750,6 +1766,17 @@ public Builder disableDynamicChannelPool() {
17501766 return this ;
17511767 }
17521768
1769+ /**
1770+ * Sets whether to enable or disable grpc-gcp OpenTelemetry metrics injection. When disabled,
1771+ * Spanner will not automatically inject an OpenTelemetry {@link
1772+ * io.opentelemetry.api.metrics.Meter} into grpc-gcp. If a Meter or MetricRegistry is explicitly
1773+ * provided via {@link GcpManagedChannelOptions}, those settings will still be honored.
1774+ */
1775+ public Builder setGrpcGcpOtelMetricsEnabled (boolean enableGrpcGcpOtelMetrics ) {
1776+ this .enableGrpcGcpOtelMetrics = enableGrpcGcpOtelMetrics ;
1777+ return this ;
1778+ }
1779+
17531780 /**
17541781 * Sets the channel pool options for dynamic channel pooling. Use this to configure the dynamic
17551782 * channel pool behavior when {@link #enableDynamicChannelPool()} is enabled.
@@ -2211,6 +2238,10 @@ public boolean isGrpcGcpExtensionEnabled() {
22112238 return grpcGcpExtensionEnabled ;
22122239 }
22132240
2241+ public boolean isGrpcGcpOtelMetricsEnabled () {
2242+ return enableGrpcGcpOtelMetrics ;
2243+ }
2244+
22142245 public GcpManagedChannelOptions getGrpcGcpOptions () {
22152246 return grpcGcpOptions ;
22162247 }
0 commit comments