This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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:
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`.
> 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.
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`.
> 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.
#### Exporting client metrics to OpenTelemetry
Client metrics export to a caller-owned OpenTelemetry destination is controlled by a `MetricsProvider`,
set with `SpannerOptions.Builder.setClientMetricsProvider(MetricsProvider)`. The available
providers are:
* `DefaultMetricsProvider` (the default): no caller-owned client-metrics destination is configured.
The built-in Cloud Monitoring export follows `setBuiltInMetricsEnabled` and the
`SPANNER_DISABLE_BUILTIN_METRICS` environment variable. On Spanner Omni, where the Cloud Monitoring
export is not available, the default provider results in no client-metrics export.
* `NoopMetricsProvider`: caller-owned client metrics are explicitly disabled. The Cloud Monitoring
export is controlled separately.
* `CustomOpenTelemetryMetricsProvider`: the same Spanner client instruments are additionally recorded
on an `OpenTelemetry` instance that you provide. You own the metrics pipeline (readers, exporters
and resource). This custom destination is independent of the built-in Cloud Monitoring export on all
instance types, including Spanner Omni (`InstanceType.OMNI`), for which Cloud Monitoring export is
not available.
Client metrics are not recorded when the client runs against the Spanner emulator, regardless of the
configured `MetricsProvider`. gRPC-layer metrics are recorded on a custom destination only when the
provided `OpenTelemetry` instance is an `OpenTelemetrySdk`.
When using `CustomOpenTelemetryMetricsProvider`, it is recommended to register the Spanner
client-metrics views on a dedicated `SdkMeterProviderBuilder` with
`SpannerMetrics.configureMeterProviderBuilder(SdkMeterProviderBuilder)` before creating the
`OpenTelemetry` instance. The views rename the raw instruments, apply the Spanner latency
histogram buckets and restrict the recorded attributes to the supported client-metric labels. Attempt
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.
Cloud Spanner client supports OpenTelemetry Traces, which gives insight into the client internals and aids in debugging/troubleshooting production issues.
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.
See [Configure client-side tracing](https://cloud.google.com/spanner/docs/set-up-tracing#configure-client-side-tracing) for more details on configuring traces.
#### OpenTelemetry Dependencies
If you are using Maven, add this to your pom.xml file
Expand Down
Expand Up
@@ -129,7 +170,7 @@ custom_content: |
Spanner spanner = options.getService();
```
#### OpenTelemetry SQL Statement Tracing
The OpenTelemetry traces that are generated by the Java client include any request and transaction
tags that have been set. The traces can also include the SQL statements that are executed and the
Expand All
@@ -149,42 +190,42 @@ custom_content: |
#### OpenTelemetry API Tracing
You can enable tracing of each API call that the Spanner client executes with the `enableApiTracing`
option. These traces also include any retry attempts for an API call:
This option can also be enabled by setting the environment variable
`SPANNER_ENABLE_API_TRACING=true`.
> Note: The attribute keys that are used for additional information about retry attempts and the number of requests might change in a future release.
#### End-to-end Tracing
#### End-to-end Tracing
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:
* Identify whether the latency is due to network latency between your application and Spanner, or if the latency is occurring within Spanner.
* 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.
> Note: End-to-end traces can only be exported to [Cloud Trace](https://cloud.google.com/trace/docs).
## Instrument with OpenCensus
> Note: OpenCensus project is deprecated. See [Sunsetting OpenCensus](https://opentelemetry.io/blog/2023/sunsetting-opencensus/).
We recommend migrating to OpenTelemetry, the successor project.
## Migrate from OpenCensus to OpenTelemetry
> 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.
Expand Down
Expand Up
@@ -214,4 +255,4 @@ custom_content: |
Update your dashboards and alerts to reflect below changes
* **Metrics name** : `cloud.google.com/java` prefix has been removed from OpenTelemery metrics and instead has been added as Instrumenation Scope.
* **Metrics namespace** : OpenTelmetry exporters uses `workload.googleapis.com` namespace opposed to `custom.googleapis.com` with OpenCensus.
* **Metrics namespace** : OpenTelmetry exporters uses `workload.googleapis.com` namespace opposed to `custom.googleapis.com` with OpenCensus.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:
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`.
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`.
> 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.
> 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.
#### Exporting client metrics to OpenTelemetry
Client metrics export to a caller-owned OpenTelemetry destination is controlled by a `MetricsProvider`,
set with `SpannerOptions.Builder.setClientMetricsProvider(MetricsProvider)`. The available
providers are:
* `DefaultMetricsProvider` (the default): no caller-owned client-metrics destination is configured.
The built-in Cloud Monitoring export follows `setBuiltInMetricsEnabled` and the
`SPANNER_DISABLE_BUILTIN_METRICS` environment variable. On Spanner Omni, where the Cloud Monitoring
export is not available, the default provider results in no client-metrics export.
* `NoopMetricsProvider`: caller-owned client metrics are explicitly disabled. The Cloud Monitoring
export is controlled separately.
* `CustomOpenTelemetryMetricsProvider`: the same Spanner client instruments are additionally recorded
on an `OpenTelemetry` instance that you provide. You own the metrics pipeline (readers, exporters
and resource). This custom destination is independent of the built-in Cloud Monitoring export on all
instance types, including Spanner Omni (`InstanceType.OMNI`), for which Cloud Monitoring export is
not available.
Client metrics are not recorded when the client runs against the Spanner emulator, regardless of the
configured `MetricsProvider`. gRPC-layer metrics are recorded on a custom destination only when the
provided `OpenTelemetry` instance is an `OpenTelemetrySdk`.
When using `CustomOpenTelemetryMetricsProvider`, it is recommended to register the Spanner
client-metrics views on a dedicated `SdkMeterProviderBuilder` with
`SpannerMetrics.configureMeterProviderBuilder(SdkMeterProviderBuilder)` before creating the
`OpenTelemetry` instance. The views rename the raw instruments, apply the Spanner latency
histogram buckets and restrict the recorded attributes to the supported client-metric labels. Attempt
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.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat(spanner): add optional endpoint attribute to client metrics for location-aware routing #13740
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
feat(spanner): add optional endpoint attribute to client metrics for location-aware routing #13740
Filter by extension
Viewed files
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.