Skip to main content
Decorators provide a clean, declarative way to instrument your code. They automatically create spans with semantic meaning, making your traces easier to understand and navigate in the Netra dashboard.

Decorators: Overview

Netra provides four decorators, each designed for a specific type of operation:

@workflow

Use @workflow to mark high-level business transactions or processes. Workflows typically represent complete user-facing operations that may involve multiple steps.
When to use @workflow:
  • User-initiated actions (e.g., “submit order”, “generate report”)
  • End-to-end processes that span multiple operations
  • Top-level entry points in your application

@agent

Use @agent to mark AI agents or autonomous components that make decisions. Agent spans help you track reasoning steps and decision-making processes.
When to use @agent:
  • Autonomous AI components that make decisions
  • Multi-step reasoning processes
  • Components that orchestrate other tools or services

@task

Use @task to mark individual units of work. Tasks are typically discrete operations that perform a specific function within a larger workflow.
When to use @task:
  • Individual operations within a workflow
  • Tool calls or function executions
  • Database operations, API calls, or computations

@span

Use @span for generic tracing with full control over the span type. This is the most flexible decorator, allowing you to specify the exact span type.

Available Span Types

Decorating Classes

When you apply a decorator to a class, all public methods of that class are automatically instrumented.

Async and Generator Support

Decorators work seamlessly with async functions and generators:
For streaming responses, the span remains open until the stream is fully consumed. This ensures accurate latency measurements for streaming operations.

Automatic Parameter Capture

Decorators automatically capture function parameters as span attributes, making it easy to understand what inputs were provided:
Complex types (lists, dicts, objects) are serialized to JSON. Parameter values are truncated to 1000 characters to prevent excessively large attributes.

Exception Handling

Decorators automatically capture exceptions and mark spans with error status:

Combining Decorators with Manual Tracing

You can combine decorators with manual span operations for additional context:

Best Practices

  1. Use semantic decorators - Choose the decorator that best describes the operation’s purpose (@workflow for processes, @agent for AI components, @task for individual operations).
  2. Name spans meaningfully - Use the name parameter when the function name isn’t descriptive enough.
  3. Don’t over-instrument - Focus on high-value operations. Not every function needs a decorator.
  4. Combine with auto-instrumentation - Let auto-instrumentation handle LLM calls and database operations while using decorators for your application logic.
  5. Use class decoration sparingly - Decorating an entire class instruments all methods, which may create noise. Consider decorating individual methods instead.

Learn More

Last modified on March 17, 2026