# Trace Every Cursor Agent Turn in LangSmith

## Executive summary

This walkthrough details how to integrate LangSmith tracing with Cursor agents, ensuring that every agent turn is captured as a full, inspectable trace in LangSmith. The process involves installing the LangSmith plugin in Cursor, setting three specific environment variables (including `LANGCHAIN_TRACING_V2`), and running an end-to-end task to verify the hook's functionality.

## Key takeaways

- Full Trace Capture: By implementing this setup, every agent turn executed by Cursor is logged as a distinct trace in LangSmith, providing comprehensive visibility into the agent's execution flow.
- Trace Structure Details: Each trace captures the model run details (model name, token usage), input/output, tool runs (e.g., file reads, shell commands), and nested tasks if sub-agents are involved.
- Cross-Agent Comparison: LangSmith maintains a common trace structure that allows users to compare traces from multiple agents (Cursor, Claude Code, and Codex) within the same workspace.

## Technical details

- Prerequisites & Installation: Requires Cursor and Node.js. The LangSmith plugin is installed by pasting the provided repo URL into the Cursor settings > plugins field.
- Environment Variables: Three environment variables must be set in the shell config: `LANGCHAIN_TRACING_V2` (enables tracing), an API key for authentication, and `LANGCHAIN_API_STRATEGY` (or similar product name variable) to define where traces land.
- Verification: The hook's functionality is confirmed by tailing the log file with a specific command and observing activity after running a Cursor agent task.

## Practical implications

- Build engineers can gain deep observability into complex agentic workflows, allowing for debugging and performance analysis of multi-step tasks.
- The standardized trace structure facilitates comparing the behavior and efficiency of different LLM agents (Cursor, Claude Code, Codex) within a single platform.

## Topics

LangSmith, Agent Tracing, LLM Agents, Build Engineering Observability, Environment Variables, Trace Claude Code sessions in LangSmith, Trace Codex sessions in LangSmith

Source: https://www.youtube.com/watch?v=Ncv5TYdY7Tg
