---
name: langfuse-common-errors-9b857528d9d5
description: |
  Diagnose and fix common Langfuse errors and exceptions.
  Use when encountering Langfuse errors, debugging missing traces,
  or troubleshooting integration issues.
  Trigger with phrases like "langfuse error", "fix langfuse",
  "langfuse not working", "debug langfuse", "traces not appearing".
allowed-tools: Read, Grep, Bash(curl:*)
version: 1.0.0
license: MIT
author: Jeremy Longshore <jeremy@intentsolutions.io>
---

# Langfuse Common Errors

## Overview
Quick reference for the top 10 most common Langfuse errors and their solutions.

## Prerequisites
- Langfuse SDK installed
- API credentials configured
- Access to error logs

## Instructions

### Step 1: Identify the Error
Check error message and code in your logs or console.

### Step 2: Find Matching Error Below
Match your error to one of the documented cases.

### Step 3: Apply Solution
Follow the solution steps for your specific error.

## Output
- Identified error cause
- Applied fix
- Verified resolution

## Error Handling

### 1. Authentication Failed
**Error Message:**
```
Langfuse: Unauthorized - Invalid API key
Error: 401 Unauthorized
```

**Cause:** API key is missing, expired, or mismatched with host.

**Solution:**
```bash
# Verify environment variables are set
echo "Public: $LANGFUSE_PUBLIC_KEY"
echo "Secret: ${LANGFUSE_SECRET_KEY:0:10}..."  # Partial for security
echo "Host: $LANGFUSE_HOST"

# Test connection
curl -X GET "$LANGFUSE_HOST/api/public/health" \
  -H "Authorization: Basic $(echo -n "$LANGFUSE_PUBLIC_KEY:$LANGFUSE_SECRET_KEY" | base64)"
```

---

### 2. Traces Not Appearing in Dashboard
**Symptom:** Code runs without errors but traces don't show up.

**Cause:** Data not flushed before process exits.

**Solution:**
```typescript
// Always flush before exit
await langfuse.flushAsync();

// Or use shutdown for clean exit
await langfuse.shutdownAsync();

// Register shutdown handler
process.on("beforeExit", async () => {
  await langfuse.shutdownAsync();
});
```

---

### 3. Network/Connection Errors
**Error Message:**
```
FetchError: request to https://cloud.langfuse.com failed
ECONNREFUSED / ETIMEDOUT
```

**Cause:** Network connectivity or firewall issues.

**Solution:**
```bash
# Test connectivity
curl -v https://cloud.langfuse.com/api/public/health

# Check DNS resolution
nslookup cloud.langfuse.com

# For self-hosted, verify host URL
curl -v $LANGFUSE_HOST/api/public/health
```

```typescript
// Increase timeout if needed
const langfuse = new Langfuse({
  requestTimeout: 30000, // 30 seconds
});
```

---

### 4. Missing Token Usage
**Symptom:** Generations appear but token counts are 0.

**Cause:** Usage data not captured from LLM response.

**Solution:**
```typescript
// For streaming, enable usage in options
const stream = await openai.chat.completions.create({
  model: "gpt-4",
  messages,
  stream: true,
  stream_options: { include_usage: true }, // Important!
});

// Manually add usage if not available
generation.end({
  output: content,
  usage: {
    promptTokens: response.usage?.prompt_tokens || 0,
    completionTokens: response.usage?.completion_tokens || 0,
  },
});
```

---

### 5. Trace/Span Not Ending
**Symptom:** Traces show as "in progress" indefinitely.

**Cause:** Missing `.end()` call on spans/generations.

**Solution:**
```typescript
// Always end in try/finally
const span = trace.span({ name: "operation" });
try {
  const result = await doWork();
  span.end({ output: result });
  return result;
} catch (error) {
  span.end({ level: "ERROR", statusMessage: String(error) });
  throw error;
}

// Or use finally
const span = trace.span({ name: "operation" });
try {
  return await doWork();
} finally {
  span.end();
}
```

---

### 6. Duplicate Traces
**Symptom:** Same operation creates multiple traces.

**Cause:** Client instantiated multiple times or missing singleton.

**Solution:**
```typescript
// Use singleton pattern
let langfuseInstance: Langfuse | null = null;

export function getLangfuse(): Langfuse {
  if (!langfuseInstance) {
    langfuseInstance = new Langfuse();
  }
  return langfuseInstance;
}

// Don't create new instance per request
// BAD: const langfuse = new Langfuse(); // in handler
// GOOD: const langfuse = getLangfuse();
```

---

### 7. SDK Version Mismatch
**Error Message:**
```
TypeError: langfuse.trace is not a function
Property 'observeOpenAI' does not exist
```

**Cause:** Outdated SDK or breaking API change.

**Solution:**
```bash
# Check current version
npm list langfuse

# Update to latest
npm install langfuse@latest

# Check changelog for breaking changes
# https://github.com/langfuse/langfuse-js/releases
```

---

### 8. Environment Variable Not Loaded
**Error Message:**
```
Langfuse: Missing required configuration - publicKey
```

**Cause:** .env file not loaded or wrong variable names.

**Solution:**
```bash
# Verify .env file exists and has correct names
cat .env | grep LANGFUSE

# Required variable names:
# LANGFUSE_PUBLIC_KEY=pk-lf-...
# LANGFUSE_SECRET_KEY=sk-lf-...
# LANGFUSE_HOST=https://cloud.langfuse.com
```

```typescript
// Load .env in your app
import "dotenv/config"; // At top of entry file

// Or specify env file
import { config } from "dotenv";
config({ path: ".env.local" });
```

---

### 9. Self-Hosted Connection Issues
**Error Message:**
```
Failed to connect to localhost:3000
Certificate verification failed
```

**Cause:** Self-hosted instance not running or SSL issues.

**Solution:**
```bash
# Check if Langfuse is running
docker ps | grep langfuse
curl http://localhost:3000/api/public/health

# For HTTPS without valid cert
export NODE_TLS_REJECT_UNAUTHORIZED=0  # Development only!
```

```typescript
// Verify host URL doesn't have trailing slash
const langfuse = new Langfuse({
  baseUrl: "http://localhost:3000", // No trailing slash
});
```

---

### 10. Rate Limiting
**Error Message:**
```
Error: 429 Too Many Requests
Retry-After: 60
```

**Cause:** Exceeded Langfuse API rate limits.

**Solution:**
```typescript
// Increase batch size to reduce requests
const langfuse = new Langfuse({
  flushAt: 50,        // Batch more events
  flushInterval: 30000, // Flush less often
});

// See langfuse-rate-limits skill for advanced handling
```

## Quick Diagnostic Commands
```bash
# Check Langfuse cloud status
curl -s https://status.langfuse.com

# Verify API connectivity
curl -I https://cloud.langfuse.com/api/public/health

# Check local environment
env | grep LANGFUSE

# Test auth
curl -X GET "https://cloud.langfuse.com/api/public/traces" \
  -H "Authorization: Basic $(echo -n "$LANGFUSE_PUBLIC_KEY:$LANGFUSE_SECRET_KEY" | base64)" \
  | head -c 200
```

## Escalation Path
1. Collect evidence with `langfuse-debug-bundle`
2. Check [Langfuse Status](https://status.langfuse.com)
3. Search [GitHub Issues](https://github.com/langfuse/langfuse/issues)
4. Join [Discord Community](https://langfuse.com/discord)
5. Contact support with debug bundle

## Resources
- [Langfuse Troubleshooting](https://langfuse.com/docs/get-started)
- [Langfuse GitHub Issues](https://github.com/langfuse/langfuse/issues)
- [Langfuse Discord](https://langfuse.com/discord)

## Next Steps
For comprehensive debugging, see `langfuse-debug-bundle`.


---
Source attribution: Dicklesworthstone
Original project: https://github.com/Dicklesworthstone/pi_agent_rust/blob/f28fc46ee0db8e710d95b8b55592cd38d60f2b26/tests/ext_conformance/artifacts/plugins-community/plugins/saas-packs/langfuse-pack/skills/langfuse-common-errors/SKILL.md
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Mega AI Hub.

## Upstream license notice

MIT License (with OpenAI/Anthropic Rider)

Copyright (c) 2026 Jeffrey Emanuel

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

ADDITIONAL RIDER / RESTRICTION (OpenAI / Anthropic):

This rider is part of the "conditions" of this License. In the event of any
conflict between this rider and any other portion of this License, this rider
controls.

"Restricted Parties" means OpenAI, L.L.C.; Anthropic, PBC; any of their
respective Affiliates; and any person or entity acting directly or indirectly
on behalf of, for the benefit of, or under the direction of any of the
foregoing (including any officer, director, employee, contractor, agent,
consultant, service provider, or representative).

Notwithstanding any other provision of this License, no rights are granted to
any Restricted Party. Any purported license, sublicense, assignment, transfer,
or other permission to any Restricted Party is null and void absent the
express prior written permission of Jeffrey Emanuel.

You may not provide, disclose, distribute, sublicense, sell, lease, lend,
host, make available, or otherwise permit access to the Software or any
derivative work of the Software (as defined in applicable copyright law)
(collectively, "Derivative Works") to or for any Restricted Party.

For purposes of this rider, "use" includes, without limitation: copying,
modifying, merging, publishing, distributing, sublicensing, selling,
transferring, making available, hosting, deploying, executing, benchmarking,
testing, analyzing, indexing, or incorporating the Software or any Derivative
Works into any dataset, training corpus, evaluation harness, or pipeline for
machine learning or other automated systems.

This rider applies to the Software and all Derivative Works. As a condition of
use, you agree that this rider is a precondition to exercising any rights
under this License, and you agree that any distribution of the Software or any
Derivative Works must include this rider provision unmodified.

Any breach of this rider automatically and immediately terminates the
permissions granted by this License. Upon termination, you must immediately
cease all use and distribution of the Software and any Derivative Works and
destroy all copies under your control.

You agree that a breach of this rider would cause irreparable harm and that
Jeffrey Emanuel may seek injunctive or other equitable relief to enforce this
rider, in addition to any other remedies available at law. To the maximum
extent permitted by applicable law, the prevailing party in any action to
enforce this rider shall be entitled to recover reasonable attorneys' fees and
costs.

For purposes of this rider, "Affiliate" means any entity that directly or
indirectly controls, is controlled by, or is under common control with the
specified party. "Control" means ownership of more than 50% of the voting
securities or other ownership interest, or the power to direct management or
policies by contract or otherwise.

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Mega AI Hub resource metadata

Creator / publisher: Dicklesworthstone
Original project: https://github.com/Dicklesworthstone/pi_agent_rust/blob/f28fc46ee0db8e710d95b8b55592cd38d60f2b26/tests/ext_conformance/artifacts/plugins-community/plugins/saas-packs/langfuse-pack/skills/langfuse-common-errors/SKILL.md
Attribution basis: Source repository record

Fields of work: Development & Engineering
Roles: Backend Developer, Data Engineer, ML / AI Engineer
Specialties: API, Backend
Tools: Langfuse
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: 55331de5af83b2a9685dde19ad9f7bb71069232320d9a37a086dc18880ed1315
