Skip to main content
Decorators provide automatic timing, error capture, and input/output extraction with minimal boilerplate. Python decorators work on functions; TypeScript decorators work on class methods.

Python decorators

@pandaprobe.trace

Creates a new trace for the decorated function. Use this on your top-level entry points. Can be used with or without parentheses:
Input/output capture
  • Input: Automatically captured from function arguments (uses inspect.signature to 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.
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.
Python
@pandaprobe.span requires an active trace context. If no trace exists (no enclosing @pandaprobe.trace or pandaprobe.start_trace()), the function runs without instrumentation.

Sync and async support

Both decorators auto-detect sync vs async functions and wrap accordingly.
Python

Nesting

Python
This produces: Trace("support-agent") → Span("retrieve", RETRIEVER) → Span("generate", LLM).

Combining with wrappers

Python
The wrapper’s LLM span is automatically nested as a child of the trace.
Pair decorators with provider wrappers so LLM calls inherit hierarchy and you still get token usage and model metadata on child spans.

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.

TypeScript decorators

Import trace, span, and SpanKind from the base package. Both current Stage 3 decorators and legacy TypeScript decorator emit are supported.
TypeScript

TypeScript trace options

TypeScript span options

For input capture, a single object argument is preserved as-is; other argument lists are stored under args. Return values become span outputs. The trace decorator extracts the last user and assistant messages when the standard messages shape is used.
TypeScript decorators can decorate class methods only. For standalone functions or inline scopes, use withTrace() and withSpan().
Like Python, @span runs without instrumentation when there is no active trace, and both decorators pass through when PandaProbe is disabled or unconfigured.