From 50dbd94d91792c047c152221908795893c167206 Mon Sep 17 00:00:00 2001 From: Surbhi Garg Date: Wed, 5 Nov 2025 20:02:04 +0530 Subject: [PATCH 1/2] chore: Add spanner configuration in logs, Update Metrics documentation --- .readme-partials.yml | 22 ++++++++++++++++++++++ src/index.ts | 31 +++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/.readme-partials.yml b/.readme-partials.yml index d924cc3a9..1240d68d7 100644 --- a/.readme-partials.yml +++ b/.readme-partials.yml @@ -4,6 +4,28 @@ introduction: |- and automatic, synchronous replication for high availability. body: |- + ## Metrics + + Cloud Spanner client supports [client-side metrics](https://cloud.google.com/spanner/docs/view-manage-client-side-metrics) that you can use along with server-side metrics to optimize performance and troubleshoot performance issues if they occur. + + Client-side metrics are measured from the time a request leaves your application to the time your application receives the response. + In contrast, server-side metrics are measured from the time Spanner receives a request until the last byte of data is sent to the client. + + These metrics are enabled by default. You can opt out of using client-side metrics with the following code: + + ```javascript + const spanner = new Spanner({ + disableBuiltInMetrics: true + }); + ``` + + You can also disable these metrics by setting `SPANNER_DISABLE_BUILTIN_METRICS` to `true`. + + > Note: Client-side metrics needs `monitoring.timeSeries.create` IAM permission to export metrics data. Ask your administrator to grant your service account the [Monitoring Metric Writer](https://cloud.google.com/iam/docs/roles-permissions/monitoring#monitoring.metricWriter) (roles/monitoring.metricWriter) IAM role on the project. + + ## Traces + Refer to the Observability README to know more about tracing support in the Cloud Spanner client. + ## Multiplexed Sessions Spanner's Multiplexed Sessions can now be used as an efficient alternative to the default session pool. This feature helps reduce diff --git a/src/index.ts b/src/index.ts index fa0bb6f9d..abd593970 100644 --- a/src/index.ts +++ b/src/index.ts @@ -502,6 +502,7 @@ class Spanner extends GrpcService { this._universeDomain = universeEndpoint; this.projectId_ = options.projectId; this.configureMetrics_(options.disableBuiltInMetrics); + this._logSpannerConfigurations(config); } get universeDomain() { @@ -1662,6 +1663,36 @@ class Spanner extends GrpcService { } } + /** + * Logs the Spanner configurations that have been set. + * + * @private + */ + private _logSpannerConfigurations(config: GrpcServiceConfig): void { + try { + const afeServerTiming = Spanner.isAFEServerTimingEnabled(); + console.log( + 'Spanner configurations:\n' + + ` Project ID: ${this.projectId_}\n` + + ` Spanner Emulator Host: ${process.env.SPANNER_EMULATOR_HOST || 'not set'}\n` + + ` Base URL: ${config.baseUrl}\n` + + ` Leader aware routing enabled: ${this.routeToLeaderEnabled}\n` + + ` Built in metrics enabled: ${MetricsTracerFactory.enabled}\n` + + ` AFE Server Timing enabled: ${afeServerTiming}\n` + + ` Spanner extended tracing enabled: ${this._observabilityOptions?.enableExtendedTracing === true || process.env.SPANNER_ENABLE_EXTENDED_TRACING === 'true' || false}\n` + + ` Spanner end-to-end tracing enabled: ${this._observabilityOptions?.enableEndToEndTracing === true || process.env.SPANNER_ENABLE_END_TO_END_TRACING === 'true' || false}\n` + + ` GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS: ${process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS || 'not set'}\n` + + ` GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_PARTITIONED_OPS: ${process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_PARTITIONED_OPS || 'not set'}\n` + + ` GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_FOR_RW: ${process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_FOR_RW || 'not set'}\n ` + ); + } catch (error) { + console.log( + 'Unable to log Spanner configurations:\n' + + error + ); + } + } + /** * Prepare a gapic request. This will cache the GAX client and replace * {{projectId}} placeholders, if necessary. From 8204159c3db6715dfee7c84eef7d0ef9dca0a99a Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Wed, 5 Nov 2025 14:40:09 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20po?= =?UTF-8?q?st-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 22 ++++++++++++++++++++++ src/index.ts | 21 +++++++++------------ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 2b29dfce7..4d3cd98c4 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,28 @@ console.log(`Query: ${rows.length} found.`); rows.forEach(row => console.log(row)); ``` +## Metrics + +Cloud Spanner client supports [client-side metrics](https://cloud.google.com/spanner/docs/view-manage-client-side-metrics) that you can use along with server-side metrics to optimize performance and troubleshoot performance issues if they occur. + +Client-side metrics are measured from the time a request leaves your application to the time your application receives the response. +In contrast, server-side metrics are measured from the time Spanner receives a request until the last byte of data is sent to the client. + +These metrics are enabled by default. You can opt out of using client-side metrics with the following code: + +```javascript +const spanner = new Spanner({ + disableBuiltInMetrics: true +}); +``` + +You can also disable these metrics by setting `SPANNER_DISABLE_BUILTIN_METRICS` to `true`. + +> Note: Client-side metrics needs `monitoring.timeSeries.create` IAM permission to export metrics data. Ask your administrator to grant your service account the [Monitoring Metric Writer](https://cloud.google.com/iam/docs/roles-permissions/monitoring#monitoring.metricWriter) (roles/monitoring.metricWriter) IAM role on the project. + +## Traces +Refer to the Observability README to know more about tracing support in the Cloud Spanner client. + ## Multiplexed Sessions Spanner's Multiplexed Sessions can now be used as an efficient alternative to the default session pool. This feature helps reduce diff --git a/src/index.ts b/src/index.ts index abd593970..339af94ce 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1676,20 +1676,17 @@ class Spanner extends GrpcService { ` Project ID: ${this.projectId_}\n` + ` Spanner Emulator Host: ${process.env.SPANNER_EMULATOR_HOST || 'not set'}\n` + ` Base URL: ${config.baseUrl}\n` + - ` Leader aware routing enabled: ${this.routeToLeaderEnabled}\n` + - ` Built in metrics enabled: ${MetricsTracerFactory.enabled}\n` + - ` AFE Server Timing enabled: ${afeServerTiming}\n` + - ` Spanner extended tracing enabled: ${this._observabilityOptions?.enableExtendedTracing === true || process.env.SPANNER_ENABLE_EXTENDED_TRACING === 'true' || false}\n` + - ` Spanner end-to-end tracing enabled: ${this._observabilityOptions?.enableEndToEndTracing === true || process.env.SPANNER_ENABLE_END_TO_END_TRACING === 'true' || false}\n` + - ` GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS: ${process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS || 'not set'}\n` + - ` GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_PARTITIONED_OPS: ${process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_PARTITIONED_OPS || 'not set'}\n` + - ` GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_FOR_RW: ${process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_FOR_RW || 'not set'}\n ` + ` Leader aware routing enabled: ${this.routeToLeaderEnabled}\n` + + ` Built in metrics enabled: ${MetricsTracerFactory.enabled}\n` + + ` AFE Server Timing enabled: ${afeServerTiming}\n` + + ` Spanner extended tracing enabled: ${this._observabilityOptions?.enableExtendedTracing === true || process.env.SPANNER_ENABLE_EXTENDED_TRACING === 'true' || false}\n` + + ` Spanner end-to-end tracing enabled: ${this._observabilityOptions?.enableEndToEndTracing === true || process.env.SPANNER_ENABLE_END_TO_END_TRACING === 'true' || false}\n` + + ` GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS: ${process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS || 'not set'}\n` + + ` GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_PARTITIONED_OPS: ${process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_PARTITIONED_OPS || 'not set'}\n` + + ` GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_FOR_RW: ${process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_FOR_RW || 'not set'}\n `, ); } catch (error) { - console.log( - 'Unable to log Spanner configurations:\n' + - error - ); + console.log('Unable to log Spanner configurations:\n' + error); } }