LLM Tracing Quickstart

Setup LLM observability for your application in less than 5 minutes

Overview

Confident AI allows anyone building with any framework, language, and LLMs to setup LLM observability through tracing. Every interaction traced is evals-native, powered by DeepEval. This means apart form tracking latency, cost, and error rates, you can also run evals on:

  • Traces
  • Spans, and
  • Threads

The demo below demonstrates what it looks like on the platform:

Traces are a single execution of your LLM app, and running evals on traces is akin to the end-to-end evals for single-turn evaluation in development.

LLM Tracing: Traces with Evals

How It Works

You would setup LLM tracing either through one of our integrations, or by decorating your LLM app for Python and Typescript users. Either way, Confident AI will create an execution hierarchy of your LLM app, as well as log all components that were called for each LLM invocation:

  • Trace: The overall process of tracking and visualizing the execution flow of your LLM application
  • Span: Individual units of work within your application (e.g., LLM calls, tool executions, retrievals)

Each observed function CREATES A SPAN, and MANY SPANS MAKE UP A TRACE. When you have tracing setup, you can run evaluations on both the trace and span level.

Trace Your First LLM Call

You’ll need to get your API key as shown in the setup and installation section before continuing.

1

Installation

Install DeepEval and setup your tracing environment:

$pip install -U deepeval
2

Login to Confident AI

Get your Confident AI Project API key and login:

$export CONFIDENT_API_KEY=YOUR-API-KEY
3

Setup Tracing

The @observe decorator logs whatever it decorates within and is the primary way to instrument your LLM app for tracing.

main.py
1from openai import OpenAI
2from deepeval.tracing import observe
3
4client = OpenAI()
5
6@observe()
7def llm_app(query: str) -> str:
8 return client.chat.completions.create(
9 model="gpt-4o",
10 messages=[
11 {"role": "user", "content": query}
12 ]
13 ).choices[0].message.content
14 return
15
16# Call app to send trace to Confident AI
17llm_app("Write me a poem.")

✅ You just created a trace with a span inside it. Go to the Observatory to see your traces there.

If your llm_app has more than one function, simply decorate those functions with @observe too.

In a later section, you’ll learn how to create spans that are LLM specific, which allow you to log things like token cost and model name automatically.

Congratulations! 🎉 Now whenever you run your LLM app, all traces will be logged AND evaluated on Confident AI. Go to the the Observatory section on Confident AI to check it out.

If you don’t see the trace, it is 99.99% because your program exited before the traces had a chance to get posted. Try setting CONFIDENT_TRACE_FLUSH=YES if this is the case:

$CONFIDENT_TRACE_FLUSH=YES

In the next section, we will learn how to run evals for LLM tracing.