LLM observability: traces, OpenTelemetry GenAI, Langfuse and peers, evals in the loop

What a trace of an agent run holds, the OpenTelemetry GenAI conventions (pinned commit cb10b70), one recorded run instrumented eight ways, self-hosted Langfuse 4.53.0, a Claude Code run traced across three processes with its cost reconciled to the cent, tail sampling and redaction measured on a real OpenTelemetry Collector, and scores written back onto traces. A child of Topic: agentic-frameworks. Data as of 6 October 2026. Reading: 34 min, plus 9 in closed details.

The idea in one screen

Record every agent run as one trace: a tree of timed spans, one for the run, one for each model call and one for each tool call. Everything else on this page (cost, sampling, redaction, scores) reads the attributes on those spans, so what you put on them decides what you can answer later.

Why: a run's final answer does not say which step failed, cost too much or took too long. Observability means recording enough about every step, while it runs, to answer questions you did not think to ask beforehand.

Fig. 1, step by step: the local run of the running example (8 model calls, 7 tool calls), then the path its spans take

  1. One root span for the run. invoke_agent textstats-fixer opens first and closes last; every span of the run hangs under it and shares its 128-bit trace id.
  2. A child span per model call. Eight chat spans, each as long as the call took on the shared local server (call 4 waited 78 s) and as tall as its prompt: the context grows from 424 to 1,545 tokens as tool results pile up.
  3. A child span per tool call. Seven execute_tool spans (list_files, read_file twice, edit_file twice, run_tests twice), each after the call that asked for it; milliseconds long, drawn at a minimum width. What happened: sections 1 to 3.
  4. Attributes carry the answers. Up close, call 4's span: the model, its tokens by kind (859 in, 739 of them from the server's prompt cache, 228 out) and its 78 s. The root carries user, session and outcome. Content (prompts, tool arguments) is opt-in (sections 2 and 8).
  5. The exporter ships finished spans. Batched over OTLP, to a collector or straight to a backend; who opens which spans is section 3.
  6. The collector samples and redacts. A process you control keeps or drops whole traces and masks personal data before anything leaves your network: sections 7 and 8.
  7. The backend stores and prices. Langfuse here: tokens and cost on every span, rolled up to the root; $0 for this run, correctly, as a local model has no price. What it cost: sections 4 to 6.
  8. Evaluators read traces back and write scores. A rule wrote tests_pass = 1 onto this trace; low scores feed a dataset that gates the next change (section 9).

You need spans, context propagation and head against tail sampling in general: Observability: logs, metrics, traces, alerting owns them. The parent root's section 7 and its Production stack tab give the overview (one trace rendered and priced, a small eval gate). This page is the agent- and LLM-specific layer.

span
one timed operation: name, start and end, parent, status, attributes, events
trace
all spans sharing one 128-bit trace id: one tree per run
GenAI conventions
OpenTelemetry's agreed attribute names for model calls, agents and tools (gen_ai.*)
collector
a separate OpenTelemetry process that receives spans over OTLP and can sample, redact, rename and forward them
generation, observation
Langfuse's names: an observation is any node of its trace; a generation is a model call
head, tail sampling
keep or drop a trace when it starts (cheap, blind), or after its spans arrive (can keep failures)
score
a number or label an evaluator (a rule, a model judge or a person) writes back onto a trace

The running example is the one used across the agent pages: a small Python repository, textstats, with two planted bugs and the instruction "The tests in this repository fail. Find out why and fix the code so they pass. Do not edit the tests." The user message starts with a fake customer, "Hi, this is Dana Reyes (dana.reyes@example.com, customer ACCT-4417-2290)", so we can see where personal data ends up. Everything is measured on this page's own runs unless it says otherwise MEASURED.

What was run (6 October 2026, Apple M1 Pro, 16 GB)
  • One real agent run of the plain tool-calling loop from the parent's Same agent, six ways tab against a local model (Qwen3-4B-Instruct-2507, 4-bit, on mlx-lm): 8 model calls, 7 tool calls, both bugs fixed. Its responses were recorded, then replayed byte for byte to the same loop instrumented eight different ways, so every difference between the traces is the instrumentation's, not the model's.
  • Two Claude Code runs (Claude Haiku 4.5 through claude -p, Claude Code 2.1.291, the same task) with Claude Code's beta tracing on, launched from a small Python "application" that passes its trace context down, so one trace covers three processes.
  • Self-hosted Langfuse 4.53.0 in Docker (six containers) receiving all of it over OpenTelemetry; OpenTelemetry Collector contrib 0.162.0 in Docker for cost mapping, tail sampling and redaction.
  • Versions: Langfuse Python SDK 4.17.0, opentelemetry-sdk 1.45.1, opentelemetry-instrumentation-openai-v2 2.4b0 with opentelemetry-util-genai 0.4b0 (1.2b0 breaks its import), OpenLLMetry's opentelemetry-instrumentation-openai 0.62.4, openinference-instrumentation-openai 0.1.63, pydantic-ai-slim 2.54.0, openai 3.25.0, Claude Code 2.1.291 (Claude subscription, --setting-sources project --strict-mcp-config --no-session-persistence), mlx-community/Qwen3-4B-Instruct-2507-4bit on mlx-lm 0.32.0. Scripts, collector configurations, redacted recordings and data are in this page's src/.

Neighbours that own what this page only names: GPU counters, goodput and GPU-hour chargeback are on Observability and cost; how to grade agent runs is on Agent and trajectory evaluation; gates, golden sets and online scoring budgets are on Production eval engineering; judge design on LLM-as-judge.

1. Traces and spans

The problem. The local run made model calls and 7 tool calls in a loop. A log line per call gives a list that cannot say which model call asked for which tool, which calls belonged to which run when two runs interleave, or how long the run waited on the model against running tools.

How a trace answers it. Each span has a name, a start and end time, a parent span (none for the root), a status (unset, ok or error), attributes (key-value pairs such as the model name and token counts) and optional events (timestamped notes inside the span). The program creates spans through the OpenTelemetry API; an exporter ships finished spans over OTLP (the OpenTelemetry protocol) to a collector or straight to a backend that stores and draws them (Langfuse, Jaeger, Datadog and many others).

The same recorded run, three ways (beside this text). Predict first: what does a popular client auto-instrumentation give you for this run? The card opens on the finished run; switch the view, then step through the same recorded run three ways, operation by operation. Logs: print statements. Auto spans: one span per model call, each in a trace of its own. Agent trace: one root span for the run, a child for each model call and each tool call.

Timings are the real run's: each model call's bar is how long the shared local server took to answer it (other agents' load varied, so call 4 took 78 s). Tool calls took milliseconds and are drawn at a minimum width. Token counts are the server's.

Across processes. W3C Trace Context carries the trace id and the parent span id from one process to the next in a header, traceparent. Claude Code reads it from a TRACEPARENT environment variable in claude -p and Agent SDK sessions, and hands its own context to every Bash subprocess in the same variable (Claude Code monitoring docs). A small "application" opened a span for a ticket and started Claude Code under it; a python3 wrapper on the PATH turned the inherited TRACEPARENT into a span for the test runner MEASURED (beside this text).

One trace id, three services, spans: the ticket and the agent invocation from the application, Claude Code's interaction, model requests and tool spans, and two process tests/test_core.py spans from the test runner, each under the claude_code.tool.execution span of the Bash call that started it. No shared database or request id; the context travelled in an environment variable. The header byte by byte, and what goes wrong when a hop drops it: Observability: logs, metrics, traces, alerting.

Predict, then open. The Claude Code run fixed both bugs and its result says success. Yet two of its spans have status ERROR. What were they?
A Read of a directory (EISDIR, at 10.6 s) and a test run that exited non-zero (ShellError, at 19.0 s). Both are normal in an agent: a failed test run is how the agent learns what is wrong. Span status describes one operation, not the run's outcome. Section 7 shows what this does to error-based sampling. When everything fails, put a typed error on the root span, with the same trace id the user's request had, so the incident is one query away.

One trace id across three processes; the test runner hangs under the Bash call that started it

2. The OpenTelemetry GenAI conventions

The problem. If one library writes the model under model, another under llm.model_name and a third under gen_ai.request.model, a backend cannot compute cost or group by model without a mapping for each. The GenAI conventions are OpenTelemetry's agreed names for model calls, agents and tools.

Where they live and how stable they are. In 2026 they moved out of the main conventions repository into their own, open-telemetry/semantic-conventions-genai. This page pins commit cb10b70 (5 Oct 2026) and reads the machine-readable model files (spans.yaml, registry.yaml, metrics.yaml), not the prose. Its manifest declares stability: development and schema gen-ai-dev/1.42.0-dev, built on the main conventions v1.44.0. "Development" means names can still change without a deprecation period; packages that already follow the latest draft ask you to opt in with OTEL_SEMCONV_STABILITY_OPT_IN=gen_ai_latest_experimental (see the research notes in src/inputs/research.md) SOURCE.

Span types. The model defines span types and values of gen_ai.operation.name. Three of them carry an agent run:

SpanName formatKindOne per
invoke_agentinvoke_agent {gen_ai.agent.name}INTERNAL when the agent runs in your process, CLIENT when you call a remote oneagent run (the root of an agent trace)
chat (an inference span){gen_ai.operation.name} {gen_ai.request.model}CLIENT (INTERNAL allowed for a model in the same process)model call
execute_toolexecute_tool {gen_ai.tool.name}INTERNALtool call

The others cover the rest of an LLM application: create_agent, invoke_workflow (a multi-agent or multi-step workflow), plan, retrieval, embeddings, fetch_response (reading a stored response back), and memory operations (search_memory, create_memory and five more). Explore any of them in the explorer beside this text.

Three rules that matter in practice.

  • Requirement levels. On an inference span only gen_ai.operation.name and gen_ai.provider.name are required; gen_ai.request.model is required "if available"; token counts are only recommended. A span can follow the conventions and still be useless for cost.
  • Sampling-relevant attributes (marked S) should be set when the span is created, not when it ends, because a head sampler (one that decides at span start, section 7) only sees what exists at that moment. For an inference span these are the operation, provider, model, server address and port.
  • Content is opt-in. The system instructions, input and output messages, tool definitions, and a tool call's arguments and result are all opt_in: by default the conventions record that a call happened, not what was said. Section 8 measures which libraries respect that.

Every span type at commit cb10b70: which attributes are required, and which are content

required every span must have itcond. required when the stated condition holdsrecommended set it if you canopt-in only when the user turns it onS sampling-relevant: set it when the span starts

Counting tokens. The registry says gen_ai.usage.input_tokens "SHOULD include all types of input tokens, including cached tokens", with gen_ai.usage.cache_read.input_tokens and gen_ai.usage.cache_write.input_tokens as subsets of it. Anthropic's API counts differently, so the Anthropic section adds: "Anthropic input_tokens excludes cached tokens. Compute: gen_ai.usage.input_tokens = input_tokens + cache_read_input_tokens + cache_write_input_tokens". On the first model call of our Claude Code run that is the difference between two very different numbers (drawn to scale beside this text):

input_tokensGenAI = + + =
fresh
tokens the API reported as input_tokens (not cached)
cache read
tokens served from the prompt cache (10% of the input price for Haiku 4.5)
cache write
tokens written to the cache on this call (1.25x for a 5-minute entry, 2x for a 1-hour entry)

Anthropic's input_tokens is the sliver on the left: 10 of 13,086

The first model call of the Claude Code run, drawn to scale: 10 fresh, 8,067 cache-read and 5,009 cache-write input tokens. A dashboard that reads Anthropic's field as the GenAI value shows 10 input tokens. Cost needs the three kinds apart because they have three prices; section 6 shows what happens when they are lost.
Other attributes worth knowing (conversation, prompt version, compaction, reasoning level)

gen_ai.conversation.id groups the calls of one multi-turn conversation (Langfuse turns it into a session, measured below); gen_ai.prompt.name and gen_ai.prompt.version record which version of a managed prompt produced a call (the link a prompt registry needs); gen_ai.conversation.compacted marks a call made after the history was compacted; gen_ai.request.reasoning.level carries an effort setting. On a structured-output retry loop (validate, feed the error back, retry two or three times at most; Typed agent libraries covers Pydantic AI's ModelRetry), record a span or event per retry with the validation error and watch the retry rate: a rising rate is a prompt or model regression.

Metrics. The same commit defines histograms, among them gen_ai.client.operation.duration, gen_ai.invoke_agent.duration, gen_ai.invoke_agent.inference_calls and gen_ai.invoke_agent.tool_calls. The last two are the ones to alert on for agents: a jump in model calls per run is the earliest sign of an agent looping (put the stop reason of a step, token or wall-clock budget on the root span too; budgets themselves are on Building a harness). Token usage metrics are in a separate token-metrics.yaml, as counters such as gen_ai.client.inference.usage.input_tokens and .cache_read.input_tokens; the earlier gen_ai.client.token.usage histogram is no longer defined there, so dashboards built on older instrumentation need renaming (development-status names still move: pin the version). For a serving engine the same files define gen_ai.server.time_to_first_token ("Time to generate first token for successful responses") and gen_ai.server.time_per_output_token.

The names are still moving. The provider attribute used to be gen_ai.system; it is now gen_ai.provider.name, and gen_ai.system does not appear in this repository's registry at the pinned commit. Check what your backend maps before trusting a dashboard; section 6 is what happens when you do not.

Who writes which names (measured on our runs)
In our runs, opentelemetry-instrumentation-openai-v2 2.4b0 still writes only gen_ai.system (so its spans miss a required attribute), Pydantic AI writes both, Claude Code 2.1.291 writes gen_ai.system plus its own token names (input_tokens, cache_read_tokens, cache_creation_tokens; since 2.1.300, 14 October 2026, its spans also carry gen_ai.provider.name, gen_ai.conversation.id and gen_ai.tool.name, per the changelog), and OpenInference uses a different convention altogether (llm.token_count.prompt, input.value) MEASURED.

3. Instrumenting an agent: by hand, automatically, or by the framework

The three ways. Manual instrumentation is code you write: open a span, set attributes, close it. Auto-instrumentation is a package that patches a client library (here the openai Python client) so every call it makes produces a span, with no change to your code. Framework-native instrumentation is built into an agent framework, which knows where its own runs and tool calls begin and end.

We replayed the identical recorded run through the same loop eight ways: hand-written spans with and without content, OpenTelemetry's own opentelemetry-instrumentation-openai-v2 with and without its content switch, Traceloop's OpenLLMetry, Arize's OpenInference, Langfuse's drop-in OpenAI client, and the same agent rewritten in Pydantic AI with its built-in instrumentation. All sent their spans both to a local file and to the self-hosted Langfuse MEASURED:

"Model calls / tools / root": spans of each kind. "Traces": how many trace ids the one run was split into. "Fake PII": occurrences of the fake customer's e-mail and account id in span attributes (and, for openai-v2, in its log events). "KB": total attribute size, a proxy for storage cost. "Langfuse": the observation types Langfuse stored. Every span, attribute by attribute: tab Eight instrumentations.

What the table says.

  • Auto-instrumenting the model client does not give you an agent trace. All four client-level packages produced separate traces of one span each: no run, no tool calls, nothing linking call 3 to call 4. The agent structure only appears when something that knows about the loop opens the root and the tool spans: your code, or a framework (Pydantic AI produced the same 16-span tree as our hand-written version).
  • Content defaults differ, and the difference is the privacy policy. The GenAI conventions make content opt-in, and openai-v2 obeys: by default it records no message text. With its content switch on, the text went into log events, not span attributes. OpenLLMetry, OpenInference, Langfuse's client and Pydantic AI all record prompts and completions by default (OpenLLMetry documents TRACELOOP_TRACE_CONTENT=false to stop it; Pydantic AI's InstrumentationSettings(include_content=True) is the default).
  • Size follows content. The same run cost KB of attributes without content and KB with it by hand; OpenInference, which writes the messages twice (as one JSON blob in input.value and flattened into one attribute per message field), reached KB.
  • Cached tokens are hit and miss. The local server reported prompt-cache hits (cached_tokens). OpenLLMetry, OpenInference, Langfuse and Pydantic AI recorded them; openai-v2 and our first hand-written version did not, so a backend would price those tokens as fresh input.
Why you want content somewhere: what traces revealed about frameworks

A trace with the messages is how you check what a framework really sends. The sibling page LangChain and LangGraph recorded create_agent's first request and found it is exactly your system prompt, the user message and the tool schemas, with nothing added; the parent's Same agent, six ways tab found Pydantic AI's structured output arrives through an added final_result tool (details on Typed agent libraries) and smolagents sends a 2,231-token system prompt of its own. Those findings came from logging the requests; with content capture on, your tracing backend shows the same thing for every run.

What to do. Use auto-instrumentation for the model client (it captures parameters, tokens and errors you would forget) and add the agent skeleton yourself: one invoke_agent span around the run and one execute_tool span around each tool call, both with the conventions' names, so the client spans nest under them. If a framework already does it, as Pydantic AI does, use that. Decide content capture deliberately, per environment: on in evaluation runs, where graders need the arguments and results; off or redacted in production.

Go deeper. Every span of every variant, with each attribute classified against the conventions (required, recommended, opt-in, outside the registry), and what Langfuse made of it: tab Eight instrumentations. How each typed library's own tracing works (OpenAI Agents SDK, Pydantic AI, Google ADK): Typed agent libraries. Claude Code's telemetry as a harness feature: Claude Code, taken apart.

4. Langfuse, self-hosted, fed by every variant

What it is. Langfuse is an open-source platform for tracing, evaluating and managing prompts of LLM applications: MIT-licensed except its ee/ folders (LICENSE). ClickHouse announced it had acquired Langfuse on 16 January 2026, saying it "stays open source and self-hostable" (ClickHouse blog). Version 4 became generally available on 17 August 2026 (changelog); the latest release when we ran it was 4.53.0, published that morning (releases) SOURCE.

What it took to run. Langfuse's own Docker Compose file at tag v4.53.0, ports moved to localhost: six containers (web, worker, ClickHouse 25.12, Postgres 17, Redis 7, MinIO for S3-style blob storage), about GB of images, and GiB of memory at rest after ingesting this page's traces MEASURED.

The data model. A trace is one request or run; it contains observations, typed as span, generation (a model call), event, agent, tool, chain, retriever, evaluator, embedding or guardrail (observation types). Traces group into sessions and are attributed to users; scores attach to traces or observations. Version 4 rebuilt storage around one wide, mostly immutable ClickHouse table, in which "traces are represented as root spans within the same table instead of a separate entity", and replaced the old batch ingestion API with OpenTelemetry (v3 to v4 upgrade guide).

Fig. 2, step by step: the six containers as run here, one batch of spans through them

  1. Spans arrive over OTLP. Your app or collector posts them to langfuse-web at /api/public/otel, with the project's public and secret key as HTTP Basic auth. The same container serves the UI and the API.
  2. Redis queues, the worker ingests. Redis is the queue between web and worker: langfuse-web puts each batch on it and langfuse-worker takes it off, turns spans into observations and runs evaluators.
  3. Observations go to ClickHouse. ClickHouse holds the observations and scores, in one wide, mostly immutable table; a trace is its root span in the same table.
  4. Postgres and blob storage hold the rest. Postgres holds users, projects, prompts and datasets; blob storage (MinIO, S3-style) keeps raw events.
  5. What it costs to keep running. Memory per container at rest after ingesting this page's traces, measured, drawn as height: web 1.11 GiB, worker 1.09 GiB, ClickHouse 25.12 1.20 GiB, Postgres 17 105 MiB, MinIO 183 MiB, Redis 7 16 MiB. That is the main cost of "self-hostable": you operate a column store.
  6. Reading it back. The API reads from the same table. We saw it directly: on the default events_only deployment, the old GET /api/public/traces, /observations and /scores endpoints answer 404 with "This endpoint is not available on deployments running in Langfuse v4 events_only mode", while /api/public/v2/observations and /api/public/v3/scores work MEASURED.

How OpenTelemetry spans become observations. Every variant's model calls became generations with the model and token counts, whatever names it used; no cost was computed for any of them, because Langfuse has no price for a local model, which is correct.

The mapping rules, and what Langfuse stored from each of the eight variants

Langfuse accepts OTLP at /api/public/otel with the project's public and secret key as HTTP Basic auth. Its mapping, from its docs: the observation type comes from langfuse.observation.type, then gen_ai.operation.name, then "model present means generation"; the model from gen_ai.request.model, llm.model_name or model; usage from gen_ai.usage.* or llm.token_count.* (OpenTelemetry integration). What it stored from our eight variants MEASURED:

Every variant's model calls became generations with the model and token counts, including OpenInference's llm.* names and Langfuse's own langfuse.observation.* attributes. Langfuse also split cached tokens out of the input into a separate input_cached_tokens bucket (its usage keys are non-overlapping: "each token must be counted in exactly one key", docs). Our hand-written gen_ai.conversation.id became the session id, and Pydantic AI's became a session too. No cost was computed for any of them: Langfuse has no price for a local model, which is correct. The Claude Code run in section 6 is where prices come in.

Telemetry loss is silent
On the first attempt, two of the eight variants (openai-v2 and Pydantic AI) lost every span: Langfuse, still warming up, answered their exports with HTTP 500 ("stream is not readable", 12 times in its log). The agents finished normally; the only trace of the failure was one exporter warning on standard error, "Failed to export spans batch due to timeout, max retries or shutdown". The reruns were ingested MEASURED. Watch the exporter's own metrics, or put a collector with a retry queue between your app and the backend.

What a backend gives you: the tree, with cost, tokens, latency and scores on every node

Langfuse trace view of a Google ADK agent run (before ADK 2.13): a tree of invocation, agent_run, two call_llm generations and a say_hello tool, each with latency, tokens and cost; hallucination and toxicity scores on the root
Notice the same shape as section 1 (run, model calls, the tool under the call that asked for it), the cost rolled up to the root (Σ $0.001043), the token counts per generation (35 → 62), and two evaluator scores attached to the trace (section 9). Not our run: Langfuse's own Google ADK example, from before ADK 2.13 dropped the call_llm span (table below). Credit: Langfuse GmbH, langfuse-docs, MIT licence, source.
Langfuse's other halves (evaluators, prompt labels, masking, SDK sampling) and gateway spans

Langfuse's other halves (from its docs, used only where marked): scores and datasets (section 9, measured); LLM-as-a-judge evaluators that run on observations as they arrive ("observation-level evaluators are the recommended target for live production data; trace-level evaluators are deprecated", docs); prompt management, where labels such as production and staging point at prompt versions and an unlabelled fetch serves production (docs); masking in the SDK before export (mask_otel_spans in the Python SDK v4); and sampling in the SDK (sample_rate, decided per trace).

With a gateway. If your model calls already go through LiteLLM, its langfuse_otel callback sends a GenAI span per request to the same endpoint with usage and cost, and LiteLLM now recommends it over the older langfuse callback (LiteLLM docs) SOURCE. Gateway spans see every request but not the agent around it; app spans see the agent. Run both and join them on the trace id. After a retry or a fallback the deployment that answered may not be the one the app asked for; the LiteLLM proxy names it in the x-litellm-model-id response header, so copy that onto the model span and the trace shows which deployment answered (Gateways and routing, section 2, which counts that header to check a routing strategy). Retries, cooldowns and fallbacks themselves are its section 3. Evaluate every model in a fallback chain, or a fallback is a silent quality cliff.

5. The tools, compared by design

All of these accept OpenTelemetry, so the cheapest insurance is to instrument with OpenTelemetry and treat the backend as configuration. They differ in what they put first, who can run them, and the licence. Facts checked on 6 October 2026 against each vendor's own docs and repositories (not run here except Langfuse) SOURCE:

ToolLeads withRun it yourselfLicenceIts unit of workNotes
LangfuseTracing, then prompts and evalsYes, six containers (above)MIT outside ee/Trace of typed observationsOwned by ClickHouse since Jan 2026; v4 is OpenTelemetry-only ingestion
LangSmithTracing and evals for LangChain and LangGraphOnly as an Enterprise add-on (docs)Platform proprietary; SDKs MITA run ("a single unit of work"), a trace (runs of one operation), a thread (a multi-turn session) (concepts)OTLP at /otel/v1/traces; LangGraph Studio became LangSmith Studio on 14 Oct 2025
BraintrustEvals: an eval is data, a task and evaluators (docs)Hybrid: you run the data plane, Enterprise only (docs)ProprietaryExperiment; trace of typed spansOnline scoring of production logs at a sampling rate; OTLP at api.braintrust.dev/otel
Arize PhoenixTracing and evals, strong on retrievalYes (Docker, Kubernetes)Elastic License 2.0: source-available, not open source in the OSI sense (LICENSE)OpenInference spans (openinference.span.kind: LLM, TOOL, AGENT, ...)Since 15.10.0 (15 May 2026) converts GenAI-convention spans to OpenInference on ingest (release note); Arize AX is the commercial tier
OpenLLMetry (Traceloop)Not a backend: instrumentation for many providers, vector stores and frameworksLibraryApache 2.0OpenTelemetry spansTraceloop acquired by ServiceNow (reported 2 Mar 2026; ServiceNow called it "recently completed" on 5 May 2026, press release)

How to choose. If you need the data on your own machines and do not want an Enterprise contract, the choice is Langfuse or Phoenix; read Phoenix's licence before offering it as a service. If your agent is LangGraph and you are happy with a hosted service, LangSmith understands its runs best (see LangChain and LangGraph). If your bottleneck is "is version 3 better than version 2" rather than debugging, Braintrust is built around that question. Whatever you pick, keep a collector in front so you can switch or send to two at once.

When the vendor runs the loop, the spans between your request and its result are produced inside the vendor's process and you see only what they export. Treat trace export as a procurement question: what is exported, in which conventions, with what content, and for how long it is kept.

Hosted runtimes and SDKs: what each exports (vendor docs, 6 October 2026, not run here)
Runtime or SDKWhat you can trace
OpenAI Agents API (public beta 10 Sep 2026)Exports per-session traces as OTLP JSON: GET /v1/agents/sessions/{session_id}/traces; attribute conventions not stated (docs)
Claude Managed Agents (public beta 8 Apr 2026)No OpenTelemetry export found; an event log per session (span.model_request_start and _end, tool use, session.usage with 5-minute and 1-hour cache-write counts) and a session viewer in the Console
OpenAI Agents SDKTracing on by default, sent to OpenAI's traces dashboard, not OpenTelemetry; unavailable under Zero Data Retention; replace with set_trace_processors() or disable with OPENAI_AGENTS_DISABLE_TRACING=1
Google ADKOpenTelemetry GenAI spans (invoke_agent, execute_tool, generate_content); Google's own guide recommends ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS=false. ADK 2.13.0 (22 Oct 2026) defaults to the GenAI conventions v2 and drops its older call_llm span (the release notes call it removed in the highlights, deprecated in the changelog); ADK_TELEMETRY_SCHEMA_VERSION_OPT_IN=otel_semconv_1_36 keeps the old schema, so dashboards and queries keyed on call_llm need changing or that switch (release notes)
Claude CodeBeta tracing (sections 1 and 6) plus OpenTelemetry metrics and events; since 2.1.307 a claude_code.safety_event event for each tool call that a permission rule, auto mode, a safety check, a hook or the sandbox stopped, prompted or sent back, so blocked actions can be counted and alerted on beside cost (changelog)

Sources for each row are in src/inputs/research.md; the runtimes themselves are compared on the parent's Production stack tab.

One run, priced four ways: only the explicit cache lifetime matches the run's own total

6. Cost attribution: from spans to dollars, reconciled

The problem. The bill says what you spent; it does not say which agent, user, feature or step spent it. A trace can, if each model span carries the model and the token counts by kind, and the backend multiplies them by the right prices. Two things go wrong in practice: the counts arrive under names the backend does not read, and the prices the backend applies are not the ones you paid.

The experiment. The Claude Code run reported total_cost_usd = for turns (an API-price equivalent; the subscription paid). We sent its recorded trace to Langfuse three times through a collector, changing only how the token counts were labelled MEASURED:

  1. The reference. Claude Code reported total_cost_usd = for the run: fresh input, cache-write (all 1-hour), cache-read and output tokens across 8 model calls.
  2. Raw spans: $0. Sent as Claude Code wrote them. Langfuse recognised the model on all 8 llm_request spans and made them generations, but found no gen_ai.usage.* attributes (Claude Code names its counts input_tokens, cache_read_tokens, cache_creation_tokens), so usage was empty and cost $0.
  3. Renamed to the GenAI conventions: short. A collector transform (OTTL) wrote gen_ai.usage.input_tokens as the sum of all three input kinds, plus cache_read and cache_write. Langfuse split them into buckets and priced them: , % short, because the cache writes were priced at the 5-minute rate.
  4. Cache lifetime made explicit: exact. A second transform passed the counts in Langfuse's own usage_details attribute with the key input_cache_creation_1h. Langfuse now prices the writes at 2x: , equal to the reference.
  5. A third source agrees. Claude Code's own claude_code.cost.usage metric, summed over its delta exports, is : one total, no breakdown by kind.

Three independent totals agree. The run's own total_cost_usd, Langfuse's sum over generations once the counts carried their cache duration, and Claude Code's claude_code.cost.usage metric (delta temporality, summed over its exports) all give . The formula, with Haiku 4.5's list prices per million tokens (input $1, 1-hour cache write $2, cache read $0.10, output $5; Anthropic pricing):

cost = ( × 1 + × 2 + × 0.10 + × 5) / 106 = $

The 16% gap in step 3 is cache-write tokens priced at the 5-minute rate (1.25x) instead of the 1-hour rate (2x) that Claude Code used on these runs (ephemeral_1h_input_tokens in its usage, and in the shared facts for the agent pages). The GenAI conventions have one cache_write count and no field for the cache's lifetime, so a backend that follows them faithfully must guess; Langfuse's model table has separate input_cache_creation_5m and _1h prices, so passing the count under the explicit key fixed it. An open Langfuse issue reports the same mispricing from its LangChain integration (#17450).

Rolling cost up. Once each model span has a correct cost, attribution is a group-by over the trace: by the root's attributes for user, ticket and feature (our application set app.user, app.ticket, app.feature on its span), by gen_ai.conversation.id for a session, by span name for a step. Langfuse propagates user, session and tags to every observation when you set them with propagate_attributes() (its Python SDK v4, the one used here; Python SDK v5, a major release on 14 October 2026, comes with a v4 to v5 migration guide, so check it before copying v4 code). Reconcile against a second source: the gateway's spend log, the provider's invoice, or, as here, the harness's own metric. Two sources that disagree by a fixed ratio usually mean a price or a token kind is wrong, as in step 3 above. Other usual causes of a gap: cache reads counted as fresh input, a model name that matches no price entry, and spans that were sampled away or lost.

Do not count twice. If the agent span carries the run's total tokens under the same names as the model spans, a backend that sums all spans counts them twice. Pydantic AI writes the totals on its agent span as gen_ai.aggregated_usage.* for this reason (its use_aggregated_usage_attribute_names setting, default on).

The reconciliation call by call: eight model requests under each labelling

Haiku 4.5 list prices per million tokens: input $1, 5-minute cache write $1.25, 1-hour cache write $2, cache read $0.10, output $5 (Anthropic pricing). The "check" column recomputes each call at the 1-hour rate.

Go deeper. Budgets and spend limits enforced at the gateway (LiteLLM virtual keys, measured): the parent's Production stack tab and Gateways and routing (sections 5 and 6, rate limits and budgets). Why Claude Code writes a 1-hour cache and what that costs: Context engineering.

The same 49 spans, four collector setups: only waiting for the root keeps the failure without holding it for a minute

7. Sampling agent traces

The problem. Keeping every trace costs storage and money, and with content on a single run of our small task was 30 to 100 KB of attributes. Sampling keeps a subset. Head sampling decides when the root span starts (usually "keep 10% of trace ids") and is cheap, but cannot know whether the run will fail. Tail sampling decides after seeing the spans, so it can keep every failure; in OpenTelemetry it is the collector's tail_sampling processor, which holds a trace's spans in memory for decision_wait (30 s by default) after the first one arrives, evaluates its policies once, and then forwards or drops (processor README at v0.162.0). The general mechanics are on Observability: logs, metrics, traces, alerting; here is what is different about agents.

Agent traces break three assumptions. They are long (minutes, hours for some harnesses), so a fixed wait decides before the run ends. Their root span ends last, so the outcome arrives last. And their spans fail routinely: our successful Claude Code run already had two ERROR spans (section 1). We replayed that run's 49 spans into a real collector at their recorded end times (29 s from first to last), after marking its final tool execution and its root as failed, through four tail-sampling setups that all keep "any trace with an ERROR span" MEASURED:

  1. The first span arrives (0.1 s). The collector starts this trace's clock: with decision_wait at 5 s it will decide at 5.1 s, on whatever has arrived by then.
  2. Decision at 5 s, with no error in view. Four spans are buffered, all OK, so "any span ERROR" says drop. A decision cache (1,000 sampled and 1,000 non-sampled trace ids remembered) changes nothing here.
  3. The first ERROR arrives too late. With a 5-second wait the collector decided before the first error span arrived (6.35 s into the replay) and dropped the trace.
  4. The failed root is dropped too. Every later span, the failures included, followed that decision: 0 of 49 kept.

Ticks on the timeline: spans as they arrive (red: status ERROR; the last two were marked failed by us). Measured on otelcol-contrib 0.162.0.

The setting made for this case is decision_wait_after_root_received: wait as long as you like (300 s here), but decide shortly (2 s) after the root span arrives.

And the policy must look at the run, not at any span. We replayed the same trace twice more, once marked failed and once exactly as recorded (a success with two recoverable errors), through two policies that both wait for the root MEASURED:

PolicyFailed runSuccessful run
status_code: [ERROR] on any span (kept, wrongly)
ottl_condition: IsRootSpan() and span.status.code == STATUS_CODE_ERROR

The application has to say whether the run failed, on the root span: an ERROR status or an attribute such as app.outcome. Our first attempt at the root condition, parent_span_id.string == "", matched nothing and raised no error (the policy's error_mode: ignore swallowed it); only the empty output file showed it. Test a sampling policy with a known failing trace before you trust it.

Soft failures need scores, not status. The worst agent failures end with status OK: the tests pass but the agent edited the tests, or the answer is wrong. No status-based rule keeps those. Keep a small random share of everything (so you can estimate rates), every run whose root says failed, and every run an online evaluator scored low (section 9); count runs with metrics, which are computed before sampling. Langfuse's SDK can also sample, per trace, with sample_rate (docs).

Simulator: any decision_wait, either policy, on the same 49 spans (checked against the six collector runs)

The recorded Claude Code trace, 49 spans arriving at their real end times over 29 s, the root last. The simulator applies the processor's documented rules to these arrival times; each preset is an outcome measured on the real collector (six collector pipelines, seven outcomes), and the simulator is checked against every one. Predict first: at what wait does the failed run start being kept?

Presets measured on the real collector:

Late spans: in our runs the collector still held the trace's decision in memory, so spans arriving after a "drop" were dropped too, with or without the decision cache. Under heavy load, once a trace is evicted from the buffer without a decision cache, late spans are "buffered for decision_wait seconds and then a new sampling decision is made" (processor README), which yields a fragment of the trace instead. The simulator shows the measured behaviour.

8. Personal data and secrets in traces

The problem. A trace with content holds every prompt, every tool argument and every tool result. In an agent that means customer messages, file contents, shell output and the paths of the machine it ran on, copied to a second system with its own access rules and retention. Prompts were opt-in in the conventions for exactly this reason.

What leaked in our runs MEASURED:

  • Libraries that capture content by default put the fake customer's e-mail and account id into every model span of the run (section 3's table): OpenLLMetry, OpenInference, Langfuse's client and Pydantic AI. openai-v2 and our hand-written spans did not until we turned content on.
  • Claude Code by default redacts the prompt (user_prompt = <REDACTED>), tool inputs and tool output, but puts the account identity on every span: user.email, user.account_uuid, user.id and organization.id were on all of its spans. The docs say user.email and organization.id are "always included when available"; the OTEL_METRICS_INCLUDE_* switches cover only session id, account uuid, version, entrypoint and repository (see src/inputs/research.md). If a trace leaves the developer's machine, that is personal data in every span.
  • With Claude Code's content switches on (OTEL_LOG_USER_PROMPTS=1, OTEL_LOG_TOOL_DETAILS=1, OTEL_LOG_TOOL_CONTENT=1), the prompt with the customer's e-mail appeared on the interaction span, file paths on tool spans, and tool.output span events held file contents, diffs and shell output. The operating-system login name appeared times outside the identity attributes: in absolute file paths (the working folder sits under the home folder) and in the output of an ls -la the agent ran, where the file-owner column is the login name. The content-on trace carried % more attribute bytes than the default run's (52 spans against 49).

Where to remove it, in order of preference. (1) Do not capture it: leave content off in production and turn it on per environment. (2) Mask in the SDK before export (Langfuse's mask_otel_spans, a custom span processor), which only covers that SDK's spans. (3) Redact in a collector you control, before data leaves your network, which covers every service at once. We measured three collector policies with the redaction processor (beta for traces) on the content-on Claude Code trace and on the content-on hand-instrumented trace (beside this text; pick a policy):

What the measurement says. Masking by pattern caught every e-mail, the account ids and every path, in span attributes and in span event attributes alike, and still missed the login name in ls -la output, because no pattern described it. A keyed hash (hmac-sha256) does the same job while keeping values joinable: the same e-mail always becomes the same digest, so you can still count one customer's runs. The allow-list of keys removed everything not on the list ( attributes on the Claude Code trace) and left nothing to leak, at the price of the content you wanted to debug with. A deny-list fails open on whatever you did not think of; an allow-list fails closed. In production, use the allow-list and keep full content only where access is controlled and retention is short. The attack side of the same problem (prompt injection, exfiltration through tools) is on Agent security.

Two content-on spans through three collector policies: only the allow-list leaves nothing

The collector configurations used (cost mapping, redaction, tail sampling), to copy

Collector otel/opentelemetry-collector-contrib:0.162.0 in Docker. Each configuration passed otelcol-contrib validate before use. Two lessons from writing them: an hmac_key shorter than 32 bytes is rejected for hmac-sha256; and an OTTL condition that matches nothing does not fail, so test policies with a trace you know should match.


9. Evals in the loop

The idea. Traces are the raw material for evaluation. Online evaluation scores a sample of production traces as they arrive, with code checks where they can decide and a model judge where they cannot, and writes the result back onto the trace as a score. Offline evaluation reruns a fixed dataset of tasks before every change; interesting production traces get promoted into that dataset. The same trace store serves debugging, monitoring and regression testing, which is the main argument for an integrated platform over plain OpenTelemetry.

What we ran. A 55-line scorer read each run's outcome and wrote four rule-based scores to Langfuse through its API (tests_pass, summary_complete, turns, and cost_usd for the Claude run), then read scores back from /api/public/v3/scores. We also created a dataset and promoted the local run's trace into it as an item with sourceTraceId set and an expected output MEASURED.

Fig. 3, step by step: one trace store serves debugging, monitoring and the regression gate

  1. Traces in one store. The three runs we scored: the hand-instrumented local run, the same run through Pydantic AI, and the Claude Code run, each a trace under its root span.
  2. The evaluator reads each run. Online, a sample of production traces is scored as it arrives; here a rule-based scorer read every run's outcome: test result, final message, turns and cost.
  3. Scores are written back onto the traces. Four per run, drawn as bars: tests_pass and summary_complete (0 or 1), turns (8, 8 and 13) and cost_usd ($0.0421 for the Claude run; none for the local model). Eleven scores, read back from the API.
  4. A pass that should have been a fail. The local run's summary_complete is 1, yet its summary names only one of its two fixes (the box below). A score is only as good as the check behind it.
  5. Failures are promoted into a dataset. The local run's trace became a dataset item, with sourceTraceId pointing back at it and an expected output.
  6. Every change passes the gate. Offline: every prompt, model, tool or harness change must pass the dataset before it ships, which produces new traces, which are sampled and scored again.
A rule that passed a summary it should have failed
The local model fixed both bugs but its final message describes only the tokenize change; it mentions the second one only as a test name ("including the apostrophes test, ties handling"). Our keyword rule looked for "tie" and scored the summary complete. Cheap checks drift from what they mean; check them against labelled cases (here: the diff contains two changes, the summary names one), and use a judge or a stricter structured check where a keyword cannot decide.

Making it a loop. Sample live traces for scoring (vendor docs suggest 1 to 10% for high volume, more for critical paths, and the judge bill is a budget line: figures on Production eval engineering); alert on score rates and on the agent metrics from section 2 (model calls and tool calls per run, cost per run, p95 duration); promote failures to the dataset; gate every prompt, model, tool or harness change on that dataset. The parent's Production stack tab runs a small gate over 18 recorded runs. How to grade a trajectory rather than a final answer: Agent and trajectory evaluation; judge design and biases: LLM-as-judge; alert design: Observability: logs, metrics, traces, alerting. Version prompts outside code and promote them by label after the gate; with gen_ai.prompt.name and gen_ai.prompt.version on every model span, a regression can be traced to a prompt version (Langfuse's labels in section 4; gates on Production eval engineering).

Corrections to the old version of this page (checked against primary sources on 6 October 2026)
  • "the v3 stack: Postgres + ClickHouse + Redis + S3": Langfuse is on version 4 (GA 17 Aug 2026), same four stores, observations-first storage and OpenTelemetry-only ingestion; v3 gets security fixes until the end of January 2027.
  • "Langfuse calls span-tree nodes observations (span/generation/event)": there are now ten observation types, including agent, tool, chain, retriever, evaluator, embedding and guardrail.
  • "Arize Phoenix: open source": Elastic License 2.0, source-available. It now also ingests GenAI-convention spans directly (since May 2026).
  • "LangSmith ... tracing arbitrary code means adopting their SDK anyway": LangSmith accepts OpenTelemetry at /otel/v1/traces; the SDK is optional.
  • "OpenAI's Agents API and Anthropic's Managed Agents both ... since September 2026": Managed Agents entered public beta on 8 April 2026; the Agents API on 10 September 2026. The Agents API exports OTLP JSON traces; for Managed Agents we found an event log, not OpenTelemetry.
  • "Native LiteLLM integration: point the proxy's logging callback at Langfuse": still true, but it now goes through OpenTelemetry, and LiteLLM recommends the langfuse_otel callback.
  • OpenLLMetry is still Apache 2.0, but Traceloop now belongs to ServiceNow (2026).
  • Claude Code 2.1.274's effort span attribute and managed-settings event: confirmed (September 2026).