Overview
The@task decorator creates a child span for a single unit of work — an LLM call, data processing step, validation, or any discrete operation within a workflow.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
name | str | None | Function name | Display name for the task span. |
version | int | None | None | Version number for the task. |
method_name | str | None | None | Required when decorating a class. Specifies which method to use as the entry point. |
processors | str | List[str] | None | None | Route this span to specific named processors. See add_processor. |
Function usage
Class usage
Features
- Automatic I/O capture — Function arguments and return values are serialized as span input/output (up to 1MB).
- Exception recording — Exceptions are automatically recorded on the span with error status.
- Async support — Works with
async deffunctions and generators.
Best practices
- Keep tasks small and focused on a single operation
- Use task names that reflect intent, not implementation details
- Nest tasks inside workflows for proper trace hierarchy