SpanData¶
- class opik.api_objects.span.SpanData(trace_id: str, id: str = <factory>, parent_span_id: str | None = None, name: str | None = None, type: ~typing.Literal['general', 'tool', 'llm', 'guardrail'] = 'general', start_time: ~datetime.datetime | None = <factory>, end_time: ~datetime.datetime | None = None, metadata: ~typing.Dict[str, ~typing.Any] | None = None, input: ~typing.Dict[str, ~typing.Any] | None = None, output: ~typing.Dict[str, ~typing.Any] | None = None, tags: ~typing.List[str] | None = None, usage: ~typing.Dict[str, ~typing.Any] | ~opik.llm_usage.opik_usage.OpikUsage | None = None, feedback_scores: ~typing.List[~opik.types.FeedbackScoreDict] | None = None, project_name: str | None = None, model: str | None = None, provider: ~opik.types.LLMProvider | str | None = None, error_info: ~opik.types.ErrorInfoDict | None = None, total_cost: float | None = None, attachments: ~typing.List[~opik.api_objects.attachment.attachment.Attachment] | None = None)¶
Bases:
objectThe SpanData object is returned when calling
opik.opik_context.get_current_span_data()from a tracked function.- trace_id: str¶
- id: str¶
- parent_span_id: str | None = None¶
- name: str | None = None¶
- type: Literal['general', 'tool', 'llm', 'guardrail'] = 'general'¶
- start_time: datetime | 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: Dict[str, Any] | OpikUsage | None = None¶
- feedback_scores: List[FeedbackScoreDict] | None = None¶
- project_name: str | None = None¶
- model: str | None = None¶
- provider: LLMProvider | str | None = None¶
- error_info: ErrorInfoDict | None = None¶
- total_cost: float | None = None¶
- attachments: List[Attachment] | None = None¶
- create_child_span_data(name: str | None = None, type: Literal['general', 'tool', 'llm', 'guardrail'] = '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: Dict[str, Any] | OpikUsage | None = None, feedback_scores: List[FeedbackScoreDict] | None = None, model: str | None = None, provider: LLMProvider | str | None = None, error_info: ErrorInfoDict | None = None, total_cost: float | None = None, attachments: List[Attachment] | None = None) SpanData¶
- update(**new_data: Any) SpanData¶
Updates the attributes of the object with the provided key-value pairs. This method checks if an attribute exists before updating it and merges the data appropriately for specific keywords like metadata, output, input, attachments, and tags. If a key doesn’t correspond to an attribute of the object or the provided value is None, the update is skipped.
- Parameters:
**new_data – Key-value pairs of attributes to update. Keys should match existing attributes on the object, and values that are None will not update.
- Returns:
The updated object instance.
- Return type:
- property as_start_parameters: Dict[str, Any]¶
Returns parameters of this span to be sent to the server when starting a new span.
- property as_parameters: Dict[str, Any]¶
Returns all parameters of this span to be sent to the server.