Skip to content

Commit 057ad66

Browse files
authored
feat(langchain): add last trace id property to CallbackHandler (#1230)
1 parent 3daf4c9 commit 057ad66

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

langfuse/langchain/CallbackHandler.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ def __init__(self, *, public_key: Optional[str] = None) -> None:
6363
self.prompt_to_parent_run_map: Dict[UUID, Any] = {}
6464
self.updated_completion_start_time_memo: Set[UUID] = set()
6565

66+
self.last_trace_id = None
67+
6668
def on_llm_new_token(
6769
self,
6870
token: str,
@@ -187,6 +189,8 @@ def on_chain_start(
187189
level=span_level,
188190
)
189191

192+
self.last_trace_id = self.runs[run_id].trace_id
193+
190194
except Exception as e:
191195
langfuse_logger.exception(e)
192196

@@ -573,6 +577,8 @@ def __on_llm_action(
573577
else:
574578
self.runs[run_id] = self.client.start_generation(**content)
575579

580+
self.last_trace_id = self.runs[run_id].trace_id
581+
576582
except Exception as e:
577583
langfuse_logger.exception(e)
578584

0 commit comments

Comments
 (0)