File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -323,13 +323,22 @@ def _get_span_key_from_baggage_key(key: str) -> Optional[str]:
323323 if not key .startswith (LANGFUSE_BAGGAGE_PREFIX ):
324324 return None
325325
326- if "user_id" in key :
326+ # Remove prefix to get the actual key name
327+ suffix = key [len (LANGFUSE_BAGGAGE_PREFIX ) :]
328+
329+ # Exact match for user_id and session_id
330+ if suffix == "user_id" :
327331 return LangfuseOtelSpanAttributes .TRACE_USER_ID
328332
329- if "session_id" in key :
333+ if suffix == "session_id" :
330334 return LangfuseOtelSpanAttributes .TRACE_SESSION_ID
331335
332- return f"{ LangfuseOtelSpanAttributes .TRACE_METADATA } .{ key } "
336+ # Metadata keys have format: langfuse_metadata_{key_name}
337+ if suffix .startswith ("metadata_" ):
338+ metadata_key = suffix [len ("metadata_" ) :]
339+ return f"{ LangfuseOtelSpanAttributes .TRACE_METADATA } .{ metadata_key } "
340+
341+ return None
333342
334343
335344def _get_propagated_span_key (key : PropagatedKeys ) -> str :
You can’t perform that action at this time.
0 commit comments