api-ai-langfuse
LLM observability with Langfuse — OpenTelemetry-based tracing, evaluations, prompt management, datasets, and production best practices
npx skills add majiayu000/claude-skill-registry --skill api-ai-langfuse --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
What it does
Guides adding observability to LLM applications using Langfuse. It instructs installing tracing and OpenTelemetry packages, enabling automatic context propagation via startActiveObservation or observe, and using observeOpenAI for OpenAI SDK tracing. It also describes managing prompts with LangfuseClient, applying scores/evaluations, and using datasets/experiments. It emphasizes flushing via forceFlush or sdk.shutdown in short-lived processes and environment-based credentials handling.
How it works
- Install core tracing:
@langfuse/tracing,@langfuse/otel, and@opentelemetry/sdk-node. - Use
startActiveObservation()to create an observation, propagate context automatically, and end it when the callback completes. - Use
observe()to wrap functions for automatic input/output capture and timing. - For OpenAI calls, wrap the client with
observeOpenAI()to enable zero-config tracing. - Manage prompts with
LangfuseClientfrom@langfuse/client, includingprompt.get,compile, and chat prompt handling. - Attach scores/evaluations via
LangfuseClient/langfuse.score.createwith data types NUMERIC, CATEGORICAL, BOOLEAN, and optionally per-observation. - Use datasets and experiments for testing; link prompts to traces as part of traces.
- Ensure flushing and shutdown: call
forceFlush()orsdk.shutdown()in short-lived processes; calllangfuse.score.flush()when needed.
When to use it
- Adding observability and tracing to LLM application code (any provider)
- Wrapping OpenAI SDK calls for automatic token/cost tracking
- Managing prompt templates with versioning, labels, and variable compilation
- Evaluating LLM output quality with scores (numeric, categorical, boolean)
- Running experiments against datasets for regression testing
- Tracking sessions, users, and metadata across multi-turn conversations
- Monitoring LLM costs and token usage in production
What it can touch
- OpenTelemetry setup via
instrumentation.ts(top of entry point) - Tracing APIs:
startActiveObservation,observe,startObservation, andobserveOpenAI - Langfuse client:
LangfuseClient,prompt.get,prompt.compile,score.create,score.flush - OpenAI integration:
@langfuse/openaiwrapper - Environment variables:
LANGFUSE_SECRET_KEY,LANGFUSE_PUBLIC_KEY,LANGFUSE_BASE_URL
Caveats
- Requires environment-based credentials (never hardcode credentials)
- OpenAI auto-instrumentation relies on
observeOpenAI()for zero-config tracing; manual generation observations are discouraged - Short-lived processes must flush/shutdown to avoid lost events
- Context propagation relies on using
startActiveObservation()orobserve()for nested tracing; manualstartObservation()needs explicit.end()calls
# Langfuse Observability Patterns > **Quick Guide:** Use the Langfuse TypeScript SDK (built on OpenTelemetry) to add observability to LLM applications. Install `@langfuse/tracing`, `@langfuse/otel`, and `@opentelemetry/sdk-node` for core tracing. Use `startActiveObservation()` for automatic context propagation or `observe()` to wrap functions. Use `@langfuse/openai` with `observeOpenAI()` for zero-config OpenAI tracing. Use `LangfuseClient` from `@langfuse/client` for prompt management, scores, and datasets. Always call `forceFlush()` or `sdk.shutdown()` in short-lived processes. --- <critical_requirements> ## CRITICAL: Before Using This Skill > **All code must follow project conventions in CLAUDE.md** (kebab-case, named exports, import ordering, `import type`, named constants) **(You MUST import and register `instrumentation.ts` at the top of your entry point BEFORE any other imports -- OpenTelemetry must instrument modules before they are loaded)** **(You MUST call `forceFlush()` or `sdk.shutdown()` in short-lived processes (serverless, scripts, CLI tools) -- events are batched and will be lost without explicit flushing)** **(You MUST use `@langfuse/openai` with `observeOpenAI()`
- CRITICAL: Before Using This Skill
- Examples Index
- Philosophy
- Core Patterns
- Pattern 1: OpenTelemetry Setup
- Pattern 2: Tracing with startActiveObservation
- Pattern 3: The observe() Wrapper
- Pattern 4: OpenAI Auto-Instrumentation
- Pattern 5: Prompt Management
- Pattern 6: Scores and Evaluations
- Pattern 7: Flush and Shutdown
- Performance Optimization
- Sampling for High-Volume Applications
- Key Optimization Patterns
What does the api-ai-langfuse skill do?
LLM observability with Langfuse — OpenTelemetry-based tracing, evaluations, prompt management, datasets, and production best practices
How do I install it?
Run `npx skills add majiayu000/claude-skill-registry --skill api-ai-langfuse --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From majiayu000/claude-skill-registry, a repository with 534 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
