Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .readme-partials.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ class Spanner extends GrpcService {
this._universeDomain = universeEndpoint;
this.projectId_ = options.projectId;
this.configureMetrics_(options.disableBuiltInMetrics);
this._logSpannerConfigurations(config);
}

get universeDomain() {
Expand Down Expand Up @@ -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.
Expand Down
Loading