# Send traces from any OpenTelemetry SDK

Point an OpenTelemetry exporter at Amiril with three standard variables, learn the span attributes Amiril reads and check that your traces arrived.

Amiril is an OpenTelemetry destination. Your agent exports its spans with OpenTelemetry's own SDK, and three standard variables point that exporter at Amiril. You add no Amiril code.

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

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>"
```

The OTLP exporter in every OpenTelemetry SDK reads them. Amiril takes OTLP over HTTP as protobuf or JSON, but not over gRPC.

## Export spans from your agent [#export-spans-from-your-agent]

If your agent runs on a framework, its guide lists the instrumentation to install and the lines that turn on export. There are guides for [Google ADK](/traces/google-adk), [LangGraph](/traces/langgraph), [CrewAI](/traces/crewai) and [other frameworks](/traces#send-traces-from-a-framework).

Otherwise you set up OpenTelemetry yourself. Install the SDK and its OTLP HTTP exporter:

```bash tab="Python"
pip install opentelemetry-sdk opentelemetry-exporter-otlp-proto-http
```

```bash tab="TypeScript"
npm install @opentelemetry/api @opentelemetry/context-async-hooks @opentelemetry/resources @opentelemetry/sdk-trace @opentelemetry/exporter-trace-otlp-proto
```

When the agent starts, register a tracer provider that sends spans through that exporter. Then write a span for each step. The Python script does both for one payments agent run with one `issue_payment` call. The TypeScript lines register the provider:

```py tab="Python" title="first_trace.py"
import json

from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor

# The exporter reads the endpoint and the API key from the OTEL_ variables.
provider = TracerProvider(resource=Resource.create({"service.name": "payments-agent"}))
provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter()))
trace.set_tracer_provider(provider)
tracer = trace.get_tracer("payments-agent")

# One run of the payments agent: a root span with one tool call inside it.
with tracer.start_as_current_span("invoke_agent payments") as run:
    run.set_attribute("gen_ai.operation.name", "invoke_agent")
    run.set_attribute("gen_ai.agent.name", "payments")
    with tracer.start_as_current_span("execute_tool issue_payment") as call:
        call.set_attribute("gen_ai.operation.name", "execute_tool")
        call.set_attribute("gen_ai.tool.name", "issue_payment")
        call.set_attribute("gen_ai.tool.call.arguments", json.dumps({"amount": 120, "currency": "EUR"}))
        call.set_attribute("gen_ai.tool.call.result", json.dumps({"status": "sent"}))

# Send the spans before the script exits.
provider.shutdown()
```

```ts tab="TypeScript" title="tracing.ts"
import { context, trace } from "@opentelemetry/api";
import { AsyncLocalStorageContextManager } from "@opentelemetry/context-async-hooks";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
import { detectResources, envDetector } from "@opentelemetry/resources";
import { BatchSpanProcessor, TracerProvider } from "@opentelemetry/sdk-trace";

// A script must call `await provider.shutdown()` before it exits, or its last spans are lost.
export const provider = new TracerProvider({
  resource: detectResources({ detectors: [envDetector] }),
  spanProcessors: [new BatchSpanProcessor({ exporter: new OTLPTraceExporter() })],
});
trace.setGlobalTracerProvider(provider);
context.setGlobalContextManager(new AsyncLocalStorageContextManager());
```

## Span attributes Amiril reads [#span-attributes-amiril-reads]

Amiril reads the OpenTelemetry GenAI conventions, OpenInference and OpenLLMetry. Framework instrumentations set these attributes for you. If you write spans yourself, as the script above does, this is what Amiril looks for:

- **One trace per run.** Amiril reads the trace's root span as the run and every span under it as a step.
- **The agent's name.** Put it in `gen_ai.agent.name`, on the root span or on an `invoke_agent` span. Each name you send becomes an agent in Amiril, listed under **Unregistered** on the **Agents** page until you [register](/agents) it. A run without one lands under **Unattributed**.
- **Tool calls.** Set `gen_ai.operation.name` to `execute_tool`, the tool in `gen_ai.tool.name`, and its arguments as JSON in `gen_ai.tool.call.arguments`. The result goes in `gen_ai.tool.call.result`. [Rules](/rules) and [rarity factors](/monitor/signals) read the arguments.
- **Model calls.** Set `gen_ai.operation.name` to `chat`, with `gen_ai.request.model` and the token counts in `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens`.
- **Sessions.** When several runs belong to one conversation, put its id in `gen_ai.conversation.id`.

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

Run your agent once. While the setup panel is open, **First data** changes to "A trace arrived. Data is reaching this workspace."

After that, the **Connections** card on the **Data** page shows the time of the **Last trace received**, with a **Receiving** badge while traces keep coming. The runs show on the **Traces** page. Each has a **Scoring** badge until Amiril has ranked it against the agent's other runs.

If nothing arrives, read what your exporter logged. In Python, the exporter logs each failed export with its HTTP status, so a wrong key or endpoint shows up there. In Node.js it stays silent until you set a logger with OpenTelemetry's `diag.setLogger`.

## Next steps

- [Send your first trace](https://docs.amiril.ai/quickstart/traces.md): Send one run of a payments agent to Amiril over OpenTelemetry, then find it on the Traces page. A short Python script and about five minutes.
- [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.
- [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.

## 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.
- [Limits and defaults](https://docs.amiril.ai/assistant/limits.md): Every limit and default a customer can hit in Amiril, with its number: plan amounts, ingest sizes and rates, imports, rules, backtests, API and MCP rates, page sizes, retention, name lengths.
- [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.
