1414from datetime import datetime
1515from typing import Any , Dict , List , Literal , Optional , Union
1616
17+ from langfuse ._client .constants import (
18+ ObservationTypeGenerationLike ,
19+ ObservationTypeSpanLike ,
20+ )
21+
1722from langfuse ._utils .serializer import EventSerializer
1823from langfuse .model import PromptClient
1924from langfuse .types import MapValue , SpanLevel
@@ -93,9 +98,12 @@ def create_span_attributes(
9398 level : Optional [SpanLevel ] = None ,
9499 status_message : Optional [str ] = None ,
95100 version : Optional [str ] = None ,
101+ observation_type : Optional [
102+ Union [ObservationTypeSpanLike , Literal ["event" ]]
103+ ] = "span" ,
96104) -> dict :
97105 attributes = {
98- LangfuseOtelSpanAttributes .OBSERVATION_TYPE : "span" ,
106+ LangfuseOtelSpanAttributes .OBSERVATION_TYPE : observation_type ,
99107 LangfuseOtelSpanAttributes .OBSERVATION_LEVEL : level ,
100108 LangfuseOtelSpanAttributes .OBSERVATION_STATUS_MESSAGE : status_message ,
101109 LangfuseOtelSpanAttributes .VERSION : version ,
@@ -122,9 +130,10 @@ def create_generation_attributes(
122130 usage_details : Optional [Dict [str , int ]] = None ,
123131 cost_details : Optional [Dict [str , float ]] = None ,
124132 prompt : Optional [PromptClient ] = None ,
133+ observation_type : Optional [ObservationTypeGenerationLike ] = "generation" ,
125134) -> dict :
126135 attributes = {
127- LangfuseOtelSpanAttributes .OBSERVATION_TYPE : "generation" ,
136+ LangfuseOtelSpanAttributes .OBSERVATION_TYPE : observation_type ,
128137 LangfuseOtelSpanAttributes .OBSERVATION_LEVEL : level ,
129138 LangfuseOtelSpanAttributes .OBSERVATION_STATUS_MESSAGE : status_message ,
130139 LangfuseOtelSpanAttributes .VERSION : version ,
0 commit comments