# Using Langfuse for LLM Observability (/typescript-sdk/langfuse-usage)

Complete guide to using Langfuse for LLM observability, tracing, and analytics in the Inkeep Agent Framework



Langfuse is an open-source LLM engineering platform that provides specialized observability for AI applications, including token usage tracking, model performance analytics, and detailed LLM interaction tracing.

## Quick Start

### 1. Setup Langfuse Account

First, create a Langfuse account and get your API keys:

1. **Sign up** at [Langfuse Cloud](https://cloud.langfuse.com)
2. **Create a new project** in your Langfuse dashboard
3. **Get your API keys** from the project settings:
   * Public Key: `pk-lf-xxxxxxxxxx`
   * Secret Key: `sk-lf-xxxxxxxxxx`

### 2. Configure Langfuse

To integrate Langfuse with your Inkeep Agent Framework instrumentation, you need to modify your instrumentation file to include the Langfuse span processor.

Replace the default setup with a custom NodeSDK configuration:

Set your environment variables:

```bash
LANGFUSE_PUBLIC_KEY=pk-lf-xxxxxxxxxx
LANGFUSE_SECRET_KEY=sk-lf-xxxxxxxxxx
LANGFUSE_BASE_URL=https://us.cloud.langfuse.com
```

Update your instrumentation file:

```typescript
import {
  defaultSpanProcessors,
  defaultContextManager,
  defaultResource,
  defaultTextMapPropagator,
  defaultInstrumentations,
} from "@inkeep/agents-api/instrumentation";
import { NodeSDK } from "@opentelemetry/sdk-node";
import { LangfuseSpanProcessor } from "@langfuse/otel";

export const defaultSDK = new NodeSDK({
  resource: defaultResource,
  contextManager: defaultContextManager,
  textMapPropagator: defaultTextMapPropagator,
  spanProcessors: [...defaultSpanProcessors, new LangfuseSpanProcessor()],
  instrumentations: defaultInstrumentations,
});

defaultSDK.start();
```

<Note>
  Make sure to install the required dependencies in your agents API directory:
  `bash cd apps/agents-api pnpm add @opentelemetry/sdk-node @langfuse/otel `
</Note>

#### What This Configuration Does

* **Preserves all default instrumentation**: Uses the same resource, context manager, propagator, and instrumentations as the default setup
* **Adds Langfuse span processor**: Extends the default span processors with Langfuse's processor for specialized LLM observability
* **Maintains compatibility**: Your existing traces will continue to work while adding Langfuse-specific features

## Dataset setup and execution

Use the [Inkeep Agent Cookbook](https://github.com/inkeep/agents/tree/main/agents-cookbook) which provides ready-to-use scripts for creating and running Langfuse dataset evaluations programmatically.

#### 1. Clone the Agents Repository

```bash
git clone https://github.com/inkeep/agents.git
cd agents/agents-cookbook/evals/langfuse-dataset-example
```

**Set up environment variables in a `.env` file:**

```bash