# Use distributed tracing

All inbound requests to a Cloud Run function automatically
generate a basic set of *trace data* to help you measure timing and
identify causes of latency in your function.

For more detailed tracing, you can add [additional instrumentation](https://docs.cloud.google.com/trace/docs/setup.md.txt#instrumenting_tracing_for_applications) to your
Cloud Run function. This lets you measure the time it takes for
the request to complete different sub-operations within your
function, such as database queries, API requests, or complex business
logic. Each of these layer-specific time measurements is a called a *span*.

You can view an analysis of your traces with [Cloud Trace](https://docs.cloud.google.com/trace/docs/overview.md.txt).

## Trace sampling rate

Cloud Run functions performs tracing at a maximum rate of one request per
ten second interval for each Cloud Run function instance. You can also
[force a particular request to be traced](https://docs.cloud.google.com/trace/docs/setup.md.txt#force-trace).

## Billing charges

Automatically generated traces, whether sampled or forced, don't cause billing
charges. However, if you use Cloud Trace libraries and
add your own spans by correlating them to Cloud Run functions provided spans,
you are charged by [Cloud Trace](https://cloud.google.com/stackdriver/pricing#trace-costs).

## When to add instrumentation

If you need more trace information than the automatically-generated trace data,
you must add instrumentation code to your service to enable additional tracing.
For example, you need to add instrumentation to:

- Create custom trace spans, such as monitoring how long it takes your service to get results back from API requests.
- 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](https://docs.cloud.google.com/trace/docs/setup.md.txt#instrumenting_tracing_for_applications).

> [!NOTE]
> **Note:** If you add custom tracing, [adding labels to your spans](https://docs.cloud.google.com/trace/docs/trace-labels.md.txt) makes it easier to filter for them in the Cloud Trace UI.

## View your traces

To view an analysis of your trace data, see [viewing traces](https://docs.cloud.google.com/trace/docs/finding-traces.md.txt).