This document describes how to capture custom client-side metrics using OpenCensus. Custom client-side metrics can help find the source of latency in your system. For more information, see Identify the latency point.
Spanner client libraries also provide statistics and traces using the OpenCensus observability framework. By default, the framework is disabled.
You need to be familiar with custom metrics associated with OpenCensus and have the OpenCensus metrics libraries and the Google Cloud Observability exporter available to your application before capturing custom metrics.
Capture client round-trip latency
Client round-trip latency is the duration in milliseconds between the first byte of the Spanner API request that the client sends to the database and the last byte of the response that the client receives from the database. The API request can be sent through the Google Front End (GFE) or theCloud Spanner API frontend.
You can capture client round-trip latency using the following code:
Java
Go
The code sample appends the string roundtrip_latency
to the metric name when
it's exported to Cloud Monitoring. You can search for this metric in
Cloud Monitoring using the appended string.
Capture GFE latency
GFE latency is the duration in milliseconds between when the Google network receives a remote procedure call from the client and when the GFE receives the first byte of the response.
You can capture GFE latency using the following code:
Java
Go
The code sample appends the string spanner/gfe_latency
to the metric name when
it's exported to Cloud Monitoring. You can search for this metric in
Cloud Monitoring using the appended string.
Capture Cloud Spanner API request latency
Cloud Spanner API request latency is the time in seconds between the first byte of client request that the Cloud Spanner API frontend receives and the last byte of response that the Cloud Spanner API frontend sends.
This latency metric is available as part of Spanner metrics in Cloud Monitoring.
Capture query latency
Query latency is the duration in milliseconds to run SQL queries in the Spanner database.
You can capture query latency using the following code:
Java
Go
The code sample appends the string spanner/query_stats_elapsed
to the metric name when
it's exported to Cloud Monitoring. You can search for this metric on
Cloud Monitoring using the appended string.
View metrics in the Metrics Explorer
In the Google Cloud console, go to the Metrics Explorer page.
Select your project.
Click Select a metric.
Search for a latency metrics using the following strings:
roundtrip_latency
: for the client round-trip latency metric.spanner/gfe_latency
: for the GFE latency metric.spanner/query_stats_elapsed
: for the query latency metric.
Select the metric, then click Apply.
For more information on grouping or aggregating your metric, see Build queries using menus.
What's next
Learn more about OpenCensus.
Learn how to use metrics to diagnose latency.