@google-cloud/spanner 8.13.0 → 9.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +1 -16
  2. package/build/src/batch-transaction.js +15 -12
  3. package/build/src/codec.d.ts +18 -30
  4. package/build/src/codec.js +197 -79
  5. package/build/src/common.d.ts +14 -0
  6. package/build/src/common.js +28 -3
  7. package/build/src/database.d.ts +31 -41
  8. package/build/src/database.js +147 -315
  9. package/build/src/helper.d.ts +12 -0
  10. package/build/src/helper.js +44 -0
  11. package/build/src/index.d.ts +24 -8
  12. package/build/src/index.js +303 -147
  13. package/build/src/instance.d.ts +15 -2
  14. package/build/src/instance.js +11 -2
  15. package/build/src/instrument.d.ts +12 -1
  16. package/build/src/instrument.js +13 -0
  17. package/build/src/metrics/constants.d.ts +13 -6
  18. package/build/src/metrics/constants.js +24 -14
  19. package/build/src/metrics/external-types.d.ts +14 -0
  20. package/build/src/metrics/interceptor.js +39 -44
  21. package/build/src/metrics/metrics-tracer-factory.d.ts +25 -14
  22. package/build/src/metrics/metrics-tracer-factory.js +119 -78
  23. package/build/src/metrics/metrics-tracer.d.ts +19 -6
  24. package/build/src/metrics/metrics-tracer.js +147 -55
  25. package/build/src/metrics/spanner-metrics-exporter.js +4 -0
  26. package/build/src/metrics/transform.d.ts +3 -4
  27. package/build/src/metrics/transform.js +16 -10
  28. package/build/src/multiplexed-session.d.ts +26 -2
  29. package/build/src/multiplexed-session.js +39 -11
  30. package/build/src/partial-result-stream.d.ts +26 -33
  31. package/build/src/partial-result-stream.js +263 -283
  32. package/build/src/request-stream-coordinator.d.ts +88 -0
  33. package/build/src/request-stream-coordinator.js +229 -0
  34. package/build/src/request_id_header.d.ts +6 -4
  35. package/build/src/request_id_header.js +24 -24
  36. package/build/src/session-factory.d.ts +62 -60
  37. package/build/src/session-factory.js +46 -86
  38. package/build/src/session-pool.d.ts +97 -227
  39. package/build/src/session-pool.js +74 -547
  40. package/build/src/session.js +1 -1
  41. package/build/src/transaction-runner.js +1 -12
  42. package/build/src/transaction.d.ts +21 -5
  43. package/build/src/transaction.js +107 -136
  44. package/package.json +28 -37
@@ -505,10 +505,15 @@ class Instance extends common.GrpcServiceObject {
505
505
  * @param {string} name The name of the instance.
506
506
  * @param {SessionPoolOptions|SessionPoolCtor} [poolOptions] Session pool
507
507
  * configuration options.
508
+ * **Deprecated**. Session pool options is deprecated and will be removed in a future release.
509
+ * Multiplexed sessions are now used for all operations by default, eliminating
510
+ * the need for session pooling.
508
511
  * @param {spannerClient.spanner.v1.ExecuteSqlRequest.IQueryOptions} [queryOptions]
509
512
  * Default query options to use with the database. These options will be
510
513
  * overridden by any query options set in environment variables or that
511
514
  * are specified on a per-query basis.
515
+ * @param {string} [databaseRole] The database role to use for sessions on
516
+ * the database.
512
517
  * @return {Database} A Database object.
513
518
  *
514
519
  * @example
@@ -524,8 +529,8 @@ class Instance extends common.GrpcServiceObject {
524
529
  if (!name) {
525
530
  throw new google_gax_1.GoogleError('A name is required to access a Database object.');
526
531
  }
527
- // Only add an additional key for SessionPoolOptions and QueryOptions if an
528
- // options object with at least one value was passed in.
532
+ // Only add an additional key for SessionPoolOptions, QueryOptions, and databaseRole
533
+ // if provided.
529
534
  let optionsKey = poolOptions && Object.keys(poolOptions).length > 0
530
535
  ? '/' + JSON.stringify(Object.entries(poolOptions).sort())
531
536
  : '';
@@ -533,6 +538,9 @@ class Instance extends common.GrpcServiceObject {
533
538
  optionsKey =
534
539
  optionsKey + '/' + JSON.stringify(Object.entries(queryOptions).sort());
535
540
  }
541
+ if (databaseRole) {
542
+ optionsKey = optionsKey + '/' + databaseRole;
543
+ }
536
544
  const key = name.split('/').pop() + optionsKey;
537
545
  if (!this.databases_.has(key)) {
538
546
  const db = new database_1.Database(this, name, poolOptions, queryOptions, databaseRole);
@@ -569,6 +577,7 @@ class Instance extends common.GrpcServiceObject {
569
577
  }
570
578
  callback(err, resp);
571
579
  });
580
+ return null;
572
581
  });
573
582
  }
574
583
  exists(optionsOrCallback, cb) {
@@ -43,8 +43,19 @@ interface traceConfig {
43
43
  requestTag?: string | null;
44
44
  opts?: ObservabilityOptions;
45
45
  }
46
+ interface QueryWithRequestOptions {
47
+ sql?: string | SQLStatement;
48
+ requestOptions?: {
49
+ requestTag?: string | null;
50
+ transactionTag?: string | null;
51
+ } | null;
52
+ }
53
+ declare function getQueryTraceConfig(query?: string | QueryWithRequestOptions | null): {
54
+ sql?: string | SQLStatement;
55
+ requestTag?: string | null;
56
+ };
46
57
  declare const SPAN_NAMESPACE_PREFIX = "CloudSpanner";
47
- export { SPAN_NAMESPACE_PREFIX, traceConfig };
58
+ export { SPAN_NAMESPACE_PREFIX, traceConfig, QueryWithRequestOptions, getQueryTraceConfig, };
48
59
  declare function ensureInitialContextManagerSet(): void;
49
60
  export { ensureInitialContextManagerSet };
50
61
  /**
@@ -17,6 +17,7 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.SPAN_NAMESPACE_PREFIX = exports.TRACER_VERSION = exports.TRACER_NAME = void 0;
19
19
  exports.getTracer = getTracer;
20
+ exports.getQueryTraceConfig = getQueryTraceConfig;
20
21
  exports.ensureInitialContextManagerSet = ensureInitialContextManagerSet;
21
22
  exports.isTracingEnabled = isTracingEnabled;
22
23
  exports._resetTracingEnabledForTest = _resetTracingEnabledForTest;
@@ -45,6 +46,18 @@ function getTracer(tracerProvider) {
45
46
  // Otherwise use the global tracer.
46
47
  return api_1.trace.getTracer(TRACER_NAME, TRACER_VERSION);
47
48
  }
49
+ function getQueryTraceConfig(query) {
50
+ if (typeof query === 'string') {
51
+ return { sql: query };
52
+ }
53
+ if (query && typeof query === 'object') {
54
+ return {
55
+ sql: query.sql,
56
+ requestTag: query.requestOptions?.requestTag,
57
+ };
58
+ }
59
+ return {};
60
+ }
48
61
  const SPAN_NAMESPACE_PREFIX = 'CloudSpanner'; // TODO: discuss & standardize this prefix.
49
62
  exports.SPAN_NAMESPACE_PREFIX = SPAN_NAMESPACE_PREFIX;
50
63
  const { AsyncHooksContextManager, } = require('@opentelemetry/context-async-hooks');
@@ -1,10 +1,17 @@
1
- import { View } from '@opentelemetry/sdk-metrics';
1
+ import { ViewOptions } from '@opentelemetry/sdk-metrics';
2
2
  export declare const SPANNER_METER_NAME = "spanner-nodejs";
3
3
  export declare const CLIENT_METRICS_PREFIX = "spanner.googleapis.com/internal/client";
4
4
  export declare const SPANNER_RESOURCE_TYPE = "spanner_instance_client";
5
+ /**
6
+ * @deprecated No longer used after eliminating the background tracer cleanup timer.
7
+ */
5
8
  export declare const TRACER_CLEANUP_THRESHOLD_MS: number;
9
+ /**
10
+ * @deprecated No longer used after eliminating the background tracer cleanup timer.
11
+ */
6
12
  export declare const TRACER_CLEANUP_INTERVAL_MS: number;
7
13
  export declare const ATTR_CLOUD_REGION = "cloud.region";
14
+ export declare const ATTR_CLOUD_AVAILABILITY_ZONE = "cloud.availability_zone";
8
15
  export declare const MIN_EXPORT_FREQUENCY_MS: number;
9
16
  export declare const MONITORED_RES_LABEL_KEY_PROJECT = "project_id";
10
17
  export declare const MONITORED_RES_LABEL_KEY_INSTANCE = "instance_id";
@@ -29,8 +36,8 @@ export declare const METRIC_NAME_AFE_CONNECTIVITY_ERROR_COUNT = "afe_connectivit
29
36
  export declare const METRIC_NAMES: Set<string>;
30
37
  export declare const UNKNOWN_ATTRIBUTE = "unknown";
31
38
  export declare const HISTOGRAM_BUCKET_BOUNDARIES: number[];
32
- export declare const OPERATION_LATENCY_VIEW: View;
33
- export declare const ATTEMPT_LATENCY_VIEW: View;
34
- export declare const GFE_LATENCY_VIEW: View;
35
- export declare const AFE_LATENCY_VIEW: View;
36
- export declare const METRIC_VIEWS: View[];
39
+ export declare const OPERATION_LATENCY_VIEW: ViewOptions;
40
+ export declare const ATTEMPT_LATENCY_VIEW: ViewOptions;
41
+ export declare const GFE_LATENCY_VIEW: ViewOptions;
42
+ export declare const AFE_LATENCY_VIEW: ViewOptions;
43
+ export declare const METRIC_VIEWS: ViewOptions[];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.METRIC_VIEWS = exports.AFE_LATENCY_VIEW = exports.GFE_LATENCY_VIEW = exports.ATTEMPT_LATENCY_VIEW = exports.OPERATION_LATENCY_VIEW = exports.HISTOGRAM_BUCKET_BOUNDARIES = exports.UNKNOWN_ATTRIBUTE = exports.METRIC_NAMES = exports.METRIC_NAME_AFE_CONNECTIVITY_ERROR_COUNT = exports.METRIC_NAME_AFE_LATENCIES = exports.METRIC_NAME_GFE_CONNECTIVITY_ERROR_COUNT = exports.METRIC_NAME_GFE_LATENCIES = exports.METRIC_NAME_ATTEMPT_COUNT = exports.METRIC_NAME_OPERATION_COUNT = exports.METRIC_NAME_ATTEMPT_LATENCIES = exports.METRIC_NAME_OPERATION_LATENCIES = exports.METRIC_LABELS = exports.METRIC_LABEL_KEY_STATUS = exports.METRIC_LABEL_KEY_METHOD = exports.METRIC_LABEL_KEY_DATABASE = exports.METRIC_LABEL_KEY_CLIENT_NAME = exports.METRIC_LABEL_KEY_CLIENT_UID = exports.MONITORED_RESOURCE_LABELS = exports.MONITORED_RES_LABEL_KEY_CLIENT_HASH = exports.MONITORED_RES_LABEL_KEY_LOCATION = exports.MONITORED_RES_LABEL_KEY_INSTANCE_CONFIG = exports.MONITORED_RES_LABEL_KEY_INSTANCE = exports.MONITORED_RES_LABEL_KEY_PROJECT = exports.MIN_EXPORT_FREQUENCY_MS = exports.ATTR_CLOUD_REGION = exports.TRACER_CLEANUP_INTERVAL_MS = exports.TRACER_CLEANUP_THRESHOLD_MS = exports.SPANNER_RESOURCE_TYPE = exports.CLIENT_METRICS_PREFIX = exports.SPANNER_METER_NAME = void 0;
3
+ exports.METRIC_VIEWS = exports.AFE_LATENCY_VIEW = exports.GFE_LATENCY_VIEW = exports.ATTEMPT_LATENCY_VIEW = exports.OPERATION_LATENCY_VIEW = exports.HISTOGRAM_BUCKET_BOUNDARIES = exports.UNKNOWN_ATTRIBUTE = exports.METRIC_NAMES = exports.METRIC_NAME_AFE_CONNECTIVITY_ERROR_COUNT = exports.METRIC_NAME_AFE_LATENCIES = exports.METRIC_NAME_GFE_CONNECTIVITY_ERROR_COUNT = exports.METRIC_NAME_GFE_LATENCIES = exports.METRIC_NAME_ATTEMPT_COUNT = exports.METRIC_NAME_OPERATION_COUNT = exports.METRIC_NAME_ATTEMPT_LATENCIES = exports.METRIC_NAME_OPERATION_LATENCIES = exports.METRIC_LABELS = exports.METRIC_LABEL_KEY_STATUS = exports.METRIC_LABEL_KEY_METHOD = exports.METRIC_LABEL_KEY_DATABASE = exports.METRIC_LABEL_KEY_CLIENT_NAME = exports.METRIC_LABEL_KEY_CLIENT_UID = exports.MONITORED_RESOURCE_LABELS = exports.MONITORED_RES_LABEL_KEY_CLIENT_HASH = exports.MONITORED_RES_LABEL_KEY_LOCATION = exports.MONITORED_RES_LABEL_KEY_INSTANCE_CONFIG = exports.MONITORED_RES_LABEL_KEY_INSTANCE = exports.MONITORED_RES_LABEL_KEY_PROJECT = exports.MIN_EXPORT_FREQUENCY_MS = exports.ATTR_CLOUD_AVAILABILITY_ZONE = exports.ATTR_CLOUD_REGION = exports.TRACER_CLEANUP_INTERVAL_MS = exports.TRACER_CLEANUP_THRESHOLD_MS = exports.SPANNER_RESOURCE_TYPE = exports.CLIENT_METRICS_PREFIX = exports.SPANNER_METER_NAME = void 0;
4
4
  // Copyright 2025 Google LLC
5
5
  //
6
6
  // Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,12 +18,18 @@ const sdk_metrics_1 = require("@opentelemetry/sdk-metrics");
18
18
  exports.SPANNER_METER_NAME = 'spanner-nodejs';
19
19
  exports.CLIENT_METRICS_PREFIX = 'spanner.googleapis.com/internal/client';
20
20
  exports.SPANNER_RESOURCE_TYPE = 'spanner_instance_client';
21
- // Maximum time to keep MetricsTracers before considering them stale, and stop tracking them.
21
+ /**
22
+ * @deprecated No longer used after eliminating the background tracer cleanup timer.
23
+ */
22
24
  exports.TRACER_CLEANUP_THRESHOLD_MS = 60 * 60 * 1000; // 60 minutes
25
+ /**
26
+ * @deprecated No longer used after eliminating the background tracer cleanup timer.
27
+ */
23
28
  exports.TRACER_CLEANUP_INTERVAL_MS = 30 * 60 * 1000; // 30 Minutes
24
29
  // OTel semantic conventions
25
30
  // See https://github.com/open-telemetry/opentelemetry-js/blob/main/semantic-conventions/README.md#unstable-semconv
26
31
  exports.ATTR_CLOUD_REGION = 'cloud.region';
32
+ exports.ATTR_CLOUD_AVAILABILITY_ZONE = 'cloud.availability_zone';
27
33
  // Minimum period that must past between metric exports
28
34
  exports.MIN_EXPORT_FREQUENCY_MS = 30 * 1000;
29
35
  // Monitored resource labels
@@ -81,22 +87,26 @@ exports.HISTOGRAM_BUCKET_BOUNDARIES = [
81
87
  800000.0, 1600000.0, 3200000.0,
82
88
  ];
83
89
  // Defined Views for metric aggregation
84
- exports.OPERATION_LATENCY_VIEW = new sdk_metrics_1.View({
90
+ const HISTOGRAM_AGGREGATION = {
91
+ type: sdk_metrics_1.AggregationType.EXPLICIT_BUCKET_HISTOGRAM,
92
+ options: { boundaries: exports.HISTOGRAM_BUCKET_BOUNDARIES },
93
+ };
94
+ exports.OPERATION_LATENCY_VIEW = {
85
95
  instrumentName: exports.METRIC_NAME_OPERATION_LATENCIES,
86
- aggregation: new sdk_metrics_1.ExplicitBucketHistogramAggregation(exports.HISTOGRAM_BUCKET_BOUNDARIES),
87
- });
88
- exports.ATTEMPT_LATENCY_VIEW = new sdk_metrics_1.View({
96
+ aggregation: HISTOGRAM_AGGREGATION,
97
+ };
98
+ exports.ATTEMPT_LATENCY_VIEW = {
89
99
  instrumentName: exports.METRIC_NAME_ATTEMPT_LATENCIES,
90
- aggregation: new sdk_metrics_1.ExplicitBucketHistogramAggregation(exports.HISTOGRAM_BUCKET_BOUNDARIES),
91
- });
92
- exports.GFE_LATENCY_VIEW = new sdk_metrics_1.View({
100
+ aggregation: HISTOGRAM_AGGREGATION,
101
+ };
102
+ exports.GFE_LATENCY_VIEW = {
93
103
  instrumentName: exports.METRIC_NAME_GFE_LATENCIES,
94
- aggregation: new sdk_metrics_1.ExplicitBucketHistogramAggregation(exports.HISTOGRAM_BUCKET_BOUNDARIES),
95
- });
96
- exports.AFE_LATENCY_VIEW = new sdk_metrics_1.View({
104
+ aggregation: HISTOGRAM_AGGREGATION,
105
+ };
106
+ exports.AFE_LATENCY_VIEW = {
97
107
  instrumentName: exports.METRIC_NAME_AFE_LATENCIES,
98
- aggregation: new sdk_metrics_1.ExplicitBucketHistogramAggregation(exports.HISTOGRAM_BUCKET_BOUNDARIES),
99
- });
108
+ aggregation: HISTOGRAM_AGGREGATION,
109
+ };
100
110
  exports.METRIC_VIEWS = [
101
111
  exports.OPERATION_LATENCY_VIEW,
102
112
  exports.ATTEMPT_LATENCY_VIEW,
@@ -18,3 +18,17 @@ export declare enum ValueType {
18
18
  DOUBLE = "DOUBLE",
19
19
  DISTRIBUTION = "DISTRIBUTION"
20
20
  }
21
+ /**
22
+ * A Google Cloud Monitoring monitored resource.
23
+ *
24
+ * Previously imported from `@google-cloud/opentelemetry-resource-util`, which is
25
+ * deprecated and scheduled for archival. The interface is a plain data shape, so
26
+ * it is declared locally instead.
27
+ * See https://cloud.google.com/monitoring/api/ref_v3/rest/v3/MonitoredResource
28
+ */
29
+ export interface MonitoredResource {
30
+ type: string;
31
+ labels: {
32
+ [key: string]: string;
33
+ };
34
+ }
@@ -15,7 +15,7 @@
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.MetricInterceptor = void 0;
17
17
  const google_gax_1 = require("google-gax");
18
- const metrics_tracer_factory_1 = require("./metrics-tracer-factory");
18
+ const common_1 = require("../common");
19
19
  /**
20
20
  * Interceptor for recording metrics on gRPC calls.
21
21
  *
@@ -30,19 +30,13 @@ const metrics_tracer_factory_1 = require("./metrics-tracer-factory");
30
30
  const MetricInterceptor = (options, nextCall) => {
31
31
  return new google_gax_1.grpc.InterceptingCall(nextCall(options), {
32
32
  start: function (metadata, listener, next) {
33
- // Record attempt metric on request start
34
- const resourcePrefix = metadata.get('google-cloud-resource-prefix')[0];
35
- const match = resourcePrefix?.match(/^projects\/([^/]+)\//);
36
- const projectId = match ? match[1] : undefined;
37
- let factory;
38
- if (projectId) {
39
- factory = metrics_tracer_factory_1.MetricsTracerFactory.getInstance(projectId);
40
- }
41
- const requestId = metadata.get('x-goog-spanner-request-id')[0];
42
- const metricsTracer = factory?.getCurrentTracer(requestId);
33
+ // Record attempt metric on request start.
34
+ // The tracer is carried directly on the call options.
35
+ const metricsTracer = options?.metricsTracer ?? null;
43
36
  metricsTracer?.recordAttemptStart();
44
- const newListener = {
45
- onReceiveMetadata: function (metadata, next) {
37
+ const afeServerTimingEnabled = (0, common_1.isAFEServerTimingEnabled)();
38
+ const interceptingListener = {
39
+ onReceiveMetadata: function (metadata) {
46
40
  // Record GFE/AFE Metrics
47
41
  // GFE/AFE latency if available,
48
42
  // or else increase the GFE/AFE connectivity error count
@@ -51,44 +45,45 @@ const MetricInterceptor = (options, nextCall) => {
51
45
  const serverTimingHeader = serverTimingEntries.length > 0
52
46
  ? String(serverTimingEntries[0])
53
47
  : undefined;
54
- const gfeTiming = metricsTracer?.extractGfeLatency(serverTimingHeader);
48
+ const gfeTiming = metricsTracer.extractGfeLatency(serverTimingHeader);
55
49
  metricsTracer.gfeLatency = gfeTiming ?? null;
56
- const afeTiming = metricsTracer?.extractAfeLatency(serverTimingHeader);
57
- metricsTracer.afeLatency = afeTiming ?? null;
50
+ if (afeServerTimingEnabled) {
51
+ const afeTiming = metricsTracer.extractAfeLatency(serverTimingHeader);
52
+ metricsTracer.afeLatency = afeTiming ?? null;
53
+ }
58
54
  }
59
- next(metadata);
55
+ listener.onReceiveMetadata(metadata);
60
56
  },
61
- onReceiveMessage: function (message, next) {
62
- next(message);
57
+ onReceiveMessage: function (message) {
58
+ listener.onReceiveMessage(message);
63
59
  },
64
- onReceiveStatus: function (status, next) {
65
- next(status);
66
- // Record attempt metric completion
67
- metricsTracer?.recordAttemptCompletion(status.code);
68
- if (metricsTracer?.gfeLatency) {
69
- metricsTracer?.recordGfeLatency(status.code);
70
- }
71
- else {
72
- metricsTracer?.recordGfeConnectivityErrorCount(status.code);
73
- }
74
- if (metricsTracer?.afeLatency) {
75
- metricsTracer?.recordAfeLatency(status.code);
76
- }
77
- else {
78
- metricsTracer?.recordAfeConnectivityErrorCount(status.code);
60
+ onReceiveStatus: function (status) {
61
+ if (metricsTracer) {
62
+ // Record attempt metric completion before notifying downstream listener
63
+ metricsTracer.recordAttemptCompletion(status?.code);
64
+ if (typeof metricsTracer.gfeLatency === 'number' &&
65
+ Number.isFinite(metricsTracer.gfeLatency) &&
66
+ metricsTracer.gfeLatency >= 0) {
67
+ metricsTracer.recordGfeLatency(status?.code);
68
+ }
69
+ else {
70
+ metricsTracer.recordGfeConnectivityErrorCount(status?.code);
71
+ }
72
+ if (afeServerTimingEnabled) {
73
+ if (typeof metricsTracer.afeLatency === 'number' &&
74
+ Number.isFinite(metricsTracer.afeLatency) &&
75
+ metricsTracer.afeLatency >= 0) {
76
+ metricsTracer.recordAfeLatency(status?.code);
77
+ }
78
+ else {
79
+ metricsTracer.recordAfeConnectivityErrorCount(status?.code);
80
+ }
81
+ }
79
82
  }
83
+ listener.onReceiveStatus(status);
80
84
  },
81
85
  };
82
- next(metadata, newListener);
83
- },
84
- sendMessage: function (message, next) {
85
- next(message);
86
- },
87
- halfClose: function (next) {
88
- next();
89
- },
90
- cancel: function (next) {
91
- next();
86
+ next(metadata, interceptingListener);
92
87
  },
93
88
  });
94
89
  };
@@ -29,10 +29,10 @@ export declare class MetricsTracerFactory {
29
29
  private _clientName;
30
30
  private _clientUid;
31
31
  private _location;
32
+ private _locationPromise;
33
+ private _metricReaders;
32
34
  private _projectId;
33
- private _currentOperationTracers;
34
- private _currentOperationLastUpdatedMs;
35
- private _intervalTracerCleanup;
35
+ private _attributesCache;
36
36
  static enabled: boolean;
37
37
  /**
38
38
  * Private constructor to enforce singleton pattern.
@@ -48,10 +48,14 @@ export declare class MetricsTracerFactory {
48
48
  * @param projectId Optional GCP project ID for the factory instantiation. Does nothing for subsequent calls.
49
49
  * @returns The singleton MetricsTracerFactory instance or null if disabled.
50
50
  */
51
- static getInstance(projectId: string): MetricsTracerFactory | null;
51
+ static getInstance(projectId?: string): MetricsTracerFactory | null;
52
52
  /**
53
53
  * Returns the MeterProvider, creating it and metric instruments if not already initialized.
54
54
  * Client-wide attributes that are known at this time are cached to be provided to all MetricsTracers.
55
+ *
56
+ * If called again with readers when the existing MeterProvider has none, the provider is
57
+ * recreated with those readers. If readers are already attached, additional readers are ignored.
58
+ *
55
59
  * @param readers Optional array of MetricReader instances to attach to the MeterProvider.
56
60
  * @returns The OTEL MeterProvider instance.
57
61
  */
@@ -96,6 +100,14 @@ export declare class MetricsTracerFactory {
96
100
  * Returns the Client Name.
97
101
  */
98
102
  get clientName(): string;
103
+ /**
104
+ * Returns the detected client location.
105
+ */
106
+ get location(): string;
107
+ /**
108
+ * Returns true if the MeterProvider is initialized with at least one MetricReader.
109
+ */
110
+ hasMetricReaders(): boolean;
99
111
  /**
100
112
  * Creates a new MetricsTracer for a given resource name and method, and stores it for later retrieval.
101
113
  * Returns null if metrics are disabled.
@@ -103,7 +115,7 @@ export declare class MetricsTracerFactory {
103
115
  * @param method The gRPC method name.
104
116
  * @returns A new MetricsTracer instance or null if metrics are disabled.
105
117
  */
106
- createMetricsTracer(method: string, formattedName: string, requestId: string): MetricsTracer | null;
118
+ createMetricsTracer(method: string, formattedName: string, requestId?: string): MetricsTracer | null;
107
119
  /**
108
120
  * Takes a formatted name and parses the project, instance, and database.
109
121
  * @param formattedName The formatted resource name (e.g., full database path).
@@ -116,16 +128,14 @@ export declare class MetricsTracerFactory {
116
128
  };
117
129
  /**
118
130
  * Retrieves the current MetricsTracer for a given request id.
119
- * Returns null if no tracer exists for the request.
120
- * Does not implicitly create MetricsTracers as that should be done
121
- * explicitly using the createMetricsTracer function.
122
- * request id is expected to be as set in the gRPC metadata.
131
+ * @deprecated MetricsTracer is carried directly on the call context.
123
132
  * @param requestId The request id of the gRPC call set under 'x-goog-spanner-request-id'.
124
- * @returns The MetricsTracer instance or null if not found.
133
+ * @returns null.
125
134
  */
126
135
  getCurrentTracer(requestId: string): MetricsTracer | null;
127
136
  /**
128
137
  * Removes the MetricsTracer associated with the given request id.
138
+ * @deprecated MetricsTracer is carried directly on the call context.
129
139
  * @param requestId The request id of the gRPC call set under 'x-goog-spanner-request-id'.
130
140
  */
131
141
  clearCurrentTracer(requestId: string): void;
@@ -155,10 +165,11 @@ export declare class MetricsTracerFactory {
155
165
  */
156
166
  private static _generateClientHash;
157
167
  /**
158
- * Gets the location (region) of the client, otherwise returns to the "global" region.
159
- * Uses GcpDetectorSync to detect the region from the environment.
160
- * @returns The detected region string, or "global" if not found.
168
+ * Gets the location (region or zone) of the client, or defaults to "global".
169
+ * Uses the GCP resource detector to detect the location from the environment.
170
+ * Checks `cloud.region` first and falls back to `cloud.availability_zone`
171
+ * for zonal GKE clusters where `cloud.region` is not set.
172
+ * @returns The detected location string, or "global" if not found.
161
173
  */
162
174
  private static _detectClientLocation;
163
- private _cleanMetricsTracers;
164
175
  }