View and manage client-side metrics

This page offers information about viewing and managing client-side metrics. Client-side metrics offer latency information about the client's RPC requests to Spanner.

Spanner provides 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. 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.

Access client-side metrics

Client-side metrics are available on the following client libraries:

  • Java in version 6.81.0 and later.
  • Go in version 1.71.0 and later.

Client-side metrics are available after you enable the Cloud Monitoring API.

Enable the Monitoring API

Client-side metrics are available for users or service accounts that are granted the Identity and Access Management (IAM) monitoring.timeSeries.create permission. This permission is included in the following Spanner IAM roles:

For more information about granting roles, see Manage access to projects, folders, and organizations.

You might also be able to get the required monitoring.timeSeries.create IAM permission through custom roles.

View metrics in the Metrics Explorer

  1. In the Google Cloud console, go to the Metrics Explorer page.

    Go to Metrics Explorer

  2. Select your project.

  3. Click Select a metric.

  4. Search for spanner.googleapis.com/client.

  5. Select the metric, and then click Apply.

For more information about grouping or aggregating your metric, see Build queries using menus.

Your application needs to run for at least a minute before you can view any published metrics.

Opt out of client-side metrics

If you are already using OpenTelemetry to capture custom client metrics, you can choose to opt out of using client-side metrics by using the following code:

Java

Spanner spanner =
  SpannerOptions.newBuilder()
    .setProjectId("test-project")
    .setBuiltInMetricsEnabled(false)
    .build()
    .getService();

Go

    client, err := spanner.NewClientWithConfig(ctx, database, spanner.ClientConfig{
    DisableNativeMetrics: true,
    })

Costs

There is no charge to view client-side metrics in Cloud Monitoring. Use of the Monitoring API might incur charges. For more information, see Google Cloud Observability pricing.

What's next