Agent skill · data analytics · jeremylongshore
langfuse-sdk-patterns
Langfuse SDK best practices, patterns, and idiomatic usage.
Why this skill is useful
Provides specific patterns and idiomatic usage for the Langfuse SDK that enhance LLM observability and tracing, which the AI may not generate on its own.
What it needs
Requires @langfuse/client, @langfuse/otel, @langfuse/tracing, @opentelemetry/sdk-node installed locally. About 5k tokens when loaded. Last updated 2026-08-07. 2,604 stars on the source repository.
What this skill does
Langfuse SDK Patterns Overview Production-quality patterns for the Langfuse SDK: singleton clients, the observe wrapper, startActiveObservation for nested traces, session tracking, graceful shutdown, and error-safe tracing. Prerequisites Completed langfuse-install-auth setup Understanding of async/await patterns For v4+: @langfuse/tracing, @langfuse/otel, @opentelemetry/sdk-node Instructions Pattern 1: Singleton Client with Graceful Shutdown Legacy v3 singleton: Pattern 2: observe Wrapper for Existing Functions The observe wrapper is the most ergonomic way to add tracing. It wraps any function and auto-creates a span. Pattern 3: startActiveObservation for Inline Control Use when you need fine-grained control over observation lifecycle within a function: Pattern 4: Session and User Tracking Link traces across conversation turns for user-level analytics: Pattern 5: Error-Safe Tracing Never let tracing failures break your application: Pattern 6: Legacy v3 -- Always End Spans Anti-Patterns to Avoid Anti-Pattern Problem Correct Pattern ------------- --------- ----------------- new Langfuse() per request Memory leaks, duplicate traces Singleton client Awaiting flush in hot path Adds latency to every request Background flush, shutdown handler Logging full request bodies Trace payloads too large Truncate/summarize inputs Missing .end() on spans (v3) Spans show "in progress" forever Use try/finally or observe wrapper Hardcoding API keys Security risk Environment variables only Output Use this skill to produce a small integration plan and implementation diff: one process-lifetime client, trace and observation names that describe the user operation, safe input/output capture, and a shutdown path that drains pending events. Record the SDK generation assumed by the code so a future upgrade does not mix v3 span APIs with the v4+ OpenTelemetry APIs. Error Handling Treat observability as non-critical infrastructure. …
How to use it
Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:
@skills jeremylongshore/langfuse-sdk-patterns