@@ -150,6 +150,7 @@ export type GetInstanceConfigOperationsCallback = PagedCallback<
150150 * Indicates which replicas or regions should be used for non-transactional reads or queries.
151151 * DirectedReadOptions won't be set for readWrite transactions"
152152 * @property {ObservabilityOptions } [observabilityOptions] Sets the observability options to be used for OpenTelemetry tracing
153+ * @property {boolean } [disableBuiltInMetrics=True] If set to true, built-in metrics will be disabled.
153154 */
154155export interface SpannerOptions extends GrpcClientOptions {
155156 apiEndpoint ?: string ;
@@ -160,6 +161,7 @@ export interface SpannerOptions extends GrpcClientOptions {
160161 directedReadOptions ?: google . spanner . v1 . IDirectedReadOptions | null ;
161162 defaultTransactionOptions ?: Pick < RunTransactionOptions , 'isolationLevel' > ;
162163 observabilityOptions ?: ObservabilityOptions ;
164+ disableBuiltInMetrics ?: boolean ;
163165 interceptors ?: any [ ] ;
164166 /**
165167 * The Trusted Cloud Domain (TPC) DNS of the service used to make requests.
@@ -315,7 +317,7 @@ class Spanner extends GrpcService {
315317 defaultTransactionOptions : RunTransactionOptions ;
316318 _observabilityOptions : ObservabilityOptions | undefined ;
317319 private _universeDomain : string ;
318- private _isEmulatorEnabled : boolean ;
320+ private _isInSecureCredentials : boolean ;
319321 private static _isAFEServerTimingEnabled : boolean | undefined ;
320322 readonly _nthClientId : number ;
321323
@@ -443,14 +445,12 @@ class Spanner extends GrpcService {
443445 ) ;
444446 }
445447
446- let isEmulatorEnabled = false ;
447448 const emulatorHost = Spanner . getSpannerEmulatorHost ( ) ;
448449 if (
449450 emulatorHost &&
450451 emulatorHost . endpoint &&
451452 emulatorHost . endpoint . length > 0
452453 ) {
453- isEmulatorEnabled = true ;
454454 options . servicePath = emulatorHost . endpoint ;
455455 options . port = emulatorHost . port ;
456456 options . sslCreds = grpc . credentials . createInsecure ( ) ;
@@ -477,7 +477,7 @@ class Spanner extends GrpcService {
477477 this . routeToLeaderEnabled = false ;
478478 }
479479
480- this . _isEmulatorEnabled = isEmulatorEnabled ;
480+ this . _isInSecureCredentials = options . sslCreds ?. _isSecure ( ) === false ;
481481 this . options = options ;
482482 this . auth = new GoogleAuth ( this . options ) ;
483483 this . clients_ = new Map ( ) ;
@@ -495,7 +495,7 @@ class Spanner extends GrpcService {
495495 ensureInitialContextManagerSet ( ) ;
496496 this . _nthClientId = nextSpannerClientId ( ) ;
497497 this . _universeDomain = universeEndpoint ;
498- this . configureMetrics_ ( ) ;
498+ this . configureMetrics_ ( options . disableBuiltInMetrics ) ;
499499 }
500500
501501 get universeDomain ( ) {
@@ -1614,10 +1614,11 @@ class Spanner extends GrpcService {
16141614 /**
16151615 * Setup the OpenTelemetry metrics capturing for service metrics to Google Cloud Monitoring.
16161616 */
1617- configureMetrics_ ( ) {
1617+ configureMetrics_ ( disableBuiltInMetrics ?: boolean ) {
16181618 const metricsEnabled =
16191619 process . env . SPANNER_DISABLE_BUILTIN_METRICS !== 'true' &&
1620- ! this . _isEmulatorEnabled ;
1620+ ! disableBuiltInMetrics &&
1621+ ! this . _isInSecureCredentials ;
16211622 MetricsTracerFactory . enabled = metricsEnabled ;
16221623 if ( metricsEnabled ) {
16231624 const factory = MetricsTracerFactory . getInstance ( this . projectId ) ;
0 commit comments