track

opik.track(type: Literal['general', 'tool', 'llm'] = 'general', tags: List[str] | None = None, metadata: Dict[str, Any] | None = None, capture_input: bool = True, ignore_arguments: List[str] | None = None, capture_output: bool = True, generations_aggregator: Callable[[List[Any]], Any] | None = None, flush: bool = False, project_name: str | 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.

  • ignore_arguments – The list of the arguments NOT to include into span/trace inputs.

  • capture_output – Whether to capture the output result.

  • generations_aggregator – Function to aggregate generation results.

  • flush – Whether to flush the client after logging.

  • project_name – The name of the project to log data.

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.