@google-cloud/spanner 8.0.0 → 8.2.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 (54) hide show
  1. package/README.md +2 -0
  2. package/build/protos/google/spanner/admin/database/v1/spanner_database_admin.proto +35 -0
  3. package/build/protos/google/spanner/v1/change_stream.proto +451 -0
  4. package/build/protos/google/spanner/v1/commit_response.proto +9 -4
  5. package/build/protos/google/spanner/v1/transaction.proto +40 -356
  6. package/build/protos/protos.d.ts +2087 -4
  7. package/build/protos/protos.js +6191 -349
  8. package/build/protos/protos.json +556 -25
  9. package/build/src/batch-transaction.js +2 -2
  10. package/build/src/codec.js +20 -21
  11. package/build/src/common-grpc/service.js +10 -10
  12. package/build/src/common.d.ts +1 -0
  13. package/build/src/common.js +9 -1
  14. package/build/src/database.d.ts +3 -2
  15. package/build/src/database.js +16 -14
  16. package/build/src/helper.d.ts +90 -0
  17. package/build/src/helper.js +154 -0
  18. package/build/src/index.d.ts +36 -1
  19. package/build/src/index.js +179 -8
  20. package/build/src/instrument.js +3 -2
  21. package/build/src/metrics/constants.d.ts +36 -0
  22. package/build/src/metrics/constants.js +106 -0
  23. package/build/src/metrics/external-types.d.ts +20 -0
  24. package/build/src/metrics/external-types.js +32 -0
  25. package/build/src/metrics/interceptor.d.ts +13 -0
  26. package/build/src/metrics/interceptor.js +87 -0
  27. package/build/src/metrics/metrics-tracer-factory.d.ts +165 -0
  28. package/build/src/metrics/metrics-tracer-factory.js +389 -0
  29. package/build/src/metrics/metrics-tracer.d.ts +204 -0
  30. package/build/src/metrics/metrics-tracer.js +371 -0
  31. package/build/src/metrics/spanner-metrics-exporter.d.ts +35 -0
  32. package/build/src/metrics/spanner-metrics-exporter.js +119 -0
  33. package/build/src/metrics/transform.d.ts +144 -0
  34. package/build/src/metrics/transform.js +272 -0
  35. package/build/src/multiplexed-session.d.ts +1 -1
  36. package/build/src/multiplexed-session.js +2 -4
  37. package/build/src/partial-result-stream.js +9 -5
  38. package/build/src/session-factory.d.ts +34 -0
  39. package/build/src/session-factory.js +30 -0
  40. package/build/src/session-pool.js +1 -2
  41. package/build/src/table.d.ts +2 -0
  42. package/build/src/table.js +5 -0
  43. package/build/src/transaction-runner.d.ts +6 -0
  44. package/build/src/transaction-runner.js +8 -0
  45. package/build/src/transaction.d.ts +44 -1
  46. package/build/src/transaction.js +202 -49
  47. package/build/src/v1/database_admin_client.d.ts +34 -0
  48. package/build/src/v1/database_admin_client.js +167 -1
  49. package/build/src/v1/database_admin_client_config.json +4 -0
  50. package/build/src/v1/instance_admin_client.d.ts +120 -0
  51. package/build/src/v1/instance_admin_client.js +312 -13
  52. package/build/src/v1/spanner_client.js +108 -0
  53. package/build/src/v1/spanner_proto_list.json +1 -0
  54. package/package.json +15 -8
@@ -0,0 +1,106 @@
1
+ "use strict";
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;
4
+ // Copyright 2025 Google LLC
5
+ //
6
+ // Licensed under the Apache License, Version 2.0 (the "License");
7
+ // you may not use this file except in compliance with the License.
8
+ // You may obtain a copy of the License at
9
+ //
10
+ // http://www.apache.org/licenses/LICENSE-2.0
11
+ //
12
+ // Unless required by applicable law or agreed to in writing, software
13
+ // distributed under the License is distributed on an "AS IS" BASIS,
14
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ // See the License for the specific language governing permissions and
16
+ // limitations under the License.
17
+ const sdk_metrics_1 = require("@opentelemetry/sdk-metrics");
18
+ exports.SPANNER_METER_NAME = 'spanner-nodejs';
19
+ exports.CLIENT_METRICS_PREFIX = 'spanner.googleapis.com/internal/client';
20
+ exports.SPANNER_RESOURCE_TYPE = 'spanner_instance_client';
21
+ // Maximum time to keep MetricsTracers before considering them stale, and stop tracking them.
22
+ exports.TRACER_CLEANUP_THRESHOLD_MS = 60 * 60 * 1000; // 60 minutes
23
+ exports.TRACER_CLEANUP_INTERVAL_MS = 30 * 60 * 1000; // 30 Minutes
24
+ // OTel semantic conventions
25
+ // See https://github.com/open-telemetry/opentelemetry-js/blob/main/semantic-conventions/README.md#unstable-semconv
26
+ exports.ATTR_CLOUD_REGION = 'cloud.region';
27
+ // Minimum period that must past between metric exports
28
+ exports.MIN_EXPORT_FREQUENCY_MS = 30 * 1000;
29
+ // Monitored resource labels
30
+ exports.MONITORED_RES_LABEL_KEY_PROJECT = 'project_id';
31
+ exports.MONITORED_RES_LABEL_KEY_INSTANCE = 'instance_id';
32
+ exports.MONITORED_RES_LABEL_KEY_INSTANCE_CONFIG = 'instance_config';
33
+ exports.MONITORED_RES_LABEL_KEY_LOCATION = 'location';
34
+ exports.MONITORED_RES_LABEL_KEY_CLIENT_HASH = 'client_hash';
35
+ exports.MONITORED_RESOURCE_LABELS = new Set([
36
+ exports.MONITORED_RES_LABEL_KEY_PROJECT,
37
+ exports.MONITORED_RES_LABEL_KEY_INSTANCE,
38
+ exports.MONITORED_RES_LABEL_KEY_INSTANCE_CONFIG,
39
+ exports.MONITORED_RES_LABEL_KEY_LOCATION,
40
+ exports.MONITORED_RES_LABEL_KEY_CLIENT_HASH,
41
+ ]);
42
+ // Metric labels
43
+ exports.METRIC_LABEL_KEY_CLIENT_UID = 'client_uid';
44
+ exports.METRIC_LABEL_KEY_CLIENT_NAME = 'client_name';
45
+ exports.METRIC_LABEL_KEY_DATABASE = 'database';
46
+ exports.METRIC_LABEL_KEY_METHOD = 'method';
47
+ exports.METRIC_LABEL_KEY_STATUS = 'status';
48
+ exports.METRIC_LABELS = new Set([
49
+ exports.METRIC_LABEL_KEY_CLIENT_UID,
50
+ exports.METRIC_LABEL_KEY_CLIENT_NAME,
51
+ exports.METRIC_LABEL_KEY_DATABASE,
52
+ exports.METRIC_LABEL_KEY_METHOD,
53
+ exports.METRIC_LABEL_KEY_STATUS,
54
+ ]);
55
+ // Metric names
56
+ exports.METRIC_NAME_OPERATION_LATENCIES = 'operation_latencies';
57
+ exports.METRIC_NAME_ATTEMPT_LATENCIES = 'attempt_latencies';
58
+ exports.METRIC_NAME_OPERATION_COUNT = 'operation_count';
59
+ exports.METRIC_NAME_ATTEMPT_COUNT = 'attempt_count';
60
+ exports.METRIC_NAME_GFE_LATENCIES = 'gfe_latencies';
61
+ exports.METRIC_NAME_GFE_CONNECTIVITY_ERROR_COUNT = 'gfe_connectivity_error_count';
62
+ exports.METRIC_NAME_AFE_LATENCIES = 'afe_latencies';
63
+ exports.METRIC_NAME_AFE_CONNECTIVITY_ERROR_COUNT = 'afe_connectivity_error_count';
64
+ exports.METRIC_NAMES = new Set([
65
+ exports.METRIC_NAME_OPERATION_LATENCIES,
66
+ exports.METRIC_NAME_ATTEMPT_LATENCIES,
67
+ exports.METRIC_NAME_GFE_LATENCIES,
68
+ exports.METRIC_NAME_OPERATION_COUNT,
69
+ exports.METRIC_NAME_ATTEMPT_COUNT,
70
+ exports.METRIC_NAME_GFE_CONNECTIVITY_ERROR_COUNT,
71
+ exports.METRIC_NAME_AFE_LATENCIES,
72
+ exports.METRIC_NAME_AFE_CONNECTIVITY_ERROR_COUNT,
73
+ ]);
74
+ exports.UNKNOWN_ATTRIBUTE = 'unknown';
75
+ // Histogram Bucket boundaries
76
+ exports.HISTOGRAM_BUCKET_BOUNDARIES = [
77
+ 0.0, 0.5, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0,
78
+ 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 25.0, 30.0, 40.0, 50.0, 65.0, 80.0,
79
+ 100.0, 130.0, 160.0, 200.0, 250.0, 300.0, 400.0, 500.0, 650.0, 800.0, 1000.0,
80
+ 2000.0, 5000.0, 10000.0, 20000.0, 50000.0, 100000.0, 200000.0, 400000.0,
81
+ 800000.0, 1600000.0, 3200000.0,
82
+ ];
83
+ // Defined Views for metric aggregation
84
+ exports.OPERATION_LATENCY_VIEW = new sdk_metrics_1.View({
85
+ 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({
89
+ 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({
93
+ 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({
97
+ instrumentName: exports.METRIC_NAME_AFE_LATENCIES,
98
+ aggregation: new sdk_metrics_1.ExplicitBucketHistogramAggregation(exports.HISTOGRAM_BUCKET_BOUNDARIES),
99
+ });
100
+ exports.METRIC_VIEWS = [
101
+ exports.OPERATION_LATENCY_VIEW,
102
+ exports.ATTEMPT_LATENCY_VIEW,
103
+ exports.GFE_LATENCY_VIEW,
104
+ exports.AFE_LATENCY_VIEW,
105
+ ];
106
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1,20 @@
1
+ import { GoogleAuth } from 'google-auth-library';
2
+ export interface ExporterOptions {
3
+ /**
4
+ * Optional authentication options for Google services.
5
+ */
6
+ auth: GoogleAuth;
7
+ }
8
+ export declare enum MetricKind {
9
+ UNSPECIFIED = "METRIC_KIND_UNSPECIFIED",
10
+ GAUGE = "GAUGE",
11
+ DELTA = "DELTA",
12
+ CUMULATIVE = "CUMULATIVE"
13
+ }
14
+ /** The value type of a metric. */
15
+ export declare enum ValueType {
16
+ VALUE_TYPE_UNSPECIFIED = "VALUE_TYPE_UNSPECIFIED",
17
+ INT64 = "INT64",
18
+ DOUBLE = "DOUBLE",
19
+ DISTRIBUTION = "DISTRIBUTION"
20
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ // Copyright 2025 Google LLC
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.ValueType = exports.MetricKind = void 0;
17
+ var MetricKind;
18
+ (function (MetricKind) {
19
+ MetricKind["UNSPECIFIED"] = "METRIC_KIND_UNSPECIFIED";
20
+ MetricKind["GAUGE"] = "GAUGE";
21
+ MetricKind["DELTA"] = "DELTA";
22
+ MetricKind["CUMULATIVE"] = "CUMULATIVE";
23
+ })(MetricKind || (exports.MetricKind = MetricKind = {}));
24
+ /** The value type of a metric. */
25
+ var ValueType;
26
+ (function (ValueType) {
27
+ ValueType["VALUE_TYPE_UNSPECIFIED"] = "VALUE_TYPE_UNSPECIFIED";
28
+ ValueType["INT64"] = "INT64";
29
+ ValueType["DOUBLE"] = "DOUBLE";
30
+ ValueType["DISTRIBUTION"] = "DISTRIBUTION";
31
+ })(ValueType || (exports.ValueType = ValueType = {}));
32
+ //# sourceMappingURL=external-types.js.map
@@ -0,0 +1,13 @@
1
+ import { grpc } from 'google-gax';
2
+ /**
3
+ * Interceptor for recording metrics on gRPC calls.
4
+ *
5
+ * This interceptor records attempt metrics at the start and completion of each gRPC call,
6
+ * and also records Google Front End (GFE), AFE metrics such as latency and connectivity errors
7
+ * based on the presence and value of the 'server-timing' header in the response metadata.
8
+ *
9
+ * @param {object} options - The gRPC call options, including method definition.
10
+ * @param {function} nextCall - The next function to call in the gRPC request chain.
11
+ * @returns {grpc.InterceptingCall} - The intercepting call with added metrics recording.
12
+ */
13
+ export declare const MetricInterceptor: (options: any, nextCall: any) => grpc.InterceptingCall;
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ // Copyright 2025 Google LLC
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // https://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.MetricInterceptor = void 0;
17
+ const google_gax_1 = require("google-gax");
18
+ const metrics_tracer_factory_1 = require("./metrics-tracer-factory");
19
+ /**
20
+ * Interceptor for recording metrics on gRPC calls.
21
+ *
22
+ * This interceptor records attempt metrics at the start and completion of each gRPC call,
23
+ * and also records Google Front End (GFE), AFE metrics such as latency and connectivity errors
24
+ * based on the presence and value of the 'server-timing' header in the response metadata.
25
+ *
26
+ * @param {object} options - The gRPC call options, including method definition.
27
+ * @param {function} nextCall - The next function to call in the gRPC request chain.
28
+ * @returns {grpc.InterceptingCall} - The intercepting call with added metrics recording.
29
+ */
30
+ const MetricInterceptor = (options, nextCall) => {
31
+ return new google_gax_1.grpc.InterceptingCall(nextCall(options), {
32
+ start: function (metadata, listener, next) {
33
+ // Record attempt metric on request start
34
+ const factory = metrics_tracer_factory_1.MetricsTracerFactory.getInstance();
35
+ const requestId = metadata.get('x-goog-spanner-request-id')[0];
36
+ const metricsTracer = factory?.getCurrentTracer(requestId);
37
+ metricsTracer?.recordAttemptStart();
38
+ const newListener = {
39
+ onReceiveMetadata: function (metadata, next) {
40
+ // Record GFE/AFE Metrics
41
+ // GFE/AFE latency if available,
42
+ // or else increase the GFE/AFE connectivity error count
43
+ if (metricsTracer) {
44
+ const serverTimingHeader = metadata.getMap()['server-timing'];
45
+ const gfeTiming = metricsTracer?.extractGfeLatency(serverTimingHeader);
46
+ metricsTracer.gfeLatency = gfeTiming ?? null;
47
+ const afeTiming = metricsTracer?.extractAfeLatency(serverTimingHeader);
48
+ metricsTracer.afeLatency = afeTiming ?? null;
49
+ }
50
+ next(metadata);
51
+ },
52
+ onReceiveMessage: function (message, next) {
53
+ next(message);
54
+ },
55
+ onReceiveStatus: function (status, next) {
56
+ next(status);
57
+ // Record attempt metric completion
58
+ metricsTracer?.recordAttemptCompletion(status.code);
59
+ if (metricsTracer?.gfeLatency) {
60
+ metricsTracer?.recordGfeLatency(status.code);
61
+ }
62
+ else {
63
+ metricsTracer?.recordGfeConnectivityErrorCount(status.code);
64
+ }
65
+ if (metricsTracer?.afeLatency) {
66
+ metricsTracer?.recordAfeLatency(status.code);
67
+ }
68
+ else {
69
+ metricsTracer?.recordAfeConnectivityErrorCount(status.code);
70
+ }
71
+ },
72
+ };
73
+ next(metadata, newListener);
74
+ },
75
+ sendMessage: function (message, next) {
76
+ next(message);
77
+ },
78
+ halfClose: function (next) {
79
+ next();
80
+ },
81
+ cancel: function (next) {
82
+ next();
83
+ },
84
+ });
85
+ };
86
+ exports.MetricInterceptor = MetricInterceptor;
87
+ //# sourceMappingURL=interceptor.js.map
@@ -0,0 +1,165 @@
1
+ import { MeterProvider, MetricReader } from '@opentelemetry/sdk-metrics';
2
+ import { Counter, Histogram } from '@opentelemetry/api';
3
+ import { MetricsTracer } from './metrics-tracer';
4
+ /**
5
+ * Factory class for creating and managing MetricsTracer instances and OTEL metric instruments.
6
+ *
7
+ * The MetricsTracerFactory is responsible for:
8
+ * - Creating and managing a singleton instance for metrics collection.
9
+ * - Initializing and providing OTEL MeterProvider.
10
+ * - Generating and storing client-specific metadata (UID, hash, name, location, projectId).
11
+ * - Creating and tracking MetricsTracer instances for individual gRPC Spanner operations.
12
+ * - Providing utility methods for extracting resource attributes and managing tracers.
13
+ *
14
+ * This class is designed to be used as a singleton. Metrics collection can be enabled or disabled
15
+ * globally via the static `enabled` property, that is set from the SpannerClient.
16
+ */
17
+ export declare class MetricsTracerFactory {
18
+ private static _instance;
19
+ private _meterProvider;
20
+ private _instrumentAttemptCounter;
21
+ private _instrumentAttemptLatency;
22
+ private _instrumentOperationCounter;
23
+ private _instrumentOperationLatency;
24
+ private _instrumentGfeConnectivityErrorCount;
25
+ private _instrumentGfeLatency;
26
+ private _instrumentAfeConnectivityErrorCount;
27
+ private _instrumentAfeLatency;
28
+ private _clientHash;
29
+ private _clientName;
30
+ private _clientUid;
31
+ private _location;
32
+ private _projectId;
33
+ private _currentOperationTracers;
34
+ private _currentOperationLastUpdatedMs;
35
+ private _intervalTracerCleanup;
36
+ static _readers: MetricReader[];
37
+ static enabled: boolean;
38
+ /**
39
+ * Private constructor to enforce singleton pattern.
40
+ * Initializes client metadata and detects client location if metrics are enabled.
41
+ * Location will default to global if host machine is not a GCE or GKE instance.
42
+ * @param projectId The GCP project ID used by the Spanner Client.
43
+ */
44
+ private constructor();
45
+ /**
46
+ * Returns the singleton instance of MetricsTracerFactory.
47
+ * If metrics are disabled, returns null.
48
+ * The instance is created only once, and enabling/disabling metrics can only be done on the initial call.
49
+ * @param projectId Optional GCP project ID for the factory instantiation. Does nothing for subsequent calls.
50
+ * @returns The singleton MetricsTracerFactory instance or null if disabled.
51
+ */
52
+ static getInstance(projectId?: string): MetricsTracerFactory | null;
53
+ /**
54
+ * Returns the MeterProvider, creating it and metric instruments if not already initialized.
55
+ * Client-wide attributes that are known at this time are cached to be provided to all MetricsTracers.
56
+ * @param readers Optional array of MetricReader instances to attach to the MeterProvider.
57
+ * @returns The OTEL MeterProvider instance.
58
+ */
59
+ getMeterProvider(readers?: MetricReader[]): MeterProvider;
60
+ /**
61
+ * Resets the singleton instance of the MetricsTracerFactory.
62
+ */
63
+ static resetInstance(): Promise<void>;
64
+ /**
65
+ * Resets the MeterProvider.
66
+ */
67
+ resetMeterProvider(): Promise<void>;
68
+ /**
69
+ * Returns the attempt latency histogram instrument.
70
+ */
71
+ get instrumentAttemptLatency(): Histogram;
72
+ /**
73
+ * Returns the attempt counter instrument.
74
+ */
75
+ get instrumentAttemptCounter(): Counter;
76
+ /**
77
+ * Returns the operation latency histogram instrument.
78
+ */
79
+ get instrumentOperationLatency(): Histogram;
80
+ /**
81
+ * Returns the operation counter instrument.
82
+ */
83
+ get instrumentOperationCounter(): Counter;
84
+ /**
85
+ * Returns the GFE connectivity error count counter instrument.
86
+ */
87
+ get instrumentGfeConnectivityErrorCount(): Counter;
88
+ /**
89
+ * Returns the GFE latency histogram instrument.
90
+ */
91
+ get instrumentGfeLatency(): Histogram;
92
+ /**
93
+ * Returns the Client UID.
94
+ */
95
+ get clientUid(): string;
96
+ /**
97
+ * Returns the Client Name.
98
+ */
99
+ get clientName(): string;
100
+ /**
101
+ * Creates a new MetricsTracer for a given resource name and method, and stores it for later retrieval.
102
+ * Returns null if metrics are disabled.
103
+ * @param formattedName The formatted resource name (e.g., full database path).
104
+ * @param method The gRPC method name.
105
+ * @returns A new MetricsTracer instance or null if metrics are disabled.
106
+ */
107
+ createMetricsTracer(method: string, formattedName: string, requestId: string): MetricsTracer | null;
108
+ /**
109
+ * Takes a formatted name and parses the project, instance, and database.
110
+ * @param formattedName The formatted resource name (e.g., full database path).
111
+ * @returns An object containing project, instance, and database strings.
112
+ */
113
+ getInstanceAttributes(formattedName: string): {
114
+ project: string;
115
+ instance: string;
116
+ database: string;
117
+ };
118
+ /**
119
+ * Retrieves the current MetricsTracer for a given request id.
120
+ * Returns null if no tracer exists for the request.
121
+ * Does not implicitly create MetricsTracers as that should be done
122
+ * explicitly using the createMetricsTracer function.
123
+ * request id is expected to be as set in the gRPC metadata.
124
+ * @param requestId The request id of the gRPC call set under 'x-goog-spanner-request-id'.
125
+ * @returns The MetricsTracer instance or null if not found.
126
+ */
127
+ getCurrentTracer(requestId: string): MetricsTracer | null;
128
+ /**
129
+ * Removes the MetricsTracer associated with the given request id.
130
+ * @param requestId The request id of the gRPC call set under 'x-goog-spanner-request-id'.
131
+ */
132
+ clearCurrentTracer(requestId: string): void;
133
+ private _extractOperationRequest;
134
+ /**
135
+ * Creates and initializes all metric instruments (counters and histograms) for the MeterProvider.
136
+ * Instruments are only created if metrics are enabled.
137
+ */
138
+ private _createMetricInstruments;
139
+ /**
140
+ * Generates a unique identifier for the client_uid metric field. The identifier is composed of a
141
+ * UUID, the process ID (PID), and the hostname.
142
+ * @returns A unique string identifier for the client.
143
+ */
144
+ private static _generateClientUId;
145
+ /**
146
+ * Generates a 6-digit zero-padded lowercase hexadecimal hash using the 10 most significant bits
147
+ * of a 64-bit hash value.
148
+ *
149
+ * The primary purpose of this function is to generate a hash value for the `client_hash`
150
+ * resource label using `client_uid` metric field. The range of values is chosen to be small
151
+ * enough to keep the cardinality of the Resource targets under control. Note: If at later time
152
+ * the range needs to be increased, it can be done by increasing the value of `kPrefixLength` to
153
+ * up to 24 bits without changing the format of the returned value.
154
+ * @param clientUid The client UID string to hash.
155
+ * @returns A 6-digit hexadecimal hash string.
156
+ */
157
+ private static _generateClientHash;
158
+ /**
159
+ * Gets the location (region) of the client, otherwise returns to the "global" region.
160
+ * Uses GcpDetectorSync to detect the region from the environment.
161
+ * @returns The detected region string, or "global" if not found.
162
+ */
163
+ private static _detectClientLocation;
164
+ private _cleanMetricsTracers;
165
+ }