langfuse-sdk-patterns

Featured

Langfuse SDK best practices, patterns, and idiomatic usage. Use when learning Langfuse SDK patterns, implementing proper tracing, or following best practices for LLM observability. Trigger with phrases like "langfuse patterns", "langfuse best practices", "langfuse SDK guide", "how to use langfuse", "langfuse idioms".

AI & Automation 2,266 stars 315 forks Updated today MIT

Install

View on GitHub

Quality Score: 99/100

Stars 20%
100
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# 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 ```typescript // src/lib/langfuse.ts -- single file, import everywhere import { LangfuseClient } from "@langfuse/client"; import { LangfuseSpanProcessor } from "@langfuse/otel"; import { NodeSDK } from "@opentelemetry/sdk-node"; // Singleton client for prompts, datasets, scores let client: LangfuseClient | null = null; export function getLangfuseClient(): LangfuseClient { if (!client) { client = new LangfuseClient(); } return client; } // One-time OTel setup (call at app entry point) let sdk: NodeSDK | null = null; export function initTracing(): NodeSDK { if (!sdk) { sdk = new NodeSDK({ spanProcessors: [new LangfuseSpanProcessor()], }); sdk.start(); // Graceful shutdown on process exit const shutdown = async () => { await sdk?.shutdown(); process.exit(0); }; process.on("SIGTERM", shutdown); process.on("SIGINT", shutdown); } return sdk; } ``` **Legacy v3 singleton:** ```typescript import { Langfuse } from "langfuse"; let instance: L...

Details

Author
jeremylongshore
Repository
jeremylongshore/claude-code-plugins-plus-skills
Created
7 months ago
Last Updated
today
Language
Python
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category

AI & Automation Featured

langfuse-reference-architecture

Production-grade Langfuse architecture patterns and best practices. Use when designing LLM observability infrastructure, planning Langfuse deployment, or implementing enterprise-grade tracing architecture. Trigger with phrases like "langfuse architecture", "langfuse design", "langfuse infrastructure", "langfuse enterprise", "langfuse at scale".

2,266 Updated today
jeremylongshore
AI & Automation Featured

langfuse-hello-world

Create a minimal working Langfuse trace example. Use when starting a new Langfuse integration, testing your setup, or learning basic Langfuse tracing patterns. Trigger with phrases like "langfuse hello world", "langfuse example", "langfuse quick start", "first langfuse trace", "simple langfuse code".

2,266 Updated today
jeremylongshore
AI & Automation Featured

langfuse-performance-tuning

Optimize Langfuse tracing performance for high-throughput applications. Use when experiencing latency issues, optimizing trace overhead, or scaling Langfuse for production workloads. Trigger with phrases like "langfuse performance", "optimize langfuse", "langfuse latency", "langfuse overhead", "langfuse slow".

2,266 Updated today
jeremylongshore
AI & Automation Featured

langfuse-rate-limits

Implement Langfuse rate limiting, batching, and backoff patterns. Use when handling rate limit errors, optimizing trace ingestion, or managing high-volume LLM observability workloads. Trigger with phrases like "langfuse rate limit", "langfuse throttling", "langfuse 429", "langfuse batching", "langfuse high volume".

2,266 Updated today
jeremylongshore
AI & Automation Featured

langfuse-local-dev-loop

Set up Langfuse local development workflow with hot reload and debugging. Use when developing LLM applications locally, debugging traces, or setting up a fast iteration loop with Langfuse. Trigger with phrases like "langfuse local dev", "langfuse development", "debug langfuse traces", "langfuse hot reload", "langfuse dev workflow".

2,266 Updated today
jeremylongshore