If you are creating a new function, see the Console Quickstart on Cloud Run. The content on this page only applies to existing legacy functions created with the Cloud Functions v1 API.
Stay organized with collections
Save and categorize content based on your preferences.
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 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.
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.
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.
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-03 UTC."],[[["\u003cp\u003eCloud Run functions automatically generate basic trace data for inbound requests to measure timing and identify latency issues.\u003c/p\u003e\n"],["\u003cp\u003eAdding instrumentation to your Cloud Run function allows for detailed tracing of sub-operations like database queries and API requests.\u003c/p\u003e\n"],["\u003cp\u003eCloud Run traces at a maximum rate of one request per ten seconds per function instance, with the ability to force tracing on specific requests.\u003c/p\u003e\n"],["\u003cp\u003eAutomatically generated traces do not incur billing charges, but custom spans created with Cloud Trace libraries do.\u003c/p\u003e\n"],["\u003cp\u003eInstrumentation is necessary to create custom trace spans and propagate trace context across multiple services, in order to monitor different service operations.\u003c/p\u003e\n"]]],[],null,["# Use distributed tracing\n=======================\n\nAll inbound requests to a Cloud Run function automatically\ngenerate a basic set of *trace data* to help you measure timing and\nidentify causes of latency in your function.\n\nFor more detailed tracing, you can add [additional instrumentation](/trace/docs/setup#instrumenting_tracing_for_applications) to your\nCloud Run function. This lets you measure the time it takes for\nthe request to complete different sub-operations within your\nfunction, such as database queries, API requests, or complex business\nlogic. Each of these layer-specific time measurements is a called a *span*.\n\nYou can view an analysis of your traces with [Cloud Trace](/trace/docs/overview).\n\nTrace sampling rate\n-------------------\n\nCloud Run functions performs tracing at a maximum rate of one request per\nten second interval for each Cloud Run function instance. You can also\n[force a particular request to be traced](/trace/docs/setup#force-trace).\n\nBilling charges\n---------------\n\nAutomatically generated traces, whether sampled or forced, don't cause billing\ncharges. However, if you use Cloud Trace libraries and\nadd your own spans by correlating them to Cloud Run functions provided spans,\nyou are charged by [Cloud Trace](/stackdriver/pricing#trace-costs).\n\nWhen to add instrumentation\n---------------------------\n\nIf you need more trace information than the automatically-generated trace data,\nyou must add instrumentation code to your service to enable additional tracing.\nFor example, you need to add instrumentation to:\n\n- Create custom trace spans, such as monitoring how long it takes your service to get results back from API requests.\n- Propagate trace context so Cloud Trace shows the request flow across multiple services as a single request.\n\nTo add instrumentation, refer to [Instrumenting tracing for applications](/trace/docs/setup#instrumenting_tracing_for_applications).\n| **Note:** If you add custom tracing, [adding labels to your spans](/trace/docs/trace-labels) makes it easier to filter for them in the Cloud Trace UI.\n\nView your traces\n----------------\n\nTo view an analysis of your trace data, see [viewing traces](/trace/docs/finding-traces)."]]