> ## Documentation Index
> Fetch the complete documentation index at: https://docs.praison.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Langfuse

> Use Langfuse observability with PraisonAI TypeScript

# Langfuse Observability

Production observability with Langfuse.

## Environment Variables

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
export LANGFUSE_SECRET_KEY=sk-lf-...
export LANGFUSE_PUBLIC_KEY=pk-lf-...
export LANGFUSE_HOST=https://cloud.langfuse.com  # optional
```

| Variable              | Required | Description          |
| --------------------- | -------- | -------------------- |
| `LANGFUSE_SECRET_KEY` | Yes      | Langfuse secret key  |
| `LANGFUSE_PUBLIC_KEY` | Yes      | Langfuse public key  |
| `LANGFUSE_HOST`       | No       | Custom Langfuse host |

## Features

| Feature | Supported |
| ------- | --------- |
| Traces  | ✅         |
| Spans   | ✅         |
| Events  | ✅         |
| Errors  | ✅         |
| Metrics | ✅         |
| Export  | ✅         |

## Quick Start

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import { Agent, setObservabilityAdapter } from 'praisonai';
import { LangfuseObservabilityAdapter } from 'praisonai/observability';

// Initialize Langfuse adapter
const obs = new LangfuseObservabilityAdapter();
await obs.initialize();
setObservabilityAdapter(obs);

// Create agent with tracing
const agent = new Agent({
  name: 'TracedAgent',
  instructions: 'You are a helpful assistant.',
  llm: 'openai/gpt-4o-mini'
});

// Run with automatic tracing
const response = await agent.chat('Hello!');

// Flush traces to Langfuse
await obs.flush();
```

## Multi-Agent Tracing

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import { Agent, Agents, setObservabilityAdapter } from 'praisonai';
import { LangfuseObservabilityAdapter } from 'praisonai/observability';

const obs = new LangfuseObservabilityAdapter();
await obs.initialize();
setObservabilityAdapter(obs);

const researcher = new Agent({
  name: 'Researcher',
  instructions: 'Research topics.',
  llm: 'openai/gpt-4o'
});

const writer = new Agent({
  name: 'Writer',
  instructions: 'Write summaries.',
  llm: 'openai/gpt-4o-mini'
});

const agents = new AgentTeam({
  agents: [researcher, writer],
  tasks: [
    { agent: researcher, description: 'Research {topic}' },
    { agent: writer, description: 'Summarize findings' }
  ]
});

await agents.start({ topic: 'AI trends' });
await obs.flush();
```

## Troubleshooting

### Missing API Keys

```
Error: Langfuse SDK not available
```

**Solution**: Set both `LANGFUSE_SECRET_KEY` and `LANGFUSE_PUBLIC_KEY`.

### Traces Not Appearing

**Solution**: Ensure you call `await obs.flush()` before the process exits.

## Related

* [Langfuse CLI Usage](/docs/js/observability/langfuse-cli)
* [Observability Overview](/docs/js/observability)
