Span¶
- class opik.api_objects.span.Span(id: str, trace_id: str, project_name: str, message_streamer: Streamer, parent_span_id: str | None = None)¶
Bases:
object
- __init__(id: str, trace_id: str, project_name: str, message_streamer: Streamer, parent_span_id: str | None = None)¶
A Span object. This object should not be created directly, instead use the span method of a Trace (
opik.Opik.span()
) or another Span (opik.Span.span()
).
- 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[str] | None = None, usage: UsageDict | None = None) None ¶
End the span 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 span. If not provided, the current time will be used.
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.
- 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[str] | None = None, usage: UsageDict | None = None, model: str | None = None, provider: str | None = None) None ¶
Update the span attributes.
- Parameters:
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.
provider – The provider of LLM.
- Returns:
None
- 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) Span ¶
Create a new child span within the current span.
- Parameters:
id – The ID of the span, should be in UUIDv7 format. If not provided, a new ID will be generated.
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.
- Returns:
The created child 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 span.
- 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
- get_distributed_trace_headers() DistributedTraceHeadersDict ¶
Returns headers dictionary to be passed into tracked function on remote node.