Trace¶
- class opik.api_objects.trace.Trace(id: str, message_streamer: Streamer, project_name: str)¶
Bases:
object
- __init__(id: str, message_streamer: Streamer, project_name: str)¶
A Trace object. This object should not be created directly, instead use
opik.Opik.trace()
to create a new trace.
- end(end_time: datetime | None = None, metadata: Dict[str, Any] | None = None, input: Dict[str, Any] | None = None, output: Dict[str, Any] | None = None, tags: List[Any] | None = None, error_info: ErrorInfoDict | None = None) None ¶
End the trace and update its attributes.
This method is similar to the update method, but it automatically computes the end time if not provided.
- Parameters:
end_time – The end time of the trace. If not provided, the current time will be used.
metadata – Additional metadata to be associated with the trace.
input – The input data for the trace.
output – The output data for the trace.
tags – A list of tags to be associated with the trace.
error_info – The dictionary with error information (typically used when the trace function has failed).
- Returns:
None
- update(end_time: datetime | None = None, metadata: Dict[str, Any] | None = None, input: Dict[str, Any] | None = None, output: Dict[str, Any] | None = None, tags: List[Any] | None = None, error_info: ErrorInfoDict | None = None) None ¶
Update the trace attributes.
- Parameters:
end_time – The end time of the trace.
metadata – Additional metadata to be associated with the trace.
input – The input data for the trace.
output – The output data for the trace.
tags – A list of tags to be associated with the trace.
error_info – The dictionary with error information (typically used when the trace function has failed).
- Returns:
None
- span(id: str | None = None, parent_span_id: str | None = None, name: str | None = None, type: Literal['general', 'tool', 'llm'] = 'general', start_time: datetime | None = None, end_time: datetime | None = None, metadata: Dict[str, Any] | None = None, input: Dict[str, Any] | None = None, output: Dict[str, Any] | None = None, tags: List[str] | None = None, usage: UsageDict | None = None, model: str | None = None, provider: str | None = None, error_info: ErrorInfoDict | None = None) Span ¶
Create a new span within the trace.
- Parameters:
id – The ID of the span, should be in UUIDv7 format. If not provided, a new ID will be generated.
parent_span_id – The ID of the parent span, if any.
name – The name of the span.
type – The type of the span. Defaults to “general”.
start_time – The start time of the span. If not provided, current time will be used.
end_time – The end time of the span.
metadata – Additional metadata to be associated with the span.
input – The input data for the span.
output – The output data for the span.
tags – A list of tags to be associated with the span.
usage – Usage information for the span.
model – The name of LLM (in this case type parameter should be == llm)
provider – The provider of LLM.
error_info – The dictionary with error information (typically used when the span function has failed).
- Returns:
The created span object.
- Return type:
- log_feedback_score(name: str, value: float, category_name: str | None = None, reason: str | None = None) None ¶
Log a feedback score for the trace.
- Parameters:
name – The name of the feedback score.
value – The value of the feedback score.
category_name – The category name for the feedback score.
reason – The reason for the feedback score.
- Returns:
None