Created on init, completed on result — with agent name, user ID, and metadata.
Tool Calls
Every tool execution (Bash, Read, Write, etc.) with input, output, and tool use ID.
Tokens & Cost
Prompt tokens, completion tokens, total tokens, and estimated cost in USD.
Conversation Threading
Group related sessions with convoId — multi-turn conversations appear linked.
Errors
Failed tool calls, errored sessions, and generator exceptions — all recorded.
Duration
Wall-clock time from start to result, plus API-side duration when available.
Consume the stream until the result message to record final tokens/cost/output. If you close the
generator early (for example via break/return), the session is marked failed with
Session interrupted (generator closed early) so runs do not remain stuck in running.
The wrapper uses PostToolUse and PostToolUseFailure hooks to capture every tool execution. Hooks fire asynchronously and never block the agent. A session-ready gate ensures hooks wait for session creation before tracking.
// No extra code needed — tool calls are tracked automaticallyfor await (const message of trackedQuery({ prompt: 'Read package.json and tell me the project name', options: { allowedTools: ['Bash', 'Read', 'Glob'], },})) { // Each tool call (Read, Bash, etc.) is recorded as an event // with input args, output, and execution metadata}
In the dashboard, each tool call appears as an event under the session timeline.
If the agent errors, the generator throws, or the consumer closes the stream early, the session is
automatically marked as failed with a clear failure reason.
try { for await (const message of trackedQuery({ prompt: 'Deploy to production', })) { // ... }} catch (error) { // Session already marked as failed in Sentrial // with failure_reason = error.message console.error(error);}