[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6F7RQS0TRKR3QCQTZVH8366":3,"skill-same:01M6F7RQS0TRKR3QCQTZVH8366":74},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":42,"linkOnly":43,"markdownContent":44,"markdownBody":45,"frontMatter":46,"refName":51,"commitSha":52,"skillDirectory":53,"forksCount":54,"repositoryHtmlUrl":55,"repositoryHomepageUrl":6,"ownerHtmlUrl":56,"ownerBlogUrl":57,"ownerDescription":58,"updatedAt":59,"install":60,"resources":73},"01M6F7RQS0TRKR3QCQTZVH8366","langfuse-reference-architecture",null,"Production-grade Langfuse architecture patterns and best practices.\nUse when designing LLM observability infrastructure, planning Langfuse deployment,\nor implementing enterprise-grade tracing architecture.\nTrigger with phrases like \"langfuse architecture\", \"langfuse design\",\n\"langfuse infrastructure\", \"langfuse enterprise\", \"langfuse at scale\".","Dicklesworthstone\u002Fpi_agent_rust","Dicklesworthstone","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F35050222?v=4","01M6CG26AR942CSVMN1M5E3DSE","Jeff Emanuel","01M6CG26EPP71PSHW1VDS71121",1992,"MIT","https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fpi_agent_rust\u002Fblob\u002Fmain\u002Ftests\u002Fext_conformance\u002Fartifacts\u002Fplugins-community\u002Fplugins\u002Fsaas-packs\u002Flangfuse-pack\u002Fskills\u002Flangfuse-reference-architecture\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41],"architecture","langfuse reference architecture","langfuse","reference","when","design","implementing","at","trigger","io","patterns","use","edit","write","read","architecture patterns","Enterprise","tracing","observability","best practices","planning","deployment","infrastructure","2026-11-10 10:12:30",false,"---\nname: langfuse-reference-architecture\ndescription: |\n  Production-grade Langfuse architecture patterns and best practices.\n  Use when designing LLM observability infrastructure, planning Langfuse deployment,\n  or implementing enterprise-grade tracing architecture.\n  Trigger with phrases like \"langfuse architecture\", \"langfuse design\",\n  \"langfuse infrastructure\", \"langfuse enterprise\", \"langfuse at scale\".\nallowed-tools: Read, Write, Edit\nversion: 1.0.0\nlicense: MIT\nauthor: Jeremy Longshore \u003Cjeremy@intentsolutions.io>\n---\n\n# Langfuse Reference Architecture\n\n## Overview\nProduction-grade architecture patterns for Langfuse LLM observability at scale.\n\n## Prerequisites\n- Understanding of distributed systems\n- Knowledge of cloud infrastructure\n- Familiarity with observability patterns\n\n## Architecture Patterns\n\n### Pattern 1: Basic Cloud Architecture\n\n```\n┌─────────────────────────────────────────────────────────────┐\n│                     Application Layer                        │\n├─────────────────────────────────────────────────────────────┤\n│                                                              │\n│  ┌──────────┐    ┌──────────┐    ┌──────────┐              │\n│  │ API      │    │ Worker   │    │ Cron     │              │\n│  │ Service  │    │ Service  │    │ Jobs     │              │\n│  └────┬─────┘    └────┬─────┘    └────┬─────┘              │\n│       │               │               │                     │\n│       └───────────────┴───────────────┘                     │\n│                       │                                      │\n│              ┌────────┴────────┐                            │\n│              │ Langfuse SDK    │                            │\n│              │ (Singleton)     │                            │\n│              └────────┬────────┘                            │\n│                       │                                      │\n└───────────────────────┼──────────────────────────────────────┘\n                        │\n                        ▼\n┌─────────────────────────────────────────────────────────────┐\n│                  Langfuse Cloud                              │\n│  ┌─────────────────────────────────────────────────────┐   │\n│  │ Ingestion API → Processing → PostgreSQL → Dashboard  │   │\n│  └─────────────────────────────────────────────────────┘   │\n└─────────────────────────────────────────────────────────────┘\n```\n\n### Pattern 2: Self-Hosted Architecture\n\n```\n┌─────────────────────────────────────────────────────────────┐\n│                        VPC                                   │\n├─────────────────────────────────────────────────────────────┤\n│                                                              │\n│  ┌─────────────────────────────────────────────────────┐   │\n│  │                 Application Cluster                  │   │\n│  │  ┌───────┐  ┌───────┐  ┌───────┐  ┌───────┐       │   │\n│  │  │ Pod 1 │  │ Pod 2 │  │ Pod 3 │  │ Pod N │       │   │\n│  │  └───┬───┘  └───┬───┘  └───┬───┘  └───┬───┘       │   │\n│  │      └──────────┴─────┬────┴──────────┘            │   │\n│  └─────────────────────────┼──────────────────────────┘   │\n│                            │                               │\n│                   ┌────────┴────────┐                     │\n│                   │ Internal LB     │                     │\n│                   └────────┬────────┘                     │\n│                            │                               │\n│  ┌─────────────────────────┼──────────────────────────┐   │\n│  │         Langfuse Self-Hosted Cluster                │   │\n│  │  ┌───────────┐    ┌───────────┐    ┌───────────┐  │   │\n│  │  │ Langfuse  │    │ Langfuse  │    │ Langfuse  │  │   │\n│  │  │ Instance 1│    │ Instance 2│    │ Instance 3│  │   │\n│  │  └─────┬─────┘    └─────┬─────┘    └─────┬─────┘  │   │\n│  │        └────────────────┼────────────────┘         │   │\n│  │                         │                          │   │\n│  │                ┌────────┴────────┐                 │   │\n│  │                │ PostgreSQL RDS  │                 │   │\n│  │                │ (Multi-AZ)      │                 │   │\n│  │                └─────────────────┘                 │   │\n│  └────────────────────────────────────────────────────┘   │\n└─────────────────────────────────────────────────────────────┘\n```\n\n### Pattern 3: High-Scale Architecture with Buffer\n\n```\n┌─────────────────────────────────────────────────────────────┐\n│                    Application Layer                         │\n├─────────────────────────────────────────────────────────────┤\n│                                                              │\n│  ┌────────────────────────────────────────────────────┐    │\n│  │              Regional Application Clusters          │    │\n│  │  ┌─────────┐  ┌─────────┐  ┌─────────┐            │    │\n│  │  │ US-East │  │ EU-West │  │ AP-South│            │    │\n│  │  └────┬────┘  └────┬────┘  └────┬────┘            │    │\n│  │       └────────────┼────────────┘                  │    │\n│  └────────────────────┼───────────────────────────────┘    │\n│                       │                                     │\n│              ┌────────┴────────┐                           │\n│              │ Langfuse SDK    │                           │\n│              │ (Batched)       │                           │\n│              └────────┬────────┘                           │\n│                       │                                     │\n│              ┌────────┴────────┐                           │\n│              │  Message Queue  │  ← Buffer for high volume │\n│              │  (SQS\u002FKafka)    │                           │\n│              └────────┬────────┘                           │\n│                       │                                     │\n│              ┌────────┴────────┐                           │\n│              │ Ingestion       │  ← Async workers          │\n│              │ Workers         │                           │\n│              └────────┬────────┘                           │\n│                       │                                     │\n└───────────────────────┼─────────────────────────────────────┘\n                        │\n                        ▼\n┌─────────────────────────────────────────────────────────────┐\n│                  Langfuse (Cloud\u002FSelf-Hosted)                │\n└─────────────────────────────────────────────────────────────┘\n```\n\n## Instructions\n\n### Step 1: Implement Singleton SDK Pattern\n\n```typescript\n\u002F\u002F lib\u002Flangfuse\u002Fclient.ts\nimport { Langfuse } from \"langfuse\";\n\nclass LangfuseClient {\n  private static instance: Langfuse | null = null;\n  private static shutdownRegistered = false;\n\n  static getInstance(): Langfuse {\n    if (!LangfuseClient.instance) {\n      LangfuseClient.instance = new Langfuse({\n        publicKey: process.env.LANGFUSE_PUBLIC_KEY!,\n        secretKey: process.env.LANGFUSE_SECRET_KEY!,\n        baseUrl: process.env.LANGFUSE_HOST,\n        \u002F\u002F Production settings\n        flushAt: parseInt(process.env.LANGFUSE_FLUSH_AT || \"25\"),\n        flushInterval: parseInt(process.env.LANGFUSE_FLUSH_INTERVAL || \"5000\"),\n        requestTimeout: 15000,\n      });\n\n      if (!LangfuseClient.shutdownRegistered) {\n        LangfuseClient.registerShutdown();\n      }\n    }\n\n    return LangfuseClient.instance;\n  }\n\n  private static registerShutdown() {\n    const shutdown = async (signal: string) => {\n      console.log(`${signal} received. Flushing Langfuse...`);\n      if (LangfuseClient.instance) {\n        await LangfuseClient.instance.shutdownAsync();\n        LangfuseClient.instance = null;\n      }\n    };\n\n    process.on(\"SIGTERM\", () => shutdown(\"SIGTERM\"));\n    process.on(\"SIGINT\", () => shutdown(\"SIGINT\"));\n    process.on(\"beforeExit\", () => shutdown(\"beforeExit\"));\n\n    LangfuseClient.shutdownRegistered = true;\n  }\n}\n\nexport const langfuse = LangfuseClient.getInstance();\n```\n\n### Step 2: Implement Trace Context Propagation\n\n```typescript\n\u002F\u002F lib\u002Flangfuse\u002Fcontext.ts\nimport { AsyncLocalStorage } from \"async_hooks\";\n\ninterface TraceContext {\n  traceId: string;\n  parentSpanId?: string;\n  userId?: string;\n  sessionId?: string;\n}\n\nconst traceStorage = new AsyncLocalStorage\u003CTraceContext>();\n\nexport function withTraceContext\u003CT>(\n  context: TraceContext,\n  fn: () => T\n): T {\n  return traceStorage.run(context, fn);\n}\n\nexport function getTraceContext(): TraceContext | undefined {\n  return traceStorage.getStore();\n}\n\n\u002F\u002F Middleware for Express\nexport function langfuseMiddleware() {\n  return (req: Request, res: Response, next: NextFunction) => {\n    const trace = langfuse.trace({\n      name: `${req.method} ${req.path}`,\n      userId: req.user?.id,\n      sessionId: req.session?.id,\n      metadata: {\n        method: req.method,\n        path: req.path,\n        userAgent: req.headers[\"user-agent\"],\n      },\n    });\n\n    const context: TraceContext = {\n      traceId: trace.id,\n      userId: req.user?.id,\n      sessionId: req.session?.id,\n    };\n\n    withTraceContext(context, () => {\n      \u002F\u002F Attach trace to request for easy access\n      req.langfuseTrace = trace;\n\n      \u002F\u002F Finish trace on response\n      res.on(\"finish\", () => {\n        trace.update({\n          output: { statusCode: res.statusCode },\n          level: res.statusCode >= 400 ? \"ERROR\" : undefined,\n        });\n      });\n\n      next();\n    });\n  };\n}\n```\n\n### Step 3: Implement Queue-Based Ingestion\n\n```typescript\n\u002F\u002F lib\u002Flangfuse\u002Fqueue.ts\nimport { SQSClient, SendMessageCommand } from \"@aws-sdk\u002Fclient-sqs\";\nimport { Langfuse } from \"langfuse\";\n\ninterface QueuedTrace {\n  name: string;\n  input?: any;\n  output?: any;\n  metadata?: Record\u003Cstring, any>;\n  userId?: string;\n  sessionId?: string;\n  timestamp: string;\n}\n\n\u002F\u002F Producer: Application sends to queue\nclass QueuedLangfuseProducer {\n  private sqs: SQSClient;\n  private queueUrl: string;\n\n  constructor() {\n    this.sqs = new SQSClient({});\n    this.queueUrl = process.env.LANGFUSE_QUEUE_URL!;\n  }\n\n  async trace(params: Omit\u003CQueuedTrace, \"timestamp\">) {\n    const message: QueuedTrace = {\n      ...params,\n      timestamp: new Date().toISOString(),\n    };\n\n    await this.sqs.send(\n      new SendMessageCommand({\n        QueueUrl: this.queueUrl,\n        MessageBody: JSON.stringify(message),\n        MessageGroupId: params.sessionId || \"default\",\n      })\n    );\n  }\n}\n\n\u002F\u002F Consumer: Worker processes queue\nclass QueuedLangfuseConsumer {\n  private langfuse: Langfuse;\n\n  constructor() {\n    this.langfuse = new Langfuse();\n  }\n\n  async processMessage(message: QueuedTrace) {\n    const trace = this.langfuse.trace({\n      name: message.name,\n      input: message.input,\n      output: message.output,\n      metadata: message.metadata,\n      userId: message.userId,\n      sessionId: message.sessionId,\n      timestamp: new Date(message.timestamp),\n    });\n\n    return trace.id;\n  }\n\n  async processBatch(messages: QueuedTrace[]) {\n    for (const message of messages) {\n      await this.processMessage(message);\n    }\n    await this.langfuse.flushAsync();\n  }\n}\n```\n\n### Step 4: Multi-Environment Configuration\n\n```typescript\n\u002F\u002F config\u002Flangfuse.ts\ntype Environment = \"development\" | \"staging\" | \"production\";\n\ninterface LangfuseEnvironmentConfig {\n  publicKey: string;\n  secretKey: string;\n  host: string;\n  flushAt: number;\n  flushInterval: number;\n  enabled: boolean;\n  sampling: {\n    rate: number;\n    alwaysSampleErrors: boolean;\n  };\n}\n\nconst ENVIRONMENT_CONFIGS: Record\u003CEnvironment, LangfuseEnvironmentConfig> = {\n  development: {\n    publicKey: process.env.LANGFUSE_PUBLIC_KEY_DEV!,\n    secretKey: process.env.LANGFUSE_SECRET_KEY_DEV!,\n    host: process.env.LANGFUSE_HOST_DEV || \"http:\u002F\u002Flocalhost:3000\",\n    flushAt: 1,\n    flushInterval: 1000,\n    enabled: true,\n    sampling: { rate: 1.0, alwaysSampleErrors: true },\n  },\n  staging: {\n    publicKey: process.env.LANGFUSE_PUBLIC_KEY_STAGING!,\n    secretKey: process.env.LANGFUSE_SECRET_KEY_STAGING!,\n    host: process.env.LANGFUSE_HOST_STAGING || \"https:\u002F\u002Fcloud.langfuse.com\",\n    flushAt: 15,\n    flushInterval: 5000,\n    enabled: true,\n    sampling: { rate: 0.5, alwaysSampleErrors: true },\n  },\n  production: {\n    publicKey: process.env.LANGFUSE_PUBLIC_KEY_PROD!,\n    secretKey: process.env.LANGFUSE_SECRET_KEY_PROD!,\n    host: process.env.LANGFUSE_HOST || \"https:\u002F\u002Fcloud.langfuse.com\",\n    flushAt: 25,\n    flushInterval: 5000,\n    enabled: true,\n    sampling: { rate: 0.1, alwaysSampleErrors: true },\n  },\n};\n\nexport function getLangfuseConfig(): LangfuseEnvironmentConfig {\n  const env = (process.env.NODE_ENV || \"development\") as Environment;\n  return ENVIRONMENT_CONFIGS[env] || ENVIRONMENT_CONFIGS.development;\n}\n```\n\n### Step 5: Implement Service Mesh Tracing\n\n```typescript\n\u002F\u002F For microservices: propagate trace context across services\ninterface TraceHeaders {\n  \"x-langfuse-trace-id\": string;\n  \"x-langfuse-parent-id\"?: string;\n  \"x-langfuse-session-id\"?: string;\n}\n\n\u002F\u002F Outgoing request: inject headers\nfunction injectTraceHeaders(headers: Headers) {\n  const context = getTraceContext();\n  if (context) {\n    headers.set(\"x-langfuse-trace-id\", context.traceId);\n    if (context.parentSpanId) {\n      headers.set(\"x-langfuse-parent-id\", context.parentSpanId);\n    }\n    if (context.sessionId) {\n      headers.set(\"x-langfuse-session-id\", context.sessionId);\n    }\n  }\n}\n\n\u002F\u002F Incoming request: extract headers and continue trace\nfunction extractTraceContext(request: Request): TraceContext | null {\n  const traceId = request.headers.get(\"x-langfuse-trace-id\");\n  if (!traceId) return null;\n\n  return {\n    traceId,\n    parentSpanId: request.headers.get(\"x-langfuse-parent-id\") || undefined,\n    sessionId: request.headers.get(\"x-langfuse-session-id\") || undefined,\n  };\n}\n\n\u002F\u002F Create linked trace in downstream service\nfunction createLinkedTrace(parentContext: TraceContext, name: string) {\n  return langfuse.trace({\n    name,\n    sessionId: parentContext.sessionId,\n    metadata: {\n      parentTraceId: parentContext.traceId,\n      parentSpanId: parentContext.parentSpanId,\n    },\n  });\n}\n```\n\n## Output\n- Singleton SDK pattern with graceful shutdown\n- Trace context propagation\n- Queue-based async ingestion\n- Multi-environment configuration\n- Service mesh integration\n\n## Architecture Decision Matrix\n\n| Pattern | Use Case | Complexity | Scale |\n|---------|----------|------------|-------|\n| Basic Cloud | Small apps | Low | 100K traces\u002Fday |\n| Self-Hosted | Data privacy | Medium | 1M traces\u002Fday |\n| Queue-Based | High volume | High | 10M+ traces\u002Fday |\n\n## Error Handling\n| Issue | Cause | Solution |\n|-------|-------|----------|\n| Multiple instances | No singleton | Use singleton pattern |\n| Lost traces | No shutdown | Register shutdown handlers |\n| Cross-service gaps | No propagation | Implement header injection |\n| Scale issues | Direct ingestion | Add message queue buffer |\n\n## Resources\n- [Langfuse Self-Hosting](https:\u002F\u002Flangfuse.com\u002Fdocs\u002Fdeployment\u002Fself-host)\n- [Langfuse Architecture](https:\u002F\u002Flangfuse.com\u002Fdocs)\n- [OpenTelemetry Context](https:\u002F\u002Fopentelemetry.io\u002Fdocs\u002Fconcepts\u002Fcontext-propagation\u002F)\n\n## Next Steps\nFor multi-environment setup, see `langfuse-multi-env-setup`.\n","# Langfuse Reference Architecture\n\n## Overview\nProduction-grade architecture patterns for Langfuse LLM observability at scale.\n\n## Prerequisites\n- Understanding of distributed systems\n- Knowledge of cloud infrastructure\n- Familiarity with observability patterns\n\n## Architecture Patterns\n\n### Pattern 1: Basic Cloud Architecture\n\n```\n┌─────────────────────────────────────────────────────────────┐\n│                     Application Layer                        │\n├─────────────────────────────────────────────────────────────┤\n│                                                              │\n│  ┌──────────┐    ┌──────────┐    ┌──────────┐              │\n│  │ API      │    │ Worker   │    │ Cron     │              │\n│  │ Service  │    │ Service  │    │ Jobs     │              │\n│  └────┬─────┘    └────┬─────┘    └────┬─────┘              │\n│       │               │               │                     │\n│       └───────────────┴───────────────┘                     │\n│                       │                                      │\n│              ┌────────┴────────┐                            │\n│              │ Langfuse SDK    │                            │\n│              │ (Singleton)     │                            │\n│              └────────┬────────┘                            │\n│                       │                                      │\n└───────────────────────┼──────────────────────────────────────┘\n                        │\n                        ▼\n┌─────────────────────────────────────────────────────────────┐\n│                  Langfuse Cloud                              │\n│  ┌─────────────────────────────────────────────────────┐   │\n│  │ Ingestion API → Processing → PostgreSQL → Dashboard  │   │\n│  └─────────────────────────────────────────────────────┘   │\n└─────────────────────────────────────────────────────────────┘\n```\n\n### Pattern 2: Self-Hosted Architecture\n\n```\n┌─────────────────────────────────────────────────────────────┐\n│                        VPC                                   │\n├─────────────────────────────────────────────────────────────┤\n│                                                              │\n│  ┌─────────────────────────────────────────────────────┐   │\n│  │                 Application Cluster                  │   │\n│  │  ┌───────┐  ┌───────┐  ┌───────┐  ┌───────┐       │   │\n│  │  │ Pod 1 │  │ Pod 2 │  │ Pod 3 │  │ Pod N │       │   │\n│  │  └───┬───┘  └───┬───┘  └───┬───┘  └───┬───┘       │   │\n│  │      └──────────┴─────┬────┴──────────┘            │   │\n│  └─────────────────────────┼──────────────────────────┘   │\n│                            │                               │\n│                   ┌────────┴────────┐                     │\n│                   │ Internal LB     │                     │\n│                   └────────┬────────┘                     │\n│                            │                               │\n│  ┌─────────────────────────┼──────────────────────────┐   │\n│  │         Langfuse Self-Hosted Cluster                │   │\n│  │  ┌───────────┐    ┌───────────┐    ┌───────────┐  │   │\n│  │  │ Langfuse  │    │ Langfuse  │    │ Langfuse  │  │   │\n│  │  │ Instance 1│    │ Instance 2│    │ Instance 3│  │   │\n│  │  └─────┬─────┘    └─────┬─────┘    └─────┬─────┘  │   │\n│  │        └────────────────┼────────────────┘         │   │\n│  │                         │                          │   │\n│  │                ┌────────┴────────┐                 │   │\n│  │                │ PostgreSQL RDS  │                 │   │\n│  │                │ (Multi-AZ)      │                 │   │\n│  │                └─────────────────┘                 │   │\n│  └────────────────────────────────────────────────────┘   │\n└─────────────────────────────────────────────────────────────┘\n```\n\n### Pattern 3: High-Scale Architecture with Buffer\n\n```\n┌─────────────────────────────────────────────────────────────┐\n│                    Application Layer                         │\n├─────────────────────────────────────────────────────────────┤\n│                                                              │\n│  ┌────────────────────────────────────────────────────┐    │\n│  │              Regional Application Clusters          │    │\n│  │  ┌─────────┐  ┌─────────┐  ┌─────────┐            │    │\n│  │  │ US-East │  │ EU-West │  │ AP-South│            │    │\n│  │  └────┬────┘  └────┬────┘  └────┬────┘            │    │\n│  │       └────────────┼────────────┘                  │    │\n│  └────────────────────┼───────────────────────────────┘    │\n│                       │                                     │\n│              ┌────────┴────────┐                           │\n│              │ Langfuse SDK    │                           │\n│              │ (Batched)       │                           │\n│              └────────┬────────┘                           │\n│                       │                                     │\n│              ┌────────┴────────┐                           │\n│              │  Message Queue  │  ← Buffer for high volume │\n│              │  (SQS\u002FKafka)    │                           │\n│              └────────┬────────┘                           │\n│                       │                                     │\n│              ┌────────┴────────┐                           │\n│              │ Ingestion       │  ← Async workers          │\n│              │ Workers         │                           │\n│              └────────┬────────┘                           │\n│                       │                                     │\n└───────────────────────┼─────────────────────────────────────┘\n                        │\n                        ▼\n┌─────────────────────────────────────────────────────────────┐\n│                  Langfuse (Cloud\u002FSelf-Hosted)                │\n└─────────────────────────────────────────────────────────────┘\n```\n\n## Instructions\n\n### Step 1: Implement Singleton SDK Pattern\n\n```typescript\n\u002F\u002F lib\u002Flangfuse\u002Fclient.ts\nimport { Langfuse } from \"langfuse\";\n\nclass LangfuseClient {\n  private static instance: Langfuse | null = null;\n  private static shutdownRegistered = false;\n\n  static getInstance(): Langfuse {\n    if (!LangfuseClient.instance) {\n      LangfuseClient.instance = new Langfuse({\n        publicKey: process.env.LANGFUSE_PUBLIC_KEY!,\n        secretKey: process.env.LANGFUSE_SECRET_KEY!,\n        baseUrl: process.env.LANGFUSE_HOST,\n        \u002F\u002F Production settings\n        flushAt: parseInt(process.env.LANGFUSE_FLUSH_AT || \"25\"),\n        flushInterval: parseInt(process.env.LANGFUSE_FLUSH_INTERVAL || \"5000\"),\n        requestTimeout: 15000,\n      });\n\n      if (!LangfuseClient.shutdownRegistered) {\n        LangfuseClient.registerShutdown();\n      }\n    }\n\n    return LangfuseClient.instance;\n  }\n\n  private static registerShutdown() {\n    const shutdown = async (signal: string) => {\n      console.log(`${signal} received. Flushing Langfuse...`);\n      if (LangfuseClient.instance) {\n        await LangfuseClient.instance.shutdownAsync();\n        LangfuseClient.instance = null;\n      }\n    };\n\n    process.on(\"SIGTERM\", () => shutdown(\"SIGTERM\"));\n    process.on(\"SIGINT\", () => shutdown(\"SIGINT\"));\n    process.on(\"beforeExit\", () => shutdown(\"beforeExit\"));\n\n    LangfuseClient.shutdownRegistered = true;\n  }\n}\n\nexport const langfuse = LangfuseClient.getInstance();\n```\n\n### Step 2: Implement Trace Context Propagation\n\n```typescript\n\u002F\u002F lib\u002Flangfuse\u002Fcontext.ts\nimport { AsyncLocalStorage } from \"async_hooks\";\n\ninterface TraceContext {\n  traceId: string;\n  parentSpanId?: string;\n  userId?: string;\n  sessionId?: string;\n}\n\nconst traceStorage = new AsyncLocalStorage\u003CTraceContext>();\n\nexport function withTraceContext\u003CT>(\n  context: TraceContext,\n  fn: () => T\n): T {\n  return traceStorage.run(context, fn);\n}\n\nexport function getTraceContext(): TraceContext | undefined {\n  return traceStorage.getStore();\n}\n\n\u002F\u002F Middleware for Express\nexport function langfuseMiddleware() {\n  return (req: Request, res: Response, next: NextFunction) => {\n    const trace = langfuse.trace({\n      name: `${req.method} ${req.path}`,\n      userId: req.user?.id,\n      sessionId: req.session?.id,\n      metadata: {\n        method: req.method,\n        path: req.path,\n        userAgent: req.headers[\"user-agent\"],\n      },\n    });\n\n    const context: TraceContext = {\n      traceId: trace.id,\n      userId: req.user?.id,\n      sessionId: req.session?.id,\n    };\n\n    withTraceContext(context, () => {\n      \u002F\u002F Attach trace to request for easy access\n      req.langfuseTrace = trace;\n\n      \u002F\u002F Finish trace on response\n      res.on(\"finish\", () => {\n        trace.update({\n          output: { statusCode: res.statusCode },\n          level: res.statusCode >= 400 ? \"ERROR\" : undefined,\n        });\n      });\n\n      next();\n    });\n  };\n}\n```\n\n### Step 3: Implement Queue-Based Ingestion\n\n```typescript\n\u002F\u002F lib\u002Flangfuse\u002Fqueue.ts\nimport { SQSClient, SendMessageCommand } from \"@aws-sdk\u002Fclient-sqs\";\nimport { Langfuse } from \"langfuse\";\n\ninterface QueuedTrace {\n  name: string;\n  input?: any;\n  output?: any;\n  metadata?: Record\u003Cstring, any>;\n  userId?: string;\n  sessionId?: string;\n  timestamp: string;\n}\n\n\u002F\u002F Producer: Application sends to queue\nclass QueuedLangfuseProducer {\n  private sqs: SQSClient;\n  private queueUrl: string;\n\n  constructor() {\n    this.sqs = new SQSClient({});\n    this.queueUrl = process.env.LANGFUSE_QUEUE_URL!;\n  }\n\n  async trace(params: Omit\u003CQueuedTrace, \"timestamp\">) {\n    const message: QueuedTrace = {\n      ...params,\n      timestamp: new Date().toISOString(),\n    };\n\n    await this.sqs.send(\n      new SendMessageCommand({\n        QueueUrl: this.queueUrl,\n        MessageBody: JSON.stringify(message),\n        MessageGroupId: params.sessionId || \"default\",\n      })\n    );\n  }\n}\n\n\u002F\u002F Consumer: Worker processes queue\nclass QueuedLangfuseConsumer {\n  private langfuse: Langfuse;\n\n  constructor() {\n    this.langfuse = new Langfuse();\n  }\n\n  async processMessage(message: QueuedTrace) {\n    const trace = this.langfuse.trace({\n      name: message.name,\n      input: message.input,\n      output: message.output,\n      metadata: message.metadata,\n      userId: message.userId,\n      sessionId: message.sessionId,\n      timestamp: new Date(message.timestamp),\n    });\n\n    return trace.id;\n  }\n\n  async processBatch(messages: QueuedTrace[]) {\n    for (const message of messages) {\n      await this.processMessage(message);\n    }\n    await this.langfuse.flushAsync();\n  }\n}\n```\n\n### Step 4: Multi-Environment Configuration\n\n```typescript\n\u002F\u002F config\u002Flangfuse.ts\ntype Environment = \"development\" | \"staging\" | \"production\";\n\ninterface LangfuseEnvironmentConfig {\n  publicKey: string;\n  secretKey: string;\n  host: string;\n  flushAt: number;\n  flushInterval: number;\n  enabled: boolean;\n  sampling: {\n    rate: number;\n    alwaysSampleErrors: boolean;\n  };\n}\n\nconst ENVIRONMENT_CONFIGS: Record\u003CEnvironment, LangfuseEnvironmentConfig> = {\n  development: {\n    publicKey: process.env.LANGFUSE_PUBLIC_KEY_DEV!,\n    secretKey: process.env.LANGFUSE_SECRET_KEY_DEV!,\n    host: process.env.LANGFUSE_HOST_DEV || \"http:\u002F\u002Flocalhost:3000\",\n    flushAt: 1,\n    flushInterval: 1000,\n    enabled: true,\n    sampling: { rate: 1.0, alwaysSampleErrors: true },\n  },\n  staging: {\n    publicKey: process.env.LANGFUSE_PUBLIC_KEY_STAGING!,\n    secretKey: process.env.LANGFUSE_SECRET_KEY_STAGING!,\n    host: process.env.LANGFUSE_HOST_STAGING || \"https:\u002F\u002Fcloud.langfuse.com\",\n    flushAt: 15,\n    flushInterval: 5000,\n    enabled: true,\n    sampling: { rate: 0.5, alwaysSampleErrors: true },\n  },\n  production: {\n    publicKey: process.env.LANGFUSE_PUBLIC_KEY_PROD!,\n    secretKey: process.env.LANGFUSE_SECRET_KEY_PROD!,\n    host: process.env.LANGFUSE_HOST || \"https:\u002F\u002Fcloud.langfuse.com\",\n    flushAt: 25,\n    flushInterval: 5000,\n    enabled: true,\n    sampling: { rate: 0.1, alwaysSampleErrors: true },\n  },\n};\n\nexport function getLangfuseConfig(): LangfuseEnvironmentConfig {\n  const env = (process.env.NODE_ENV || \"development\") as Environment;\n  return ENVIRONMENT_CONFIGS[env] || ENVIRONMENT_CONFIGS.development;\n}\n```\n\n### Step 5: Implement Service Mesh Tracing\n\n```typescript\n\u002F\u002F For microservices: propagate trace context across services\ninterface TraceHeaders {\n  \"x-langfuse-trace-id\": string;\n  \"x-langfuse-parent-id\"?: string;\n  \"x-langfuse-session-id\"?: string;\n}\n\n\u002F\u002F Outgoing request: inject headers\nfunction injectTraceHeaders(headers: Headers) {\n  const context = getTraceContext();\n  if (context) {\n    headers.set(\"x-langfuse-trace-id\", context.traceId);\n    if (context.parentSpanId) {\n      headers.set(\"x-langfuse-parent-id\", context.parentSpanId);\n    }\n    if (context.sessionId) {\n      headers.set(\"x-langfuse-session-id\", context.sessionId);\n    }\n  }\n}\n\n\u002F\u002F Incoming request: extract headers and continue trace\nfunction extractTraceContext(request: Request): TraceContext | null {\n  const traceId = request.headers.get(\"x-langfuse-trace-id\");\n  if (!traceId) return null;\n\n  return {\n    traceId,\n    parentSpanId: request.headers.get(\"x-langfuse-parent-id\") || undefined,\n    sessionId: request.headers.get(\"x-langfuse-session-id\") || undefined,\n  };\n}\n\n\u002F\u002F Create linked trace in downstream service\nfunction createLinkedTrace(parentContext: TraceContext, name: string) {\n  return langfuse.trace({\n    name,\n    sessionId: parentContext.sessionId,\n    metadata: {\n      parentTraceId: parentContext.traceId,\n      parentSpanId: parentContext.parentSpanId,\n    },\n  });\n}\n```\n\n## Output\n- Singleton SDK pattern with graceful shutdown\n- Trace context propagation\n- Queue-based async ingestion\n- Multi-environment configuration\n- Service mesh integration\n\n## Architecture Decision Matrix\n\n| Pattern | Use Case | Complexity | Scale |\n|---------|----------|------------|-------|\n| Basic Cloud | Small apps | Low | 100K traces\u002Fday |\n| Self-Hosted | Data privacy | Medium | 1M traces\u002Fday |\n| Queue-Based | High volume | High | 10M+ traces\u002Fday |\n\n## Error Handling\n| Issue | Cause | Solution |\n|-------|-------|----------|\n| Multiple instances | No singleton | Use singleton pattern |\n| Lost traces | No shutdown | Register shutdown handlers |\n| Cross-service gaps | No propagation | Implement header injection |\n| Scale issues | Direct ingestion | Add message queue buffer |\n\n## Resources\n- [Langfuse Self-Hosting](https:\u002F\u002Flangfuse.com\u002Fdocs\u002Fdeployment\u002Fself-host)\n- [Langfuse Architecture](https:\u002F\u002Flangfuse.com\u002Fdocs)\n- [OpenTelemetry Context](https:\u002F\u002Fopentelemetry.io\u002Fdocs\u002Fconcepts\u002Fcontext-propagation\u002F)\n\n## Next Steps\nFor multi-environment setup, see `langfuse-multi-env-setup`.\n",{"name":5,"author":47,"license":15,"version":48,"description":49,"allowed-tools":50},"Jeremy Longshore \u003Cjeremy@intentsolutions.io>","1.0.0","Production-grade Langfuse architecture patterns and best practices.\nUse when designing LLM observability infrastructure, planning Langfuse deployment,\nor implementing enterprise-grade tracing architecture.\nTrigger with phrases like \"langfuse architecture\", \"langfuse design\",\n\"langfuse infrastructure\", \"langfuse enterprise\", \"langfuse at scale\".\n","Read, Write, Edit","main","90b50ed0778745a80fd5bfb13b1843d45b9e82f7","tests\u002Fext_conformance\u002Fartifacts\u002Fplugins-community\u002Fplugins\u002Fsaas-packs\u002Flangfuse-pack\u002Fskills\u002Flangfuse-reference-architecture",233,"https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fpi_agent_rust","https:\u002F\u002Fgithub.com\u002FDicklesworthstone","https:\u002F\u002Fwww.jeffreyemanuel.com\u002F","Building in NY","2026-11-15 01:54:15",{"source":8,"skillName":5,"commands":61,"prompt":71,"zipAvailable":72},[62,65,68],{"tool":63,"command":64},"npx","npx skills add Dicklesworthstone\u002Fpi_agent_rust --skill langfuse-reference-architecture",{"tool":66,"command":67},"bunx","bunx skills add Dicklesworthstone\u002Fpi_agent_rust --skill langfuse-reference-architecture",{"tool":69,"command":70},"pnpm","pnpm dlx skills add Dicklesworthstone\u002Fpi_agent_rust --skill langfuse-reference-architecture","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fpi_agent_rust\u002Fblob\u002Fmain\u002Ftests\u002Fext_conformance\u002Fartifacts\u002Fplugins-community\u002Fplugins\u002Fsaas-packs\u002Flangfuse-pack\u002Fskills\u002Flangfuse-reference-architecture\u002FSKILL.md",true,[],[75,104,136,155,181,205],{"skillNo":76,"name":77,"nameZh":6,"description":78,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":79,"licenseFileUrl":80,"sourceHtmlUrl":81,"categories":82,"keywords":83,"publishedAt":103},"01M6FCR7G5A005P364Z6ZWCJDP","theme-factory","Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with colors\u002Ffonts that you can apply to any artifact that has been creating, or can generate a new theme on-the-fly.","Apache-2.0","https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fpi_agent_rust\u002Fblob\u002Fmain\u002Ftests\u002Fext_conformance\u002Fartifacts\u002Ftemplates-davila7\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fcreative-design\u002Ftheme-factory\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fpi_agent_rust\u002Fblob\u002Fmain\u002Ftests\u002Fext_conformance\u002Fartifacts\u002Ftemplates-davila7\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fcreative-design\u002Ftheme-factory\u002FSKILL.md",[],[84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102],"theme factory","factory","theme","docs","toolkit","generate","artifacts","SET","fly","slides","landing","html","styling","artifact","pages","themes","with","you","fonts","2026-11-11 15:11:14",{"skillNo":105,"name":106,"nameZh":6,"description":107,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":79,"licenseFileUrl":108,"sourceHtmlUrl":109,"categories":110,"keywords":111,"publishedAt":42},"01M6FEGPPK0ZTKCCM0R3E3KS33","web-artifacts-builder","Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn\u002Fui). Use for complex artifacts requiring state management, routing, or shadcn\u002Fui components - not for simple single-file HTML\u002FJSX artifacts.","https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fpi_agent_rust\u002Fblob\u002Fmain\u002Ftests\u002Fext_conformance\u002Fartifacts\u002Ftemplates-davila7\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Futilities\u002Fweb-artifacts-builder\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fpi_agent_rust\u002Fblob\u002Fmain\u002Ftests\u002Fext_conformance\u002Fartifacts\u002Ftemplates-davila7\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Futilities\u002Fweb-artifacts-builder\u002FSKILL.md",[],[112,113,90,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,30,95,129,130,131,132,133,134,135],"web artifacts builder","web","artifacts builder","builder","frontend","css","components","react","component","routing","state management","state","shadcn","file","ui","Tools","Tailwind","single-file","simple","ui components","multi","for","jsx","suite",{"skillNo":137,"name":138,"nameZh":6,"description":139,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":79,"licenseFileUrl":140,"sourceHtmlUrl":141,"categories":142,"keywords":143,"publishedAt":42},"01M6FEE9VTK1W4GY21AKREJXRG","webapp-testing","Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.","https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fpi_agent_rust\u002Fblob\u002Fmain\u002Ftests\u002Fext_conformance\u002Fartifacts\u002Ftemplates-davila7\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fsecurity\u002Fwebapp-testing\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fpi_agent_rust\u002Fblob\u002Fmain\u002Ftests\u002Fext_conformance\u002Fartifacts\u002Ftemplates-davila7\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fsecurity\u002Fwebapp-testing\u002FSKILL.md",[],[144,145,146,116,147,148,113,149,88,150,126,151,152,153,154,100,133],"testing","webapp testing","webapp","screenshots","playwright","debugging","browser","logs","applications","behavior","local",{"skillNo":156,"name":157,"nameZh":6,"description":158,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":159,"sourceHtmlUrl":160,"categories":161,"keywords":162,"publishedAt":42},"01M6FE20F7ZTQBFWKF4MPJ2SBX","neuropixels-analysis","Neuropixels neural recording analysis. Load SpikeGLX\u002FOpenEphys data, preprocess, motion correction, Kilosort4 spike sorting, quality metrics, Allen\u002FIBL curation, AI-assisted visual analysis, for Neuropixels 1.0\u002F2.0 extracellular electrophysiology. Use when working with neural recordings, spike sorting, extracellular electrophysiology, or when the user mentions Neuropixels, SpikeGLX, Open Ephys, Kilosort, quality metrics, or unit curation.","https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fpi_agent_rust\u002Fblob\u002Fmain\u002Ftests\u002Fext_conformance\u002Fartifacts\u002Ftemplates-davila7\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fscientific\u002Fneuropixels-analysis\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fpi_agent_rust\u002Fblob\u002Fmain\u002Ftests\u002Fext_conformance\u002Fartifacts\u002Ftemplates-davila7\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fscientific\u002Fneuropixels-analysis\u002FSKILL.md",[],[163,164,165,166,167,168,169,170,30,171,172,173,174,175,176,177,100,178,179,180,133,23],"analysis","neuropixels analysis","spike","metrics","data","open","quality","user","recordings","Neural","motion","visual","quality metrics","unit","sorting","curation","recording","load",{"skillNo":182,"name":183,"nameZh":6,"description":184,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":79,"licenseFileUrl":185,"sourceHtmlUrl":186,"categories":187,"keywords":188,"publishedAt":42},"01M6FDP0PDK6F1GGX395C7625Z","skill-creator","Guide for creating effective skills. This skill should be used when users want to create a new skill (or update an existing skill) that extends Claude's capabilities with specialized knowledge, workflows, or tool integrations.","https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fpi_agent_rust\u002Fblob\u002Fmain\u002Ftests\u002Fext_conformance\u002Fartifacts\u002Ftemplates-davila7\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fproductivity\u002Fskill-creator\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fpi_agent_rust\u002Fblob\u002Fmain\u002Ftests\u002Fext_conformance\u002Fartifacts\u002Ftemplates-davila7\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fproductivity\u002Fskill-creator\u002FSKILL.md",[],[189,190,191,192,193,194,195,196,197,198,199,200,201,202,100,133,203,23,204],"skill creator","creator","workflows","create","update","capabilities","knowledge","tool","integrations","specialized","guide","new skill","existing skill","users","Existing","new",{"skillNo":206,"name":207,"nameZh":6,"description":208,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":209,"sourceHtmlUrl":210,"categories":211,"keywords":212,"publishedAt":42},"01M6FDM8Y7VK7NYG9SM7QPA3PW","notebooklm","Use this skill to query your Google NotebookLM notebooks directly from Claude Code for source-grounded, citation-backed answers from Gemini. Browser automation, library management, persistent auth. Drastically reduced hallucinations through document-only responses.","https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fpi_agent_rust\u002Fblob\u002Fmain\u002Ftests\u002Fext_conformance\u002Fartifacts\u002Ftemplates-davila7\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fproductivity\u002Fnotebooklm\u002FLICENSE","https:\u002F\u002Fgithub.com\u002FDicklesworthstone\u002Fpi_agent_rust\u002Fblob\u002Fmain\u002Ftests\u002Fext_conformance\u002Fartifacts\u002Ftemplates-davila7\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fproductivity\u002Fnotebooklm\u002FSKILL.md",[],[207,213,214,215,216,217,218,150,219,220,30,221,222,223,224,133,225],"google","browser automation","gemini","automation","auth","code","library","management","only","document","query","Citation","source"]