LangSmith Observability
Status: ACTIVE (pulled from docs.langchain.com) Source: https://docs.langchain.com/oss/python/langgraph/observability Timestamp: 2026-05-11
Traces show each step your application takes from input to output. Use LangSmith to visualize these execution steps, debug, evaluate, and monitor your agents.
Enable Tracing
export LANGSMITH_TRACING=true
export LANGSMITH_API_KEY=<your-api-key>
By default, traces log to the default project.
Trace Selectively
import langsmith as ls
# This WILL be traced
with ls.tracing_context(enabled=True):
agent.invoke({"messages": [...]})
# This will NOT be traced (if LANGSMITH_TRACING not set)
agent.invoke({"messages": [...]})
Log to a Specific Project
Static (entire application):
export LANGSMITH_PROJECT=my-agent-project
Dynamic (per-operation):
with ls.tracing_context(project_name="email-agent-test", enabled=True):
response = agent.invoke({"messages": [...]})
Add Metadata and Tags
response = agent.invoke(
{"messages": [{"role": "user", "content": "Send a welcome email"}]},
config={
"tags": ["production", "email-assistant", "v1.0"],
"metadata": {
"user_id": "user_123",
"session_id": "session_456",
"environment": "production"
}
}
)
Mask Sensitive Data
Prevent sensitive data from being logged:
from langsmith.anonymizer import create_anonymizer
from langchain_core.tracers.langchain import LangChainTracer
from langsmith import Client
anonymizer = create_anonymizer([
# Matches SSNs
{ "pattern": r"\b\d{3}-?\d{2}-?\d{4}\b", "replace": "<ssn>" }
])
tracer_client = Client(anonymizer=anonymizer)
tracer = LangChainTracer(client=tracer_client)
graph = (
StateGraph(MessagesState)
...
.compile()
.with_config({'callbacks': [tracer]})
)