Integrate EvalGate with LangChain workflows
Add distributed tracing and evaluations to LangChain chains, agents, and RAG pipelines to monitor quality and catch regressions in production.LangChain makes it easy to build complex LLM pipelines, but that complexity introduces more failure points — a broken tool, a retrieval miss, or a degraded prompt can silently reduce quality across thousands of requests. Wrapping your LangChain components with EvalGate tracing gives you end-to-end visibility into every step and lets you run structured evaluations against known-good baselines. This guide covers setup, tracing common LangChain patterns, running evaluations against chains, and monitoring production workflows.
Install dependencies
.env:
.env
Initialize the SDK
Tracing LangChain components
Simple chains
Wrap your chain call in aWorkflowTracer workflow and create spans for each step:
Agents with tool use
UsetraceWorkflowStep to wrap each agent invocation so tool calls appear as named spans:
RAG pipelines
For multi-step RAG pipelines, usetraceWorkflowStep to create separate spans for embedding, retrieval, and generation:
Multi-turn conversations with memory
Group a full conversation session as a single workflow, with one span per turn:Running evaluations against chains
Write eval test cases
Define test cases for your chain withcreateTestSuite, pass chain outputs through the executor, and assert quality with built-in assertions:
Gate regressions in CI
Once your test suite is defined, add a gate step so every code change is compared against the baseline:.github/workflows/evalgate.yml
Monitoring production chains
Add rich metadata
Include request context in workflow metadata to enable filtering and debugging in the dashboard:Tracing strategy by level
- High level
- Mid level
- Low level
Trace the entire chain as a single workflow for end-to-end monitoring. Best for production health checks and cost tracking.
Label production traces for your golden dataset
After collecting production traces, use the CLI to label them interactively and build evaluation coverage from real failures:Sample traces for high-throughput applications — trace 10% of requests to keep overhead low while retaining full error visibility. EvalGate samples 100% of error traces by default.
Best practices
Name spans after steps
Use descriptive span names like
embed-query and retrieve-docs instead of generic names like step-1. Specific names make timeline debugging much faster.Attach relevant metadata
Include
userId, sessionId, and model version in workflow metadata so you can filter traces by user segment or model version in the dashboard.Test at each layer
Test retrieval, generation, and end-to-end quality separately. A passing end-to-end score can mask a broken retrieval step.
Promote failures to tests
When a production chain produces a bad output, capture that input as a test case in your eval suite so the same failure cannot recur.
Troubleshooting
Traces not appearing in the dashboard? Confirm the SDK is initialized with the correctEVALGATE_API_KEY and that WorkflowTracer is instantiated before any workflow calls.
Spans are missing or out of order?
Make sure every async call inside a traceWorkflowStep callback is properly await-ed. Unawaited promises can resolve after the span closes, causing incomplete data.
High latency overhead?
The SDK adds roughly 10ms of overhead per trace upload. Use enableBatching: true when initializing the client to group writes into fewer API calls.