Using distributed tracing

Incoming requests to Cloud Run servicesautomatically generate traces that you can view inCloud Trace.You can use these traces to identify sources of any latency issues in yourimplementation without needing to add further instrumentation in Cloud Trace.The standard W3C trace context propagation headertraceparent is automatically populated for Cloud Run requests.

However, if you do addadditional instrumentation,you can also use Cloud Trace to measure the time it takes forthe request to propagate through each layer in your implementation, for example,the time it takes to complete a database query, receive results from an APIrequest, or run some complex business logic. Each of theselayer-specific time measurements is a "span". You can view the tracesin Cloud Trace as waterfall graphs reflecting the latency values.

Billing charges

Automatically generated traces in Cloud Run, whether sampled orforced, do not result in billing charges. However, if you use Cloud Trace libraries andadd your own spans by correlating them to Cloud Run provided spans,you will be charged byCloud Trace.

Trace sampling rate

Cloud Run doesn't sample the traces for every request. When used withCloud Run, requests are sampled at a maximum rate of0.1 requests per secondfor each instance (or one request every 10 seconds). You can alsoforce a particular request to betraced. If you force a request to betraced, this request is sampled at a maximum rate of 0.1 second for eachinstance (or 10 requests per second).

Cloud Run does not support configuration of the Cloud Runsample rate.

When to add instrumentation

Traces are automatically generated without any instrumentationrequired in your service. However, in some cases, you may want to add instrumentationcode to your service to take full advantage of the Cloud Trace feature. For example,you need to add instrumentation if you want to:

  • Create custom trace spans, for example, to get timing data for how long it takes yourservice to get work back from the Cloud Translation API.
  • Propagate trace context so Cloud Trace shows the request flow acrossmultiple services as a single request.

To add instrumentation, refer toInstrumenting tracing for applications.Note that traces resulting from instrumentation in your service will incurstandardCloud Trace billing charges.

Note: If you instrument trace and use custom spans, you may want toadd labels to the spans to make it easier to filterfor them in the Cloud Trace UI.

Viewing traces

To learn more, refer to the documentation onviewing traces.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-19 UTC.