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.
@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.
@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.
@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: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
-
Use semantic decorators - Choose the decorator that best describes the operation’s purpose (
@workflowfor processes,@agentfor AI components,@taskfor individual operations). -
Name spans meaningfully - Use the
nameparameter when the function name isn’t descriptive enough. - Don’t over-instrument - Focus on high-value operations. Not every function needs a decorator.
- Combine with auto-instrumentation - Let auto-instrumentation handle LLM calls and database operations while using decorators for your application logic.
- Use class decoration sparingly - Decorating an entire class instruments all methods, which may create noise. Consider decorating individual methods instead.
Learn More
- Manual Tracing - Fine-grained control with SpanWrapper
- Auto Instrumentation - Zero-code tracing for supported libraries
- Spans - Understanding span types and attributes
