Agent Tracing: See Every Tool Call and Provider Attempt

OpenRouter ·

Agent Tracing: See Every Tool Call and Provider Attempt

When an agent running in your harness sends a tool the wrong argument, or one step takes two minutes, a request log will not tell you much. It shows each call on its own, so you cannot see which step in the run went wrong or why.

Agent tracing gives you that view. It records each step of a run as a timed span and links the spans into one trace. Your code records the tool calls and how the run ended, and OpenRouter Broadcast records each model generation and each provider attempt. Both sides use OpenTelemetry, so their spans land in the same trace and you can read one run from start to finish.

We traced 27 runs of an order-support agent on three models and sent both sets of spans into Jaeger. The agent’s own spans caught the bad tool argument in all 9 runs where the model sent one. Our spans showed which provider served every call, recorded three provider failures we recovered from, and showed that a 133-second model call was almost all spent waiting on the provider.

Tl;dr

  • Record tool calls and the run in your own code, and add a Broadcast destination to get our spans for each generation and provider attempt.
  • Pass your trace id and span id in the request’s trace field, and we place our spans inside your run.
  • The TypeScript SDK takes camelCase keys (traceId, parentSpanId), while a raw HTTP body takes snake_case.
  • Privacy Mode drops prompt and completion text but keeps tokens, cost, and timing.
  • In 27 runs, all 98 model calls matched one of our generation spans, with the same cost on both sides.

What is agent tracing?

A trace is the record of one agent run, and it is made of spans. Each span is one timed step, such as the whole run, a model call, a tool call, or a provider attempt. Spans that share a trace id and point to a parent form a tree, which is what separates LLM tracing from plain logging, where every line stands alone.

Each side of your system sees part of the tree. Your agent code knows what it sent to each tool and how the run ended, but not which provider served a model call, whether we retried with another provider, or how long the provider took to send its first token. We know all of that, but we cannot see what your tools did between turns.

Diagram showing an agent sending OTLP spans directly and OpenRouter Broadcast sending provider attempt spans to the same tracing backend under one trace ID.

Both sides send spans in the OpenTelemetry Protocol (OTLP) format, so this setup feeds any backend you already use for LLM observability. When every request carries your trace id and span id, the backend puts both sides in one tree.

What should an agent trace include?

From your own code, you want a span for the run, one for each model call, and one for each tool call. The OpenRouter Agent SDK lifecycle hooks give you the data for each. SessionEnd tells you why the run ended (complete, error, max_turns, or user). PostModelCall gives you the generation id (responseId), the model, the duration, the turn number, and token usage with cost, but not the prompt or reply. PostToolUse gives you the tool name, arguments, output, and duration, and PostToolUseFailure gives you the tool name, arguments, and error.

From our side, Broadcast sends an LLM Generation span for every model call, with no code on your part. It holds the model, the provider, tokens, cost, user.id, router timing, and the provider’s time to first token. If you turn on Cost under Additional generation metadata, it also carries billing fields such as billed_service_tier and upstream_id, the provider’s own request id.

Each generation span has two kinds of child span. A provider-attempt span, named like provider attempt 1: Google, records each attempt with its own status and duration. In our test, a call with one attempt always had an attempt span exactly as long as the provider’s time to first token. A generation span covers the streaming after the first token.

How do you trace tool calls and model calls in your agent?

Open a run span when the agent starts, add a child span from each lifecycle hook, and close the run span when the run ends, even if it fails.

When PostToolUseFailure fires, mark the tool span as an error and keep the message, so a bad argument stands out even after the model fixes it. Store responseId on your model-call span, because it matches gen_ai.response.id on our generation span. Also mark the run span as an error in your catch block, because PostModelCall does not fire for a request that fails before a full response comes back.

Pass a customer id in the user field as well. We record it as user.id, so you can filter both sides by customer. The user tracking guide covers how to pick a stable id.

How do you add our spans to your agent’s trace?

Add a Broadcast destination under Settings > Observability, then send your trace id and span id with every request. Broadcast can send to Langfuse, Datadog, an OpenTelemetry Collector, a Webhook, and many other destinations. We send traces after each request finishes, so Broadcast does not slow down your responses. In our test, Jaeger ran on a laptop that Broadcast could not reach, so we used a Webhook destination and a small relay that forwarded each payload into Jaeger.

The request’s trace field takes trace_id, parent_span_id, trace_name, span_name, and generation_name, and any other key shows up as trace.metadata.. With the Agent SDK, you take the ids from your run span and pass them in camelCase.

const { traceId, spanId } = runSpan.spanContext();
const result = callModel(client, {
  model: "anthropic/claude-haiku-5.5",
  input: prompt,
  tools,
  user: customerId,
  trace: { traceId, parentSpanId: spanId, traceName: "support-agent run" },
  hooks,
});

Here client is an OpenRouter instance, and callModel comes from @openrouter/agent. Every generation span came back with the run’s trace id and the run span as its parent. That places it next to the matching model-call span, and the generation id lines the two up.

Without the SDK, put the ids in the request body.

{
  "model": "anthropic/claude-haiku-5.5",
  "messages": [{ "role": "user", "content": "Where is my order ORD-10442?" }],
  "user": "customer_8812",
  "trace": {
    "trace_id": "4bf92f3577b34da6a3ce929d0e0e4736",
    "parent_span_id": "00f067aa0ba902b7",
    "trace_name": "support-agent run"
  }
}

We made two mistakes while setting this up. First, we sent bcast_test_001 as a trace id. Real trace ids are 32 hex characters and span ids are 16, so our span came back under a different trace id that matched nothing. Taking the ids from spanContext() avoids this.

Second, we passed snake_case keys to the TypeScript SDK. TypeScript rejects trace: { trace_id, parent_span_id } with error TS2353. When we forced it through with a type cast, the SDK threw no error and sent an empty trace object, so each of the four model calls landed in its own separate trace. With camelCase keys, all four joined.

How do you trace LLM calls without sending prompts to your tracing vendor?

Turn on Privacy Mode in the Privacy section of a Broadcast destination. You set it per destination, so you can send full traces to one destination for debugging and private traces to another for cost tracking.

With Privacy Mode on, we remove the prompt, the reply, and the error text before we send the trace. We ran all 27 test runs this way and searched every payload for words from our prompts and tool results, and none showed up. Tokens, cost, model, provider, and user.id were on every generation span, and failed provider attempts kept their HTTP status code.

Some things still go out. Model parameters are kept, including any stop sequences, so our test stop sequence PRIVATE_STOP_TEST appeared as gen_ai.request.stop_sequences, and custom trace metadata is still exported. Each generation span also carries your OpenRouter account’s user id and the name of the API key that made the request.

If you cannot send prompts to an outside vendor at all, send your tool spans to a backend you run yourself and let Broadcast add our spans with Privacy Mode on—keeping both custom trace metadata and caller-supplied stop sequences strictly non-sensitive, or disabling trace export altogether if you cannot guarantee that.

What did each side catch in 27 agent runs?

We built an order-support agent for an outdoor gear shop with @openrouter/agent 0.11.0 and a step limit of 8. Its lookup_order tool rejects any id that does not look like ORD-12345, though its description does not say so. Its get_shipment tool always answers “pending, try again”, and issue_refund takes the amount in cents.

We gave it three tasks. One customer asks about “order 10442” without the ORD- prefix, another asks why order ORD-10518 has not arrived, and a third wants a refund on one of two headlamps in order ORD-10377.

On November 10, 2026, we ran each task three times on Gemini 3.8 Flash, Claude Haiku 5.5, and DeepSeek V4.1 Flash. The 27 runs made 98 model calls for $0.0227 in total. Every model call matched exactly one of our generation spans, and the cost on each span equaled the cost the SDK reported.

What happenedRunsYour agent’s spansOpenRouter’s spans
The model sent 10442 instead of ORD-10442, and the tool returned “order_id must look like ORD-12345, got ‘10442’”9 of 9The failed lookup_order span with the bad argument and error. The model retried with ORD-10442 in 8 of 9 runsOne more generation, with nothing about why
The carrier never answered9 of 9Each get_shipment call. Gemini called it twice in every run, Haiku once, and DeepSeek once or twiceOne more generation for each call
The agent refunded one headlamp9 of 9 correctThe exact arguments (amount: 4999, sku LAMP-400)Nothing about the amount
Which provider served each callAll 98 callsNot visibleGemini on Google Vertex AI (35) and Google AI Studio (3), Haiku on Claude Platform on AWS (30), DeepSeek across nine providers
A provider failed and OpenRouter tried another3 generations, all in one Gemini runSlow model callsBoth attempts for each, with HTTP status and duration

No run ended in an error, but two Gemini 3.8 Flash runs show what each side sees that the other cannot.

The slowest run took 151.7 seconds. The agent’s spans showed one model call taking 133.5 seconds, and our generation span showed that the attempt to Google lasted 131.2 seconds of it. Almost all of that call was spent waiting for Google’s first token.

The other was a refund run of about 48 seconds. Its first model call got a 504 error from Google after 10,282 ms, and we then got the response from Google AI Studio in 2,044 ms. The next two calls did the same after Google returned 400 errors. The agent’s spans showed only slow model calls. In the same run, the SDK sent the HTTP request for its second model call twice, and we have a generation for only one of those two requests, starting 11.4 seconds after the agent’s model-call span. We did not record what happened to the unanswered request, but those seconds appear only in the agent’s trace.

Jaeger waterfall view of a support-agent run joining local tool-call spans and OpenRouter Broadcast provider spans in one trace.

Our spans also explain speed differences between models, which is the part of LLM monitoring your own code cannot measure. The table shows medians for one model call.

ModelYour agent sees (SDK durationMs)OpenRouter generation spanProvider time to first token
Gemini 3.8 Flash3,154.5 ms2,454.5 ms1,963.5 ms
Claude Haiku 5.52,149.8 ms1,490.5 ms1,177.0 ms
DeepSeek V4.1 Flash1,848.2 ms1,350.5 ms769.0 ms

The agent’s numbers run 498 to 700 ms longer than ours because they also count time outside OpenRouter, such as the network trip. Gemini’s median time to first token was about 1.7 times Haiku’s and 2.6 times DeepSeek’s.

Frequently asked questions

What is the difference between LLM tracing and logging?

A log line records one event on its own. A trace links every step of one run with timing and parent-child order, so you can see which step caused the next and where the time went.

Does OpenTelemetry work for LLM agents?

Yes. Our agent’s spans and our Broadcast spans both use OTLP, and they landed in the same Jaeger trace once each request carried the run’s trace_id and parent_span_id.

Can I trace LLM calls without the OpenRouter Agent SDK?

Yes. Any agent loop can open a span around each tool call and model call, and the trace field with trace_id and parent_span_id works on any OpenRouter request.

Can I trace LLM calls without logging prompts?

Yes. Turn on Privacy Mode for the Broadcast destination, and we strip the prompt, the reply, and the error text while still sending tokens, cost, timing, and the provider. Keep in mind that stop sequences are still sent.

Can I send only some traces?

Yes. Each Broadcast destination has its own sampling rate, so a rate of 0.5 sends about half of your traces. When you pass a session_id, sampling keeps or drops a whole session together. You can also choose which API keys a destination receives traces from, or exclude certain keys.

Next steps

Set up a destination with the Broadcast guide. An OpenTelemetry Collector sends our spans to any OTLP backend, and a Webhook lets you handle the data yourself. Then add tool and model spans to your agent with the Agent SDK lifecycle hooks, and pass a user id on every request so you can filter both sides by customer. Once you can see what each customer costs, our Team Spend Controls setup guide shows you how to cap it.

By subscribing you agree to receive the OpenRouter newsletter: model usage data, product updates, and research reports, about one email a week. Unsubscribe anytime via the link in every email. See our Privacy Policy.