Incoming requests to Cloud Run services
automatically generate traces that you can view in Cloud Trace.
You can use these traces to identify sources of any latency issues in your
implementation without needing to add further instrumentation in Cloud Trace.
The standard W3C trace context propagation header traceparent
is automatically populated for Cloud Run requests.
However, if you do add additional instrumentation, you can also use Cloud Trace to measure the time it takes for the request to propagate through each layer in your implementation, for example, the time it takes to complete a database query, receive results from an API request, or run some complex business logic. Each of these layer-specific time measurements is a "span". You can view the traces in Cloud Trace as waterfall graphs reflecting the latency values.
Billing charges
Automatically generated traces in Cloud Run, whether sampled or forced, do not result in billing charges. However, if you use Cloud Trace libraries and add your own spans by correlating them to Cloud Run provided spans, you will be charged by Cloud Trace.
Trace sampling rate
Cloud Run doesn't sample the traces for every request. When used with Cloud Run, requests are sampled at a maximum rate of 0.1 requests per second for each instance (or one request every 10 seconds). You can also force a particular request to be traced. If you force a request to be traced, this request is sampled at a maximum rate of 0.1 second for each instance (or 10 requests per second).
Cloud Run does not support configuration of the Cloud Run sample rate.
When to add instrumentation
Traces are automatically generated without any instrumentation required in your service. However, in some cases, you may want to add instrumentation code 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 your service to get work back from the Cloud Translation API.
- Propagate trace context so Cloud Trace shows the request flow across multiple services as a single request.
To add instrumentation, refer to Instrumenting tracing for applications Note that traces resulting from instrumentation in your service will incur standard Cloud Trace billing charges.
Viewing traces
To learn more, refer to the documentation on viewing traces.