[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-19。"],[],[],null,["# Trace labels\n\nTrace provides a mechanism for you to add meaningful data to your\nspans. If you are using the Cloud Trace API V1,\nyou can add labels, which are key-value pairs, by using the\n[`labels`](/trace/docs/reference/v1/rest/v1/projects.traces#TraceSpan.FIELDS.labels) field in the\nCloud Trace API [`TraceSpan`](/trace/docs/reference/v1/rest/v1/projects.traces#TraceSpan) object.\nIf you are using the Cloud Trace API V2, you can add information by\nwith an `Attributes` object.\n\nWhen you explore a span, labels for that span are displayed in the\n**Attributes** tab. For example, the following screenshot illustrates this tab:\n\nFor information about how to access this information, see\n[Find and explore traces](/trace/docs/finding-traces).\n\nThe `labels` field is a map of key-value pairs. They keys and values are stored\nas strings. For string length restrictions, see the\n[API reference for `labels`](/trace/docs/reference/v1/rest/v1/projects.traces#TraceSpan.FIELDS.labels).\n\nThere is a limit of 32 labels per span.\n\nPredefined keys\n---------------\n\n| **Note:** Fields like a complete URL might contain sensitive or other Personally Identifiable Information (PII). Be careful to avoid inadvertently including sensitive or PII content in trace labels.\n\n### Canonical labels\n\nThe following table lists the supported predefined keys, includes a description,\nand in some cases, includes an example:\n\n`†`This label and its value are displayed in the **Details** table that is included in the **Trace details** view. \n\n### Canonical labels for GKE\n\nThe following table lists all of the canonical\nlabels for a GKE container:\n\nExample\n-------\n\nThe following is a partial JSON representation of a\n`Trace` object that includes multiple labels: \n\n```\n{\n \"projectId\": \"a-sample-project\",\n \"traceId\": \"00000000000000004db6dd68e7d37f57\",\n \"spans\": [\n {\n \"spanId\": \"12913864118554233534\",\n \"kind\": \"RPC_SERVER\",\n \"name\": \"http://192.0.2.0/\",\n \"startTime\": \"2024-04-02T19:37:34.149058Z\",\n \"endTime\": \"2025-04-02T19:37:34.151136Z\",\n \"parentSpanId\": \"5599906629317525335\",\n \"labels\": {\n \"/component\": \"default\",\n \"/http/host\": \"192.0.2.0\",\n \"/http/status_code\": \"200\",\n \"/http/url\": \"http://192.0.2.0/\",\n \"zipkin.io/http.route\": \"/**\",\n \"/http/method\": \"GET\",\n \"zipkin.io/endpoint.ipv4\": \"10.16.1.6\",\n \"zipkin.io/http.path\": \"/\",\n \"zipkin.io/mvc.controller.class\": \"ResourceHttpRequestHandler\"\n }\n }\n ]\n}\n```\n\nThe previous trace was taken from a system using a Zipkin collector.\nIn this case, the labels with `zipkin.io` keys were added by that collector.\n\nPrefix `g.co`\n-------------\n\nIn some cases, the displayed labels\ncontain a `g.co` prefix. The `g.co` prefix indicates\nthat this label was generated by a Google service. If you are running your\nservice on App Engine or other Google Cloud infrastructure, you might\nsee labels such as the following:\n\nCustom labels\n-------------\n\nYou can create custom labels. If you create a custom label, we recommend\nthat you use the following formats:\n\n- `/category/product/key` for agents of well-known products. For example, `/db/mongodb/read_size`.\n- `short_host/path/key` for domain-specific keys. For example, `g.co/agent`.\n\nIf you create a lot of custom labels, then that might incur\nperformance impacts due to the increased label cardinality.\n\nAs illustrated in the [Example](#example) section, if you use a Zipkin\ncollector or a library such as OpenTelemetry, it might\nadd labels to your trace spans.\n\nUsing OpenTelemetry\n-------------------\n\nIf you are using OpenTelemetry libraries, then ensure you use the\n[OpenTelemetry Semantic Conventions](https://opentelemetry.io/docs/specs/semconv/general/trace/) when creating spans."]]