Need more detail? Connect your coding agent to the full docs.

Skip to Content
AMIRILDocs

Send traces from the Anthropic SDK

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.

The Anthropic SDK traces its own calls once your app sets up OpenTelemetry, with no instrumentation package. Each call to the SDK's tool runner becomes one run in Amiril. A model call made outside the tool runner does not make a run.

Install

pip install opentelemetry-sdk opentelemetry-exporter-otlp-proto-http

Turn on trace export

Run these lines once when your agent starts, before it creates its client.

tracing.py
from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor

provider = TracerProvider()
provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter()))
trace.set_tracer_provider(provider)

Set the endpoint and key

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

  1. Switch to the environment 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:

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 ANTHROPIC_OPEN_TELEMETRY_TRACES_CONTENT_MODE="content"
export OTEL_SERVICE_NAME="payments"

The first three lines point the exporter at Amiril. ANTHROPIC_OPEN_TELEMETRY_TRACES_CONTENT_MODE puts tool arguments and messages on the SDK's spans. OTEL_SERVICE_NAME names your service, and the next step makes it the agent's name.

Name the agent

The tool runner's spans carry no agent name, 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 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

Run the agent and open Traces. The run belongs to the payments agent. Open it to see each tool call with its arguments, and each model call. The SDK does not record a tool's result.

A new run shows a Scoring badge until Amiril has ranked it. If no run appears, read what the exporter logged.

Next steps

Last updated on