You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: java-spanner/.readme-partials.yaml
+65-24Lines changed: 65 additions & 24 deletions
Original file line number
Diff line number
Diff line change
@@ -53,29 +53,70 @@ custom_content: |
53
53
## Metrics
54
54
55
55
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.
56
-
57
-
Client-side metrics are measured from the time a request leaves your application to the time your application receives the response.
56
+
57
+
Client-side metrics are measured from the time a request leaves your application to the time your application receives the response.
58
58
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.
59
-
60
-
These metrics are enabled by default. You can opt out of using client-side metrics with the following code:
61
-
59
+
60
+
The default Cloud Monitoring export for these metrics is enabled by default. You can opt out of the default Cloud Monitoring export with the following code:
You can also disable these metrics by setting `SPANNER_DISABLE_BUILTIN_METRICS` to `true`.
69
-
70
-
> 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.
67
+
68
+
You can also disable the default Cloud Monitoring export by setting `SPANNER_DISABLE_BUILTIN_METRICS` to `true`. These controls affect only the Cloud Monitoring export. They do not affect a caller-owned client-metrics export configured with `CustomOpenTelemetryMetricsProvider`.
69
+
70
+
> Note: Client-side metrics needs `monitoring.timeSeries.create` IAM permission to export metrics data to Cloud Monitoring. 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.
71
+
72
+
#### Exporting client metrics to OpenTelemetry
73
+
74
+
Client metrics export to a caller-owned OpenTelemetry destination is controlled by a `MetricsProvider`,
75
+
set with `SpannerOptions.Builder.setClientMetricsProvider(MetricsProvider)`. The available
76
+
providers are:
77
+
78
+
* `DefaultMetricsProvider` (the default): no caller-owned client-metrics destination is configured.
79
+
The built-in Cloud Monitoring export follows `setBuiltInMetricsEnabled` and the
80
+
`SPANNER_DISABLE_BUILTIN_METRICS` environment variable. On Spanner Omni, where the Cloud Monitoring
81
+
export is not available, the default provider results in no client-metrics export.
82
+
* `NoopMetricsProvider`: caller-owned client metrics are explicitly disabled. The Cloud Monitoring
83
+
export is controlled separately.
84
+
* `CustomOpenTelemetryMetricsProvider`: the same Spanner client instruments are additionally recorded
85
+
on an `OpenTelemetry` instance that you provide. You own the metrics pipeline (readers, exporters
86
+
and resource). This custom destination is independent of the built-in Cloud Monitoring export on all
87
+
instance types, including Spanner Omni (`InstanceType.OMNI`), for which Cloud Monitoring export is
88
+
not available.
89
+
90
+
Client metrics are not recorded when the client runs against the Spanner emulator, regardless of the
91
+
configured `MetricsProvider`. gRPC-layer metrics are recorded on a custom destination only when the
92
+
provided `OpenTelemetry` instance is an `OpenTelemetrySdk`.
93
+
94
+
When using `CustomOpenTelemetryMetricsProvider`, it is recommended to register the Spanner
95
+
client-metrics views on a dedicated `SdkMeterProviderBuilder` with
96
+
`SpannerMetrics.configureMeterProviderBuilder(SdkMeterProviderBuilder)` before creating the
97
+
`OpenTelemetry` instance. The views rename the raw instruments, apply the Spanner latency
98
+
histogram buckets and restrict the recorded attributes to the supported client-metric labels. Attempt
99
+
metrics include the routed `endpoint` label when Spanner Omni location-aware routing supplies it.
Cloud Spanner client supports OpenTelemetry Traces, which gives insight into the client internals and aids in debugging/troubleshooting production issues.
114
+
Cloud Spanner client supports OpenTelemetry Traces, which gives insight into the client internals and aids in debugging/troubleshooting production issues.
74
115
75
116
By default, the functionality is disabled. You need to add OpenTelemetry dependencies, enable OpenTelemetry traces and must configure the OpenTelemetry with appropriate exporters at the startup of your application.
76
117
77
118
See [Configure client-side tracing](https://cloud.google.com/spanner/docs/set-up-tracing#configure-client-side-tracing) for more details on configuring traces.
78
-
119
+
79
120
#### OpenTelemetry Dependencies
80
121
81
122
If you are using Maven, add this to your pom.xml file
@@ -129,7 +170,7 @@ custom_content: |
129
170
130
171
Spanner spanner = options.getService();
131
172
```
132
-
173
+
133
174
#### OpenTelemetry SQL Statement Tracing
134
175
The OpenTelemetry traces that are generated by the Java client include any request and transaction
135
176
tags that have been set. The traces can also include the SQL statements that are executed and the
@@ -149,42 +190,42 @@ custom_content: |
149
190
#### OpenTelemetry API Tracing
150
191
You can enable tracing of each API call that the Spanner client executes with the `enableApiTracing`
151
192
option. These traces also include any retry attempts for an API call:
This option can also be enabled by setting the environment variable
161
202
`SPANNER_ENABLE_API_TRACING=true`.
162
203
163
204
> Note: The attribute keys that are used for additional information about retry attempts and the number of requests might change in a future release.
164
-
165
-
#### End-to-end Tracing
166
-
205
+
206
+
#### End-to-end Tracing
207
+
167
208
In addition to client-side tracing, you can opt in for [end-to-end tracing](https://cloud.google.com/spanner/docs/tracing-overview#end-to-end-side-tracing). End-to-end tracing helps you understand and debug latency issues that are specific to Spanner such as the following:
168
209
* Identify whether the latency is due to network latency between your application and Spanner, or if the latency is occurring within Spanner.
169
210
* Identify the Google Cloud regions that your application requests are being routed through and if there is a cross-region request. A cross-region request usually means higher latencies between your application and Spanner.
Refer to [Configure end-to-end tracing](https://cloud.google.com/spanner/docs/set-up-tracing#configure-end-to-end-tracing) to configure end-to-end tracing and to understand its attributes.
179
-
220
+
180
221
> Note: End-to-end traces can only be exported to [Cloud Trace](https://cloud.google.com/trace/docs).
181
-
182
-
222
+
223
+
183
224
## Instrument with OpenCensus
184
225
185
226
> Note: OpenCensus project is deprecated. See [Sunsetting OpenCensus](https://opentelemetry.io/blog/2023/sunsetting-opencensus/).
186
227
We recommend migrating to OpenTelemetry, the successor project.
187
-
228
+
188
229
## Migrate from OpenCensus to OpenTelemetry
189
230
190
231
> Using the [OpenTelemetry OpenCensus Bridge](https://mvnrepository.com/artifact/io.opentelemetry/opentelemetry-opencensus-shim), you can immediately begin exporting your metrics and traces with OpenTelemetry.
@@ -214,4 +255,4 @@ custom_content: |
214
255
215
256
Update your dashboards and alerts to reflect below changes
216
257
* **Metrics name** : `cloud.google.com/java` prefix has been removed from OpenTelemery metrics and instead has been added as Instrumenation Scope.
217
-
* **Metrics namespace** : OpenTelmetry exporters uses `workload.googleapis.com` namespace opposed to `custom.googleapis.com` with OpenCensus.
258
+
* **Metrics namespace** : OpenTelmetry exporters uses `workload.googleapis.com` namespace opposed to `custom.googleapis.com` with OpenCensus.
Client-side metrics are measured from the time a request leaves your application to the time your application receives the response.
156
156
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.
157
157
158
-
These metrics are enabled by default. You can opt out of using client-side metrics with the following code:
158
+
The default Cloud Monitoring export for these metrics is enabled by default. You can opt out of the default Cloud Monitoring export with the following code:
You can also disable these metrics by setting `SPANNER_DISABLE_BUILTIN_METRICS` to `true`.
166
+
You can also disable the default Cloud Monitoring export by setting `SPANNER_DISABLE_BUILTIN_METRICS` to `true`. These controls affect only the Cloud Monitoring export. They do not affect a caller-owned client-metrics export configured with `CustomOpenTelemetryMetricsProvider`.
167
167
168
-
> 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.
168
+
> Note: Client-side metrics needs `monitoring.timeSeries.create` IAM permission to export metrics data to Cloud Monitoring. 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.
169
+
170
+
#### Exporting client metrics to OpenTelemetry
171
+
172
+
Client metrics export to a caller-owned OpenTelemetry destination is controlled by a `MetricsProvider`,
173
+
set with `SpannerOptions.Builder.setClientMetricsProvider(MetricsProvider)`. The available
174
+
providers are:
175
+
176
+
*`DefaultMetricsProvider` (the default): no caller-owned client-metrics destination is configured.
177
+
The built-in Cloud Monitoring export follows `setBuiltInMetricsEnabled` and the
178
+
`SPANNER_DISABLE_BUILTIN_METRICS` environment variable. On Spanner Omni, where the Cloud Monitoring
179
+
export is not available, the default provider results in no client-metrics export.
180
+
*`NoopMetricsProvider`: caller-owned client metrics are explicitly disabled. The Cloud Monitoring
181
+
export is controlled separately.
182
+
*`CustomOpenTelemetryMetricsProvider`: the same Spanner client instruments are additionally recorded
183
+
on an `OpenTelemetry` instance that you provide. You own the metrics pipeline (readers, exporters
184
+
and resource). This custom destination is independent of the built-in Cloud Monitoring export on all
185
+
instance types, including Spanner Omni (`InstanceType.OMNI`), for which Cloud Monitoring export is
186
+
not available.
187
+
188
+
Client metrics are not recorded when the client runs against the Spanner emulator, regardless of the
189
+
configured `MetricsProvider`. gRPC-layer metrics are recorded on a custom destination only when the
190
+
provided `OpenTelemetry` instance is an `OpenTelemetrySdk`.
191
+
192
+
When using `CustomOpenTelemetryMetricsProvider`, it is recommended to register the Spanner
193
+
client-metrics views on a dedicated `SdkMeterProviderBuilder` with
194
+
`SpannerMetrics.configureMeterProviderBuilder(SdkMeterProviderBuilder)` before creating the
195
+
`OpenTelemetry` instance. The views rename the raw instruments, apply the Spanner latency
196
+
histogram buckets and restrict the recorded attributes to the supported client-metric labels. Attempt
197
+
metrics include the routed `endpoint` label when Spanner Omni location-aware routing supplies it.
Cloud Spanner client supports OpenTelemetry Traces, which gives insight into the client internals and aids in debugging/troubleshooting production issues.
0 commit comments