@google-cloud/spanner 8.7.0 → 8.7.1
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.
package/build/src/index.d.ts
CHANGED
package/build/src/index.js
CHANGED
|
@@ -163,6 +163,7 @@ class Spanner extends service_1.GrpcService {
|
|
|
163
163
|
sessionLabels;
|
|
164
164
|
_universeDomain;
|
|
165
165
|
_isInSecureCredentials;
|
|
166
|
+
_metricsEnabled = false;
|
|
166
167
|
static _isAFEServerTimingEnabled;
|
|
167
168
|
_nthClientId;
|
|
168
169
|
/**
|
|
@@ -766,10 +767,12 @@ class Spanner extends service_1.GrpcService {
|
|
|
766
767
|
configureMetrics_(disableBuiltInMetrics) {
|
|
767
768
|
// Only enable metrics if not explicitly disabled and we are not using
|
|
768
769
|
// insecure credentials.
|
|
769
|
-
const
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
770
|
+
const metricsExplicitlyDisabled = process.env.SPANNER_DISABLE_BUILTIN_METRICS === 'true' ||
|
|
771
|
+
!!disableBuiltInMetrics;
|
|
772
|
+
this._metricsEnabled =
|
|
773
|
+
!metricsExplicitlyDisabled && !this._isInSecureCredentials;
|
|
774
|
+
metrics_tracer_factory_1.MetricsTracerFactory.enabled = this._metricsEnabled;
|
|
775
|
+
if (this._metricsEnabled) {
|
|
773
776
|
try {
|
|
774
777
|
this.auth.getProjectId((err, projectId) => {
|
|
775
778
|
if (err || !projectId) {
|
|
@@ -778,7 +781,6 @@ class Spanner extends service_1.GrpcService {
|
|
|
778
781
|
err);
|
|
779
782
|
return;
|
|
780
783
|
}
|
|
781
|
-
metrics_tracer_factory_1.MetricsTracerFactory.enabled = metricsEnabled;
|
|
782
784
|
this.projectId_ = projectId;
|
|
783
785
|
const factory = metrics_tracer_factory_1.MetricsTracerFactory.getInstance(projectId);
|
|
784
786
|
const periodicReader = new sdk_metrics_1.PeriodicExportingMetricReader({
|
|
@@ -848,7 +850,7 @@ class Spanner extends service_1.GrpcService {
|
|
|
848
850
|
// Attach the x-goog-spanner-request-id to the currently active span.
|
|
849
851
|
(0, request_id_header_1.attributeXGoogSpannerRequestIdToActiveSpan)(config);
|
|
850
852
|
const interceptors = [];
|
|
851
|
-
if (
|
|
853
|
+
if (this._metricsEnabled) {
|
|
852
854
|
interceptors.push(interceptor_1.MetricInterceptor);
|
|
853
855
|
}
|
|
854
856
|
const requestFn = gaxClient[config.method].bind(gaxClient, reqOpts,
|
|
@@ -919,7 +921,9 @@ class Spanner extends service_1.GrpcService {
|
|
|
919
921
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
920
922
|
request(config, callback) {
|
|
921
923
|
let metricsTracer = null;
|
|
922
|
-
if (
|
|
924
|
+
if (this._metricsEnabled &&
|
|
925
|
+
config.client === 'SpannerClient' &&
|
|
926
|
+
this.projectId_) {
|
|
923
927
|
metricsTracer =
|
|
924
928
|
metrics_tracer_factory_1.MetricsTracerFactory?.getInstance(this.projectId_)?.createMetricsTracer(config.method, config.reqOpts.database ?? config.reqOpts.session, config.headers['x-goog-spanner-request-id']) ?? null;
|
|
925
929
|
}
|
|
@@ -982,7 +986,9 @@ class Spanner extends service_1.GrpcService {
|
|
|
982
986
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
983
987
|
requestStream(config) {
|
|
984
988
|
let metricsTracer = null;
|
|
985
|
-
if (
|
|
989
|
+
if (this._metricsEnabled &&
|
|
990
|
+
config.client === 'SpannerClient' &&
|
|
991
|
+
this.projectId_) {
|
|
986
992
|
metricsTracer =
|
|
987
993
|
metrics_tracer_factory_1.MetricsTracerFactory?.getInstance(this.projectId_)?.createMetricsTracer(config.method, config.reqOpts.session ?? config.reqOpts.database, config.headers['x-goog-spanner-request-id']) ?? null;
|
|
988
994
|
}
|
|
@@ -255,7 +255,7 @@ class MetricsTracerFactory {
|
|
|
255
255
|
* @param requestId The request id of the gRPC call set under 'x-goog-spanner-request-id'.
|
|
256
256
|
*/
|
|
257
257
|
clearCurrentTracer(requestId) {
|
|
258
|
-
const operationRequest = this._extractOperationRequest(requestId);
|
|
258
|
+
const operationRequest = this._extractOperationRequest(requestId) || requestId;
|
|
259
259
|
if (!this._currentOperationTracers.has(operationRequest)) {
|
|
260
260
|
return;
|
|
261
261
|
}
|
|
@@ -14,7 +14,7 @@ declare class MetricAttemptTracer {
|
|
|
14
14
|
/**
|
|
15
15
|
* Returns the start time of the attempt.
|
|
16
16
|
*/
|
|
17
|
-
get startTime():
|
|
17
|
+
get startTime(): number;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* MetricOperationTracer tracks the lifecycle and metadata of a single gRPC spanner operation,
|
|
@@ -50,7 +50,7 @@ declare class MetricOperationTracer {
|
|
|
50
50
|
/**
|
|
51
51
|
* Returns the start time of the operation.
|
|
52
52
|
*/
|
|
53
|
-
get startTime():
|
|
53
|
+
get startTime(): number;
|
|
54
54
|
/**
|
|
55
55
|
* Increments the attempt count and creates a new MetricAttemptTracer
|
|
56
56
|
* for tracking the next attempt within this operation.
|
|
@@ -107,7 +107,7 @@ export declare class MetricsTracer {
|
|
|
107
107
|
*/
|
|
108
108
|
constructor(_instrumentAttemptCounter: Counter | null, _instrumentAttemptLatency: Histogram | null, _instrumentOperationCounter: Counter | null, _instrumentOperationLatency: Histogram | null, _instrumentGfeConnectivityErrorCount: Counter | null, _instrumentGfeLatency: Histogram | null, _instrumentAfeConnectivityErrorCount: Counter | null, _instrumentAfeLatency: Histogram | null, enabled: boolean, _database: string, _instance: string, _projectId: string, _methodName: string, _request: string);
|
|
109
109
|
/**
|
|
110
|
-
* Returns the difference in milliseconds between two
|
|
110
|
+
* Returns the difference in milliseconds between two times.
|
|
111
111
|
* @param start The start time.
|
|
112
112
|
* @param end The end time.
|
|
113
113
|
* @returns The time difference in milliseconds.
|
|
@@ -29,7 +29,7 @@ class MetricAttemptTracer {
|
|
|
29
29
|
_startTime;
|
|
30
30
|
status;
|
|
31
31
|
constructor() {
|
|
32
|
-
this._startTime =
|
|
32
|
+
this._startTime = performance.now();
|
|
33
33
|
this.status = grpc_js_1.status[grpc_js_1.status.UNKNOWN];
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
@@ -63,7 +63,7 @@ class MetricOperationTracer {
|
|
|
63
63
|
_currentAttempt;
|
|
64
64
|
constructor() {
|
|
65
65
|
this._attemptCount = 0;
|
|
66
|
-
this._startTime =
|
|
66
|
+
this._startTime = performance.now();
|
|
67
67
|
this._currentAttempt = null;
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
@@ -167,13 +167,13 @@ class MetricsTracer {
|
|
|
167
167
|
this._clientAttributes[constants_1.MONITORED_RES_LABEL_KEY_INSTANCE] = _instance;
|
|
168
168
|
}
|
|
169
169
|
/**
|
|
170
|
-
* Returns the difference in milliseconds between two
|
|
170
|
+
* Returns the difference in milliseconds between two times.
|
|
171
171
|
* @param start The start time.
|
|
172
172
|
* @param end The end time.
|
|
173
173
|
* @returns The time difference in milliseconds.
|
|
174
174
|
*/
|
|
175
175
|
_getMillisecondTimeDifference(start, end) {
|
|
176
|
-
return end
|
|
176
|
+
return end - start;
|
|
177
177
|
}
|
|
178
178
|
/**
|
|
179
179
|
* Gets the current client and resource attributes for metrics.
|
|
@@ -224,7 +224,7 @@ class MetricsTracer {
|
|
|
224
224
|
return;
|
|
225
225
|
this.currentOperation.currentAttempt.status = grpc_js_1.status[statusCode];
|
|
226
226
|
const attemptAttributes = this._createAttemptOtelAttributes();
|
|
227
|
-
const endTime =
|
|
227
|
+
const endTime = performance.now();
|
|
228
228
|
const attemptLatencyMilliseconds = this._getMillisecondTimeDifference(this.currentOperation.currentAttempt.startTime, endTime);
|
|
229
229
|
this.instrumentAttemptLatency?.record(attemptLatencyMilliseconds, attemptAttributes);
|
|
230
230
|
this.instrumentAttemptCounter?.add(1, attemptAttributes);
|
|
@@ -247,7 +247,7 @@ class MetricsTracer {
|
|
|
247
247
|
recordOperationCompletion() {
|
|
248
248
|
if (!this.enabled || !this.currentOperation)
|
|
249
249
|
return;
|
|
250
|
-
const endTime =
|
|
250
|
+
const endTime = performance.now();
|
|
251
251
|
const operationAttributes = this._createOperationOtelAttributes();
|
|
252
252
|
const operationLatencyMilliseconds = this._getMillisecondTimeDifference(this.currentOperation.startTime, endTime);
|
|
253
253
|
this.instrumentOperationCounter?.add(1, operationAttributes);
|