# Send traces from the Claude Agent SDK

Send each run of a Claude Agent SDK agent to Amiril over OpenTelemetry by setting environment variables, then name the agent after your service.

The Claude Agent SDK runs Claude Code, and Claude Code exports OpenTelemetry traces once telemetry is on. There is nothing to install and no tracing code to add, in Python or TypeScript.

## Set the endpoint and key [#set-the-endpoint-and-key]

Claude Code reads its telemetry settings from the environment, and the Agent SDK passes your agent's environment on to it.

In Amiril, create an API key and copy the endpoint:

1. Switch to the [environment](/traces/environments-and-keys) your runs belong to, with the menu at the top of the page.
2. Open **Data** and select **Set up a new installation**. It opens a panel that connects an agent to Amiril.
3. In the panel, enter a **Key name** under **Create a new key** and select **Create key**.
4. Copy the key and the **OpenTelemetry traces endpoint**.

Then set these variables where your agent runs:

```bash
export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="<OpenTelemetry traces endpoint>"
export OTEL_EXPORTER_OTLP_TRACES_PROTOCOL="http/protobuf"
export OTEL_EXPORTER_OTLP_TRACES_HEADERS="Authorization=Bearer <your API key>"
export CLAUDE_CODE_ENABLE_TELEMETRY="1"
export CLAUDE_CODE_ENHANCED_TELEMETRY_BETA="1"
export OTEL_TRACES_EXPORTER="otlp"
export OTEL_LOG_TOOL_CONTENT="1"
export OTEL_SERVICE_NAME="payments"
```

The first three lines point the exporter at Amiril. `CLAUDE_CODE_ENABLE_TELEMETRY` turns on Claude Code's telemetry. `CLAUDE_CODE_ENHANCED_TELEMETRY_BETA` adds traces, which Claude Code still marks as beta. `OTEL_TRACES_EXPORTER` sends the traces over OTLP and `OTEL_LOG_TOOL_CONTENT` adds tool results to the spans. `OTEL_SERVICE_NAME` names your service, and the next step makes it the agent's name.

## Name the agent [#name-the-agent]

Claude Code puts no agent name on its spans, so its runs land under **Unattributed** on the **Agents** page, with every other run that has no agent name. Tell Amiril to read the name from `service.name` instead.

The setting covers the whole environment. After the change, every run in it takes its agent name from `service.name`, even a run that already named its agent. To leave your other agents as they are, send this one to an [environment](/traces/environments-and-keys) of its own.

If you keep one environment, each agent you already have keeps its display name and settings. Only the name it is seen under changes, to the service name on its runs. Two agents with the same service name become one agent, so give each service its own `OTEL_SERVICE_NAME` first. Changing the setting needs the admin role.

1. Open **Agents**, find **Where agent names come from** and select **Change**.
2. Under **Read the agent name from**, choose **A trace metadata field**. Enter `service.name` as the **Metadata field**.
3. Select **Apply**, then **Re-process imports** to confirm. The button names imports, but live runs are re-read too.

Re-reading the runs usually takes a few minutes.

## Check that traces arrived [#check-that-traces-arrived]

Run the agent and open **Traces**. The run belongs to the `payments` agent. Open it to see each tool call with its result, and each model call. Claude Code does not record a tool's arguments. So [rules](/rules) and [rarity factors](/monitor/signals) that read arguments have nothing to check on these runs.

A new run shows a **Scoring** badge until Amiril has ranked it. If no run appears, [read what the exporter logged](/traces/opentelemetry#check-that-traces-arrived).

## Next steps

- [Find a run and see why it was flagged](https://docs.amiril.ai/monitor/runs.md): Open a run from an issue, the Anomalies page or the Traces page and see why Amiril flagged it. Then review it to teach Amiril which rarity factors are noise.
- [Set up environments and API keys](https://docs.amiril.ai/traces/environments-and-keys.md): Create an environment such as Staging and an API key that sends to it, so test runs stay out of production. Then put the key where each service runs.
- [Send traces from the Anthropic SDK](https://docs.amiril.ai/traces/anthropic-sdk.md): The Anthropic SDK traces itself in Python or TypeScript once OpenTelemetry is set up. Send each tool runner call to Amiril as a run named after your service.
- [Send traces from LiveKit Agents](https://docs.amiril.ai/traces/livekit.md): Give LiveKit Agents a tracer provider and send each voice session to Amiril over OpenTelemetry as one run, with every turn and the tool calls made in it.

## More detail

- [Trace attributes Amiril reads](https://docs.amiril.ai/assistant/traces/attributes.md): Every span attribute and Langfuse field Amiril reads, per dialect: what makes a run, tool call or generation, how agent and session are found, the OTLP receiver, and what is ignored.
- [Troubleshooting](https://docs.amiril.ai/assistant/troubleshooting.md): Symptom, cause, how to confirm and fix for common Amiril problems: missing runs, plan limits, wrong agent or environment, rules that never fire or never block, SDK, key, import and MCP failures.
