Skip to main content
Observability is a critical requirement for applications built with Large Language Models (LLMs). LLMs are non-deterministic, which means that the same prompt can produce different responses. This behavior makes debugging and monitoring more challenging than with traditional software. LangSmith addresses this by providing end-to-end visibility into how your application handles a request. Each request generates a trace, which captures the full record of what happened. Within a trace are individual runs, the specific operations your application performed, such as an LLM call or a retrieval step. Tracing runs allows you to inspect, debug, and validate your application’s behavior. In this quickstart, you will set up a minimal Retrieval Augmented Generation (RAG) application and add tracing with LangSmith. You will:
  1. Configure your environment.
  2. Create an application that retrieves context and calls an LLM.
  3. Enable tracing to capture both the retrieval step and the LLM call.
  4. View the resulting traces in the LangSmith UI.
If you prefer to watch a video on getting started with tracing, refer to the quickstart Video guide.

Prerequisites

Before you begin, make sure you have: The example app in this quickstart will use OpenAI as the LLM provider. You can adapt the example for your app’s LLM provider.
If you’re building an application with LangChain or LangGraph, you can enable LangSmith tracing with a single environment variable. Get started by reading the guides for tracing with LangChain or tracing with LangGraph.

1. Create a directory and install dependencies

In your terminal, create a directory for your project and install the dependencies in your environment:

2. Set up environment variables

Set the following environment variables:
  • LANGSMITH_TRACING
  • LANGSMITH_API_KEY
  • OPENAI_API_KEY (or your LLM provider’s API key)
  • (optional) LANGSMITH_WORKSPACE_ID: If your LangSmith API key is linked to multiple workspaces, set this variable to specify which workspace to use.
If you’re using Anthropic, use the Anthropic wrapper to trace your calls. For other providers, use the traceable wrapper.

3. Define your application

You can use the example app code outlined in this step to instrument a RAG application. Or, you can use your own application code that includes an LLM call. This is a minimal RAG app that uses the OpenAI SDK directly without any LangSmith tracing added yet. It has three main parts:
  • Retriever function: Simulates document retrieval that always returns the same string.
  • OpenAI client: Instantiates a plain OpenAI client to send a chat completion request.
  • RAG function: Combines the retrieved documents with the user’s question to form a system prompt, calls the chat.completions.create() endpoint with gpt-4o-mini, and returns the assistant’s response.
Add the following code into your app file (e.g., app.py or app.ts):

4. Trace LLM calls

To start, you’ll trace all your OpenAI calls. LangSmith provides wrappers: This snippet wraps the OpenAI client so that every subsequent model call is logged automatically as a traced child run in LangSmith.
  1. Include the highlighted lines in your app file:
  2. Call your application:
    You’ll receive the following output:
  3. In the LangSmith UI, navigate to the default Tracing Project for your workspace (or the workspace you specified in Step 2). You’ll see the OpenAI call you just instrumented.
LangSmith UI showing an LLM call trace called ChatOpenAI with a system and human input followed by an AI Output.

5. Trace an entire application

You can also use the traceable decorator for Python or TypeScript to trace your entire application instead of just the LLM calls.
  1. Include the highlighted code in your app file:
  2. Call the application again to create a run:
  3. Return to the LangSmith UI, navigate to the default Tracing Project for your workspace (or the workspace you specified in Step 2). You’ll find a trace of the entire app pipeline with the rag step and the ChatOpenAI LLM call.
LangSmith UI showing a trace of the entire application called rag with an input followed by an output.

Next steps

Here are some topics you might want to explore next:

Video guide


Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.