@@ -68,7 +68,7 @@ def create_trace_attributes(
6868 metadata : Optional [Any ] = None ,
6969 tags : Optional [List [str ]] = None ,
7070 public : Optional [bool ] = None ,
71- ):
71+ ) -> dict :
7272 attributes = {
7373 LangfuseOtelSpanAttributes .TRACE_NAME : name ,
7474 LangfuseOtelSpanAttributes .TRACE_USER_ID : user_id ,
@@ -93,7 +93,7 @@ def create_span_attributes(
9393 level : Optional [SpanLevel ] = None ,
9494 status_message : Optional [str ] = None ,
9595 version : Optional [str ] = None ,
96- ):
96+ ) -> dict :
9797 attributes = {
9898 LangfuseOtelSpanAttributes .OBSERVATION_TYPE : "span" ,
9999 LangfuseOtelSpanAttributes .OBSERVATION_LEVEL : level ,
@@ -122,7 +122,7 @@ def create_generation_attributes(
122122 usage_details : Optional [Dict [str , int ]] = None ,
123123 cost_details : Optional [Dict [str , float ]] = None ,
124124 prompt : Optional [PromptClient ] = None ,
125- ):
125+ ) -> dict :
126126 attributes = {
127127 LangfuseOtelSpanAttributes .OBSERVATION_TYPE : "generation" ,
128128 LangfuseOtelSpanAttributes .OBSERVATION_LEVEL : level ,
@@ -151,13 +151,13 @@ def create_generation_attributes(
151151 return {k : v for k , v in attributes .items () if v is not None }
152152
153153
154- def _serialize (obj ) :
154+ def _serialize (obj : Any ) -> Optional [ str ] :
155155 return json .dumps (obj , cls = EventSerializer ) if obj is not None else None
156156
157157
158158def _flatten_and_serialize_metadata (
159159 metadata : Any , type : Literal ["observation" , "trace" ]
160- ):
160+ ) -> dict :
161161 prefix = (
162162 LangfuseOtelSpanAttributes .OBSERVATION_METADATA
163163 if type == "observation"
@@ -171,7 +171,7 @@ def _flatten_and_serialize_metadata(
171171 else :
172172 for key , value in metadata .items ():
173173 metadata_attributes [f"{ prefix } .{ key } " ] = (
174- value
174+ str ( value )
175175 if isinstance (value , str ) or isinstance (value , int )
176176 else _serialize (value )
177177 )
0 commit comments