Cloud Run 서비스에 대한 수신 요청은 Cloud Trace에서 볼 수 있는 trace를 자동으로 생성합니다.
Cloud Trace에 계측을 추가할 필요 없이 이러한 trace를 사용하여 구현의 지연 시간 문제의 원인을 파악할 수 있습니다.
Cloud Run 요청에 대해 표준 W3C trace 컨텍스트 전파 헤더 traceparent가 자동으로 채워집니다.
그러나 추가 계측을 추가할 경우 Cloud Trace를 사용하여 요청이 구현의 각 레이어에 전파되는 데 걸리는 시간(예: 데이터베이스 쿼리를 완료하거나, API 요청에서 결과를 수신하거나, 복잡한 비즈니스 로직을 실행하는 데 걸리는 시간)을 측정할 수도 있습니다. 이러한 각 레이어별 시간 측정을 '스팬'이라고 합니다. Cloud Trace에서 지연 시간 값을 반영하는 폭포형 그래프로 트레이스를 볼 수 있습니다.
청구액
샘플링 여부와 상관없이 Cloud Run에서 자동으로 생성된 trace에는 요금이 청구되지 않습니다. 하지만 Cloud Trace 라이브러리를 사용하고 이와 Cloud Run 제공 스팬의 상관관계를 찾아 자체 스팬을 추가할 경우 Cloud Trace에 따라 요금이 청구됩니다.
Trace 샘플링 레이트
Cloud Run은 모든 요청의 trace를 샘플링하지 않습니다. Cloud Run에서 사용하면 요청은 인스턴스마다 최대 요청 속도(초당 요청 0.1개 또는 10초마다 요청 1개)로 샘플링됩니다. 또한 특정 요청을 trace하도록 지정할 수 있습니다. 요청을 강제로 추적하면 이 요청은 인스턴스마다 최대 0.1초(또는 초당 요청 10개) 속도로 샘플링됩니다.
Cloud Run은 Cloud Run 샘플링 레이트 구성을 지원하지 않습니다.
계측을 추가해야 하는 경우
서비스에 필요한 계측 없이 트레이스가 자동으로 생성됩니다. 하지만 경우에 따라 Cloud Trace 기능을 최대한 활용하기 위해 계측 코드를 서비스에 추가할 수 있습니다. 예를 들어 다음을 수행하려면 계측을 추가해야 합니다.
예를 들어 Cloud Translation API에서 작업을 다시 가져오는 데 걸리는 시간 데이터를 가져오기 위해 커스텀 trace 스팬을 만듭니다.
Cloud Trace가 여러 서비스의 요청 흐름을 단일 요청으로 표시하도록 trace 컨텍스트를 전파합니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[],[],null,["# Using distributed tracing\n\nIncoming requests to Cloud Run services\nautomatically generate traces that you can view in [Cloud Trace](/trace/docs/overview).\nYou can use these traces to identify sources of any latency issues in your\nimplementation without needing to add further instrumentation in Cloud Trace.\nThe standard W3C trace context propagation header [`traceparent`](https://www.w3.org/TR/trace-context/#traceparent-header) is automatically populated for Cloud Run requests.\n\nHowever, if you do add [additional instrumentation](/trace/docs/setup#instrumenting_tracing_for_applications),\nyou can also use Cloud Trace to measure the time it takes for\nthe request to propagate through each layer in your implementation, for example,\nthe time it takes to complete a database query, receive results from an API\nrequest, or run some complex business logic. Each of these\nlayer-specific time measurements is a \"span\". You can view the traces\nin Cloud Trace as waterfall graphs reflecting the latency values.\n\nBilling charges\n---------------\n\nAutomatically generated traces in Cloud Run, whether sampled or\nforced, do not result in billing charges. However, if you use Cloud Trace libraries and\nadd your own spans by correlating them to Cloud Run provided spans,\nyou will be charged by [Cloud Trace](/stackdriver/pricing#trace-costs).\n\nTrace sampling rate\n-------------------\n\nCloud Run doesn't sample the traces for every request. When used with\nCloud Run, requests are sampled at a maximum rate of\n0.1 requests per second\nfor each instance (or one request every 10 seconds). You can also [force a particular request to be\ntraced](/trace/docs/setup#force-trace). If you force a request to be\ntraced, this request is sampled at a maximum rate of 0.1 second for each\ninstance (or 10 requests per second).\n\nCloud Run does not support configuration of the Cloud Run\nsample rate.\n\nWhen to add instrumentation\n---------------------------\n\nTraces are automatically generated without any instrumentation\nrequired in your service. However, in some cases, you may want to add instrumentation\ncode to your service to take full advantage of the Cloud Trace feature. For example,\nyou need to add instrumentation if you want to:\n\n- 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.\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)\nNote that traces resulting from instrumentation in your service will incur\nstandard [Cloud Trace billing charges](/stackdriver/pricing).\n| **Note:** If you instrument trace and use custom spans, you may want to [add labels to the spans](/trace/docs/trace-labels) to make it easier to filter for them in the Cloud Trace UI.\n\nViewing traces\n--------------\n\nTo learn more, refer to the documentation on\n[viewing traces](/trace/docs/finding-traces)."]]