@pandaprobe.trace and @pandaprobe.span decorators provide automatic instrumentation for your functions. They handle timing, error capture, and input/output extraction with minimal boilerplate.
@pandaprobe.trace
Creates a new trace for the decorated function. Use this on your top-level entry points.
| Parameter | Type | Default | Description |
|---|---|---|---|
name | str | None | Function name | Custom trace name |
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 |
- Input: Automatically captured from function arguments (uses
inspect.signatureto build a JSON-friendly dict). - Output: Automatically captured from the return value.
- At the trace level, the SDK extracts only the last user message from input and the last assistant message from output.
Why trace-level message extraction?
Why trace-level message extraction?
Trace views often focus on the conversational turn. Full structured arguments remain available in raw span data when you need deeper inspection.
@pandaprobe.span
Creates a new span within the current trace. Use this on inner functions.
| Parameter | Type | Default | Description |
|---|---|---|---|
name | str | None | Function name | Custom span name |
kind | str | SpanKind | OTHER | Span kind (LLM, TOOL, AGENT, etc.) |
model | str | None | None | Model name (for LLM spans) |
metadata | dict | None | None | Key-value metadata |
Sync and async support
Both decorators auto-detect sync vs async functions and wrap accordingly.- Sync
- Async
Nesting
Trace("support-agent") → Span("retrieve", RETRIEVER) → Span("generate", LLM).
Combining with wrappers
No-op behavior
If the SDK is disabled (PANDAPROBE_ENABLED=false) or no client is available, both decorators pass through transparently: the decorated function runs normally with no overhead.
No-op mode is intentional for local development and tests where you omit API keys or disable tracing globally.
