Skip to main content
Use Lemma’s LangChain integration when your app runs chains, chat models, retrievers, tools, or agents through LangChain callbacks. Each root execution owns one complete Lemma trace: current-turn input, final answer or root error, promoted thread_id / user_id, typed nested generations/tools/spans, and real wall-clock timing. Standalone LLM/tool/retriever callbacks finalize their own owned trace. Missing-parent events never overwrite concurrent trace state. You do not need to wrap LangChain calls in lemma.trace(). Pass the callback handler through LangChain’s callbacks option, then flush() to send the trace.

TypeScript

Install LangChain and the Lemma SDK:
Pass langChain() as a callback handler:

Python

Install the optional extra:
Pass langchain() as a callback handler:

What Lemma records

Promote identity from configurable metadata/tag keys (threadIdKey / thread_id_key, userIdKey / user_id_key). Defaults also check conversation_id, session_id, and resourceId. Prompts, tool inputs, outputs, model output text, and error messages are always recorded. Redact secrets and sensitive user data before they reach the chain.

Debugging

Enable debug mode while developing to confirm that spans arrive live and stay nested under the expected parent: