Skip to content

Commit dfa5185

Browse files
committed
push
1 parent 328fcb5 commit dfa5185

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

langfuse/langchain/CallbackHandler.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ def __init__(
135135
self._updated_completion_start_time_memo: Set[UUID] = set()
136136
self._propagation_context_manager: Optional[_AgnosticContextManager] = None
137137
self._trace_context = trace_context
138+
self._child_to_parent_run_id_map: Dict[UUID, Optional[UUID]] = {}
138139

139140
self.last_trace_id: Optional[str] = None
140141

@@ -289,7 +290,13 @@ def _parse_langfuse_trace_attributes(
289290
if tags is not None or (
290291
"langfuse_tags" in metadata and isinstance(metadata["langfuse_tags"], list)
291292
):
292-
merged_tags = list(set(metadata["langfuse_tags"]) | set(tags or []))
293+
langfuse_tags = (
294+
metadata["langfuse_tags"]
295+
if "langfuse_tags" in metadata
296+
and isinstance(metadata["langfuse_tags"], list)
297+
else []
298+
)
299+
merged_tags = list(set(langfuse_tags) | set(tags or []))
293300
attributes["tags"] = [str(tag) for tag in set(merged_tags)]
294301

295302
attributes["metadata"] = _strip_langfuse_keys_from_dict(metadata, False)
@@ -851,6 +858,11 @@ def __on_llm_action(
851858
registered_prompt = self._prompt_to_parent_run_map.get(
852859
current_parent_run_id
853860
)
861+
if registered_prompt is not None:
862+
break
863+
current_parent_run_id = self._child_to_parent_run_id_map.get(
864+
current_parent_run_id
865+
)
854866

855867
content = {
856868
"name": self.get_langchain_run_name(serialized, **kwargs),
@@ -1007,7 +1019,7 @@ def on_llm_error(
10071019
langfuse_logger.exception(e)
10081020

10091021
def _reset(self) -> None:
1010-
self._child_to_parent_run_id_map: Dict[UUID, Optional[UUID]] = {}
1022+
self._child_to_parent_run_id_map = {}
10111023

10121024
def __join_tags_and_metadata(
10131025
self,

0 commit comments

Comments
 (0)