[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2024-12-21 UTC。"],[],[],null,["# Trace context\n\nThis document briefly describes *context* , which refers to state, and\nto *context propagation*, which refers to passing state information to\nchild operations. For distributed tracing, the trace ID and the ID of the\nspan being processed must be passed to child operations.\n\nChild operations create a span and set the following fields:\n\n- *Span ID*: A unique identifier for the child operation. If the same operation is executed multiple times, then there are multiple spans for that operation, each with a unique identifier.\n- *Trace ID*: The unique identifier of the end-to-end operation in which this particular overall operation took place. The value of this field is provided by the parent.\n- *Parent span ID* : The unique identifier of parent's span. The value of this field is provided by the parent. For root spans, this ID is `null`.\n\nThe values of the trace ID, span ID, and parent span ID fields let a\ndistributed tracing system correctly link spans together to form a trace.\nFor example, Cloud Trace stores spans in a repository, and it uses these\nID fields to identify which spans compose a trace.\n\nContext might include other state information that is useful for distributed\ntracing. For example, the World Wide Web Consortium (W3C) standard includes\ninformation about whether the parent span was [sampled](/trace/docs/trace-sampling).\n\nProtocols for context propagation\n---------------------------------\n\nThe following sections describe how specific request protocols\npropagate context.\n\n### HTTP requests\n\nFor HTTP requests, context propagation is typically accomplished through\nHTTP headers such as the `traceparent` and `tracestate` headers, which were\n[standardized by W3C](https://www.w3.org/TR/trace-context/).\nGoogle Cloud services that support trace context propagation typically support\nboth the `traceparent` and the [legacy `X-Cloud-Trace-Context` header](#legacy-http-header).\n\nWhen possible, we recommend that you use the\n[`traceparent` header](https://www.w3.org/TR/trace-context/) in your applications. Your\napplication might need to use the legacy `X-Cloud-Trace-Context` header or it\nmight need to support receiving trace context in a different format.\n\nIf you have an application that only supports the `X-Cloud-Trace-Context`\nheader, then we recommend that you update your application to support, and\nprioritize, the `traceparent` header. Your application can continue to use the\n`X-Cloud-Trace-Context` header as a fallback solution.\n\nThe following table summarizes some significant differences between\nthe two headers:\n\n#### Legacy `X-Cloud-Trace-Context` header\n\n| **Note:** When possible, we recommend that you use the [`traceparent` header](https://www.w3.org/TR/trace-context/) in your applications.\n\nThe `X-Cloud-Trace-Context` header that is used by Google Cloud predates the\nW3C specification.\nFor backwards compatibility, some Google Cloud services continue to accept,\ngenerate, and propagate the `X-Cloud-Trace-Context` header. However, it is\nlikely that these systems also support the `traceparent` header.\n\nThe `X-Cloud-Trace-Context` header has the following format: \n\n X-Cloud-Trace-Context: TRACE_ID/SPAN_ID;o=OPTIONS\n\nThe fields of header are defined as follows:\n\n- `TRACE_ID` is a 32-character hexadecimal value representing a 128-bit number.\n- `SPAN_ID` is a 64-bit decimal representation of the unsigned span ID.\n- `OPTIONS` supports `0` (parent not sampled) and `1` (parent was sampled).\n\n### gRPC requests\n\nFor [gRPC](https://grpc.io/) requests, context propagation is accomplished using\n[gRPC metadata](https://grpc.io/docs/guides/metadata/), which is implemented on top of HTTP headers.\ngRPC applications might use the `traceparent` header or a\nmetadata context key called `grpc-trace-bin`.\n\nFor components that you own, we recommend that you use the `traceparent` header.\n\nContext propagation for Google Cloud services\n---------------------------------------------\n\n| **Note:** Cloud Trace isn't responsible for context propagation. Context propagation is the responsibility of the components that submit data to Cloud Trace. These components include Google Cloud services and user applications.\n\nGoogle Cloud services might act as initiators or intermediaries in request\nprocessing. For example, the following services are known to participate in\nprocessing requests:\n\n- [Apigee](/apigee/docs/api-platform/develop/enabling-distributed-trace)\n- [App Engine](/appengine)\n- [Cloud Endpoints](/endpoints/docs/openapi/tracing#trace_sampling_rate)\n- [Cloud Load Balancing](/load-balancing)\n- [Cloud Run](/run/docs/trace)\n- [Cloud Scheduler](/scheduler)\n- [Cloud Tasks](/tasks)\n- [Pub/Sub](/pubsub)\n\nSupport for trace context initiation and propagation is\ndependent on the particular Google Cloud service.\nTo request that a Google Cloud service add support for context propagation,\nuse the [Google Issue Tracker](https://developers.google.com/issue-tracker/guides/access-ui).\n\nContext propagation in your applications\n----------------------------------------\n\nSome instrumentation libraries, such as OpenTelemetry,\ncan propagate a `context` object that contains the data necessary for tracing.\nFor a list of OpenTelemetry libraries that support tracing, see\n[Language APIs \\& SDKs](https://opentelemetry.io/docs/languages/).\n\nIf you rely on an open-source library, then determine whether\ncontext propagation is available and whether configuration is required.\nFor example, if you use OpenTelemetry to instrument a Go app, then your app should\ncall `SetTextMapPropagator`, which configures the context to use the\nW3C `traceparent` format. For an example, see\n[Go instrumentation sample](/stackdriver/docs/instrumentation/setup/go).\n\nWhen there isn't a suitable instrumentation library,\nyou must ensure that your application propagates\nthe trace context to child operations.\n\nWhat's next\n-----------\n\n- Learn about [Trace sampling](/trace/docs/trace-sampling).\n\n- OpenTelemetry resources:\n\n - [OpenTelemetry home](https://opentelemetry.io/)\n - [OpenTelemetry context](https://opentelemetry.io/docs/specs/otel/context/)"]]