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
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: