Skip to main content
LangSmith gives you end-to-end visibility into your LLM application by capturing traces; a complete record of every step that ran during a request, from the inputs passed in to the final output returned. In this quickstart, you will add tracing to an AI assistant and view the results in LangSmith.
If you’re building with LangChain or LangGraph, you can enable LangSmith tracing with a single environment variable. Refer to trace with LangChain or trace with LangGraph.

Prerequisites

Before you begin, make sure you have: This example uses OpenAI as the LLM provider. You can adapt it for your own provider.

1. Set up your environment

  1. Create a project directory, install the dependencies, and configure the required environment variables:
  2. Export your environment variables in your shell:
    To send traces to a specific project, use the LANGSMITH_PROJECT environment variable. If this is not set, LangSmith will create a default tracing project automatically on trace ingestion.
    If you are using Anthropic, use the Anthropic wrapper. For other providers, use the @traceable decorator 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.
Create a file called app.py (or index.ts) with the following code:

3. Run the app and view your traces

Run the app:
Open the LangSmith UI and navigate to your default tracing project. You will see a trace for the assistant function with the OpenAI call nested inside it. LangSmith UI showing a trace with an outer application span and a nested LLM call span. The outer span captures your assistant function’s inputs and outputs. The nested ChatOpenAI span records the exact prompt sent to the model and the response returned.

Next steps

After logging traces, use Polly to analyze them and get AI-powered insights into your application’s performance.