npx skills add ...
npx skills add langchain-ai/skills-benchmarks --skill langsmith-trace
npx skills add langchain-ai/skills-benchmarks --skill langsmith-trace
INVOKE THIS SKILL when working with LangSmith tracing OR querying traces. Covers adding tracing to applications and querying/exporting trace data. Uses the langsmith CLI tool.
Authentication is REQUIRED: either set the LANGSMITH_API_KEY environment variable, or pass the --api-key flag to CLI commands (preferred):
IMPORTANT: Always check the environment variables or .env file for LANGSMITH_PROJECT before querying or interacting with LangSmith. This tells you which project contains the relevant traces and data. If the LangSmith project is not available, use your best judgement to identify the right one.
CLI Tool
<trace_langchain_oss> For LangChain/LangGraph apps, tracing is automatic. Just set environment variables:
Optional variables:
LANGSMITH_PROJECT - specify project name (defaults to "default")LANGCHAIN_CALLBACKS_BACKGROUND=false - use for serverless to ensure traces complete before function exit (Python)
</trace_langchain_oss><trace_other_frameworks>
For anything other than LangChain/LangGraph, read the matching reference file in references/ before writing tracing code. Each reference covers install, env vars, setup snippet, and gotchas specific to that framework. The setup is rarely identical across frameworks — picking the wrong pattern (e.g. using @traceable when the framework has native OTel) creates duplicate/missing spans.
Decision order:
references/otel.mdreferences/traceable.mdreferences/api.md (last resort)Routing table:
| If you're tracing… | Read |
|---|---|
| OpenAI / Azure OpenAI / Anthropic / any plain LLM client | references/traceable.md |
| AutoGen | references/autogen.md |
| CrewAI | references/crewai.md |
| Google ADK | references/google-adk.md |
Google Gemini (google-genai SDK directly) | references/google-gemini.md |
| Instructor (structured outputs) | references/instructor.md |
| LiveKit Agents (voice AI) | references/livekit.md |
| Mastra (TypeScript) | references/mastra.md |
| Microsoft Agent Framework | references/microsoft-agent-framework.md |
| Mistral | references/mistral.md |
| n8n (self-hosted) | references/n8n.md |
| OpenAI Agents SDK | references/openai-agents-sdk.md |
| OpenCode | references/opencode.md |
| OpenAI Codex CLI | references/codex.md |
| Pipecat (voice AI) | references/pipecat.md |
| PydanticAI | references/pydantic-ai.md |
| Semantic Kernel | references/semantic-kernel.md |
| Strands Agents | references/strands-agents.md |
| Temporal workflows (Go/Python/TS) | references/temporal.md |
| Vercel AI SDK | references/vercel-ai-sdk.md |
| Any other framework with native OTel | references/otel.md |
| Multi-backend OTel fan-out | references/otel.md (Collector section) |
| Raw REST (no SDK available) | references/api.md |
If the framework you need isn't listed here, check references/ — new integrations are added there, not inline.
</trace_other_frameworks>
<traces_vs_runs>
Use the langsmith CLI to query trace data.
Understanding the difference is critical:
Generally, query traces first — they provide complete context and preserve hierarchy needed for trajectory analysis and dataset generation. </traces_vs_runs>
<command_structure> Two command groups with consistent behavior:
Key differences:
traces * | runs * | |
|---|---|---|
| Filters apply to | Root run only | Any matching run |
--run-type | Not available | Available |
| Returns | Full hierarchy | Flat list |
| Export output | Directory (one file/trace) | Single file |
| </command_structure> |
<querying_traces>
Query traces using the langsmith CLI. Commands are language-agnostic.
</querying_traces>
All commands support these filters (all AND together):Basic filters:
--trace-ids abc,def - Filter to specific traces--limit N - Max results--project NAME - Project name--last-n-minutes N - Time filter--since TIMESTAMP - Time filter (ISO format)--error / --no-error - Error status--name PATTERN - Name contains (case-insensitive)Performance filters:
--min-latency SECONDS - Minimum latency (e.g., 5 for >= 5s)--max-latency SECONDS - Maximum latency--min-tokens N - Minimum total tokens--tags tag1,tag2 - Has any of these tagsAdvanced filter:
--filter QUERY - Raw LangSmith filter query for complex cases (feedback, metadata, etc.)<export_format>
Export creates .jsonl files (one run per line) with these fields:
Use --include-io or --full to include inputs/outputs (required for dataset generation).
</export_format>