docs/TRACE_EXPORT_TREE.md View source on GitHub

Reading a Datakeel execution trace

Use the existing command with a running OTLP/HTTP collector. The optional filter takes the original database ID. Omitting it exports all retained execution groups.

OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://127.0.0.1:4318/v1/traces \
  uv run datakeel export-traces --conversation-id "$CONVERSATION_ID"

The command opens the configured database read-only. It prints the number of accepted spans, including grouping and agent spans. Events are part of their owning span. An empty selection prints 0 spans without sending an HTTP request.

Following the tree

A run with two delegated specialists can look like this. Each arrow points from a parent to its child.

datakeel.accounting_group
└─ datakeel.agent  main
   ├─ chat <model>
   ├─ datakeel.tool  delegate_agent  [A]
   ├─ datakeel.tool  delegate_agent  [B]
   ├─ datakeel.agent  catalog-analyst      (span link to A)
   │  ├─ chat <model>
   │  └─ datakeel.tool  search_files       (FAILED)
   └─ datakeel.agent  evidence-reviewer    (span link to B)
      ├─ chat <model>
      └─ event  datakeel.tool.started      (RUNNING, incomplete)
What to inspect How the exporter establishes it
Accounting group Each settled model belongs to its persisted accounting ID, falling back to its recorded conversation or run ID. Extraction and transcription retain their run ID, and label drafts retain their plan ID.
Agent ancestry A conversation row identifies the agent. A specialist's parent_conversation_id identifies its parent agent. The session.id of a model or tool connects it to that session's agent.
Separate billing owner When a conversational model's recorded accounting group differs from its session's family, the model stays in the billing trace and links to the session's agent in the family trace. Filtering to the billing group can leave that link's target outside the export.
Delegation link The exporter derives the durable invocation ID with the same invocation_identity(parent_session_id, parent_tool_call_id) function used at dispatch. A matching completed delegate_agent in that parent session supplies the span link. A matching pending dispatch supplies its invocation ID for joining to the start event.
Missing correlation An unattached model, tool or specialist stays under its accounting group with datakeel.unknown_parent=true. A recorded parent-tool ID without a matching delegation is marked datakeel.parent_tool_unresolved=true. Sessions and tools can share a group even when the particular model turn that issued a tool call is unknown.
Tool-only execution A conversation can have tools or recovery events before its first settled model. A recorded specialist creation is also activity. A tool with a session but no conversation row is grouped by its session. Each tool with no session gets an independent trace.

Filtering by root ID includes its recorded family. Filtering by child ID keeps the selected calls and includes ancestor agents and their matching delegation invocations as context. Accordingly, an envelope can cover a smaller interval in a filtered view. An unused root conversation alone has no execution to export.

Time and status

  • A completed tool uses the stored dispatch and completion instants. datakeel.tool.elapsed_ms is the independently measured elapsed time. A failed tool has OTLP status ERROR and the fixed category tool_failure.
  • A dispatch without a durable completion produces one datakeel.tool.started event at its stored start time. datakeel.incomplete=true means the outcome is still unknown at export time. A process crash and an in-flight invocation can have the same durable state.
  • A model's end timestamp is its settlement time. Its start is that time minus the recorded latency, rounded to nanoseconds and bounded by the Unix epoch. datakeel.timing=estimated_from_settlement identifies this reconstruction.
  • Agent and accounting spans carry datakeel.timing=observed_activity_envelope. Their bounds cover recorded creation, selected calls, descendant activity and timestamped events. Overlapping specialists can overlap in the viewer. An envelope can also include idle gaps. Its length cannot measure CPU time, active work or time spent awaiting a human.
  • datakeel.audit carries the stored instant, audit ID and kind for RESUME_AUTHORIZED, RESUME_DENIED, REJECTED_REPLAN, REJECTED_REPLAN_DENIED and INTERRUPT_INVALIDATED. Audit events are read through a narrow read-only projection. The interactive audit reader also locks its conversation, which a read-only PostgreSQL export cannot do.

Billing and privacy

Count openinference.span.kind=LLM spans to count model calls. Each carries one durable trace ID and reservation ID. The cost in USD and its exact integer nanodollar representation come from settlement. datakeel.accounted_tokens, datakeel.billing_status, the budget-exceeded flag and the price version describe that same charge. An unknown charge can retain the conservative reservation. Summing the settled costs once per model preserves the ledger.

Known or separately observed provider usage has input, output and cache counts. Input already includes cache reads and writes. GenAI and OpenInference token attributes are two views of the same observation. Missing observations leave those fields absent, including for unknown billing. Parent spans contain no billing totals.

The wire projection uses an explicit set of ID, category and measurement fields. Logical IDs are encoded as sha256: followed by the lowercase SHA-256 digest of the original UTF-8 string. This also covers UUID-shaped input. To find a local record in a viewer, compute the fingerprint locally and match it to datakeel.trace.id, datakeel.tool_invocation.id or session.id. Public tool, specialist and model names can be displayed directly. Unrecognized values become a fixed category or a fingerprint.

Prompts, messages, completions, parameters, results, raw errors, audit reasons, captions, source text, canaries and lease tokens are excluded. The resource carries only the Datakeel service name and version. Collector authorization headers remain part of the HTTP transport.

Re-export and delivery

Trace and span IDs derive from a versioned hash of the group and the durable fact identity. Re-exporting the same selection from unchanged storage reproduces the same IDs, links, timestamps and attributes across processes. The exporter reads existing facts without calling providers, dispatching tools, settling budgets or advancing checkpoints.

Delivery is at least once. Each synchronous batch contains at most 256 spans. A collector may accept one batch before a later batch fails, or accept a request before its response is lost. Retrying the command resends the selection. Consumers can deduplicate by (trace_id, span_id) and events by their durable audit or invocation ID. A later export can reflect a previously pending tool's real completion. Storage readers can also observe newer facts if execution is still in progress.

Permanent HTTP errors, exhausted retries, malformed protobuf responses and OTLP partial success with rejected spans fail the command. A success count requires every batch to pass the transport checks. The acceptance tests decode real loopback HTTP protobuf on SQLite and PostgreSQL and compare independent CLI replays. Phoenix and Langfuse GUI behavior is unverified.