Prerequisites
Before you begin, make sure you have:- A LangSmith account: Sign up or log in at smith.langchain.com.
- A LangSmith API key: Follow the Create an API key guide.
- An OpenAI API key: Generate this from the OpenAI dashboard.
1. Set up your environment
-
Create a project directory, install the dependencies, and configure the required environment variables:
-
Export your environment variables in your shell:
If you are using Anthropic, use the Anthropic wrapper. For other providers, use theTo send traces to a specific project, use the
LANGSMITH_PROJECTenvironment variable. If this is not set, LangSmith will create a default tracing project automatically on trace ingestion.@traceabledecorator to trace calls manually.
2. Build the app
The following app uses two LangSmith tools to add tracing:wrap_openai: wraps the OpenAI client so every model call is automatically logged.@traceable: wraps a function so its inputs, outputs, and nested runs appear as a single trace in LangSmith.
app.py (or index.ts) with the following code:
3. Run the app and view your traces
Run the app:assistant function with the OpenAI call nested inside it.

assistant function’s inputs and outputs. The nested ChatOpenAI span records the exact prompt sent to the model and the response returned.
Next steps
- Tracing integrations: LangChain, LangGraph, Anthropic, and other providers.
- Trace an LLM application: a full lifecycle tutorial, from prototyping through production.
- Filter traces: search and navigate large tracing projects.
- Log to a specific project: send traces to a named project instead of default.
After logging traces, use Polly to analyze them and get AI-powered insights into your application’s performance.
Connect these docs to Claude, VSCode, and more via MCP for real-time answers.


