1212
1313import json
1414from datetime import datetime
15- from typing import Any , Dict , List , Literal , Optional
15+ from typing import Any , Dict , List , Literal , Optional , Union
1616
1717from langfuse ._utils .serializer import EventSerializer
1818from langfuse .model import PromptClient
@@ -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,20 +151,20 @@ 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"
164164 else LangfuseOtelSpanAttributes .TRACE_METADATA
165165 )
166166
167- metadata_attributes = {}
167+ metadata_attributes : Dict [ str , Union [ str , int , None ]] = {}
168168
169169 if not isinstance (metadata , dict ):
170170 metadata_attributes [prefix ] = _serialize (metadata )
0 commit comments