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.
Before you begin
- Client-side metrics are available after you enable the Cloud Monitoring API. 
- 
  
  
  
  
  
  
  
    
    
    
    
    
    
      
      
        
        
      
      
    
    
    
    
    
  
  
  
  
  
  
  
  
    
    
    
    
  
    
    
    
    
      
      
      
      
      
      
        
        
          
        
        
      
      
      
      
      
    
  
  
  To ensure that your service account has the necessary permission to access client-side metrics, ask your administrator to grant your service account the Monitoring Metric Writer ( roles/monitoring.metricWriter) IAM role on the project. For more information about granting roles, see Manage access to projects, folders, and organizations.This predefined role contains the monitoring.timeSeries.createpermission, which is required to access client-side metrics.Your administrator might also be able to give your service account this permission with custom roles or other predefined roles. 
Access client-side metrics
You can access client-side metrics using the following client libraries:
To view the client-side metrics in the Metrics Explorer, do the following:
- In the Google Cloud console, go to the Metrics Explorer page. 
- Select your project. 
- Click Select a metric. 
- Search for - spanner.googleapis.com/client.
- 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,
    })
Pricing
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.