Skip to content

Commit 831270d

Browse files
Langchain callback handler docs (#1476)
feat: Add trace_context to LangchainCallbackHandler Co-authored-by: Cursor Agent <[email protected]>
1 parent 9afb9a8 commit 831270d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

langfuse/langchain/CallbackHandler.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,19 @@ def __init__(
104104
Args:
105105
public_key: Optional Langfuse public key. If not provided, will use the default client configuration.
106106
update_trace: Whether to update the Langfuse trace with the chains input / output / metadata / name. Defaults to False.
107+
trace_context: Optional context for connecting to an existing trace (distributed tracing) or
108+
setting a custom trace id for the root LangChain run. Pass a `TraceContext` dict, e.g.
109+
`{"trace_id": "<trace_id>"}` (and optionally `{"parent_span_id": "<span_id>"}`) to link
110+
the trace to an upstream system.
111+
112+
Example:
113+
Use a custom trace id without context managers:
114+
115+
```python
116+
from langfuse.langchain import CallbackHandler
117+
118+
handler = CallbackHandler(trace_context={"trace_id": "my-trace-id"})
119+
```
107120
"""
108121
self.client = get_client(public_key=public_key)
109122
self.run_inline = True

0 commit comments

Comments
 (0)