Skip to content

Commit da81030

Browse files
committed
push
1 parent 59bd332 commit da81030

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

langfuse/_client/propagation.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff 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

335344
def _get_propagated_span_key(key: PropagatedKeys) -> str:

0 commit comments

Comments
 (0)