Skip to content

Tracing

The collector is an OTLP/HTTP endpoint on this server:

POST http://localhost:8020/api/otel/v1/traces

It accepts application/x-protobuf and application/json, gzip or not, from any OpenTelemetry SDK. Spans are stored as received and converted to ATIF with the agent's mapping when a run or the Runs page asks for them.

From Python with the SDK

from evalkit.sdk import tracing

tracing.register(agent="myagent-sdk")

register adds an exporter for this server to your global tracer provider, creating one if none is set. Your existing exporters keep running. The exporter carries an X-Evalkit-Agent header, which names the agent on the server; the evalkit.agent resource attribute is only set when register creates the provider itself. It reads the server URL from EVALKIT_SERVER_URL or your evalkit login, and the token from EVALKIT_OTEL_TOKEN, an agent token (evalkit tokens create --agent <agent>); a login token is not accepted, because it expires under a long-running process.

An existing span pipeline

register changes the global provider. When you build your own pipeline, take evalkit's parts and put them where you need them:

from evalkit.sdk import tracing

exporter = tracing.exporter(agent="myagent-sdk")    # OTLPSpanExporter: URL, token and X-Evalkit-Agent set
processor = tracing.processor(agent="myagent-sdk")  # batch processor around that exporter
provider.add_span_processor(processor)              # what register does for you
headers = tracing.headers(agent="myagent-sdk")      # the same headers, for an exporter you build yourself

All three resolve the server and token the same way register does. processor also stamps the run's session.id and evalkit.* attributes on spans that start under a task call (or under tracing.eval_run, below).

Spans handed straight to a processor or exporter, for example by a bridge that converts another tool's spans, never pass through the provider, so register cannot see them. Hand them to tracing.processor(...) too: give the bridge that processor, or one processor that fans out to all of yours and evalkit's (OpenTelemetry's SynchronousMultiSpanProcessor). Those spans are already finished, so processor cannot stamp them: the bridge copies session.id onto each span it converts. How eval-only export treats them is below.

Choosing what a shared worker exports

A worker that serves both app runs (production, staging or manual use) and eval runs exports every span it makes, so every app turn also becomes a session on this server, which you can browse on the Runs page and pull with evalkit runs pull <agent> --source app. Whether to send app traffic is your choice. eval_run marks eval runs either way, and to send only those, filter on the mark:

from evalkit.sdk import tracing

provider.add_span_processor(tracing.processor(agent="myagent", only=tracing.is_eval_span))

def handle_job(job):
    if job.evalkit:                           # the task's metadata, sent along with the job
        with tracing.eval_run(job.evalkit):
            return run_agent(job)
    return run_agent(job)

The task passes its metadata argument along with the job (see SDK runs). eval_run stamps session.id (the SDK's session id), evalkit.case_id, evalkit.experiment_id and evalkit.repetition on every span started inside it, so the worker's spans join the run's session and the task returns only the answer. is_eval_span is true for a span that carries evalkit.case_id. The stamp lives in a context variable: spans started in another thread need that thread to run inside eval_run too.

A harness agent learns that a run is an eval run from the metadata of POST /runs: experiment_id, case_id and repetition. That is what it passes to eval_run, with the run_id it returns as the session id: tracing.eval_run({**metadata, "session_id": run_id}).

only decides by trace, not by span. It is any function that takes a span and returns a bool, and it runs on each span as the span starts and again as it ends. Once it is true for one span, the processor keeps every span of that span's trace that reaches it: spans started inside eval_run, the job's own spans started before eval_run in the same trace, and finished spans a bridge hands straight to the processor. Spans of other traces are dropped. A custom only picks whole traces the same way.

The rule for order: a span is kept when its trace is already marked by the time the span ends. The first span started inside eval_run marks its trace as it starts, before anything under it ends, so spans that end before it and spans a bridge hands over later are both kept. A span that ends before any span of its trace was marked is dropped. A bridge that may hand spans over that early can copy the evalkit.* attributes onto them, so each one marks its own trace. A bridge should copy session.id either way: the server gives each span the session of its outermost ancestor that carries one, and the span's own session.id when no ancestor does.

The processor remembers the 10,000 most recently used eval traces and forgets the oldest. Each kept span refreshes its trace, so a trace is only forgotten once 10,000 other eval traces have been used since its last span.

Spans from another process in the same trace, such as an MCP gateway pod the agent calls, never reach this processor. They go through that process's own exporter, so that process makes its own choice: either it continues the trace, wraps its work in eval_run with the run's metadata sent along with the request, and filters with only=tracing.is_eval_span too, or it exports everything.

Do not use a sampler for this: a sampler drops spans for every exporter, your own backend included.

Around every task call the SDK opens a root span named evalkit.run with session.id set to the run id, and stamps session.id, evalkit.experiment_id, evalkit.case_id and evalkit.repetition onto every span your code starts underneath it. That is what groups a trace into one session. When the task returns RunResult(session_id=...), the root span takes that session id instead, so it joins the agent's session rather than sitting alone; see SDK runs for agents in another process.

From any OpenTelemetry SDK

Point the exporter at the collector and name the agent, either with a header or an attribute:

export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://localhost:8020/api/otel/v1/traces
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer <token>,X-Evalkit-Agent=myagent"
export OTEL_RESOURCE_ATTRIBUTES="evalkit.agent=myagent"   # alternative to the header

The collector picks the agent per span: the span's evalkit.agent attribute first, then the resource's, then the X-Evalkit-Agent header. One process that serves several agents can therefore share one exporter and set evalkit.agent on each agent's spans. The value is an agent reference (myagent or myagent@workspace). Every agent a batch names is checked as if it came in the header: an agent token writes only its own agent, a login token only agents in workspaces you can write to (your own, or a shared one where you are a writer). If any span names an agent the token may not write, the whole batch is refused.

Put the session id on the outermost span of each turn, in the attribute your mapping's session_id rule names (session.id in the openinference preset, gen_ai.conversation.id in gen_ai). Each span belongs to the session of its outermost ancestor that carries one, even when the span carries a session attribute of its own. A span with no such ancestor keeps its own session. So a root span with a session sets the session for the whole trace, and a root span without one (an HTTP server's request span) does not matter.

Agent behind an HTTP server

When the agent runs behind FastAPI, Express or any other instrumented HTTP server, the server's request span (POST /chat) is the root of the trace and carries no session id. Pick one:

  • Start a span of your own around each turn and put the session id on it. The agent's spans underneath join that session:
with tracer.start_as_current_span("turn", attributes={"session.id": session_id}):
    answer = await agent.run(question)
  • With OpenInference, wrap the turn in using_session(session_id); it stamps session.id onto every span started inside it:
from openinference.instrumentation import using_session

with using_session(session_id):
    answer = await agent.run(question)
  • Turn off the server framework's tracing, so the agent's own spans are the roots.

Pydantic AI sets its own gen_ai.conversation.id on its spans. Your turn span's id already wins over it in evalkit. Passing yours anyway, agent.run(question, conversation_id=session_id), is optional: it keeps the ids the same in other trace tools.

evalkit traces check warns when a session's trace root is outside the session and names the top span the session starts from.

Deployed agents

A service cannot carry a person's token. Mint an agent token, bound to one agent and valid only for the collector:

evalkit tokens create --agent ouragent@dev     # needs writer on dev
evalkit tokens list
evalkit tokens revoke <id>

Set it on the deployment as EVALKIT_OTEL_TOKEN next to EVALKIT_SERVER_URL; tracing.register, tracing.exporter and tracing.processor require the token. For a non-Python exporter put it in OTEL_EXPORTER_OTLP_HEADERS. Use an agent token for any exporter outside the process that calls run_experiment too, even on your laptop: the login token expires under a long-running worker.

The collector logs every refused export as otel export rejected with the status, the reason (expired token, invalid token, unknown agent, forbidden, too large, malformed) and the agent. OpenTelemetry exporters only log a failed export on their side, so a silent agent is worth checking in both logs.

Size limits and large spans

LLM spans from OpenInference and GenAI instrumentations carry the full input of each call: the messages so far, the system prompt and the tool schemas. Every turn repeats the whole context, so a long agent session grows with roughly the square of its turns. A 14-minute chat with subagents can store hundreds of MB of span attributes.

The server has two limits, both set in its config:

Limit Default What happens past it
otel.max_batch_bytes 16 MiB One export request (after gzip is undone) gets 413 and its spans are dropped. Exporters do not split a refused batch, so keep batches small.
otel.max_session_bytes 384 MiB Reading the session (a run's trajectory, evalkit traces check, the Mappings tab) gets 413 with the session's size and the limit. A run records the trajectory as unavailable and logs the message. --dump spans.json still works.

otel.max_session_bytes counts the span attributes a trajectory build loads, not everything stored. evalkit reads the input messages (and system prompt) of an LLM span only for the first LLM call under each root span and in each subagent; later calls add only their output, tool calls and tokens to the trajectory. So the build leaves the input of every later LLM call in the database and does not count it. The limit keeps one session from using up the server's memory, so raise it only together with the server's memory limit.

For agents with large spans, send fewer spans per export and give each export more time. For the Python SDK, tracing.register included:

export OTEL_BSP_MAX_EXPORT_BATCH_SIZE=16   # spans per export; default 512
export OTEL_BSP_MAX_QUEUE_SIZE=2048        # spans waiting for export; raise it if the exporter logs "Queue full"
export OTEL_EXPORTER_OTLP_TIMEOUT=60       # seconds per export in Python; default 10

OpenTelemetry SDKs keep at most 128 attributes per span (OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT). OpenInference writes each message as several attributes (llm.input_messages.0.message.role, ….content, …), so a long conversation passes the limit and the SDK drops attributes, which loses messages or parts of them. The Python SDK logs "Attributes dict is full" when it happens. Each exported span says how many attributes it lost; evalkit stores that count, and evalkit traces check warns on its llm line when an LLM span lost any. Raise the limit before the SDK starts:

export OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT=4096

Other SDKs follow the OpenTelemetry spec and read OTEL_EXPORTER_OTLP_TIMEOUT in milliseconds (60000). A 10 MB span can take more than 10 s to upload, longer than the default timeout. In an OpenTelemetry Collector, set send_batch_max_size on the batch processor and timeout on the otlphttp exporter instead.

Exporting to evalkit and another backend

The standard OTLP variables name one endpoint. To keep exporting to your tracing backend and send the same spans here, either:

  • add a second otlphttp exporter to the OpenTelemetry Collector the agent already exports to (recommended for deployed agents), or
  • add a second span processor and exporter in code. tracing.register does this for Python.
exporters:
  otlphttp/evalkit:
    traces_endpoint: http://localhost:8020/api/otel/v1/traces
    headers:
      Authorization: Bearer ${env:EVALKIT_OTEL_TOKEN}
      X-Evalkit-Agent: ouragent@dev
service:
  pipelines:
    traces:
      exporters: [otlp/existing, otlphttp/evalkit]

The collector speaks OTLP over HTTP only, not gRPC. Bodies may be chunked with no Content-Length (the JavaScript exporter sends them that way); a proxy in front of the collector must allow that.

The main agent and subagents

An AGENT span (openinference.span.kind=AGENT, or gen_ai.operation.name=invoke_agent) becomes a subagent trajectory only when another agent started it: it sits under a tool span, or it carries the tool_call_id of the call that started it. The subagent is named by the span's agent.name (gen_ai.agent.name), or by the span name when that is missing. Every other AGENT span is part of the main agent's own work, so an outer wrapper span, graph nodes tagged AGENT and one root span per chat turn all end up in one trajectory.

The main agent is the root span when it is an AGENT span; otherwise, as with the SDK's evalkit.run span, the earliest AGENT span that is not inside another one. When a session holds several root spans, one per chat turn, evalkit puts them in time order and takes the answer from the last one.

Each user message appears in the trajectory once, as a user step, before the first LLM call that has it in its input. So a chat's later turns show up as new user steps. Two limits:

  • evalkit loads the input messages only of the first LLM call under each root span (see the size limit above). When every turn of a chat runs inside one trace, only the first user message is loaded; give each turn its own root span to see them all.
  • When a framework sends only the latest user message instead of the whole history, evalkit adds a user step for each text it has not seen yet. A user message repeated word for word ("yes", then "yes" again) then shows up once.

Two mapping fields change this when the shape is wrong for your agent: main_agent pins the main agent, and subagent_spans keeps sibling agents (a crew whose agents hand over without a tool call) as separate subagent trajectories. See Mappings.

Harness agents with traces

A harness agent created with --trajectory-source otel keeps the whole Harness API flow and skips GET /runs/{id}/trajectory: it puts the run id it returned on its spans, in the attribute its mapping's session_id rule names, and evalkit polls the session until it settles. The harness declares provides.trajectory: false; evalkit still runs the trajectory evaluators because the trajectory comes from the collector.

The session evalkit polls is the run_id that POST /runs returns, so there is no separate session field. A queue-backed agent whose worker picks its own session id returns that id as run_id, or puts the run_id it returned on its spans in that session attribute. To export only eval runs from a harness that also serves production, see Choosing what a shared worker exports above.

Importing history from a trace source

evalkit imports traces from trace sources. Supported today: Phoenix and Langfuse. For another, file a GitHub issue.

An admin registers a trace source once. An OTel agent then names it in its settings, with the agent's project in that store and, optionally, a trace filter. Imports always read from there: evalkit traces import and the agent page's Import tab take no source, project or filter of their own. To import from somewhere else, change the agent's settings first.

evalkit trace-sources create phx --url https://phoenix.example.com --api-key-env PHOENIX_API_KEY
evalkit trace-sources create lf --provider langfuse --url https://cloud.langfuse.com --api-key-env LANGFUSE_KEYS
  • The trace source's API key is shared with every user in effect: anyone can import any project that key can read.
  • Imported traces land in the agent's workspace. Every user can read every workspace, so traces imported into your personal workspace are visible to everyone on the server. See Where runs happen.

Langfuse

  • Langfuse Cloud, or self-hosted Langfuse v4.59.0 or later.
  • The key: a Langfuse key pair reads exactly one project. Put the public key and secret key in one env var, joined with a colon: LANGFUSE_KEYS=pk-lf-...:sk-lf-.... Any other shape is refused with 422. --project is that project's name, and is checked against the key.
  • The mapping: use the langfuse preset (--mapping langfuse). Langfuse stores observations, not the spans the agent sent, and evalkit rebuilds each one with the Langfuse SDK's attribute names (langfuse.observation.*, session.id). So a gen_ai or openinference mapping finds no messages on spans imported from Langfuse, whatever the agent sent.
  • The preset reads the messages of agents that send OTel spans to Langfuse as they are. Agents traced with Langfuse's @observe decorator log their functions' arguments instead of chat messages, so for them only, point the preset's input_messages at the messages with path, for example {"attribute": "langfuse.observation.input", "path": "args.0", "message_format": "openai"}. See Mappings.
  • The preset also reads LangChain and LangGraph agents traced with Langfuse's LangChain callback (CallbackHandler) as they are. Their tool spans carry no call id, so evalkit matches tool results to calls by time and order, and evalkit traces check reports "0 matched to calls by id".
  • OTel exporters: send the header x-langfuse-ingestion-version: 4 to Langfuse. Without it Langfuse can take up to 15 minutes to show spans, so experiments miss them and imports skip them. Langfuse's own SDKs (Python 4.7.0 and later, JS 5.4.0 and later) send it; a self-hosted Langfuse can instead set LANGFUSE_MIGRATION_V4_NATIVE_OTEL_BEHAVIOUR=direct.
  • Langfuse Cloud limits how many requests a project may make. When it answers 429, a range import waits as long as Langfuse asks and goes on where it stopped. It fails only after 10 minutes of rate limits without progress; continue it later. A trace filter keeps imports small.
  • A time range import walks from --until back to --since, newest traces first. Traces that become readable after the import passed them are not imported: leave --until at least 15 minutes in the past, or import the recent part again.
  • A trace's root span must be in the Langfuse project; traces without one are not imported.

Picking the agent's traces: the trace filter

A project often holds more than one agent's traces. The agent's trace filter (--trace-filter on evalkit agents create and agents edit, Trace filter in the agent form) is the trace store's own query, kept as you type it. Imports and experiments read only the traces it matches; leave it out to read the whole project.

  • Langfuse: a JSON array of conditions in Langfuse's filter format, matched against each trace's root observation. By trace name:
evalkit agents edit myagent --trace-filter '[{"type": "string", "column": "traceName", "operator": "=", "value": "stock-agent"}]'

By OTel service name:

[{"type": "stringObject", "column": "metadata", "key": "resourceAttributes.service.name", "operator": "=", "value": "stock-agent"}]
  • Phoenix: a trace filter expression, Phoenix's Python-like query over a whole trace, needing Phoenix 20.12.0 or later. An older Phoenix ignores the filter, so evalkit refuses to save an agent with a filter against one. It reads the root span's input, output, attributes[...] and metadata[...], rollups such as error_count, and the trace's spans:
evalkit agents edit myagent --trace-filter "any(span.name == 'stock-agent' and span.parent_span is None for span in spans)"
evalkit agents edit myagent --trace-filter "metadata['agent'] == 'stock-agent'"
  • When you save the agent, evalkit sends the filter to the trace store once, so a filter the store can't read is refused then, with the store's own message.

Experiments that read a trace source

An agent that already sends its spans to its own trace store can skip the collector: name the store on the agent, and experiments import each run's session from it. The collector stays the simpler path; use this one when the agent keeps its own store and you would rather not add an exporter.

evalkit agents edit myagent --trace-source phoenix --project myagent
  • --trace-source names a registered trace source and --project the agent's project in it. Both, and --trace-filter, are checked when you save them and again when an experiment starts or resumes: an unknown source, a project the source does not have, a bad filter, or a source that does not answer is refused. Only OTel agents take a trace source.
  • Every SDK run and harness run of the agent then pulls its session from the store, with no tracing.register and no agent token. evalkit traces import and the Import tab read the same source, project and filter.
  • The session id: the SDK opens its evalkit.run span on your process's global tracer provider, which is the agent's own. An agent that runs in the task's process and continues the current trace needs no change. Any other agent takes metadata["session_id"] as its session id, or the task returns the agent's own id with RunResult(session_id=...). See SDK runs. A harness's run id must be the session id in its store.
  • evalkit.run shows in your store as the root of each eval run's trace.
  • Waiting: evalkit pulls the session every 5 seconds (in an SDK run, run_experiment(poll_interval=...)) until no new span has arrived for --import-settle seconds (15), or gives up after --import-wait seconds (120). Stores ingest spans late, and an agent's batch processor holds them for up to 5 seconds. A run whose session is still filling in at the end is partial, or unavailable without a root; raise --import-wait.
  • Running needs no write access: anyone who may run the agent can import one of its sessions. A range import needs write access to the agent.
  • Load on your store: each unsettled session costs one session read there every 5 seconds. With 4 runs at a time and fast tasks, expect about 10 sessions settling at once, so about 2 session reads a second.
  • Why a trajectory is missing shows on the run page and in the SDK's RunSummary.trajectory_note:
  • only evalkit's run span was found: the agent's spans went to another trace or another tracer provider. Pass metadata["session_id"] to the agent, or return RunResult(session_id=...).
  • session ... not found in project ...: nothing in the store carries the session id. Check the agent exports to that project and uses the id. For Langfuse, check the exporter sends x-langfuse-ingestion-version: 4.
  • spans still arriving after N s: raise --import-wait.

Message roles

evalkit reads message roles in any letter case and maps the names some frameworks use to four roles:

Role on the span Read as
assistant, model (Gemini, Google ADK), ai (LangChain), bot assistant
user, human user
system, developer (OpenAI) system
tool, function tool

The trajectory drops messages with any other role, along with their tool calls. evalkit traces check warns on its llm line and names the unknown roles it found.

Checking a session

evalkit traces check myagent-sdk <session id>

prints the settle state, span kinds, tokens, the attributes the mapping did not read and the ATIF summary. --dump spans.json writes the raw spans. --dump esf.json leaves out the input messages of every LLM call after each agent's first, as the trajectory does not use them; spans.json has the raw values. A session over otel.max_session_bytes fails the check with its size and the limit (see Size limits and large spans above). If the kinds or messages look wrong, the agent needs a mapping: see Mappings, and Framework mappings for a ready-made one per framework.