---
title: OpenTelemetry span 參考
url: https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans
description: Claude API 與 Claude SDK 所發出的 OpenTelemetry span 及 span 屬性。
featureMetadata:
  topic:
    title: OpenTelemetry
    url: https://platform.claude.com/docs/en/manage-claude/opentelemetry
  status: beta
---

<Note>
  OpenTelemetry 匯出目前為測試版。它依據您與 Anthropic 之間的協議提供，包括[特定服務條款](https://www.anthropic.com/legal/service-specific-terms)中的測試版服務章節。Span 名稱與屬性在測試期間可能會變更。
</Note>

若要設定匯出，請參閱[搭配 Claude SDK 使用 OpenTelemetry](https://platform.claude.com/docs/zh-TW/manage-claude/opentelemetry/sdk)與[搭配 Claude API 使用 OpenTelemetry](https://platform.claude.com/docs/zh-TW/manage-claude/opentelemetry/api)。

## Span 名稱與種類

| 屬性                          | SDK span                                                                                     | API span                               |
| --------------------------- | -------------------------------------------------------------------------------------------- | -------------------------------------- |
| `service.name`              | 應用程式的 `service.name`                                                                         | `claude-platform`                      |
| 檢測範圍（Instrumentation scope） | `com.anthropic.sdk.<language>` 或 `com.anthropic.sdk.cli`，在雲端平台的用戶端上另加 `.<platform>`，並附上套件的版本 | `com.anthropic.claude-platform`        |
| Span 種類                     | 請求對應的 span 上為 `CLIENT`，其他則為 `INTERNAL`                                                       | 請求對應的 span 上為 `SERVER`，其他則為 `INTERNAL` |

* **請求的 span**（span，即追蹤中的一個步驟）以該請求的 API 方法命名：`anthropic.` 後接該方法在 API 參考中的路徑，以點取代斜線，且不含 `beta`。例如，`client.beta.sessions.events.send()` (csharp, go: `client.Beta.Sessions.Events.Send()`; java: `client.beta().sessions().events().send()`; php: `$client->beta->sessions->events->send()`; ruby: `client.beta.sessions.events.send_()`) 會發送一個[傳送工作階段事件](https://platform.claude.com/docs/zh-TW/api/beta/sessions/events/send)的請求，其 span 的名稱為 [`anthropic.sessions.events.send`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-sessions-events-send)。
* **工具 span** 的名稱為固定名稱、一個空格，再加上工具名稱，例如 [`anthropic.tool_use bash`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-tool-use-anthropic-mcp-tool-use-and-anthropic-custom-tool-use)。

## Span 狀態

* **`OK`：** 該步驟已完成。
* **`ERROR`：** 該步驟失敗。
* **未設定：** 應用程式取消了該步驟，例如當它傳送了 [`user.interrupt`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/events#beta_managed_agents_user_interrupt_event) 事件時。

串流的 span 會在串流結束時結束。如果應用程式提早關閉串流，SDK span 的狀態為未設定，因此永遠不會完成的串流（例如 [`anthropic.sessions.events.stream`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-sessions-method)）的 SDK span，其狀態為未設定或 `ERROR`。

## 屬性

在有對應慣例的情況下，「attribute」（屬性）會使用 [OpenTelemetry 生成式 AI 語意慣例](https://github.com/open-telemetry/semantic-conventions-genai)（`gen_ai.*`）。Anthropic 屬性以 `anthropic.` 開頭。這些 span 遵循 2026 年 9 月 24 日提交 [`e57c543b`](https://github.com/open-telemetry/semantic-conventions-genai/tree/e57c543b4889619eb2a05702471937db5119165d) 時的慣例。這些慣例仍在開發中。

### 通用屬性

請求的每個 span 都具有下列屬性，除非說明中另有註明。其他 span 只可能具有前三個屬性：

| 屬性                          | 類型       | 說明                                                                                                                                          |
| --------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| `gen_ai.provider.name`      | `string` | `anthropic`。出現在每個 span 上。<br />**SDK：** Amazon Bedrock 用戶端（包含 Mantle）上為 `aws.bedrock`，Google Cloud's Agent Platform 的用戶端上為 `gcp.vertex_ai`。 |
| `anthropic.organization.id` | `string` | 組織的 ID。                                                                                                                                     |
| `anthropic.workspace.id`    | `string` | 執行該工作的工作區 ID。                                                                                                                               |
| `anthropic.request.id`      | `string` | `request-id` 回應標頭的值。                                                                                                                        |
| `http.request.method`       | `string` | 請求的 HTTP 方法，例如 `POST`。                                                                                                                      |
| `http.route`                | `string` | 端點的路徑，其中路徑參數以預留位置表示，例如 `/v1/sessions/{session_id}`。                                                                                         |
| `http.response.status_code` | `int`    | 最終回應的 HTTP 狀態碼。對於串流，為隨標頭一起傳送的狀態碼。沒有回應時則不存在。                                                                                                 |
| `server.address`            | `string` | 請求所傳送到的主機，例如 `api.anthropic.com`。                                                                                                           |
| `server.port`               | `int`    | 請求 URL 的連接埠，若 URL 沒有連接埠則為其 scheme 的預設連接埠。                                                                                                   |
| `url.scheme`                | `string` | URL 的 scheme，例如 `https`。                                                                                                                    |
| `url.path`                  | `string` | URL 的路徑，例如 `/v1/messages`。                                                                                                                  |
| `url.query`                 | `string` | URL 的查詢字串，僅包含端點所定義的查詢參數。若沒有這類參數則不會出現。                                                                                                       |
| `url.full`                  | `string` | 請求的 URL。                                                                                                                                    |

在 Claude Platform on AWS 上，API span 不包含 `server.address`、`server.port` 或 `url.full`。

### 工作階段屬性

在 Managed Agents 工作階段中，span 具有下列屬性。一個工作階段的 span 可能分布在多個追蹤中，因此若要組合出工作階段的檢視（例如對話紀錄），請[依這些 ID 將其 span 分組](https://platform.claude.com/docs/zh-TW/manage-claude/opentelemetry#a-managed-agents-session)。

| 屬性                       | 類型       | 說明                                                                                                                                                                                                                                                                                                                                                                     |
| ------------------------ | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `anthropic.session.id`   | `string` | 工作階段 ID。在不作用於單一工作階段的方法的 span 上不存在，例如 [`anthropic.sessions.list`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-sessions-method)。                                                                                                                                                                                                            |
| `gen_ai.conversation.id` | `string` | 該 span 所屬之工作階段執行緒的 ID。SDK 的 [`conversation_id` (typescript, java, php: `conversationId`; csharp: `ConversationId`; go: `option.WithOpenTelemetryConversationID()`) 選項](https://platform.claude.com/docs/zh-TW/manage-claude/opentelemetry/sdk#configure-the-sdk)會將此值替換為您自己的對話 ID。在 API 針對 Sessions API 請求（針對單一執行緒的請求除外）的 span 上不存在；在沒有執行緒的 SDK span 上，除非您設定該選項，否則也不存在。 |

### 內容屬性

標記為 <Badge>Content</Badge> 的屬性僅出現在內容模式下的 span 上，SDK 與 API 皆然。請參閱[指南中內容模式的差異](https://platform.claude.com/docs/zh-TW/manage-claude/opentelemetry#choose-a-content-mode)。當此內容過大時，SDK 與 API 會[將其縮短](https://platform.claude.com/docs/zh-TW/manage-claude/opentelemetry#content-limits)，並將 `anthropic.content.truncated` 設為 `true`。如果 Anthropic 的防護措施從回應中扣留了內容，API 的 span 也不會包含該內容。

訊息屬性是採用 OpenTelemetry GenAI 慣例訊息格式的 JSON 字串。在 Messages API 以及 Managed Agents 訊息事件（例如 `agent.message`）中，每個 Anthropic 內容區塊都會成為一個 GenAI 慣例訊息部分：

| Anthropic 內容區塊                                                          | GenAI 慣例訊息部分                                                                                |
| ----------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
| `text`                                                                  | `text`                                                                                      |
| `tool_use`、`server_tool_use`                                            | `tool_call`，對於具有 `toolset_name`（例如 `computer`）的 `tool_use` 區塊，並具有 `anthropic_toolset_name`  |
| `mcp_tool_use`                                                          | `tool_call`，並具有 `anthropic_mcp_server_name`                                                 |
| `tool_result`、`mcp_tool_result`、伺服器工具的結果區塊（例如 `web_search_tool_result`） | `tool_call_response`                                                                        |
| `thinking`                                                              | `reasoning`，不包含 `thinking` 區塊的簽章。不會出現在 Managed Agents span 中，因為 `agent.thinking` 事件不包含思考內容。 |
| 任何其他區塊，例如 `image`                                                       | 該區塊的 `type` 加上前綴 `anthropic_`，例如 `anthropic_image`。該部分不具有其他欄位。                              |

每個 Managed Agents 工具使用或工具結果事件也會成為一個 GenAI 慣例訊息部分：

| Managed Agents 事件                                                                        | GenAI 慣例訊息部分                                |
| ---------------------------------------------------------------------------------------- | ------------------------------------------- |
| `agent.tool_use`、`agent.custom_tool_use`                                                 | `tool_call`                                 |
| `agent.mcp_tool_use`                                                                     | `tool_call`，並具有 `anthropic_mcp_server_name` |
| `user.tool_result`、`user.custom_tool_result`、`agent.tool_result`、`agent.mcp_tool_result` | `tool_call_response`                        |

### Token 用量

下列 span 具有 token 用量屬性：[`anthropic.messages.create`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-messages-create)、[`anthropic.model_request`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-model-request)、[`anthropic.compaction`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-compaction) 以及 [`anthropic.session.outcome_evaluation`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-session-outcome-evaluation)。這些值是針對該 span 的步驟，例如請求、模型請求或壓縮。若要讓每個 token 只計算一次，請參閱[指南中如何計算 token](https://platform.claude.com/docs/zh-TW/manage-claude/opentelemetry#count-tokens)。

| 屬性                                                         | 類型    | 說明                                                                                                                                                                        |
| ---------------------------------------------------------- | ----- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `gen_ai.usage.input_tokens`                                | `int` | 輸入 token，包含快取讀取與寫入。                                                                                                                                                       |
| `gen_ai.usage.output_tokens`                               | `int` | 輸出 token。                                                                                                                                                                 |
| `gen_ai.usage.cache_write.input_tokens`                    | `int` | 寫入提示快取的 token。在 [`anthropic.session.outcome_evaluation`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-session-outcome-evaluation) span 上不存在。  |
| `anthropic.usage.cache_creation.ephemeral_5m_input_tokens` | `int` | 寫入 5 分鐘快取的 token。僅出現在 Messages API 請求的 span 上。在串流回應的 SDK span 上，僅包含第一個輸出 token 之前寫入的 token。                                                                               |
| `anthropic.usage.cache_creation.ephemeral_1h_input_tokens` | `int` | 寫入 1 小時快取的 token。僅出現在 Messages API 請求的 span 上。在串流回應的 SDK span 上，僅包含第一個輸出 token 之前寫入的 token。                                                                               |
| `gen_ai.usage.cache_read.input_tokens`                     | `int` | 從提示快取讀取的 token。在 [`anthropic.session.outcome_evaluation`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-session-outcome-evaluation) span 上不存在。 |

## Span

Span 可能來自應用程式中的 SDK，也可能來自 API，因此本參考中的每個 span 都會列出其來源。以 **Messages API：** 或 **Managed Agents：** 開頭的說明適用於該產品的 span。以來源開頭的屬性說明（例如 **SDK：** 或 **API：**）適用於該來源的 span。

### `anthropic.messages.create`

* **來源：** SDK 與 API。
* **種類：** 來自 SDK 時為 `CLIENT`，來自 API 時為 `SERVER`。
* **SDK span 的父項：** 應用程式呼叫該方法時的目前 span。若沒有目前 span，則沒有父項。
* **API span 的父項：** 請求的 `traceparent` 標頭中的 span，當請求來自 SDK 時即為 SDK span。若沒有該標頭，API span 就沒有父項。請參閱[如何傳送 `traceparent` 標頭](https://platform.claude.com/docs/zh-TW/manage-claude/opentelemetry/api#connect-api-spans-to-your-own-traces)。
* **SDK span 的子項：** 該請求的 API span。
* **API span 的子項：** 每個模型請求各一個 [`anthropic.model_request`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-model-request) span、API 在該請求中執行的每次伺服器工具或 MCP 連接器工具使用各一個[工具 span](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-tool-use-anthropic-mcp-tool-use-and-anthropic-custom-tool-use)，以及每次壓縮各一個 [`anthropic.compaction`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-compaction) span。

SDK 會為每個 Messages 請求發出此 span，無論是否為串流。

API 會為其驗證的每個 [`POST /v1/messages`](https://platform.claude.com/docs/zh-TW/api/messages/create) 請求發出此 span。對於傳送至 [OpenAI 相容端點](https://platform.claude.com/docs/zh-TW/cli-sdks-libraries/libraries/openai-sdk) `POST /v1/chat/completions` 的請求，則不會發出此 span。

API 會為一個請求發出一個 span，即使該請求由[備援模型](https://platform.claude.com/docs/zh-TW/build-with-claude/refusals-and-fallback)處理亦然。

此 span 具有 [token 用量屬性](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#token-usage)。SDK span 也具有每個[請求的 SDK span](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-resources-method) 的屬性。

| 屬性                                         | 類型         | 說明                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ------------------------------------------ | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `gen_ai.operation.name`                    | `string`   | `chat`                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `gen_ai.request.model`                     | `string`   | 請求的 [`model`](https://platform.claude.com/docs/zh-TW/api/messages/create#create.model)。                                                                                                                                                                                                                                                                                                                                                                                        |
| `gen_ai.response.id`                       | `string`   | 回應的 [`id`](https://platform.claude.com/docs/zh-TW/api/messages/create#message)。                                                                                                                                                                                                                                                                                                                                                                                                |
| `gen_ai.response.model`                    | `string`   | 處理該請求的模型。當請求使用模型別名，或由[備援模型](https://platform.claude.com/docs/zh-TW/build-with-claude/refusals-and-fallback)處理請求時，此值會與所請求的模型不同。                                                                                                                                                                                                                                                                                                                                                 |
| `anthropic.message.stop_reason`            | `string`   | 回應的 [`stop_reason`](https://platform.claude.com/docs/zh-TW/api/messages#stop_reason)，例如 `end_turn`。                                                                                                                                                                                                                                                                                                                                                                            |
| `anthropic.response.service_tier`          | `string`   | 處理該請求的服務層級：回應的 [`usage.service_tier`](https://platform.claude.com/docs/zh-TW/api/messages#usage)。請參閱[請求如何被分配層級](https://platform.claude.com/docs/zh-TW/api/service-tiers#how-requests-get-assigned-tiers)。                                                                                                                                                                                                                                                                     |
| `error.type`                               | `string`   | 失敗請求的[錯誤類型](https://platform.claude.com/docs/zh-TW/api/errors#http-errors)，例如 `rate_limit_error`。<br />**SDK：** 也包括[請求的 SDK span](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-resources-method) 中的其他值。<br />**API：** 當 API 在沒有錯誤回應的情況下結束請求時為 `api_error`。                                                                                                                                                                                         |
| `gen_ai.response.time_to_first_chunk`      | `double`   | 僅出現在串流回應的 SDK span 上。從 SDK 首次傳送請求到串流的第一個 `content_block_delta` 事件（若有）所經過的秒數。                                                                                                                                                                                                                                                                                                                                                                                                   |
| `gen_ai.usage.reasoning.output_tokens`     | `int`      | 回應的思考 token。它們是輸出 token 的一部分。當回應的用量沒有輸出 token 的詳細資訊時則不存在。                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `anthropic.usage.compaction.input_tokens`  | `int`      | 請求之[壓縮](https://platform.claude.com/docs/zh-TW/build-with-claude/compaction)的輸入 token，包含快取讀取與寫入。不屬於 `gen_ai.usage.input_tokens` 的一部分。當回應沒有壓縮時則不存在。                                                                                                                                                                                                                                                                                                                             |
| `anthropic.usage.compaction.output_tokens` | `int`      | 請求之壓縮的輸出 token。不屬於 `gen_ai.usage.output_tokens` 的一部分。當回應沒有壓縮時則不存在。                                                                                                                                                                                                                                                                                                                                                                                                             |
| `gen_ai.request.max_tokens`                | `int`      | 請求的 [`max_tokens`](https://platform.claude.com/docs/zh-TW/api/messages/create#create.max_tokens)。                                                                                                                                                                                                                                                                                                                                                                              |
| `gen_ai.request.temperature`               | `double`   | 請求的 [`temperature`](https://platform.claude.com/docs/zh-TW/api/messages/create#create.temperature)。當請求未設定時則不存在。                                                                                                                                                                                                                                                                                                                                                                |
| `gen_ai.request.top_p`                     | `double`   | 請求的 [`top_p`](https://platform.claude.com/docs/zh-TW/api/messages/create#create.top_p)。當請求未設定時則不存在。                                                                                                                                                                                                                                                                                                                                                                            |
| `gen_ai.request.top_k`                     | `int`      | 請求的 [`top_k`](https://platform.claude.com/docs/zh-TW/api/messages/create#create.top_k)。當請求未設定時則不存在。                                                                                                                                                                                                                                                                                                                                                                            |
| `gen_ai.request.stream`                    | `boolean`  | 當請求設定 [`stream: true`](https://platform.claude.com/docs/zh-TW/api/messages/create#create.stream) 時為 `true`。否則不存在。                                                                                                                                                                                                                                                                                                                                                              |
| `gen_ai.request.reasoning.level`           | `string`   | 請求的 [`output_config`](https://platform.claude.com/docs/zh-TW/api/messages/create#create.output_config) 中的 [`effort`](https://platform.claude.com/docs/zh-TW/api/messages/create#create.output_config.effort)。當請求未設定時則不存在。                                                                                                                                                                                                                                                      |
| `gen_ai.output.type`                       | `string`   | 當請求將輸出格式設為 JSON 時為 `json`。否則不存在。                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `anthropic.request.service_tier`           | `string`   | 請求的 [`service_tier`](https://platform.claude.com/docs/zh-TW/api/messages/create#create.service_tier)。當請求未設定時則不存在。                                                                                                                                                                                                                                                                                                                                                              |
| `anthropic.thinking.type`                  | `string`   | 請求的 [`thinking.type`](https://platform.claude.com/docs/zh-TW/api/messages/create#create.thinking)。當請求未設定時則不存在。                                                                                                                                                                                                                                                                                                                                                                 |
| `anthropic.thinking.budget_tokens`         | `int`      | 請求的 [`thinking`](https://platform.claude.com/docs/zh-TW/api/messages/create#create.thinking) 物件中的 [`budget_tokens`](https://platform.claude.com/docs/zh-TW/api/messages#thinking_config_enabled.budget_tokens)。當請求未設定時則不存在。                                                                                                                                                                                                                                                    |
| `anthropic.beta`                           | `string[]` | 僅出現在 SDK span 上。請求的 [`anthropic-beta`](https://platform.claude.com/docs/zh-TW/api/beta/messages/create#create.betas) 標頭中的測試版名稱。                                                                                                                                                                                                                                                                                                                                                |
| `gen_ai.system_instructions`               | `string`   | <Badge>Content</Badge> 遵循 OpenTelemetry [`SystemInstructions`](https://github.com/open-telemetry/semantic-conventions-genai/blob/e57c543b4889619eb2a05702471937db5119165d/model/gen-ai/gen-ai-system-instructions.json) 結構描述的 JSON 字串。請求的 [`system`](https://platform.claude.com/docs/zh-TW/api/messages/create#create.system) 提示。                                                                                                                                             |
| `gen_ai.input.messages`                    | `string`   | <Badge>Content</Badge> 遵循 OpenTelemetry [`InputMessages`](https://github.com/open-telemetry/semantic-conventions-genai/blob/e57c543b4889619eb2a05702471937db5119165d/model/gen-ai/gen-ai-input-messages.json) 結構描述的 JSON 字串。請求的 [`messages`](https://platform.claude.com/docs/zh-TW/api/messages/create#create.messages)。                                                                                                                                                      |
| `gen_ai.output.messages`                   | `string`   | <Badge>Content</Badge> 遵循 OpenTelemetry [`OutputMessages`](https://github.com/open-telemetry/semantic-conventions-genai/blob/e57c543b4889619eb2a05702471937db5119165d/model/gen-ai/gen-ai-output-messages.json) 結構描述的 JSON 字串。回應的 [`content`](https://platform.claude.com/docs/zh-TW/api/messages/create#message)，作為一則 `assistant` 訊息。<br />**SDK：** 在串流上，僅當應用程式依照[串流追蹤](https://platform.claude.com/docs/zh-TW/manage-claude/opentelemetry/sdk#trace-a-stream)所述的方式讀取串流時才會出現。 |
| `gen_ai.request.stop_sequences`            | `string[]` | <Badge>Content</Badge> 請求的 [`stop_sequences`](https://platform.claude.com/docs/zh-TW/api/messages/create#create.stop_sequences)。                                                                                                                                                                                                                                                                                                                                               |

請求的 span 不包含回應中的伺服器工具使用次數，例如 `web_search_requests`。取而代之的是，API 會為每次伺服器工具使用發出一個[工具 span](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-tool-use-anthropic-mcp-tool-use-and-anthropic-custom-tool-use)。

### `anthropic.messages.count_tokens`

* **來源：** SDK。API 不會為 [`POST /v1/messages/count_tokens`](https://platform.claude.com/docs/zh-TW/api/messages/count_tokens) 發出 span。
* **種類：** `CLIENT`。
* **父項：** 應用程式呼叫該方法時的目前 span；若沒有目前 span 則無。
* **子項：** 無。

| 屬性                                            | 類型       | 說明                                        |
| --------------------------------------------- | -------- | ----------------------------------------- |
| `gen_ai.request.model`                        | `string` | 請求的模型。                                    |
| `anthropic.message.count_tokens.input_tokens` | `int`    | 回應中的 token 計數。此計數並非用量。加總 token 用量時請勿將其納入。 |

### `anthropic.sessions.create`

與 [`anthropic.sessions.<method>`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-sessions-method) 相同，但下列子項與屬性除外：

* **SDK span 的子項：** 該請求的 API span。
* **API span 的子項：** 當請求具有非空的 [`initial_events`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/create#create.initial_events) 時，第一個回合的 [`anthropic.session.turn`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-session-turn) span。

| 屬性                                 | 類型       | 說明                                         |
| ---------------------------------- | -------- | ------------------------------------------ |
| `gen_ai.agent.id`                  | `string` | 建立該工作階段所依據之代理的 ID。                         |
| `gen_ai.agent.name`                | `string` | 該代理的名稱。<br />**SDK：** 當請求失敗時不存在。           |
| `gen_ai.request.model`             | `string` | 該代理的模型，負責執行主要執行緒。<br />**SDK：** 當請求失敗時不存在。 |
| `anthropic.session.environment.id` | `string` | 工作階段環境的 ID。                                |

### `anthropic.sessions.events.send`

與 [`anthropic.sessions.<method>`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-sessions-method) 相同，但 API span 的子項除外。

* **SDK span 的子項：** 該請求的 API span。
* **API span 的子項：** 因該請求的事件而啟動的每個回合的 [`anthropic.session.turn`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-session-turn) span。

### `anthropic.sessions.update`

與 [`anthropic.sessions.<method>`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-sessions-method) 相同，但 API span 的子項除外。

* **SDK span 的子項：** 該請求的 API span。
* **API span 的子項：** 因該請求提高或移除[工作階段預算](https://platform.claude.com/docs/zh-TW/managed-agents/budgets#resume-a-session-at-its-budget)而恢復的每個回合的 [`anthropic.session.turn`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-session-turn) span。

### `anthropic.session.turn`

* **來源：** API，適用於 Managed Agents 工作階段。

* **種類：** `INTERNAL`。

* **父項：** 取決於回合開始的原因：

  * 對於以非空 [`initial_events`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/create#create.initial_events) 建立之工作階段的第一個回合，為 [`anthropic.sessions.create`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-sessions-create) span。
  * 對於因事件（例如 [`user.message`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/events#beta_managed_agents_user_message_event) 事件）而開始的回合，為傳送該事件之請求的 [`anthropic.sessions.events.send`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-sessions-events-send) span。
  * 對於因透過請求提高或移除工作階段預算而恢復的回合，為 [`anthropic.sessions.update`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-sessions-update) span。
  * 對於另一個執行緒上的回合，為[工作階段所執行的代理](https://platform.claude.com/docs/zh-TW/managed-agents/multiagent-orchestration)啟動此回合時所處之該代理回合的 `anthropic.session.turn` span。
  * 對於因另一個執行緒上的代理回覆或結束其回合而開始的回合（例如由主要代理呼叫的代理），則無。

* **子項：**

  * 回合中每個模型請求各有一個 [`anthropic.model_request`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-model-request) span。
  * API 每次在回合中執行工具時各有一個工具 span，但[工具 span 章節中列出的情況](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-tool-use-anthropic-mcp-tool-use-and-anthropic-custom-tool-use)除外。
  * 工作階段所執行的代理在此回合期間於另一個執行緒上啟動的每個回合，各有一個 `anthropic.session.turn` span。
  * 此回合所啟動之結果評估的每次迭代，各有一個 [`anthropic.session.outcome_evaluation`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-session-outcome-evaluation) span。

回合在其執行緒進入 `running` 狀態時開始，並在執行緒離開該狀態時結束。

| 屬性                                   | 類型       | 說明                                                                                                                                                                                                                                                                                                                                                                                                              |
| ------------------------------------ | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `gen_ai.operation.name`              | `string` | `invoke_agent`                                                                                                                                                                                                                                                                                                                                                                                                  |
| `gen_ai.agent.id`                    | `string` | 執行該回合之執行緒的代理 ID。在[顧問](https://platform.claude.com/docs/zh-TW/managed-agents/multiagent-orchestration#advisor-threads)執行緒上不存在。                                                                                                                                                                                                                                                                                   |
| `gen_ai.agent.name`                  | `string` | 該代理的名稱。在顧問執行緒上為 `anthropic.advisor`。                                                                                                                                                                                                                                                                                                                                                                            |
| `gen_ai.request.model`               | `string` | 該代理的模型。在顧問執行緒上為顧問的模型。                                                                                                                                                                                                                                                                                                                                                                                           |
| `anthropic.session.turn.stop_reason` | `string` | 回合結束的原因：[`session.thread_status_idle`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/events#beta_managed_agents_session_thread_status_idle_event) 事件的 [`stop_reason.type`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/events#beta_managed_agents_session_thread_status_idle_event)，例如 `requires_action`。當執行緒未進入閒置狀態時不存在。                                                               |
| `error.type`                         | `string` | 若回合失敗，為結束該回合之 [`session.error`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/events#beta_managed_agents_session_error_event) 事件的 [`error.type`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/events#beta_managed_agents_session_error_event)。                                                                                                                                           |
| `gen_ai.agent.description`           | `string` | 該代理的說明。在顧問執行緒上或代理沒有說明時不存在。                                                                                                                                                                                                                                                                                                                                                                                      |
| `gen_ai.system_instructions`         | `string` | <Badge>Content</Badge> 遵循 OpenTelemetry [`SystemInstructions`](https://github.com/open-telemetry/semantic-conventions-genai/blob/e57c543b4889619eb2a05702471937db5119165d/model/gen-ai/gen-ai-system-instructions.json) 結構描述的 JSON 字串。該回合生效的系統提示。僅出現在執行緒的第一個回合上。在顧問執行緒上不存在。                                                                                                                                     |
| `gen_ai.input.messages`              | `string` | <Badge>Content</Badge> 遵循 OpenTelemetry [`InputMessages`](https://github.com/open-telemetry/semantic-conventions-genai/blob/e57c543b4889619eb2a05702471937db5119165d/model/gen-ai/gen-ai-input-messages.json) 結構描述的 JSON 字串。該回合的輸入事件：使用者訊息與工具結果、[`system.message`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/events#beta_managed_agents_system_message_event_params) 事件，以及來自其他執行緒的訊息。在顧問執行緒上不存在。 |
| `gen_ai.output.messages`             | `string` | <Badge>Content</Badge> 遵循 OpenTelemetry [`OutputMessages`](https://github.com/open-telemetry/semantic-conventions-genai/blob/e57c543b4889619eb2a05702471937db5119165d/model/gen-ai/gen-ai-output-messages.json) 結構描述的 JSON 字串。該回合的輸出事件：代理的訊息、工具使用與工具結果。                                                                                                                                                         |

### `anthropic.model_request`

* **來源：** API，適用於 Messages API 請求與 Managed Agents 工作階段。

* **種類：** `INTERNAL`。

* **父項：**

  * **Messages API：** 該請求的 [`anthropic.messages.create`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-messages-create) span。
  * **Managed Agents：** 發出該請求之回合的 [`anthropic.session.turn`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-session-turn) span。

* **子項：** 無。

在 Messages API 上，每個 span 代表 API 請求中的一個模型請求。

此 span 具有 [token 用量屬性](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#token-usage)。

| 屬性                      | 類型       | 說明                                                                                                                                                                                                                                                                                                                                             |
| ----------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `gen_ai.operation.name` | `string` | 僅出現在 Managed Agents 工作階段的 span 上，其值為 `chat`。在 Messages API 上，該請求的 [`anthropic.messages.create`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-messages-create) span 才是 `chat` 操作。                                                                                                                                   |
| `gen_ai.request.model`  | `string` | 請求的模型。                                                                                                                                                                                                                                                                                                                                         |
| `gen_ai.response.model` | `string` | 僅出現在 Messages API 請求的 span 上。執行該模型請求的模型。                                                                                                                                                                                                                                                                                                       |
| `error.type`            | `string` | **Messages API：** 若請求在此模型請求期間失敗，為 [`anthropic.messages.create`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-messages-create) span 的 `error.type`。<br />**Managed Agents：** 若模型請求失敗，為其[錯誤類型](https://platform.claude.com/docs/zh-TW/api/errors#http-errors)，例如 `rate_limit_error`。若模型請求在沒有回應的情況下失敗，則為 `api_error`。 |

### `anthropic.tool_use`、`anthropic.mcp_tool_use` 與 `anthropic.custom_tool_use`

* **來源：** SDK 與 API。

* **名稱：** `anthropic.tool_use <tool>`、`anthropic.mcp_tool_use <tool>` 或 `anthropic.custom_tool_use <tool>`，其中 `<tool>` 為工具的名稱。

* **種類：** `INTERNAL`。

* **SDK span 的父項：** 工具啟動時應用程式中的目前 span，在 Messages 工具執行器中即為 [`anthropic.messages.tool_runner`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-messages-tool-runner) span。若沒有目前 span，則沒有父項。

* **API span 的父項：**

  * **Messages API：** API 執行該工具之請求的 [`anthropic.messages.create`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-messages-create) span。
  * **Managed Agents：** 工具執行所在回合的 [`anthropic.session.turn`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-session-turn) span。對於等待 [`user.tool_confirmation`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/events#beta_managed_agents_user_tool_confirmation_event) 事件的工具使用，即為因該確認而啟動的回合。
  * 對於來自另一個工具所執行之程式碼的工具使用，為該工具的工具 span。在 Messages API 上，該工具為[程式碼執行工具](https://platform.claude.com/docs/zh-TW/agents-and-tools/tool-use/code-execution-tool)。

* **SDK span 的子項：** 工具程式碼所啟動的 span。

* **API span 的子項：** 此工具所執行之程式碼中每次工具使用各一個工具 span。例如，程式碼執行工具所執行的程式碼可能會使用 `web_search`。

Span 名稱的前綴取決於工具的類型：

* `anthropic.tool_use <tool>` 是 Messages API 上每次使用[伺服器工具](https://platform.claude.com/docs/zh-TW/agents-and-tools/tool-use/server-tools)，或每次使用 Managed Agents 代理工具集中之工具的 span。API 會執行代理工具集的工具，但在[自行託管的沙箱](https://platform.claude.com/docs/zh-TW/manage-claude/opentelemetry/sdk#trace-a-self-hosted-sandbox)中除外，此時由環境工作程序執行這些工具。
* `anthropic.mcp_tool_use <tool>` 是在 SDK、Messages API 和 Managed Agents 上每次使用 MCP 工具的 span。在 SDK 中，它是由 [Messages 工具執行器](https://platform.claude.com/docs/zh-TW/agents-and-tools/tool-use/tool-runner) 或[工作階段工具執行器](https://platform.claude.com/docs/zh-TW/managed-agents/self-hosted-sandboxes-reference#session-tool-runner)所執行之 MCP 輔助程式中的工具。在 Messages API 上，該工具來自 [MCP 連接器](https://platform.claude.com/docs/zh-TW/agents-and-tools/mcp-connector)。在 Managed Agents 上，如果[與 MCP 伺服器的連線失敗](https://platform.claude.com/docs/zh-TW/managed-agents/mcp-connector#handle-connection-and-authentication-failures)，span 名稱不會包含工具名稱。
* `anthropic.custom_tool_use <tool>` 是每次使用由應用程式定義並由工具執行器執行之工具的 span。只有 SDK 會發出此 span。

在下列情況下，API 不會發出工具 span：

* 模型要求使用由應用程式執行的工具，例如[自訂工具](https://platform.claude.com/docs/zh-TW/managed-agents/tools)。如果 SDK 中的工具執行器執行該工具，則由工具執行器發出其 span。
* **Managed Agents：** 代理使用在自行託管沙箱中執行的工具。由執行該工具的 SDK 工作程序發出其 span。請參閱[如何追蹤自行託管的沙箱](https://platform.claude.com/docs/zh-TW/manage-claude/opentelemetry/sdk#trace-a-self-hosted-sandbox)。
* **Managed Agents：** 代理使用[多代理](https://platform.claude.com/docs/zh-TW/managed-agents/multiagent-orchestration)工具或[顧問工具](https://platform.claude.com/docs/zh-TW/managed-agents/multiagent-orchestration#give-the-session-an-advisor)。
* **Managed Agents：** 代理要求使用工具，但伺服器依據 [`auto` 權限政策](https://platform.claude.com/docs/zh-TW/managed-agents/permission-policies#let-the-server-evaluate-each-call-with-auto)拒絕該使用，或應用程式在 [`user.tool_confirmation`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/events#beta_managed_agents_user_tool_confirmation_event) 事件中拒絕該使用。

| 屬性                                    | 類型       | 說明                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| ------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `gen_ai.operation.name`               | `string` | `execute_tool`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `gen_ai.tool.name`                    | `string` | 工具的名稱，例如 `bash`。在 API span 上，MCP 工具的名稱不包含伺服器名稱。在 Managed Agents 上，若與 MCP 伺服器的連線失敗，則為模型所產生的名稱，且僅出現在內容模式下的 span 上。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `gen_ai.tool.call.id`                 | `string` | **Messages API：** 模型要求使用該工具之區塊的 `id`：[`tool_use`](https://platform.claude.com/docs/zh-TW/api/messages#tool_use_block)、[`server_tool_use`](https://platform.claude.com/docs/zh-TW/api/messages#server_tool_use_block) 或 [`mcp_tool_use`](https://platform.claude.com/docs/zh-TW/api/beta/messages#beta_mcp_tool_use_block) 區塊。<br />**Managed Agents：** 代理要求使用該工具之事件的 ID：[`agent.tool_use`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/events#beta_managed_agents_agent_tool_use_event)、[`agent.mcp_tool_use`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/events#beta_managed_agents_agent_mcp_tool_use_event) 或 [`agent.custom_tool_use`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/events#beta_managed_agents_agent_custom_tool_use_event) 事件。 |
| `anthropic.mcp.server.name`           | `string` | 僅出現在 MCP 工具的 API span 上。該工具之 MCP 伺服器的名稱。在 Messages API 上，為 [`mcp_tool_use`](https://platform.claude.com/docs/zh-TW/api/beta/messages#beta_mcp_tool_use_block) 區塊的 [`server_name`](https://platform.claude.com/docs/zh-TW/api/beta/messages#beta_mcp_tool_use_block.server_name)。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `gen_ai.conversation.id`              | `string` | 工作階段執行緒 ID，如[工作階段屬性](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#session-attributes)所述。在 Messages 工具執行器中，為透過 [`conversation_id` (typescript, java, php: `conversationId`; csharp: `ConversationId`; go: `option.WithOpenTelemetryConversationID()`) 選項](https://platform.claude.com/docs/zh-TW/manage-claude/opentelemetry/sdk#configure-the-sdk)傳入的對話 ID，若未傳入則不存在。在 Messages API 請求的 API span 上不存在。                                                                                                                                                                                                                                                                                                                                                                    |
| `anthropic.session.id`                | `string` | 工作階段的 ID。對於 Managed Agents 工作階段以外的工具使用（例如在 Messages API 上或在 Messages 工具執行器中）則不存在。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `anthropic.session.thread.id`         | `string` | 僅出現在工作階段工具執行器的 SDK span 上。工作階段執行緒的 ID。對於主要執行緒上的工具使用則不存在。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `anthropic.tool.evaluated_permission` | `string` | 僅出現在 API 於 Managed Agents 工作階段中發出的 span 上。針對該工具使用評估[權限政策](https://platform.claude.com/docs/zh-TW/managed-agents/permission-policies)的結果：`allow` 或 `ask`。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `error.type`                          | `string` | 若工具使用失敗，為錯誤類型：當工具程式碼引發錯誤或工具傳回錯誤結果時為 `tool_error`。<br />**API：** 在 Messages API 上，伺服器工具的錯誤結果則改為其 [`error_code`](https://platform.claude.com/docs/zh-TW/api/messages#web_search_tool_result_error.error_code)，例如 `max_uses_exceeded`。在 Managed Agents 上，若與 MCP 伺服器的連線失敗，驗證失敗時為 `mcp_authentication_failed_error`，否則為 `mcp_connection_failed_error`。若請求在工具使用期間失敗，則為該請求的[錯誤類型](https://platform.claude.com/docs/zh-TW/api/errors#http-errors)。                                                                                                                                                                                                                                                                                                                                                 |
| `gen_ai.tool.description`             | `string` | 僅出現在 SDK span 上。工具定義中的說明。當說明為空時不存在。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `gen_ai.tool.type`                    | `string` | 僅出現在 SDK span 上。`function`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `gen_ai.tool.call.arguments`          | `string` | <Badge>Content</Badge> 遵循 OpenTelemetry [`ToolCallArguments`](https://github.com/open-telemetry/semantic-conventions-genai/blob/e57c543b4889619eb2a05702471937db5119165d/model/gen-ai/gen-ai-tool-call-arguments.json) 結構描述的 JSON 字串。工具使用的 [`input`](https://platform.claude.com/docs/zh-TW/api/messages#tool_use_block)。                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `anthropic.tool_result.content`       | `string` | <Badge>Content</Badge> 包含內容區塊陣列或單一物件的 JSON 字串。傳回給模型之工具結果的 `content`。錯誤結果也適用，但在 Managed Agents 上與 MCP 伺服器的連線失敗時除外。<br />**API：** 在 Messages API 上，字串形式的 `content` 會變成包含一個 [`text`](https://platform.claude.com/docs/zh-TW/api/messages#text_block) 區塊的陣列。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |

### `anthropic.compaction`

* **來源：** API，用於 Messages API 請求。
* **類型：** `INTERNAL`。
* **父項：** 該請求的 [`anthropic.messages.create`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-messages-create) span。
* **子項：** 無。

此 span 具有壓縮的[權杖用量屬性](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#token-usage)。在 [`anthropic.messages.create`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-messages-create) 上，壓縮的用量位於 `anthropic.usage.compaction.*` 屬性中，而非 `gen_ai.usage.*` 總計中。

| 屬性           | 類型       | 說明                                                                                      |
| ------------ | -------- | --------------------------------------------------------------------------------------- |
| `error.type` | `string` | 若請求在壓縮期間失敗，則為該請求的[錯誤類型](https://platform.claude.com/docs/zh-TW/api/errors#http-errors)。 |

### `anthropic.session.outcome_evaluation`

* **來源：** API，用於 Managed Agents 工作階段。
* **類型：** `INTERNAL`。
* **父項：** 啟動該迭代之回合的 [`anthropic.session.turn`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-session-turn) span，即使該回合在迭代之前結束亦然。
* **子項：** 無。

當結果為 `interrupted` 時，狀態為未設定；其他任何結果的狀態則為 `OK`。

此 span 具有兩個[權杖用量屬性](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#token-usage)：`gen_ai.usage.input_tokens` 和 `gen_ai.usage.output_tokens`。

| 屬性                                                 | 類型       | 說明                                                                                    |
| -------------------------------------------------- | -------- | ------------------------------------------------------------------------------------- |
| `anthropic.session.outcome.id`                     | `string` | 該迭代所評估之結果的 ID。                                                                        |
| `anthropic.session.outcome_evaluation.result`      | `string` | 迭代的結果：`satisfied`、`needs_revision`、`max_iterations_reached`、`failed` 或 `interrupted`。 |
| `anthropic.session.outcome_evaluation.iteration`   | `int`    | 迭代的編號。                                                                                |
| `anthropic.session.outcome_evaluation.explanation` | `string` | <Badge>Content</Badge> 評分者對結果的說明，以純文字呈現。                                              |

### `anthropic.messages.tool_runner`

* **來源：** SDK。
* **類型：** `INTERNAL`。
* **父項：** 迴圈開始時應用程式中目前的 span；若沒有目前的 span，則為無。
* **子項：** 迴圈中每個請求的 [`anthropic.messages.create`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-messages-create) span，以及執行器所執行之每次工具使用的[工具 span](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-tool-use-anthropic-mcp-tool-use-and-anthropic-custom-tool-use)。

此 span 隨迴圈結束。若應用程式停止執行器，狀態為未設定。若工具的程式碼引發錯誤，其工具 span 的狀態為 `ERROR`，且迴圈會繼續。此 span 沒有用量屬性，因此請從其 [`anthropic.messages.create`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-messages-create) 子項讀取用量。

| 屬性                       | 類型       | 說明                                                                                                                                                                                                                                                        |
| ------------------------ | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `gen_ai.operation.name`  | `string` | `invoke_agent`                                                                                                                                                                                                                                            |
| `gen_ai.request.model`   | `string` | 迴圈中第一個請求的模型。                                                                                                                                                                                                                                              |
| `gen_ai.conversation.id` | `string` | 透過 [`conversation_id` (typescript, java, php: `conversationId`; csharp: `ConversationId`; go: `option.WithOpenTelemetryConversationID()`) 選項](https://platform.claude.com/docs/zh-TW/manage-claude/opentelemetry/sdk#configure-the-sdk)傳入的對話 ID。若未提供則不存在。 |
| `error.type`             | `string` | 若迴圈失敗，則為結束迴圈之請求的[錯誤類型](https://platform.claude.com/docs/zh-TW/api/errors#http-errors)。當執行器本身失敗時為 `client_error`。                                                                                                                                          |
| `gen_ai.output.type`     | `string` | 當請求將輸出格式設定為 JSON 時為 `json`。否則不存在。                                                                                                                                                                                                                         |

### `anthropic.messages.batches.<method>`

* **來源：** SDK，用於每個 Message Batches 方法。
* **類型：** `CLIENT`。
* **父項：** 應用程式呼叫該方法時目前的 span；若沒有目前的 span，則為無。
* **子項：** 無。

這些 span 也具有每個[請求之 SDK span](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-resources-method) 的屬性。

| 屬性                                      | 類型       | 說明                                                                                                                       |
| --------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------ |
| `anthropic.message.batch.id`            | `string` | 該方法所作用之批次的 ID；若為 `create`，則為新批次的 ID。在 `list` 和失敗的 `create` 上不存在。                                                         |
| `anthropic.message.batch.request_count` | `int`    | 僅在 `create` 上。[`requests`](https://platform.claude.com/docs/zh-TW/api/messages/batches/create#create.requests) 陣列中的項目數量。 |

### `anthropic.sessions.<method>`

* **來源：** SDK 和 API。
* **類型：** 來自 SDK 時為 `CLIENT`，來自 API 時為 `SERVER`。
* **SDK span 的父項：** 應用程式呼叫該方法時目前的 span；若沒有目前的 span，則為無。
* **API span 的父項：** 請求之 [`traceparent` 標頭](https://platform.claude.com/docs/zh-TW/manage-claude/opentelemetry/api#connect-api-spans-to-your-own-traces)中的 span，當請求來自 SDK 時即為 SDK span；若沒有該標頭，則為無。
* **SDK span 的子項：** 該請求的 API span。
* **API span 的子項：** 無。

API 會針對 [Sessions API](https://platform.claude.com/docs/zh-TW/managed-agents/sessions) 端點的每個已驗證請求發出一個 `anthropic.sessions.<method>` span。平台代表使用者傳送的請求，例如在 Claude Console 中傳送的訊息，或由[排程部署](https://platform.claude.com/docs/zh-TW/managed-agents/scheduled-deployments)啟動的工作階段，也各有一個 span，且各自位於新的追蹤中。

<Accordion title="Span 名稱與端點">
  | Span                                       | 端點                                                                                                                                           |
  | ------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------- |
  | `anthropic.sessions.create`                | [`POST /v1/sessions`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/create)                                                       |
  | `anthropic.sessions.list`                  | [`GET /v1/sessions`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/list)                                                          |
  | `anthropic.sessions.retrieve`              | [`GET /v1/sessions/{session_id}`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/retrieve)                                         |
  | `anthropic.sessions.update`                | [`POST /v1/sessions/{session_id}`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/update)                                          |
  | `anthropic.sessions.delete`                | [`DELETE /v1/sessions/{session_id}`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/delete)                                        |
  | `anthropic.sessions.archive`               | [`POST /v1/sessions/{session_id}/archive`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/archive)                                 |
  | `anthropic.sessions.events.send`           | [`POST /v1/sessions/{session_id}/events`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/events/send)                              |
  | `anthropic.sessions.events.list`           | [`GET /v1/sessions/{session_id}/events`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/events/list)                               |
  | `anthropic.sessions.events.stream`         | [`GET /v1/sessions/{session_id}/events/stream`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/events/stream)                      |
  | `anthropic.sessions.resources.add`         | [`POST /v1/sessions/{session_id}/resources`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/resources/add)                         |
  | `anthropic.sessions.resources.list`        | [`GET /v1/sessions/{session_id}/resources`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/resources/list)                         |
  | `anthropic.sessions.resources.retrieve`    | [`GET /v1/sessions/{session_id}/resources/{resource_id}`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/resources/retrieve)       |
  | `anthropic.sessions.resources.update`      | [`POST /v1/sessions/{session_id}/resources/{resource_id}`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/resources/update)        |
  | `anthropic.sessions.resources.delete`      | [`DELETE /v1/sessions/{session_id}/resources/{resource_id}`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/resources/delete)      |
  | `anthropic.sessions.threads.list`          | [`GET /v1/sessions/{session_id}/threads`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/threads/list)                             |
  | `anthropic.sessions.threads.retrieve`      | [`GET /v1/sessions/{session_id}/threads/{thread_id}`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/threads/retrieve)             |
  | `anthropic.sessions.threads.archive`       | [`POST /v1/sessions/{session_id}/threads/{thread_id}/archive`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/threads/archive)     |
  | `anthropic.sessions.threads.events.list`   | [`GET /v1/sessions/{session_id}/threads/{thread_id}/events`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/threads/events/list)   |
  | `anthropic.sessions.threads.events.stream` | [`GET /v1/sessions/{session_id}/threads/{thread_id}/stream`](https://platform.claude.com/docs/zh-TW/api/beta/sessions/threads/events/stream) |
</Accordion>

此 span 具有[工作階段屬性](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#session-attributes)。SDK span 也具有每個[請求之 SDK span](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-resources-method) 的屬性。

| 屬性           | 類型       | 說明                                                                                                                                                                                                                                                                                                       |
| ------------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `error.type` | `string` | 失敗請求的[錯誤類型](https://platform.claude.com/docs/zh-TW/api/errors#http-errors)，例如 `rate_limit_error`。<br />**SDK：** 也包括[請求之 SDK span](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-resources-method) 中的其他值。<br />**API：** 當 API 在沒有錯誤回應的情況下關閉連線，或串流因 API 中的失敗而結束時，為 `api_error`。 |

### `anthropic.environment.work`

* **來源：** CLI，以及 Python、TypeScript 和 Go 的 SDK。
* **類型：** `INTERNAL`。
* **父項：** 環境工作程式或工作輪詢器取得工作項目時應用程式中目前的 span；若沒有目前的 span，則為無。在 `ant beta:worker poll` 中，此 span 為根 span。
* **子項：** 環境工作程式在處理該工作項目時所傳送之請求的 span，以及其為該工作項目所執行之每個工具的[工具 span](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-tool-use-anthropic-mcp-tool-use-and-anthropic-custom-tool-use)。

環境工作程式和工作輪詢器是在自行託管沙箱中認領工作項目的 [SDK 輔助工具](https://platform.claude.com/docs/zh-TW/managed-agents/self-hosted-sandboxes#sdk-helpers)。它們會為每個工作項目發出一個 `anthropic.environment.work` span，範圍從輪詢傳回該工作項目開始，直到其處理結束為止。

| 屬性                              | 類型       | 說明                                                                  |
| ------------------------------- | -------- | ------------------------------------------------------------------- |
| `anthropic.environment.id`      | `string` | 環境的 ID。                                                             |
| `anthropic.environment.work.id` | `string` | 工作項目的 ID。                                                           |
| `anthropic.session.id`          | `string` | 工作項目所屬工作階段的 ID。                                                     |
| `error.type`                    | `string` | 若某個請求結束了處理，則為該失敗請求所對應之 span 的 `error.type`。其他任何失敗則為 `client_error`。 |

### `anthropic.<resources>.<method>`

* **來源：** SDK。
* **類型：** `CLIENT`。
* **父項：** 應用程式呼叫該方法時目前的 span；若沒有目前的 span，則為無。
* **子項：** 無。

每個會傳送請求且在本頁面中沒有專屬章節的 SDK 方法，都會發出一個 `anthropic.<resources>.<method>` span，例如 `anthropic.models.list` 或 `anthropic.files.upload`。清單中每個後續頁面的請求都有自己的 span。

一個 span 涵蓋其整個請求（包括重試），並且在 SDK 擁有該值時，具有 API 同名 span 的每個屬性。SDK 會在啟動 span 時設定 `http.request.method` 和 `http.route`，以便取樣器可以使用它們。

每個請求的 SDK span，包括 [`anthropic.messages.create`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-messages-create)、[`anthropic.messages.count_tokens`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-messages-count-tokens) 和 [`anthropic.messages.batches.<method>`](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#anthropic-messages-batches-method)，都具有下列屬性：

| 屬性                          | 類型       | 說明                                                                                                                                                                                                                                                                                                                                                                                              |
| --------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `gen_ai.conversation.id`    | `string` | 透過 [`conversation_id` (typescript, java, php: `conversationId`; csharp: `ConversationId`; go: `option.WithOpenTelemetryConversationID()`) 選項](https://platform.claude.com/docs/zh-TW/manage-claude/opentelemetry/sdk#configure-the-sdk)傳入的對話 ID。若未提供，則在[工作階段屬性](https://platform.claude.com/docs/zh-TW/api/opentelemetry/spans#session-attributes)所列的 Managed Agents 請求上為工作階段執行緒 ID，在其他請求上則不存在。 |
| `anthropic.<resource>.id`   | `string` | 請求路徑中的每個 ID 各有一個屬性，方法所建立之物件的 ID 也有一個屬性。名稱取自路徑，採單數形式，例如 `anthropic.session.id` 或 `anthropic.session.thread.id`。                                                                                                                                                                                                                                                                                  |
| `gen_ai.agent.id`           | `string` | 代理的 ID，位於代理方法上。                                                                                                                                                                                                                                                                                                                                                                                 |
| `gen_ai.memory.store.id`    | `string` | 記憶儲存區的 ID，位於記憶儲存區方法上。                                                                                                                                                                                                                                                                                                                                                                           |
| `gen_ai.memory.record.id`   | `string` | 記憶的 ID，位於記憶方法上。                                                                                                                                                                                                                                                                                                                                                                                 |
| `http.request.resend_count` | `int`    | SDK 因任何原因（例如重試）重新傳送請求的次數。SDK 未重新傳送時不存在。                                                                                                                                                                                                                                                                                                                                                         |
| `error.type`                | `string` | 失敗呼叫的[錯誤類型](https://platform.claude.com/docs/zh-TW/api/errors#http-errors)，例如 `rate_limit_error`。當錯誤回應沒有錯誤類型時，為 HTTP 狀態碼，例如 `502`。當呼叫在 SDK 中失敗時，為 `connection_error`、`client_timeout_error` 或 `client_error`。當伺服器提前結束串流時，為 `api_error`。                                                                                                                                                         |
| `server.address`            | `string` | 用戶端基礎 URL 的主機，預設為 `api.anthropic.com`。在雲端平台的用戶端上，則為該平台的主機。                                                                                                                                                                                                                                                                                                                                      |
| `url.query`                 | `string` | URL 的查詢字串，僅包含端點所定義的查詢參數。沒有時不存在。在僅限中繼資料模式下，當查詢含有敏感參數（例如 `email`）時不存在。                                                                                                                                                                                                                                                                                                                            |
| `url.full`                  | `string` | 由 `url.scheme`、`server.address`、連接埠（當基礎 URL 有連接埠時）、`url.path` 和 `url.query` 組成的 URL。在僅限中繼資料模式下，只要該模式省略 `url.query`，即不存在。                                                                                                                                                                                                                                                                        |
