Skip to content

Commit 8f2581d

Browse files
chore: Add spanner configuration in logs, Update Metrics documentation (#2455)
* chore: Add spanner configuration in logs, Update Metrics documentation * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent b5c2d4f commit 8f2581d

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

.readme-partials.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@ introduction: |-
44
and automatic, synchronous replication for high availability.
55
66
body: |-
7+
## Metrics
8+
9+
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.
10+
11+
Client-side metrics are measured from the time a request leaves your application to the time your application receives the response.
12+
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.
13+
14+
These metrics are enabled by default. You can opt out of using client-side metrics with the following code:
15+
16+
```javascript
17+
const spanner = new Spanner({
18+
disableBuiltInMetrics: true
19+
});
20+
```
21+
22+
You can also disable these metrics by setting `SPANNER_DISABLE_BUILTIN_METRICS` to `true`.
23+
24+
> 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.
25+
26+
## Traces
27+
Refer to the Observability README to know more about tracing support in the Cloud Spanner client.
28+
729
## Multiplexed Sessions
830
931
Spanner's Multiplexed Sessions can now be used as an efficient alternative to the default session pool. This feature helps reduce

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,28 @@ console.log(`Query: ${rows.length} found.`);
8080
rows.forEach(row => console.log(row));
8181

8282
```
83+
## Metrics
84+
85+
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.
86+
87+
Client-side metrics are measured from the time a request leaves your application to the time your application receives the response.
88+
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.
89+
90+
These metrics are enabled by default. You can opt out of using client-side metrics with the following code:
91+
92+
```javascript
93+
const spanner = new Spanner({
94+
disableBuiltInMetrics: true
95+
});
96+
```
97+
98+
You can also disable these metrics by setting `SPANNER_DISABLE_BUILTIN_METRICS` to `true`.
99+
100+
> 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.
101+
102+
## Traces
103+
Refer to the Observability README to know more about tracing support in the Cloud Spanner client.
104+
83105
## Multiplexed Sessions
84106

85107
Spanner's Multiplexed Sessions can now be used as an efficient alternative to the default session pool. This feature helps reduce

src/index.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ class Spanner extends GrpcService {
502502
this._universeDomain = universeEndpoint;
503503
this.projectId_ = options.projectId;
504504
this.configureMetrics_(options.disableBuiltInMetrics);
505+
this._logSpannerConfigurations(config);
505506
}
506507

507508
get universeDomain() {
@@ -1662,6 +1663,33 @@ class Spanner extends GrpcService {
16621663
}
16631664
}
16641665

1666+
/**
1667+
* Logs the Spanner configurations that have been set.
1668+
*
1669+
* @private
1670+
*/
1671+
private _logSpannerConfigurations(config: GrpcServiceConfig): void {
1672+
try {
1673+
const afeServerTiming = Spanner.isAFEServerTimingEnabled();
1674+
console.log(
1675+
'Spanner configurations:\n' +
1676+
` Project ID: ${this.projectId_}\n` +
1677+
` Spanner Emulator Host: ${process.env.SPANNER_EMULATOR_HOST || 'not set'}\n` +
1678+
` Base URL: ${config.baseUrl}\n` +
1679+
` Leader aware routing enabled: ${this.routeToLeaderEnabled}\n` +
1680+
` Built in metrics enabled: ${MetricsTracerFactory.enabled}\n` +
1681+
` AFE Server Timing enabled: ${afeServerTiming}\n` +
1682+
` Spanner extended tracing enabled: ${this._observabilityOptions?.enableExtendedTracing === true || process.env.SPANNER_ENABLE_EXTENDED_TRACING === 'true' || false}\n` +
1683+
` Spanner end-to-end tracing enabled: ${this._observabilityOptions?.enableEndToEndTracing === true || process.env.SPANNER_ENABLE_END_TO_END_TRACING === 'true' || false}\n` +
1684+
` GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS: ${process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS || 'not set'}\n` +
1685+
` GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_PARTITIONED_OPS: ${process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_PARTITIONED_OPS || 'not set'}\n` +
1686+
` GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_FOR_RW: ${process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_FOR_RW || 'not set'}\n `,
1687+
);
1688+
} catch (error) {
1689+
console.log('Unable to log Spanner configurations:\n' + error);
1690+
}
1691+
}
1692+
16651693
/**
16661694
* Prepare a gapic request. This will cache the GAX client and replace
16671695
* {{projectId}} placeholders, if necessary.

0 commit comments

Comments
 (0)