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 your account is in a region other than US (the default), also set LANGSMITH_ENDPOINT to the API URL for your region. Without this, your API key won’t be recognized and requests will fail to authenticate.
    Region
    GCP US
    GCP EU
    GCP APAC
    AWS US
    For example, EU accounts: export LANGSMITH_ENDPOINT="https://eu.api.smith.langchain.com".
    If you are using Anthropic, use the Anthropic wrapper. If you are using Google Gemini, use the Gemini 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:
  • OpenAI wrapper: wraps the OpenAI client so every LLM call is automatically logged as a nested span.
  • Traceable wrapper: wraps a function so its inputs, outputs, and any nested spans appear as a single trace in LangSmith. Use @traceable in Python, traceable in TypeScript and Kotlin, and Tracing.traceFunction in Java.
The assistant function calls a tool (get_context) to retrieve relevant context, then passes that context to the model. Using the traceable wrapper on both functions captures the full pipeline in one trace, with the tool call and LLM call as nested spans. Create a file called app.py, index.ts, App.java, or App.kt with the following code:

3. Run the app

4. View your trace

In the LangSmith UI, go to Tracing and select your default project. Click the assistant row to open the trace. The Messages tab shows the conversation as it was sent to the model. Select the Details tab to see the full run tree, including the assistant function with the get_context tool call and 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 get_context span records the tool call, and the ChatOpenAI span records the exact prompt sent to the model and the response returned.
You can also inspect traces from the terminal using the LangSmith CLI.

Next steps

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