Session-Aware Ingest
This page describes how xtrace models session-oriented workflows (chat turns and agent executions), and how to verify end-to-end metadata continuity.
Problem
In multi-turn AI systems, one user journey can span multiple layers:
- a session (conversation lifecycle)
- multiple turns
- one or more agent runs
- multiple execution steps
Without stable identifiers, trace discovery and debugging become fragmented.
Metadata model
xtrace persists the following fields in trace and/or observation metadata:
session_id: conversation-level keyturn_id: per-turn keyrun_id: per-agent-run keystep_id: per-step key inside a runstep_type: step category (for exampletool_call)- optional context such as
tool_name
Recommended conventions:
- Keep
session_idstable for one conversation - Use unique
turn_idfor each turn - Use unique
run_idper execution branch - Use unique
step_idwithin each run
Python SDK instrumentation
The Python wrapper observe_openai(...) can attach these IDs when calling OpenAI-like clients.
Reference script:
scripts/verify_session_ingest.py
The script simulates:
- Chat turn instrumentation (
session_id + turn_id) - Agent run instrumentation (
session_id + turn_id + run_id + step metadata)
Then it flushes events and verifies data through query APIs.
End-to-end verification
Prerequisites:
- xtrace server is running
- API token is configured
- Python SDK is available
Run:
python scripts/verify_session_ingest.pyVerification checks:
- A trace can be found by
turn_id - A trace can be found by
run_id - At least one observation contains matching
step_idandstep_type
APIs used in verification
GET /api/public/traces?sessionId=...GET /api/public/traces/:traceId
If session-linked data is missing, first verify ID propagation, then verify client.flush(), auth token, endpoint, and query filters.