Skip to main content

Basic Usage

Simple Trace Creation

The @trace decorator automatically creates a trace span that encompasses the entire function execution. You can optionally specify custom names and tags to better organize and categorize your traces:
Both name and tags parameters are optional. If no name is provided, the function name will be used as the trace name.

Custom Trace Names

You can specify custom names for your traces:

Adding Tags to Traces

Tags help categorize and filter traces in your dashboard:

Integration with Other Decorators

Combining with Agent and Operation Decorators

The @trace decorator works seamlessly with other AgentOps decorators:

Async Function Support

The @trace decorator fully supports async functions:

Error Handling and Trace States

Automatic Error Handling

The @trace decorator automatically handles exceptions and sets appropriate trace states:

Custom Error Handling

You can implement custom error handling within traced functions:

Real-World Examples

E-commerce Order Processing

Data Analysis Workflow

Best Practices

1. Use Meaningful Names

Choose descriptive names that clearly indicate what the trace represents:

2. Add Relevant Tags

Use tags to categorize traces for easier filtering and analysis:

3. Keep Traces Focused

Each trace should represent a logical unit of work:

4. Handle Errors Appropriately

Implement proper error handling within traced functions:
The @trace decorator provides a powerful and flexible way to organize your application’s telemetry data. By creating logical groupings of operations, you can better understand your application’s behavior and performance characteristics in the AgentOps dashboard.