track

opik.track(type: Literal['general', 'tool', 'llm'] = 'general', tags: List[str] | None = None, metadata: Dict[str, Any] | None = None, capture_input: bool = True, capture_output: bool = True, generations_aggregator: Callable[[List[Any]], Any] | None = None) Callable | Callable[[Callable], Callable]

Decorator to track the execution of a function.

Can be used as @track or @track().

Parameters:
  • name – The name of the span.

  • type – The type of the span.

  • tags – Tags to associate with the span.

  • metadata – Metadata to associate with the span.

  • capture_input – Whether to capture the input arguments.

  • capture_output – Whether to capture the output result.

  • generations_aggregator – Function to aggregate generation results.

Returns:

The decorated function(if used without parentheses)

or the decorator function (if used with parentheses).

Return type:

Callable

Note

You can use this decorator to track nested functions, Opik will automatically create a trace and correctly span nested function calls.

This decorator can be used to track both synchronous and asynchronous functions, and also synchronous and asynchronous generators. It automatically detects the function type and applies the appropriate tracking logic.