@@ -89,6 +89,7 @@ def __init__(
8989 trace_id = None ,
9090 session_id = None ,
9191 user_id = None ,
92+ tags = None ,
9293 parent_observation_id = None ,
9394 ** kwargs ,
9495 ):
@@ -98,6 +99,7 @@ def __init__(
9899 self .args ["trace_id" ] = trace_id
99100 self .args ["session_id" ] = session_id
100101 self .args ["user_id" ] = user_id
102+ self .args ["tags" ] = tags
101103 self .args ["parent_observation_id" ] = parent_observation_id
102104 self .kwargs = kwargs
103105
@@ -187,17 +189,24 @@ def _get_langfuse_data_from_kwargs(
187189 if user_id is not None and not isinstance (user_id , str ):
188190 raise TypeError ("user_id must be a string" )
189191
192+ tags = kwargs .get ("tags" , None )
193+ if tags is not None and (
194+ not isinstance (tags , list ) or not all (isinstance (tag , str ) for tag in tags )
195+ ):
196+ raise TypeError ("tags must be a list of strings" )
197+
190198 parent_observation_id = kwargs .get ("parent_observation_id" , None )
191199 if parent_observation_id is not None and not isinstance (parent_observation_id , str ):
192200 raise TypeError ("parent_observation_id must be a string" )
193201 if parent_observation_id is not None and trace_id is None :
194202 raise ValueError ("parent_observation_id requires trace_id to be set" )
195203
196204 if trace_id :
197- langfuse .trace (id = trace_id , session_id = session_id , user_id = user_id )
198- elif session_id :
199- # If a session_id is provided but no trace_id, we should create a trace using the SDK and then use its trace_id
200- trace_id = langfuse .trace (session_id = session_id , user_id = user_id ).id
205+ langfuse .trace (id = trace_id , session_id = session_id , user_id = user_id , tags = tags )
206+ else :
207+ trace_id = langfuse .trace (
208+ session_id = session_id , user_id = user_id , tags = tags , name = name
209+ ).id
201210
202211 metadata = kwargs .get ("metadata" , {})
203212
0 commit comments