Learn how to instrument Langchain applications with the LangWatch Python SDK.
LangchainCallbackHandler
that deeply integrates with Langchain’s event system.
@langwatch.trace()
: Creates a parent LangWatch trace.current_trace.get_langchain_callback()
: Retrieves a LangWatch-specific callback handler linked to the current trace.RunnableConfig(callbacks=[langwatch_callback])
: Injects the handler into Langchain’s execution. Langchain emits events (on_llm_start, on_chain_end, etc.), which the handler converts into detailed LangWatch spans, correctly parented under the main trace.astream
, stream
, invoke
, ainvoke
).langwatch.setup()
openinference-instrumentation-langchain
or opentelemetry-instrumentation-langchain
for OpenLLMetry).langwatch.setup()
.