/langfuse-pack:langfuse-upgrade-migrationfrom langfuse-pack
Upgrades Langfuse SDK versions and migrates between major API changes, including v3 to v4 (OpenTelemetry rewrite) and v4 to v5. Provides step-by-step instructions, codemods, and breaking change handling.
Ships in langfuse-pack. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
!npm list langfuse @langfuse/client @langfuse/tracing @langfuse/otel 2>/dev/null | head -10 || echo 'No langfuse packages found'
!pip show langfuse 2>/dev/null | grep -E "Name|Version" || echo 'Python langfuse not installed'
Step-by-step guide for upgrading the Langfuse SDK across major versions. Covers v3 to v4 (OTel rewrite), v4 to v5, breaking changes, and automated codemods.
| SDK | Package | Architecture | Status |
|---|---|---|---|
| v3 | langfuse (single) | Custom, Langfuse class | Legacy |
| v4 | @langfuse/client, @langfuse/tracing, @langfuse/otel | OpenTelemetry-based | Stable |
| v5 | @langfuse/client, @langfuse/tracing, @langfuse/otel | OpenTelemetry + improvements | Latest |
set -euo pipefail
# Check what you have
npm list langfuse @langfuse/client @langfuse/tracing 2>/dev/null
# Check latest available
npm info @langfuse/client version
npm info @langfuse/tracing version
npm info langfuse version
# Python
pip show langfuse 2>/dev/null | grep Version
pip index versions langfuse 2>/dev/null | head -3
This is the biggest migration -- v4 rewrites tracing on OpenTelemetry.
2a. Install new packages:
set -euo pipefail
# Install v4+ packages
npm install @langfuse/client @langfuse/tracing @langfuse/otel @opentelemetry/sdk-node
# Keep langfuse v3 temporarily for comparison
# Remove after migration: npm uninstall langfuse
2b. Update initialization:
// BEFORE (v3):
import { Langfuse } from "langfuse";
const langfuse = new Langfuse({
publicKey: process.env.LANGFUSE_PUBLIC_KEY,
secretKey: process.env.LANGFUSE_SECRET_KEY,
baseUrl: process.env.LANGFUSE_HOST,
});
// AFTER (v4+):
import { LangfuseClient } from "@langfuse/client";
import { LangfuseSpanProcessor } from "@langfuse/otel";
import { NodeSDK } from "@opentelemetry/sdk-node";
// OTel setup (once at entry point)
const sdk = new NodeSDK({
spanProcessors: [new LangfuseSpanProcessor()],
});
sdk.start();
// Client for prompts, datasets, scores
const langfuse = new LangfuseClient();
2c. Update tracing calls:
// BEFORE (v3): Manual trace/span/generation
const trace = langfuse.trace({ name: "my-op", input: data });
const span = trace.span({ name: "step-1", input: data });
await doWork();
span.end({ output: result });
const gen = trace.generation({ name: "llm", model: "gpt-4o" });
gen.end({ output: response, usage: { promptTokens: 10 } });
await langfuse.flushAsync();
// AFTER (v4+): startActiveObservation with auto-nesting
import { startActiveObservation, updateActiveObservation } from "@langfuse/tracing";
await startActiveObservation("my-op", async () => {
updateActiveObservation({ input: data });
await startActiveObservation("step-1", async () => {
updateActiveObservation({ input: data });
const result = await doWork();
updateActiveObservation({ output: result });
});
await startActiveObservation({ name: "llm", asType: "generation" }, async () => {
updateActiveObservation({ model: "gpt-4o" });
const response = await callLLM();
updateActiveObservation({ output: response, usage: { promptTokens: 10 } });
});
});
2d. Update OpenAI wrapper:
// BEFORE (v3):
import { observeOpenAI } from "langfuse";
// AFTER (v4+):
import { observeOpenAI } from "@langfuse/openai";
// npm install @langfuse/openai
2e. Update environment variable:
# BEFORE: LANGFUSE_HOST or LANGFUSE_BASEURL
# AFTER: LANGFUSE_BASE_URL (LANGFUSE_BASEURL still works in v4 but not v5)
2f. Update prompt management:
// BEFORE (v3):
const prompt = await langfuse.getPrompt("my-prompt", 2); // version as positional arg
// AFTER (v4+):
const prompt = await langfuse.prompt.get("my-prompt", {
version: 2, // version in options object
type: "text", // explicit type
});
2g. Update shutdown:
// BEFORE (v3):
await langfuse.shutdownAsync();
// AFTER (v4+):
await sdk.shutdown(); // Shuts down OTel SDK + flushes spans
# BEFORE (v2):
from langfuse import Langfuse
langfuse = Langfuse()
@langfuse.observe()
def my_function():
pass
# AFTER (v3):
from langfuse.decorators import observe, langfuse_context
@observe()
def my_function():
langfuse_context.update_current_observation(
metadata={"key": "value"}
)
set -euo pipefail
# Run existing test suite
npm test
# Verify traces appear in dashboard
node -e "
const { startActiveObservation, updateActiveObservation } = require('@langfuse/tracing');
startActiveObservation('upgrade-verify', async () => {
updateActiveObservation({ input: { test: true }, output: { migrated: true } });
}).then(() => console.log('Migration verified'));
"
set -euo pipefail
# After all tests pass
npm uninstall langfuse
# Verify no lingering imports
grep -rn "from ['\"]langfuse['\"]" src/ || echo "No old imports found"
| Change | v3 | v4+ |
|---|---|---|
| Package | langfuse | @langfuse/client + @langfuse/tracing + @langfuse/otel |
| Client class | Langfuse | LangfuseClient |
| Base URL env | LANGFUSE_HOST | LANGFUSE_BASE_URL |
| Tracing | langfuse.trace() / .span() / .generation() | startActiveObservation() / observe() |
| Flush | langfuse.flushAsync() | sdk.shutdown() |
| Prompt version | getPrompt(name, version) | prompt.get(name, { version }) |
| OpenAI | import { observeOpenAI } from "langfuse" | import { observeOpenAI } from "@langfuse/openai" |
| Error | Cause | Solution |
|---|---|---|
Cannot find module '@langfuse/tracing' | Package not installed | npm install @langfuse/tracing @langfuse/otel @opentelemetry/sdk-node |
langfuse.trace is not a function | Using v4 LangfuseClient for tracing | Use startActiveObservation from @langfuse/tracing |
| Flat traces (no nesting) | OTel SDK not started | Register LangfuseSpanProcessor with NodeSDK |
LANGFUSE_HOST ignored | v5 dropped legacy env var | Rename to LANGFUSE_BASE_URL |
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
24 skills in this plugin
/langfuse-ci-integrationConfigure Langfuse CI/CD integration with GitHub Actions and automated testing.
Use when setting up automated testing, configuring CI pipelines,
or integrating Langfuse tests into your build process.
Trigger with phrases like "langfuse CI", "langfuse GitHub Actions",
"langfuse automated tests", "CI langfuse", "langfuse pipeline".
/langfuse-common-errorsDiagnose 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".
/langfuse-core-workflow-aExecute Langfuse primary workflow: Tracing LLM calls and spans.
Use when implementing LLM tracing, building traced AI features,
or adding observability to existing LLM applications.
Trigger with phrases like "langfuse tracing", "trace LLM calls",
"add langfuse to openai", "langfuse spans", "track llm requests".
/langfuse-core-workflow-bExecute Langfuse secondary workflow: Evaluation, scoring, and datasets.
Use when implementing LLM evaluation, adding user feedback,
or setting up automated quality scoring and experiment datasets.
Trigger with phrases like "langfuse evaluation", "langfuse scoring",
"rate llm outputs", "langfuse feedback", "langfuse datasets", "langfuse experiments".
/langfuse-cost-tuningMonitor and optimize LLM costs using Langfuse analytics and dashboards.
Use when tracking LLM spending, identifying cost anomalies,
or implementing cost controls for AI applications.
Trigger with phrases like "langfuse costs", "LLM spending",
"track AI costs", "langfuse token usage", "optimize LLM budget".
/langfuse-data-handlingManage Langfuse data export, retention, and compliance requirements.
Use when exporting trace data, configuring retention policies,
or implementing data compliance for LLM observability.
Trigger with phrases like "langfuse data export", "langfuse retention",
"langfuse GDPR", "langfuse compliance", "export langfuse traces".
npx claudepluginhub flight505/skill-forge --plugin langfuse-packOther plugins' skills for the same job