Context managers give you full control over trace and span lifecycle. Use them when you need to set metadata, token usage, or model information imperatively.Documentation Index
Fetch the complete documentation index at: https://docs.pandaprobe.com/llms.txt
Use this file to discover all available pages before exploring further.
Starting a trace
pandaprobe.start_trace() parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
name | str | (required) | Trace name |
input | Any | None | Trace input data |
session_id | str | None | From context | Session identifier |
user_id | str | None | From context | User identifier |
tags | list[str] | None | None | String tags |
metadata | dict | None | None | Key-value metadata |
TraceContext with:
trace_idproperty — the auto-generated trace UUID (read-only)span()method — creates child spansset_input(data)— update trace inputset_output(data)— set trace outputset_metadata(dict)— merge metadataset_status(status)— setTraceStatus(PENDING,RUNNING,COMPLETED,ERROR)
Creating spans
t.span() parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
name | str | (required) | Span name |
kind | str | SpanKind | OTHER | Span kind |
model | str | None | None | Model name |
metadata | dict | None | None | Key-value metadata |
SpanContext methods
| Method | Signature | Description |
|---|---|---|
set_input | (input: Any) | Set span input data |
set_output | (output: Any) | Set span output data |
set_model | (model: str) | Set the LLM model name |
set_token_usage | (*, prompt_tokens=0, completion_tokens=0, **extra) | Set token counts. Extra keys like reasoning_tokens, cache_read_tokens are accepted. |
set_model_parameters | (params: dict[str, Any]) | Set model params (temperature, etc.) |
set_cost | (*, total: float, **extra) | Set cost breakdown. Extra keys are accepted. |
set_completion_start_time | (ts: datetime) | Set time-to-first-token timestamp |
set_error | (error: str) | Record error message (also sets status to ERROR) |
set_metadata | (metadata: dict[str, Any]) | Merge into existing metadata |
span_id property — read-only UUID of the span.
Token and cost fields
Token and cost fields
set_token_usage and set_cost accept additional keyword arguments so you can record provider-specific breakdowns without losing structured data in the UI.Nested spans
Spans can be nested to form a tree. Parent-child relationships are tracked automatically via a context-var span stack:llm-call and tool-call spans are automatically parented to the agent span.
Error handling
On exception within a span, the status is automatically set toERROR and the error message is captured. The exception is re-raised.
Because exceptions propagate, you can rely on normal
try / except boundaries around your instrumentation while still recording span-level failures.Sync and async support
BothTraceContext and SpanContext work as sync or async context managers.
- Sync
- Async

