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/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 fa0bb6f9d..339af94ce 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,33 @@ 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.