Docs
Tracing
Overview

Tracing

LLM apps use increasingly complex abstractions (chains, agents with tools, advanced prompts). The nested traces in Langfuse help to understand what is going on and get to the root cause of problems.

Why use tracing for your LLM app?

  1. Collect user feedback from the frontend
  2. Filter down to executions that had poor quality
  3. Use the debugging UI to get to the root cause of the problem

Introduction

A trace in Langfuse consists of the following objects:

  • Each backend execution is logged with a single trace.
  • Each trace can contain multiple observations to log the individual steps of the execution.
    • Observations are of different types:
      • Events are the basic building block. They are used to track discrete events in a trace.
      • Spans represent durations of units of work in a trace.
      • Generations are spans which are used to log generations of AI models. They contain additional attributes about the model, the prompt/completion. For generations, token usage and costs are automatically calculated.
    • Observations can be nested.

Get Started

Follow the quickstart to add Langfuse tracing to your LLM app.

Advanced usage

You can extend the tracing capabilities of Langfuse by using the following features:

Event queuing/batching

Langfuse's client SDKs and integrations are all designed to queue and batch requests in the background to optimize API calls and network time. Batches are determined by a combination of time and size (number of events and size of batch).

Configuration

All integrations have a sensible default configuration, but you can customise the batching behaviour to suit your needs.

Option (Python)Option (JS)Description
flush_atflushAtThe maximum number of events to batch up before sending.
flush_interval (s)flushInterval (ms)The maximum time to wait before sending a batch.

You can e.g. set flushAt=1 to send every event immediately, or flushInterval=1000 to send every second.

Manual flushing

ℹ️

This is especially relevant for short-lived applications like serverless functions. If you do not flush the client, you may lose events.

If you want to send a batch immediately, you can call the flush method on the client. In case of network issues, flush will log an error and retry the batch, it will never throw an exception.

langfuse.flush()

Was this page useful?

Questions? We're here to help

Subscribe to updates