Install
Pattern 1: Tool decorator (simplest)
Wrap individual tool handlers — every call is traced automatically:tool_use, the execution is traced.
Pattern 2: Message response tracing
Trace all tool_use blocks from a message response:trace_response() captures the model’s decision. execute_and_trace() captures
the execution timing and result.
Pattern 3: Claude Agent SDK hooks
For the Claude Agent SDK’s higher-level agent runner:on_tool_start, on_tool_end, on_tool_error, and on_handoff.
What gets traced
| Field | Value |
|---|---|
tool_name | Tool function name or tool_use block name |
model_id | Model used (from response, e.g. claude-sonnet-4-6) |
input_tokens | Token usage from response |
output_tokens | Token usage from response |
input_args | Tool input parameters |
output_result | Tool return value (when using execute_and_trace) |
latency_ms | Auto-computed |
status | success, error, or timeout |