debug-instrumentation
Debug Your LangWatch Instrumentation
This recipe uses the LangWatch MCP to inspect your production traces and identify instrumentation issues.
Prerequisites
The LangWatch MCP must be installed with a valid API key. See MCP Setup.
Step 1: Fetch Recent Traces
Call search_traces with a recent time range (last 24h or 7d) to get an overview:
- How many traces are there?
- Do they have inputs and outputs populated, or are they
<empty>? - Are there labels and metadata (user_id, thread_id)?
Step 2: Inspect Individual Traces
For traces that look problematic, call get_trace with the trace ID to see the full span hierarchy:
- Empty input/output: The most common issue. Check if
autotrack_openai_calls(client)(Python) orexperimental_telemetry(TypeScript/Vercel AI) is configured. - Disconnected spans: Spans that don't connect to a parent trace. Usually means
@langwatch.trace()decorator is missing on the entry function. - Missing labels: No way to filter traces by feature/version. Add labels via
langwatch.get_current_trace().update(metadata={"labels": ["feature_name"]}). - Missing user_id/thread_id: Can't correlate traces to users or conversations. Add via trace metadata.
- Slow spans: Unusually long completion times may indicate API timeouts or inefficient prompts.
Step 3: Read the Integration Docs
Use fetch_langwatch_docs to read the integration guide for the project's framework. Compare the recommended setup with what's in the code.
Step 4: Apply Fixes
For each issue found:
- Identify the root cause in the code
- Apply the fix following the framework-specific docs
- Run the application to generate new traces
- Re-inspect with
search_tracesto verify the fix
Step 5: Verify Improvement
After fixes, compare before/after:
- Are inputs/outputs now populated?
- Are spans properly nested?
- Are labels and metadata present?
Common Issues and Fixes
| Issue | Cause | Fix |
|---|---|---|
All traces show <empty> input/output |
Missing autotrack or telemetry config | Add autotrack_openai_calls(client) or experimental_telemetry: { isEnabled: true } |
| Spans not connected to traces | Missing @langwatch.trace() on entry function |
Add trace decorator to the main function |
| No labels on traces | Labels not set in trace metadata | Add metadata={"labels": ["feature"]} to trace update |
| Missing user_id | User ID not passed to trace | Add user_id to trace metadata |
| Traces from different calls merged | Missing langwatch.setup() or trace context not propagated |
Ensure langwatch.setup() called at startup |
More from langwatch/skills
evaluations
Set up comprehensive evaluations for your AI agent with LangWatch — experiments (batch testing), evaluators (scoring functions), datasets, online evaluation (production monitoring), and guardrails (real-time blocking). Supports both code (SDK) and platform (CLI) approaches. Use when the user wants to evaluate, test, benchmark, monitor, or safeguard their agent.
50scenarios
Test your AI agent with simulation-based scenarios. Covers writing scenario test code (Scenario SDK), creating platform scenarios via the `langwatch` CLI, and red teaming for security vulnerabilities. Auto-detects whether to use code or platform approach based on context.
49level-up
Take your AI agent to the next level with full LangWatch integration. Adds tracing, prompt versioning, evaluation experiments, and simulation tests in one go. Use when the user wants comprehensive observability, testing, and prompt management for their agent.
37analytics
Analyze your AI agent's performance using LangWatch analytics. Use when the user wants to understand costs, latency, error rates, usage trends, or debug specific traces. Works with any LangWatch-instrumented agent.
31datasets
Generate realistic synthetic evaluation datasets by analyzing the user's codebase, prompts, production traces, and reference materials. Interactive, consultant-style — asks clarifying questions, proposes a plan, generates a preview for approval, then delivers a complete dataset uploaded to LangWatch. Use when user asks to generate, create, or build a dataset for evaluation, testing, or benchmarking.
12improve-setup
Expert AI engineering consultant for your LangWatch setup. Audits your codebase, traces, evaluations, and scenarios, then guides you to improve — starting from low-hanging fruit and going deeper. Use when you want to level up your agent's engineering quality.
8