Callbacks and tracing
A callback receives lifecycle events from LangChain runs. A trace groups the nested runs for one operation so you can inspect inputs, outputs, timing, errors, and metadata. LangSmith is LangChain’s tracing service.
Tiny example
Section titled “Tiny example”# Set LANGSMITH_TRACING=true and LANGSMITH_API_KEY in the environment.result = chain.invoke( {"ticket": "INC-104"}, config={ "run_name": "support_summary", "tags": ["production"], "metadata": {"release": "2026.08.15"}, },)Read a trace in this order
Section titled “Read a trace in this order”- Find the failed or slow user request.
- Open its nested model, retriever, and tool runs.
- Compare the actual input with the expected input.
- Check latency, token usage, retrieved document IDs, and errors.
- Turn a repeated failure into an evaluation case or alert.
Failure note
Section titled “Failure note”Tracing can capture prompts, tool arguments, retrieved text, and model output. Redact secrets and personal data, configure retention and access, and avoid putting sensitive values in tags or metadata. A trace explains what happened; it does not prove the answer was correct.