{
  "canonical_name": "langfuse/langfuse",
  "compilation_id": "pack_87c6e6cdec054a9bb190c83a3ac43a55",
  "created_at": "2026-05-15T10:35:34.866075+00:00",
  "created_by": "project-pack-compiler",
  "feedback": {
    "carrier_selection_notes": [
      "viable_asset_types=prompt, recipe, host_instruction, eval, preflight",
      "recommended_asset_types=prompt, recipe, host_instruction, eval, preflight"
    ],
    "evidence_delta": {
      "confirmed_claims": [
        "identity_anchor_present",
        "capability_and_host_targets_present",
        "install_path_declared_or_better"
      ],
      "missing_required_fields": [],
      "must_verify_forwarded": [
        "Run or inspect `pip install langfuse` in an isolated environment.",
        "Confirm the project exposes the claimed capability to at least one target host."
      ],
      "quickstart_execution_scope": "allowlisted_sandbox_smoke",
      "sandbox_command": "pip install langfuse",
      "sandbox_container_image": "python:3.12-slim",
      "sandbox_execution_backend": "docker",
      "sandbox_planner_decision": "llm_execute_isolated_install",
      "sandbox_validation_id": "sbx_323e8edd11144797b2cc30117b5d2ff8"
    },
    "feedback_event_type": "project_pack_compilation_feedback",
    "learning_candidate_reasons": [],
    "template_gaps": []
  },
  "identity": {
    "canonical_id": "project_d76c8776b862d70bf43436637f1148d6",
    "canonical_name": "langfuse/langfuse",
    "homepage_url": null,
    "license": "unknown",
    "repo_url": "https://github.com/langfuse/langfuse",
    "slug": "langfuse",
    "source_packet_id": "phit_b8e94b0121e64dec86f1a587db839bc6",
    "source_validation_id": "dval_8c486efe87fd4ad990dc77cbf338b160"
  },
  "merchandising": {
    "best_for": "需要软件开发与交付能力，并使用 chatgpt的用户",
    "github_forks": 2760,
    "github_stars": 27170,
    "one_liner_en": "🪢 Open source LLM engineering platform: LLM Observability, metrics, evals, prompt management, playground, datasets. Integrates with OpenTelemetry, Langchain, OpenAI SDK, LiteLLM, and more. 🍊YC W23",
    "one_liner_zh": "🪢 Open source LLM engineering platform: LLM Observability, metrics, evals, prompt management, playground, datasets. Integrates with OpenTelemetry, Langchain, OpenAI SDK, LiteLLM, and more. 🍊YC W23",
    "primary_category": {
      "category_id": "software-development",
      "confidence": "medium",
      "name_en": "Software Development",
      "name_zh": "软件开发与交付",
      "reason": "matched_keywords:git, sdk"
    },
    "target_user": "使用 chatgpt 等宿主 AI 的用户",
    "title_en": "langfuse",
    "title_zh": "langfuse 能力包",
    "visible_tags": [
      {
        "label_en": "Browser Agents",
        "label_zh": "浏览器 Agent",
        "source": "repo_evidence_project_characteristics",
        "tag_id": "product_domain-browser-agents",
        "type": "product_domain"
      },
      {
        "label_en": "Web Task Automation",
        "label_zh": "网页任务自动化",
        "source": "repo_evidence_project_characteristics",
        "tag_id": "user_job-web-task-automation",
        "type": "user_job"
      },
      {
        "label_en": "Browser Automation",
        "label_zh": "浏览器自动化",
        "source": "repo_evidence_project_characteristics",
        "tag_id": "core_capability-browser-automation",
        "type": "core_capability"
      },
      {
        "label_en": "Checkpoint Resume",
        "label_zh": "断点恢复流程",
        "source": "repo_evidence_project_characteristics",
        "tag_id": "workflow_pattern-checkpoint-resume",
        "type": "workflow_pattern"
      },
      {
        "label_en": "Evaluation Suite",
        "label_zh": "评测体系",
        "source": "repo_evidence_project_characteristics",
        "tag_id": "selection_signal-evaluation-suite",
        "type": "selection_signal"
      }
    ]
  },
  "packet_id": "phit_b8e94b0121e64dec86f1a587db839bc6",
  "page_model": {
    "artifacts": {
      "artifact_slug": "langfuse",
      "files": [
        "PROJECT_PACK.json",
        "QUICK_START.md",
        "PROMPT_PREVIEW.md",
        "HUMAN_MANUAL.md",
        "AI_CONTEXT_PACK.md",
        "BOUNDARY_RISK_CARD.md",
        "PITFALL_LOG.md",
        "REPO_INSPECTION.json",
        "REPO_INSPECTION.md",
        "CAPABILITY_CONTRACT.json",
        "EVIDENCE_INDEX.json",
        "CLAIM_GRAPH.json"
      ],
      "required_files": [
        "PROJECT_PACK.json",
        "QUICK_START.md",
        "PROMPT_PREVIEW.md",
        "HUMAN_MANUAL.md",
        "AI_CONTEXT_PACK.md",
        "BOUNDARY_RISK_CARD.md",
        "PITFALL_LOG.md",
        "REPO_INSPECTION.json"
      ]
    },
    "detail": {
      "capability_source": "Project Hit Packet + DownstreamValidationResult",
      "commands": [
        {
          "command": "pip install langfuse",
          "label": "Python / pip · 官方安装入口",
          "source": "https://github.com/langfuse/langfuse#readme",
          "verified": true
        }
      ],
      "display_tags": [
        "浏览器 Agent",
        "网页任务自动化",
        "浏览器自动化",
        "断点恢复流程",
        "评测体系"
      ],
      "eyebrow": "软件开发与交付",
      "glance": [
        {
          "body": "判断自己是不是目标用户。",
          "label": "最适合谁",
          "value": "需要软件开发与交付能力，并使用 chatgpt的用户"
        },
        {
          "body": "先理解能力边界，再决定是否继续。",
          "label": "核心价值",
          "value": "🪢 Open source LLM engineering platform: LLM Observability, metrics, evals, prompt management, playground, datasets. Integrates with OpenTelemetry, Langchain, OpenAI SDK, LiteLLM, and more. 🍊YC W23"
        },
        {
          "body": "未完成验证前保持审慎。",
          "label": "继续前",
          "value": "publish to Doramagic.ai project surfaces"
        }
      ],
      "guardrail_source": "Boundary & Risk Card",
      "guardrails": [
        {
          "body": "Prompt Preview 只展示流程，不证明项目已安装或运行。",
          "label": "Check 1",
          "value": "不要把试用当真实运行"
        },
        {
          "body": "chatgpt",
          "label": "Check 2",
          "value": "确认宿主兼容"
        },
        {
          "body": "publish to Doramagic.ai project surfaces",
          "label": "Check 3",
          "value": "先隔离验证"
        }
      ],
      "mode": "prompt, recipe, host_instruction, eval, preflight",
      "pitfall_log": {
        "items": [
          {
            "body": "GitHub 社区证据显示该项目存在一个安装相关的待验证问题：bug: Using client with context manager breaks the scoring",
            "category": "安装坑",
            "evidence": [
              "community_evidence:github | cevd_5afee24537ba47369cc4621f7fb18122 | https://github.com/langfuse/langfuse/issues/8138 | 来源讨论提到 python 相关条件，需在安装/试用前复核。"
            ],
            "severity": "high",
            "suggested_check": "来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。",
            "title": "来源证据：bug: Using client with context manager breaks the scoring",
            "user_impact": "可能增加新用户试用和生产接入成本。"
          },
          {
            "body": "GitHub 社区证据显示该项目存在一个安装相关的待验证问题：bug: unnamed trace name in Langfuse UI",
            "category": "安装坑",
            "evidence": [
              "community_evidence:github | cevd_a219c99fe99c4b7dab002e2b3a6296c2 | https://github.com/langfuse/langfuse/issues/13416 | 来源讨论提到 node 相关条件，需在安装/试用前复核。"
            ],
            "severity": "high",
            "suggested_check": "来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。",
            "title": "来源证据：bug: unnamed trace name in Langfuse UI",
            "user_impact": "可能增加新用户试用和生产接入成本。"
          },
          {
            "body": "GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：bug: AsyncStream' object has no attribute 'usage' when integrated with Semantic Kernel and Openlit",
            "category": "安全/权限坑",
            "evidence": [
              "community_evidence:github | cevd_8657d86702904e90b9d448770e618256 | https://github.com/langfuse/langfuse/issues/8173 | 来源类型 github_issue 暴露的待验证使用条件。"
            ],
            "severity": "high",
            "suggested_check": "来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。",
            "title": "来源证据：bug: AsyncStream' object has no attribute 'usage' when integrated with Semantic Kernel and Openlit",
            "user_impact": "可能影响授权、密钥配置或安全边界。"
          },
          {
            "body": "GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：bug: Worker shutdown takes ~1 hour in self hosted kubernetes",
            "category": "安全/权限坑",
            "evidence": [
              "community_evidence:github | cevd_cff1b1d1a1ca4eb892563c33d3aa62e9 | https://github.com/langfuse/langfuse/issues/8156 | 来源讨论提到 python 相关条件，需在安装/试用前复核。"
            ],
            "severity": "high",
            "suggested_check": "来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。",
            "title": "来源证据：bug: Worker shutdown takes ~1 hour in self hosted kubernetes",
            "user_impact": "可能影响授权、密钥配置或安全边界。"
          },
          {
            "body": "GitHub 社区证据显示该项目存在一个安装相关的待验证问题：bug: Socket timeout. Expecting data, but didn't receive any in 30000ms on idle BullMQ queues",
            "category": "安装坑",
            "evidence": [
              "community_evidence:github | cevd_49a69075a1c346789a28db93c9ec6f3f | https://github.com/langfuse/langfuse/issues/13601 | 来源讨论提到 node 相关条件，需在安装/试用前复核。"
            ],
            "severity": "medium",
            "suggested_check": "来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。",
            "title": "来源证据：bug: Socket timeout. Expecting data, but didn't receive any in 30000ms on idle BullMQ queues",
            "user_impact": "可能增加新用户试用和生产接入成本。"
          },
          {
            "body": "GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v3.169.0",
            "category": "安装坑",
            "evidence": [
              "community_evidence:github | cevd_864f213fd7694eba9a4d2fe2bb9267ab | https://github.com/langfuse/langfuse/releases/tag/v3.169.0 | 来源讨论提到 npm 相关条件，需在安装/试用前复核。"
            ],
            "severity": "medium",
            "suggested_check": "来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。",
            "title": "来源证据：v3.169.0",
            "user_impact": "可能增加新用户试用和生产接入成本。"
          },
          {
            "body": "GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v3.172.0",
            "category": "安装坑",
            "evidence": [
              "community_evidence:github | cevd_14588986ba9945eeb40cbc0508e3fed0 | https://github.com/langfuse/langfuse/releases/tag/v3.172.0 | 来源讨论提到 npm 相关条件，需在安装/试用前复核。"
            ],
            "severity": "medium",
            "suggested_check": "来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。",
            "title": "来源证据：v3.172.0",
            "user_impact": "可能影响升级、迁移或版本选择。"
          },
          {
            "body": "GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v3.173.0",
            "category": "安装坑",
            "evidence": [
              "community_evidence:github | cevd_7560a954846b4f35aedb74de1291c9a4 | https://github.com/langfuse/langfuse/releases/tag/v3.173.0 | 来源讨论提到 docker 相关条件，需在安装/试用前复核。"
            ],
            "severity": "medium",
            "suggested_check": "来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。",
            "title": "来源证据：v3.173.0",
            "user_impact": "可能影响升级、迁移或版本选择。"
          },
          {
            "body": "README/documentation is current enough for a first validation pass.",
            "category": "能力坑",
            "evidence": [
              "capability.assumptions | github_repo:642497346 | https://github.com/langfuse/langfuse | README/documentation is current enough for a first validation pass."
            ],
            "severity": "medium",
            "suggested_check": "将假设转成下游验证清单。",
            "title": "能力判断依赖假设",
            "user_impact": "假设不成立时，用户拿不到承诺的能力。"
          },
          {
            "body": "未记录 last_activity_observed。",
            "category": "维护坑",
            "evidence": [
              "evidence.maintainer_signals | github_repo:642497346 | https://github.com/langfuse/langfuse | last_activity_observed missing"
            ],
            "severity": "medium",
            "suggested_check": "补 GitHub 最近 commit、release、issue/PR 响应信号。",
            "title": "维护活跃度未知",
            "user_impact": "新项目、停更项目和活跃项目会被混在一起，推荐信任度下降。"
          },
          {
            "body": "no_demo",
            "category": "安全/权限坑",
            "evidence": [
              "downstream_validation.risk_items | github_repo:642497346 | https://github.com/langfuse/langfuse | no_demo; severity=medium"
            ],
            "severity": "medium",
            "suggested_check": "进入安全/权限治理复核队列。",
            "title": "下游验证发现风险项",
            "user_impact": "下游已经要求复核，不能在页面中弱化。"
          },
          {
            "body": "no_demo",
            "category": "安全/权限坑",
            "evidence": [
              "risks.scoring_risks | github_repo:642497346 | https://github.com/langfuse/langfuse | no_demo; severity=medium"
            ],
            "severity": "medium",
            "suggested_check": "把风险写入边界卡，并确认是否需要人工复核。",
            "title": "存在评分风险",
            "user_impact": "风险会影响是否适合普通用户安装。"
          },
          {
            "body": "GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：v3.168.0",
            "category": "安全/权限坑",
            "evidence": [
              "community_evidence:github | cevd_202b4e8c2c1f4b3790315098d1530297 | https://github.com/langfuse/langfuse/releases/tag/v3.168.0 | 来源讨论提到 node 相关条件，需在安装/试用前复核。"
            ],
            "severity": "medium",
            "suggested_check": "来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。",
            "title": "来源证据：v3.168.0",
            "user_impact": "可能影响升级、迁移或版本选择。"
          },
          {
            "body": "GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：v3.170.0",
            "category": "安全/权限坑",
            "evidence": [
              "community_evidence:github | cevd_9ed6f994e1424878aa4559a73d72fc52 | https://github.com/langfuse/langfuse/releases/tag/v3.170.0 | 来源讨论提到 docker 相关条件，需在安装/试用前复核。"
            ],
            "severity": "medium",
            "suggested_check": "来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。",
            "title": "来源证据：v3.170.0",
            "user_impact": "可能阻塞安装或首次运行。"
          },
          {
            "body": "GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：v3.174.0",
            "category": "安全/权限坑",
            "evidence": [
              "community_evidence:github | cevd_f9cb7b7232ff4cce96f0c020fe48c7f4 | https://github.com/langfuse/langfuse/releases/tag/v3.174.0 | 来源讨论提到 api key 相关条件，需在安装/试用前复核。"
            ],
            "severity": "medium",
            "suggested_check": "来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。",
            "title": "来源证据：v3.174.0",
            "user_impact": "可能影响授权、密钥配置或安全边界。"
          },
          {
            "body": "issue_or_pr_quality=unknown。",
            "category": "维护坑",
            "evidence": [
              "evidence.maintainer_signals | github_repo:642497346 | https://github.com/langfuse/langfuse | issue_or_pr_quality=unknown"
            ],
            "severity": "low",
            "suggested_check": "抽样最近 issue/PR，判断是否长期无人处理。",
            "title": "issue/PR 响应质量未知",
            "user_impact": "用户无法判断遇到问题后是否有人维护。"
          }
        ],
        "source": "ProjectPitfallLog + ProjectHitPacket + validation + community signals",
        "summary": "发现 17 个潜在踩坑项，其中 4 个为 high/blocking；最高优先级：安装坑 - 来源证据：bug: Using client with context manager breaks the scoring。",
        "title": "踩坑日志"
      },
      "snapshot": {
        "contributors": 156,
        "forks": 2760,
        "license": "unknown",
        "note": "站点快照，非实时质量证明；用于开工前背景判断。",
        "stars": 27170
      },
      "source_url": "https://github.com/langfuse/langfuse",
      "steps": [
        {
          "body": "不安装项目，先体验能力节奏。",
          "code": "preview",
          "title": "先试 Prompt"
        },
        {
          "body": "理解输入、输出、失败模式和边界。",
          "code": "manual",
          "title": "读说明书"
        },
        {
          "body": "把上下文交给宿主 AI 继续工作。",
          "code": "context",
          "title": "带给 AI"
        },
        {
          "body": "进入主力环境前先完成安装入口与风险边界验证。",
          "code": "verify",
          "title": "沙箱验证"
        }
      ],
      "subtitle": "🪢 Open source LLM engineering platform: LLM Observability, metrics, evals, prompt management, playground, datasets. Integrates with OpenTelemetry, Langchain, OpenAI SDK, LiteLLM, and more. 🍊YC W23",
      "title": "langfuse 能力包",
      "voices": [
        {
          "body": "来源平台：github。github/github_issue: bug: unnamed trace name in Langfuse UI（https://github.com/langfuse/langfuse/issues/13416）；github/github_issue: bug: Socket timeout. Expecting data, but didn't receive any in 30000ms o（https://github.com/langfuse/langfuse/issues/13601）；github/github_issue: bug: Using client with context manager breaks the scoring（https://github.com/langfuse/langfuse/issues/8138）；github/github_issue: bug: Worker shutdown takes ~1 hour in self hosted kubernetes（https://github.com/langfuse/langfuse/issues/8156）；github/github_issue: bug: AsyncStream' object has no attribute 'usage' when integrated with S（https://github.com/langfuse/langfuse/issues/8173）；github/github_release: v3.174.0（https://github.com/langfuse/langfuse/releases/tag/v3.174.0）；github/github_release: v3.173.0（https://github.com/langfuse/langfuse/releases/tag/v3.173.0）；github/github_release: v3.172.1（https://github.com/langfuse/langfuse/releases/tag/v3.172.1）；github/github_release: v3.172.0（https://github.com/langfuse/langfuse/releases/tag/v3.172.0）；github/github_release: v3.171.0（https://github.com/langfuse/langfuse/releases/tag/v3.171.0）；github/github_release: v3.170.0（https://github.com/langfuse/langfuse/releases/tag/v3.170.0）；github/github_release: v3.169.0（https://github.com/langfuse/langfuse/releases/tag/v3.169.0）。这些是项目级外部声音，不作为单独质量证明。",
          "items": [
            {
              "kind": "github_issue",
              "source": "github",
              "title": "bug: unnamed trace name in Langfuse UI",
              "url": "https://github.com/langfuse/langfuse/issues/13416"
            },
            {
              "kind": "github_issue",
              "source": "github",
              "title": "bug: Socket timeout. Expecting data, but didn't receive any in 30000ms o",
              "url": "https://github.com/langfuse/langfuse/issues/13601"
            },
            {
              "kind": "github_issue",
              "source": "github",
              "title": "bug: Using client with context manager breaks the scoring",
              "url": "https://github.com/langfuse/langfuse/issues/8138"
            },
            {
              "kind": "github_issue",
              "source": "github",
              "title": "bug: Worker shutdown takes ~1 hour in self hosted kubernetes",
              "url": "https://github.com/langfuse/langfuse/issues/8156"
            },
            {
              "kind": "github_issue",
              "source": "github",
              "title": "bug: AsyncStream' object has no attribute 'usage' when integrated with S",
              "url": "https://github.com/langfuse/langfuse/issues/8173"
            },
            {
              "kind": "github_release",
              "source": "github",
              "title": "v3.174.0",
              "url": "https://github.com/langfuse/langfuse/releases/tag/v3.174.0"
            },
            {
              "kind": "github_release",
              "source": "github",
              "title": "v3.173.0",
              "url": "https://github.com/langfuse/langfuse/releases/tag/v3.173.0"
            },
            {
              "kind": "github_release",
              "source": "github",
              "title": "v3.172.1",
              "url": "https://github.com/langfuse/langfuse/releases/tag/v3.172.1"
            },
            {
              "kind": "github_release",
              "source": "github",
              "title": "v3.172.0",
              "url": "https://github.com/langfuse/langfuse/releases/tag/v3.172.0"
            },
            {
              "kind": "github_release",
              "source": "github",
              "title": "v3.171.0",
              "url": "https://github.com/langfuse/langfuse/releases/tag/v3.171.0"
            },
            {
              "kind": "github_release",
              "source": "github",
              "title": "v3.170.0",
              "url": "https://github.com/langfuse/langfuse/releases/tag/v3.170.0"
            },
            {
              "kind": "github_release",
              "source": "github",
              "title": "v3.169.0",
              "url": "https://github.com/langfuse/langfuse/releases/tag/v3.169.0"
            }
          ],
          "status": "已收录 12 条来源",
          "title": "社区讨论"
        }
      ],
      "trial_prompt_en": "# langfuse - Prompt Preview\n\n> Copy the prompt below into your AI host before installing anything.\n> Its purpose is to let you safely feel the project's workflow, not to claim the project has already run.\n\n## Copy this prompt\n\n```text\nYou are using an independent Doramagic capability pack for langfuse/langfuse.\n\nProject:\n- Name: langfuse\n- Repository: https://github.com/langfuse/langfuse\n- Summary: 🪢 Open source LLM engineering platform: LLM Observability, metrics, evals, prompt management, playground, datasets. Integrates with OpenTelemetry, Langchain, OpenAI SDK, LiteLLM, and more. 🍊YC W23\n- Host target: ChatGPT, Claude, Codex, Cursor\n\nGoal:\nHelp me evaluate this project for the following task without installing it yet: I want to evaluate whether this project fits a real AI workflow before installing it.\n\nBefore taking action:\n1. Restate my task, success standard, and boundary.\n2. Identify whether the next step requires tools, browser access, network access, filesystem access, credentials, package installation, or host configuration.\n3. Use only the Doramagic Project Pack, the upstream repository, and the source-linked evidence listed below.\n4. If a real command, install step, API call, file write, or host integration is required, mark it as \"requires post-install verification\" and ask for approval first.\n5. If evidence is missing, say \"evidence is missing\" instead of filling the gap.\n\nPreviewable capabilities:\n- Capability 1: Use the source-backed project context to guide one small, checkable workflow step.\n\nCapabilities that require post-install verification:\n- Capability 1: Use the source-backed project context to guide one small, checkable workflow step.\n\nCore service flow:\n1. project-introduction: Project Introduction. Produce one small intermediate artifact and wait for confirmation.\n2. project-structure: Project Structure. Produce one small intermediate artifact and wait for confirmation.\n3. quickstart-guide: Quickstart Guide. Produce one small intermediate artifact and wait for confirmation.\n4. system-architecture: System Architecture. Produce one small intermediate artifact and wait for confirmation.\n5. database-schema: Database Schema (Prisma). Produce one small intermediate artifact and wait for confirmation.\n\nSource-backed evidence to keep in mind:\n- https://github.com/langfuse/langfuse\n- https://github.com/langfuse/langfuse#readme\n- .agents/skills/add-model-price/SKILL.md\n- .agents/skills/agent-setup-maintenance/SKILL.md\n- .agents/skills/analyze-cloud-costs/SKILL.md\n- .agents/skills/backend-dev-guidelines/SKILL.md\n- .agents/skills/changelog-writing/SKILL.md\n- .agents/skills/clickhouse-best-practices/SKILL.md\n- .agents/skills/code-review/SKILL.md\n- .agents/skills/datadog-query-recipes/SKILL.md\n\nFirst response rules:\n1. Start Step 1 only.\n2. Explain the one service action you will perform first.\n3. Ask exactly three questions about my target workflow, success standard, and sandbox boundary.\n4. Stop and wait for my answers.\n\nStep 1 follow-up protocol:\n- After I answer the first three questions, stay in Step 1.\n- Produce six parts only: clarified task, success standard, boundary conditions, two or three options, tradeoffs for each option, and one recommendation.\n- End by asking whether I confirm the recommendation.\n- Do not move to Step 2 until I explicitly confirm.\n\nConversation rules:\n- Advance one step at a time and wait for confirmation after each small artifact.\n- Write outputs as recommendations or planned checks, not as completed execution.\n- Do not claim tests passed, files changed, commands ran, APIs were called, or the project was installed.\n- If the user asks for execution, first provide the sandbox setup, expected output, rollback, and approval checkpoint.\n```\n"
    },
    "homepage_card": {
      "category": "软件开发与交付",
      "desc": "🪢 Open source LLM engineering platform: LLM Observability, metrics, evals, prompt management, playground, datasets. Integrates with OpenTelemetry, Langchain, OpenAI SDK, LiteLLM, and more. 🍊YC W23",
      "effort": "安装已验证",
      "forks": 2760,
      "icon": "code",
      "name": "langfuse 能力包",
      "risk": "可发布",
      "slug": "langfuse",
      "stars": 27170,
      "tags": [
        "浏览器 Agent",
        "网页任务自动化",
        "浏览器自动化",
        "断点恢复流程",
        "评测体系"
      ],
      "thumb": "gray",
      "type": "Prompt Preview"
    },
    "manual": {
      "markdown": "# https://github.com/langfuse/langfuse 项目说明书\n\n生成时间：2026-05-15 10:18:59 UTC\n\n## 目录\n\n- [Project Introduction](#project-introduction)\n- [Project Structure](#project-structure)\n- [Quickstart Guide](#quickstart-guide)\n- [System Architecture](#system-architecture)\n- [Monorepo Configuration](#monorepo-structure)\n- [Database Schema (Prisma)](#database-schema)\n- [ClickHouse Analytics Layer](#clickhouse-analytics)\n- [Queue System (Redis/BullMQ)](#queue-system)\n- [Worker Service](#worker-service)\n- [API Layer](#api-layer)\n\n<a id='project-introduction'></a>\n\n## Project Introduction\n\n### 相关页面\n\n相关主题：[System Architecture](#system-architecture)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [README.md](https://github.com/langfuse/langfuse/blob/main/README.md)\n- [packages/shared/src/constants/VERSION.ts](https://github.com/langfuse/langfuse/blob/main/packages/shared/src/constants/VERSION.ts)\n- [web/src/components/ui/AdvancedJsonViewer/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/ui/AdvancedJsonViewer/README.md)\n- [web/src/components/layouts/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/layouts/README.md)\n- [web/src/features/mcp/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/mcp/README.md)\n- [web/src/features/entitlements/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/entitlements/README.md)\n- [web/src/features/feature-flags/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/feature-flags/README.md)\n- [web/src/components/design-system/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/design-system/README.md)\n</details>\n\n# Project Introduction\n\nLangfuse is an open-source **observability and analytics platform** designed for Large Language Model (LLM) applications. It provides comprehensive tracing, evaluation, and prompt management capabilities that enable developers to monitor, debug, and optimize their AI-powered applications.\n\n## Overview\n\nLangfuse serves as a centralized platform for capturing and analyzing interactions between AI models and end users. The project is MIT licensed and supports both cloud-hosted and self-hosted deployment models, making it accessible for teams of various sizes and requirements.\n\n### Core Purpose\n\nThe platform addresses several critical needs in LLM application development:\n\n- **Observability**: Track and visualize traces, observations, and model interactions in real-time\n- **Evaluation**: Measure and analyze AI application performance through configurable scoring systems\n- **Prompt Management**: Create, version, and manage prompts with support for complex dependency resolution\n- **Collaboration**: Enable team collaboration through commenting and sharing features\n- **Analytics**: Provide insights into AI application behavior through comprehensive analytics dashboards\n\n### High-Level Architecture\n\nLangfuse follows a modern microservices-inspired architecture with clear separation between frontend, backend processing, and data storage components.\n\n```mermaid\ngraph TD\n    subgraph Frontend[\"Frontend (Next.js/React)\"]\n        UI[User Interface]\n        DesignSystem[Design System Components]\n        FeatureFlags[Feature Flags]\n    end\n    \n    subgraph Backend[\"Backend Services\"]\n        API[API Server]\n        MCP[MCP Server]\n        Worker[Worker/Queue Processing]\n    end\n    \n    subgraph Storage[\"Data Layer\"]\n        Postgres[(PostgreSQL)]\n        ClickHouse[(ClickHouse)]\n        Redis[(Redis)]\n        S3[(S3 Storage)]\n    end\n    \n    UI --> API\n    MCP --> API\n    Worker --> API\n    API --> Postgres\n    API --> ClickHouse\n    API --> Redis\n    API --> S3\n```\n\n## Technology Stack\n\nLangfuse is built using a modern technology stack optimized for performance and developer experience.\n\n### Frontend Stack\n\n| Component | Technology | Purpose |\n|-----------|------------|---------|\n| Framework | Next.js | Server-side rendering and routing |\n| UI Library | React | Component-based UI development |\n| State Management | React Context + Hooks | Local and global state |\n| Virtualization | TanStack Virtual | Efficient rendering of large lists |\n| Styling | Tailwind CSS + cva | Utility-first styling with variant handling |\n| Forms | Zod | Schema validation |\n| Data Fetching | tRPC | Type-safe API communication |\n\n资料来源：[web/src/components/design-system/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/design-system/README.md)\n\n### Backend Stack\n\n| Component | Technology | Purpose |\n|-----------|------------|---------|\n| Runtime | Node.js/TypeScript | Server-side logic |\n| Database | PostgreSQL | Primary data storage |\n| Analytics | ClickHouse | High-performance analytics queries |\n| Cache | Redis | Caching and queue management |\n| Queue | BullMQ | Background job processing |\n| Storage | S3-compatible | File and event storage |\n\n### Key Frontend Components\n\nThe frontend architecture is organized around several key systems:\n\n#### Design System\n\nThe design system (`web/src/components/design-system/`) provides reusable, primitive UI components following strict principles:\n\n- **Presentational only**: No business logic in components\n- **Explicit, typed APIs**: Strict TypeScript definitions\n- **No className/style props**: Prevents style leakage\n- **cva for variants**: Consistent variant handling\n\n```mermaid\ngraph LR\n    A[Design System] --> B[Button]\n    A --> C[Input]\n    A --> D[Modal]\n    B --> E[Consistent Styling]\n    C --> E\n    D --> E\n```\n\n资料来源：[web/src/components/design-system/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/design-system/README.md)\n\n#### Layout System\n\nAll pages use a standardized `Page` wrapper component that ensures:\n\n- Consistent layout structure\n- Sticky header behavior\n- Proper scroll management (`\"content-scroll\"` or `\"page-scroll\"`)\n- Breadcrumb navigation support\n- Custom header actions\n\n```mermaid\ngraph TD\n    Page[Page Component] --> Header[Sticky Header]\n    Page --> Content[Scrollable Content]\n    Header --> Breadcrumb[Breadcrumb Navigation]\n    Header --> Actions[Action Buttons]\n```\n\n资料来源：[web/src/components/layouts/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/layouts/README.md)\n\n#### JSON Viewer Component\n\nThe `AdvancedJsonViewer` component provides efficient rendering of large JSON datasets:\n\n- **Virtualization**: Uses TanStack Virtual for row-based rendering\n- **Iterative algorithms**: Explicit stack-based iteration to prevent stack overflow\n- **Client-side search**: In-memory matching with binary search navigation\n- **Theme support**: Customizable JSON syntax highlighting\n\n```mermaid\ngraph TD\n    Input[Large JSON Data] --> Parser[JSON Parser]\n    Parser --> TreeBuilder[Tree Builder]\n    TreeBuilder --> Virtualizer[TanStack Virtual]\n    Virtualizer --> Renderer[Row Renderer]\n    \n    Search[Search Query] --> Matcher[In-Memory Matcher]\n    Matcher --> Navigator[Binary Search Navigator]\n```\n\n资料来源：[web/src/components/ui/AdvancedJsonViewer/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/ui/AdvancedJsonViewer/README.md)\n\n## Core Features\n\n### Tracing and Observability\n\nLangfuse provides comprehensive tracing capabilities that capture the full lifecycle of AI interactions:\n\n- **Traces**: Complete request/response cycles\n- **Observations**: Individual components within a trace (spans, events, generations)\n- **Metadata**: Custom metadata attachment for context\n- **Tree Structure**: Hierarchical representation of nested observations\n\nThe tree-building system uses iterative algorithms to handle millions of observations without stack overflow:\n\n```typescript\n// Iterative traversal pattern\nfunction traverse(rootNode: TreeNode) {\n  const stack = [rootNode];\n  while (stack.length > 0) {\n    const node = stack.pop()!;\n    process(node);\n    node.children.forEach((child) => stack.push(child));\n  }\n}\n```\n\n资料来源：[web/src/components/trace/lib/tree-building.clienttest.ts](https://github.com/langfuse/langfuse/blob/main/web/src/components/trace/lib/tree-building.clienttest.ts)\n\n### Prompt Management\n\nLangfuse supports sophisticated prompt management with dependency resolution:\n\n- **Prompt Stacking**: Compose prompts from multiple sources\n- **Dependency Tags**: Reference other prompts using `@@@langfusePrompt:...@@@` syntax\n- **Resolution Modes**:\n  - `getPromptResolved`: Returns fully resolved prompt with dependencies inlined\n  - `getPromptUnresolved`: Returns raw prompt with tags preserved for analysis\n\n```mermaid\ngraph LR\n    A[Prompt A] -->|references| B[Prompt B]\n    A -->|references| C[Prompt C]\n    B -->|references| D[Prompt D]\n    A -->|resolved| E[Final Prompt]\n```\n\n资料来源：[web/src/features/mcp/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/mcp/README.md)\n\n### Score Analytics\n\nThe scoring system enables quantitative evaluation of AI application performance:\n\n- **Multiple Score Types**: Supports numeric, categorical, and boolean scores\n- **Time Series Analysis**: Track score changes over configurable intervals\n- **Distribution Analysis**: Visualize score distributions with bins and categories\n- **Comparison Mode**: Compare two scores side-by-side\n\nThe analytics layer provides interpretive functions for common metrics:\n\n| Metric | Interpretation | Threshold |\n|--------|----------------|-----------|\n| Agreement (Cohen's Kappa) | Excellent | ≥ 0.9 |\n| Agreement (Cohen's Kappa) | Good | ≥ 0.8 |\n| Agreement (Cohen's Kappa) | Fair | ≥ 0.6 |\n| Agreement (Cohen's Kappa) | Poor | ≥ 0.4 |\n\n资料来源：[web/src/features/score-analytics/lib/statistics-utils.ts](https://github.com/langfuse/langfuse/blob/main/web/src/features/score-analytics/lib/statistics-utils.ts)\n\n### Entitlements System\n\nAccess control is managed through a hierarchical entitlements system:\n\n```mermaid\ngraph TD\n    Plan[Plan] -->|contains| Entitlements[Entitlements]\n    Plan -->|contains| Limits[Entitlement Limits]\n    \n    Entitlements -->|grants| Features[Feature Access]\n    Limits -->|restricts| Resources[Resource Quotas]\n    \n    PlanTypes[Plan Types] --> OSS[OSS]\n    PlanTypes --> CloudPro[Cloud Pro]\n    PlanTypes --> SelfHostedEnterprise[Self-Hosted Enterprise]\n```\n\nAvailable entitlements include:\n\n- **Feature Flags**: Enable/disable features via `useIsFeatureEnabled` hook\n- **Entitlement Limits**: Quotas on resources (e.g., annotation queue count)\n- **Plan-based Access**: Cloud and self-hosted enterprise plans\n\n资料来源：[web/src/features/entitlements/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/entitlements/README.md)\n\n### Feature Flags\n\nFeature flags control feature availability dynamically:\n\n```typescript\nconst isFeatureEnabled = useIsFeatureEnabled(\"feature-flag-name\");\n```\n\nA feature flag is enabled when:\n\n1. Flag is in user's `feature_flags` list\n2. `LANGFUSE_ENABLE_EXPERIMENTAL_FEATURES` environment variable is set\n3. User has admin privileges\n\n资料来源：[web/src/features/feature-flags/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/feature-flags/README.md)\n\n### Collaboration Features\n\nLangfuse includes team collaboration capabilities:\n\n- **Mention Parser**: Extract and resolve user mentions in comments\n- **User References**: Syntax `@[Display Name](user:userId)` for linking users\n- **Sanitization**: Clean user-generated content for safe display\n\n```typescript\n// Mention format: @[Alice](user:alice123)\n// Parser extracts: alice123\n```\n\n资料来源：[web/src/features/comments/lib/mentionParser.clienttest.ts](https://github.com/langfuse/langfuse/blob/main/web/src/features/comments/lib/mentionParser.clienttest.ts)\n\n## Data Flow Architecture\n\n### Ingestion Pipeline\n\nEvents flow through the system in a structured pipeline:\n\n```mermaid\ngraph LR\n    S3[S3 Event Storage] --> Worker[Worker Processing]\n    Worker -->|Standard| IngestionQueue[IngestionSecondaryQueue]\n    Worker -->|OTEL| OtelQueue[OtelIngestionQueue]\n    IngestionQueue --> Postgres[(PostgreSQL)]\n    OtelQueue --> ClickHouse[(ClickHouse)]\n```\n\nEvent processing includes:\n\n- **Checkpointing**: Resume from failures using `.checkpoint` files\n- **Rate Limiting**: Client-side and server-side throttling\n- **Retry Logic**: Exponential backoff with jitter for transient failures\n- **Error Logging**: Failed events appended to `errors.csv`\n\n资料来源：[worker/src/scripts/replayIngestionEventsV2/README.md](https://github.com/langfuse/langfuse/blob/main/worker/src/scripts/replayIngestionEventsV2/README.md)\n\n### API Architecture\n\nLangfuse uses tRPC for type-safe API communication:\n\n- **Server-side validation**: Zod schemas for input validation\n- **tRPC routers**: Organized endpoint handlers\n- **API versioning**: V1 (legacy) and V2 (current) API support\n\n| API Version | GET Support | Notes |\n|-------------|-------------|-------|\n| V1 | `traceId` required | Legacy, trace-focused |\n| V2 | `traceId` optional | Adds `sessionId` support |\n\n资料来源：[packages/shared/src/features/scores/interfaces/README.md](https://github.com/langfuse/langfuse/blob/main/packages/shared/src/features/scores/interfaces/README.md)\n\n### MCP Server Architecture\n\nThe Model Context Protocol (MCP) server provides external access to Langfuse:\n\n- **Stateless per-request**: Fresh server instance for each request\n- **Context via closures**: Authentication captured in handler closures\n- **No session storage**: Request-disposable architecture\n\n```mermaid\ngraph TD\n    Request[MCP Request] --> Instance[New Server Instance]\n    Instance --> Auth[Auth Context Closure]\n    Auth --> Handler[Request Handler]\n    Handler --> Response[Response]\n    Response --> Discard[Instance Discarded]\n```\n\n资料来源：[web/src/features/mcp/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/mcp/README.md)\n\n## Filtering System\n\nLangfuse implements a sophisticated filtering system with type-safe encoding:\n\n### Filter Types\n\n| Type | Description | Example |\n|------|-------------|---------|\n| `string` | Simple string matching | Trace name |\n| `number` | Numeric comparison | Latency values |\n| `datetime` | Date/time filtering | Time ranges |\n| `boolean` | True/false matching | Flag states |\n| `arrayOptions` | Multi-value selection | Tags |\n| `categoryOptions` | Categorical filtering | Status values |\n| `positionInTrace` | Nested location | Span hierarchy |\n\n### State Management\n\nFilters support multiple storage locations:\n\n- **URL**: Persisted in query parameters\n- **Session Storage**: In-memory per session\n- **Peek Context**: Temporary state for preview panels\n\n```typescript\nconst filterOptions: UseSidebarFilterStateOptions = {\n  stateLocation: \"urlAndSessionStorage\",\n  sessionFilterContextId: projectId,\n  implicitDefaultConfig: DEFAULT_SIDEBAR_IMPLICIT_ENVIRONMENT_CONFIG,\n};\n```\n\n资料来源：[web/src/components/table/peek/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/table/peek/README.md)\n\n## Deployment Models\n\nLangfuse supports multiple deployment configurations:\n\n| Model | Plan Options | Authentication | License |\n|-------|--------------|----------------|---------|\n| Cloud | `cloud:pro` | JWT via NextAuth | Proprietary |\n| Self-Hosted | `self-hosted:enterprise` | JWT + License Key | Proprietary |\n| Open Source | `oss` | Basic auth | MIT |\n\n### Self-Hosted Configuration\n\nSelf-hosted deployments require:\n\n- PostgreSQL database\n- ClickHouse for analytics\n- Redis for caching/queues\n- S3-compatible storage for events\n- License key for enterprise features\n\n资料来源：[web/src/features/entitlements/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/entitlements/README.md)\n\n## Performance Considerations\n\n### Large Dataset Handling\n\nLangfuse handles large datasets through several mechanisms:\n\n| Scale | Mechanism | Threshold |\n|-------|-----------|-----------|\n| 10k+ rows | TanStack Virtual | Row-based rendering |\n| 1M+ nodes | Iterative algorithms | No stack overflow |\n| 10k+ search matches | Binary search | Efficient navigation |\n\n### Known Limitations\n\n- No horizontal virtualization for wide rows\n- Client-side search only (can be slow with many matches)\n- Memory constraints at 1M+ nodes\n- Read-only JSON viewer (no inline editing)\n- Wrap mode may cause layout thrashing\n\n资料来源：[web/src/components/ui/AdvancedJsonViewer/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/ui/AdvancedJsonViewer/README.md)\n\n## Development Guidelines\n\n### Testing\n\nThe project uses Jest with custom extensions:\n\n| File Pattern | Purpose | Location |\n|--------------|---------|----------|\n| `.clienttest.ts` | Client-side tests | Colocated with components |\n| `*.test.ts` | Standard unit tests | `__tests__` or inline |\n\n```bash\n# Run client tests\npnpm --filter=web run test-client --testPathPattern=\"ComponentName\"\n```\n\n### Debugging\n\nEnable debug logging via localStorage:\n\n```typescript\nlocalStorage.setItem(\"debug:ComponentName\", \"true\");\n```\n\n## Summary\n\nLangfuse is a comprehensive observability platform that bridges the gap between AI application development and operational monitoring. Its modular architecture, built on proven technologies like PostgreSQL, ClickHouse, and React, provides a scalable foundation for teams to understand, evaluate, and optimize their LLM applications.\n\nThe platform's emphasis on type safety, performance optimization, and developer experience makes it suitable for both small development teams and large-scale enterprise deployments.\n\n---\n\n<a id='project-structure'></a>\n\n## Project Structure\n\n### 相关页面\n\n相关主题：[Monorepo Configuration](#monorepo-structure), [System Architecture](#system-architecture)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [pnpm-workspace.yaml](https://github.com/langfuse/langfuse/blob/main/pnpm-workspace.yaml)\n- [turbo.json](https://github.com/langfuse/langfuse/blob/main/turbo.json)\n- [packages/shared/package.json](https://github.com/langfuse/langfuse/blob/main/packages/shared/package.json)\n- [web/package.json](https://github.com/langfuse/langfuse/blob/main/web/package.json)\n- [worker/package.json](https://github.com/langfuse/langfuse/blob/main/worker/package.json)\n</details>\n\n# Project Structure\n\n## Overview\n\nLangfuse is a comprehensive observability and analytics platform for LLM applications, structured as a **monorepo** using pnpm workspaces and Turborepo for build orchestration. The repository contains multiple packages including the frontend web application, backend worker services, and shared libraries.\n\n## Monorepo Architecture\n\n### Workspace Configuration\n\nLangfuse uses pnpm workspaces defined in `pnpm-workspace.yaml` to manage multiple packages within a single repository.\n\n```yaml\npackages:\n  - \"packages/*\"\n  - \"web\"\n  - \"worker\"\n```\n\n资料来源：[pnpm-workspace.yaml](https://github.com/langfuse/langfuse/blob/main/pnpm-workspace.yaml)\n\n### Build System (Turborepo)\n\nThe project uses Turborepo for efficient incremental builds and task caching. The turbo configuration defines the build pipeline and dependencies between packages.\n\n资料来源：[turbo.json](https://github.com/langfuse/langfuse/blob/main/turbo.json)\n\n## Package Structure\n\n### 1. Web Application (`/web`)\n\nThe frontend application built with Next.js and React, containing the user interface and client-side logic.\n\n| Directory | Purpose |\n|-----------|---------|\n| `src/components/` | Reusable UI components including layouts, tables, and specialized viewers |\n| `src/features/` | Feature-specific modules with their own logic and components |\n| `src/lib/` | Utility functions and helpers |\n| `src/hooks/` | Custom React hooks |\n\n资料来源：[web/package.json](https://github.com/langfuse/langfuse/blob/main/web/package.json)\n\n### 2. Worker Service (`/worker`)\n\nBackend service handling background processing, event ingestion, and queue management.\n\n| Directory | Purpose |\n|-----------|---------|\n| `src/scripts/` | Utility scripts for data operations and migrations |\n| `src/queues/` | Queue handlers for async processing |\n\n资料来源：[worker/package.json](https://github.com/langfuse/langfuse/blob/main/worker/package.json)\n\n### 3. Shared Packages (`/packages/shared`)\n\nCommon utilities, types, and validation schemas shared across web and worker packages.\n\n| Module | Purpose |\n|--------|---------|\n| Validation | Zod schemas for type-safe data validation |\n| Types | Shared TypeScript type definitions |\n| Utilities | Common helper functions |\n\n资料来源：[packages/shared/package.json](https://github.com/langfuse/langfuse/blob/main/packages/shared/package.json)\n\n## Web Application Structure\n\n### Component Architecture\n\n```mermaid\ngraph TD\n    A[Web Application] --> B[Layout Components]\n    A --> C[UI Components]\n    A --> D[Feature Modules]\n    \n    B --> B1[Page Wrapper]\n    B --> B2[ContainerPage]\n    B --> B3[Breadcrumb]\n    \n    C --> C1[AdvancedJsonViewer]\n    C --> C2[Table Components]\n    C --> C3[Peek Components]\n    \n    D --> D1[MCP]\n    D --> D2[Score Analytics]\n    D --> D3[Comments]\n    D --> D4[Filters]\n    D --> D5[Entitlements]\n```\n\n### Layout System\n\nThe `Page` component is the standard wrapper for all pages, providing:\n\n- **Sticky Header**: Consistent header across pages\n- **Scroll Management**: Supports `\"content-scroll\"` and `\"page-scroll\"` modes\n- **Breadcrumb Navigation**: Easy navigation path display\n- **Custom Header Actions**: Flexible button/link placement\n\nFor content that doesn't scale well with page width (e.g., settings pages), use `ContainerPage` instead.\n\n资料来源：[web/src/components/layouts/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/layouts/README.md)\n\n### Key Feature Modules\n\n#### AdvancedJsonViewer\n\nA virtualized JSON tree viewer with the following characteristics:\n\n- **Performance**: Uses TanStack Virtual for rendering large JSON structures\n- **Search**: Client-side search with regex support\n- **Theme Support**: Multiple color themes (GitHub, Monokai, Solarized)\n- **Tree Navigation**: Binary search for efficient node access\n\n资料来源：[web/src/components/ui/AdvancedJsonViewer/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/ui/AdvancedJsonViewer/README.md)\n\n#### Score Analytics\n\nProvides analytics dashboard capabilities for score data:\n\n- **Score Comparison**: Compare two scores over time\n- **Distribution Analysis**: Histogram and heatmap visualizations\n- **Time Series**: Temporal trend analysis with configurable intervals\n- **Data Transformation**: Pure functions for data processing\n\n资料来源：[web/src/features/score-analytics/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/score-analytics/README.md)\n\n#### MCP (Model Context Protocol)\n\nEnables integration with external systems through MCP:\n\n- **Stateless Architecture**: Fresh server instance per request\n- **Prompt Management**: Support for `getPrompt` and `getPromptUnresolved`\n- **Resource Handling**: MCP resources and tool support\n\n资料来源：[web/src/features/mcp/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/mcp/README.md)\n\n#### Entitlements\n\nFeature availability control system:\n\n- **Plan-based Access**: `oss`, `cloud:pro`, `self-hosted:enterprise`\n- **Entitlement Limits**: Resource quotas per plan\n- **Server/Client Support**: Available in both frontend hooks and backend\n\n资料来源：[web/src/features/entitlements/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/entitlements/README.md)\n\n### Table and Peek System\n\n#### PeekTableStateProvider\n\nManages table state for peek views (slide-over panels showing item details):\n\n```mermaid\ngraph LR\n    A[PeekTableStateProvider] --> B[Filters]\n    A --> C[Sorting]\n    A --> D[Pagination]\n    A --> E[Search]\n```\n\n**State Persistence**: Filter, sort, and pagination state persists across K/J navigation between items of the same type.\n\n**State Reset**: State clears when the peek view closes (via X button, Escape, or click outside).\n\n资料来源：[web/src/components/table/peek/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/table/peek/README.md)\n\n## Worker Service Structure\n\n### Scripts\n\nThe worker contains utility scripts for data operations:\n\n| Script | Purpose |\n|--------|---------|\n| `replayIngestionEventsV2` | Replay events from CSV to ingestion queues |\n| `refillQueueEvent` | Backfill queue with events from local files |\n\n#### Replay Ingestion Events V2\n\nReplays S3-stored events back to Langfuse:\n\n- **Batch Processing**: Processes events in configurable batches\n- **Checkpoint Support**: Resume capability via checkpoint files\n- **Rate Limiting**: Respects server-side rate limits with exponential backoff\n- **Error Handling**: Retries transient failures, logs permanent failures\n\n资料来源：[worker/src/scripts/replayIngestionEventsV2/README.md](https://github.com/langfuse/langfuse/blob/main/worker/src/scripts/replayIngestionEventsV2/README.md)\n\n#### Refill Queue Event\n\nBackfills queues with events from local JSONL files:\n\n1. Create `./worker/events.jsonl` with one JSON event per line\n2. Configure Redis connection and supporting services\n3. Run via `pnpm run --filter=worker refill-queue-event`\n\n资料来源：[worker/src/scripts/refillQueueEvent/README.md](https://github.com/langfuse/langfuse/blob/main/worker/src/scripts/refillQueueEvent/README.md)\n\n## Public API Architecture\n\n### Adding New API Routes\n\nThe project follows a structured pattern for public API development:\n\n1. **Implementation**: Wrap routes with `withMiddleware` and `createAuthedAPIRoute`\n2. **Type Definition**: Add Zod types to `/features/public-api/types` using `coerce` for primitives\n3. **Validation**: Use `validateZodSchema` for response validation\n4. **Documentation**: Add to Fern with `docs` attributes\n5. **SDK Updates**: Copy types to Python and JS SDKs\n\n```typescript\n// Response type example\nconst responseSchema = z.object({\n  data: z.string(),\n  timestamp: z.coerce.date(),\n}).strict();\n```\n\n资料来源：[web/src/features/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/README.md)\n\n## Testing Infrastructure\n\n### Client-Side Testing\n\nTests use `.clienttest.ts` extension and are colocated with components:\n\n```bash\npnpm --filter=web run test-client --testPathPattern=\"ComponentName\"\n```\n\nExample: `AdvancedJsonViewer` tests cover tree building, navigation, expansion, and search operations.\n\n资料来源：[web/src/components/ui/AdvancedJsonViewer/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/ui/AdvancedJsonViewer/README.md)\n\n### Trace Tree Building Tests\n\nPerformance tests for large observation sets:\n\n| Scale | Threshold | Structure Types |\n|-------|-----------|-----------------|\n| 10k | 500ms | flat, deep, balanced, realistic |\n| 25k | 2s | flat, realistic |\n| 50k | 5s | flat, realistic |\n| 500k | 60s | realistic |\n\n资料来源：[web/src/components/trace/lib/tree-building.clienttest.ts](https://github.com/langfuse/langfuse/blob/main/web/src/components/trace/lib/tree-building.clienttest.ts)\n\n## Development Workflow\n\n### Component Development Guidelines\n\n1. **Use Page Wrapper**: Always wrap pages with `<Page>` component\n2. **Use ContainerPage**: For settings/setup pages with non-scalable content\n3. **Follow Naming**: Use `.clienttest.ts` for client-side tests\n4. **State Management**: Use `useSidebarFilterState` for filters, `useOrderByState` for sorting\n\n### Prompt Composition\n\nFor MCP prompt features:\n\n- **Resolved Prompt**: Use `getPrompt` for executable prompts with dependencies resolved\n- **Unresolved Prompt**: Use `getPromptUnresolved` for debugging and analysis\n\n资料来源：[web/src/features/mcp/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/mcp/README.md)\n\n## Summary\n\nThe Langfuse project is organized as a well-structured monorepo with clear separation between the frontend web application, backend worker services, and shared packages. The architecture emphasizes:\n\n- **Modularity**: Feature-based organization with isolated modules\n- **Performance**: Virtualization and incremental builds\n- **Type Safety**: Zod schemas and TypeScript throughout\n- **Observability**: Built-in tracing and analytics capabilities\n\n---\n\n<a id='quickstart-guide'></a>\n\n## Quickstart Guide\n\n### 相关页面\n\n相关主题：[Project Introduction](#project-introduction)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [README.md](https://github.com/langfuse/langfuse/blob/main/README.md)\n- [docker-compose.yml](https://github.com/langfuse/langfuse/blob/main/docker-compose.yml)\n- [CONTRIBUTING.md](https://github.com/langfuse/langfuse/blob/main/CONTRIBUTING.md)\n- [web/src/components/layouts/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/layouts/README.md)\n- [worker/src/scripts/refillQueueEvent/README.md](https://github.com/langfuse/langfuse/blob/main/worker/src/scripts/refillQueueEvent/README.md)\n- [web/src/features/slack/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/slack/README.md)\n</details>\n\n# Quickstart Guide\n\nLangfuse is an open-source LLM engineering platform that provides observability, analytics, and prompt management for LLM applications. This guide walks you through setting up a local development environment, understanding the core architecture, and deploying Langfuse for production use.\n\n## Overview\n\nLangfuse supports multiple deployment scenarios:\n\n| Deployment Type | Use Case | Key Components |\n|----------------|----------|----------------|\n| Local Development | Testing and development | Docker Compose with all services |\n| Self-Hosted | Production deployment | Docker/Kubernetes with externalized services |\n| Cloud | Managed SaaS offering | Langfuse-hosted infrastructure |\n\n资料来源：[README.md:1-20]()\n\n## Architecture Overview\n\nLangfuse consists of three main components:\n\n```mermaid\ngraph TD\n    A[Web UI] --> B[Server API]\n    B --> C[(PostgreSQL)]\n    B --> D[(ClickHouse)]\n    B --> E[(Redis)]\n    F[Workers] --> C\n    F --> D\n    F --> E\n    G[S3 Storage] --> F\n```\n\n### Core Components\n\n| Component | Purpose | Technology |\n|-----------|---------|------------|\n| `web/` | Frontend UI application | Next.js, React, TanStack |\n| `server/` | API server and business logic | Node.js, tRPC, Prisma |\n| `worker/` | Background job processing | BullMQ, Redis |\n| `clickhouse/` | Analytics storage | ClickHouse |\n\n资料来源：[docker-compose.yml:1-50]()\n\n## Local Development Setup\n\n### Prerequisites\n\n- Node.js 20+ (using pnpm as package manager)\n- Docker and Docker Compose\n- Git\n\n### 1. Clone the Repository\n\n```bash\ngit clone https://github.com/langfuse/langfuse.git\ncd langfuse\n```\n\n### 2. Environment Configuration\n\nCreate a `.env` file in the root directory with the following required variables:\n\n```bash\n# Database\nDATABASE_URL=postgresql://langfuse:langfuse@localhost:5432/langfuse\n\n# ClickHouse\nCLICKHOUSE_URL=http://localhost:8123\nCLICKHOUSE_USER=langfuse\nCLICKHOUSE_PASSWORD=langfuse\n\n# Redis\nREDIS_URL=redis://localhost:6379\n\n# Auth (NextAuth.js)\nNEXTAUTH_SECRET=your-secret-key\nNEXTAUTH_URL=http://localhost:3000\n\n# S3 Storage (MinIO for local dev)\nS3_ACCESS_KEY=langfuse\nS3_SECRET_KEY=langfuse\nS3_REGION=us-east-1\nS3_ENDPOINT_URL=http://localhost:9000\nS3_EVENT_UPLOAD_BUCKET=langfuse\n```\n\n资料来源：[docker-compose.yml:50-120]()\n\n### 3. Start Infrastructure Services\n\nLaunch all supporting services using Docker Compose:\n\n```bash\ndocker compose up -d\n```\n\nThis starts the following services:\n\n| Service | Port | Purpose |\n|---------|------|---------|\n| postgres | 5432 | Primary database |\n| clickhouse | 8123 | Analytics storage |\n| redis | 6379 | Job queue broker |\n| minio | 9000/9001 | S3-compatible storage |\n\n资料来源：[docker-compose.yml:120-180]()\n\n### 4. Install Dependencies\n\n```bash\npnpm install\n```\n\n### 5. Run Database Migrations\n\n```bash\npnpm db:migrate\n```\n\n### 6. Start Development Servers\n\nLangfuse uses a monorepo structure with multiple development servers:\n\n```bash\n# Start all services in development mode\npnpm run dev\n\n# Or start individual services\npnpm --filter=server run dev    # API server\npnpm --filter=web run dev       # Web UI\npnpm --filter=worker run dev    # Background workers\n```\n\n资料来源：[CONTRIBUTING.md:50-100]()\n\n## Project Structure\n\n```\nlangfuse/\n├── web/                      # Next.js frontend\n│   ├── src/\n│   │   ├── components/       # Reusable UI components\n│   │   ├── features/         # Feature modules\n│   │   ├── pages/            # Next.js pages\n│   │   └── lib/              # Utilities\n│   └── public/               # Static assets\n├── server/                   # API server\n│   ├── src/\n│   │   ├── api/              # tRPC routers\n│   │   ├── services/         # Business logic\n│   │   └── lib/              # Utilities\n├── worker/                   # Background workers\n│   └── src/\n│       ├── workers/          # Queue processors\n│       └── scripts/          # Utility scripts\n├── clickhouse/               # ClickHouse migrations\n└── docker-compose.yml        # Local infrastructure\n```\n\n### Page Component Pattern\n\nThe `Page` component is the standard wrapper for all pages in the application:\n\n```tsx\nimport Page from \"@/src/components/layouts/Page\";\n\nexport default function MyPage() {\n  return (\n    <Page\n      title=\"My Page\"\n      scrollable\n      headerProps={{\n        breadcrumb: [{ name: \"Home\", href: \"/\" }, { name: \"My Page\" }],\n      }}\n    >\n      <div>Content here...</div>\n    </Page>\n  );\n}\n```\n\n**Important**: Every page must be wrapped inside `<Page>`—do not use `<main>` directly.\n\n资料来源：[web/src/components/layouts/README.md:1-40]()\n\n## Development Workflow\n\n### Running Tests\n\nLangfuse uses different test patterns for client and server code:\n\n```bash\n# Run all tests\npnpm run test\n\n# Client-side tests (Vitest with .clienttest.ts extension)\npnpm --filter=web run test-client --testPathPattern=\"ComponentName\"\n\n# Server-side tests (Jest)\npnpm --filter=server run test\n```\n\n#### Client Test Pattern\n\nClient tests use stack-based iteration to avoid stack overflow:\n\n```typescript\n// ✅ Safe for deep trees - iterative approach\nfunction traverse(rootNode: TreeNode) {\n  const stack = [rootNode];\n  while (stack.length > 0) {\n    const node = stack.pop()!;\n    process(node);\n    node.children.forEach((child) => stack.push(child));\n  }\n}\n```\n\n资料来源：[web/src/components/ui/AdvancedJsonViewer/README.md:80-100]()\n\n### Debug Mode\n\nEnable detailed logging for specific components:\n\n```javascript\nlocalStorage.setItem(\"debug:AdvancedJsonViewer\", \"true\");\n```\n\n### Code Quality\n\n```bash\n# Lint code\npnpm run lint\n\n# Format code\npnpm run format\n\n# Type check\npnpm run typecheck\n```\n\n资料来源：[CONTRIBUTING.md:100-150]()\n\n## Feature Modules\n\nLangfuse organizes functionality into feature modules under `web/src/features/`:\n\n| Module | Purpose |\n|--------|---------|\n| `comments/` | User comments and mentions |\n| `entitlements/` | Feature access control |\n| `feature-flags/` | Feature toggle system |\n| `filters/` | Query filtering and search |\n| `mcp/` | Model Context Protocol integration |\n| `score-analytics/` | Score analytics and visualization |\n| `slack/` | Slack integration |\n| `migrations/` | Database migrations |\n\n### Feature Flags\n\nEnable experimental features using the `useIsFeatureEnabled` hook:\n\n```tsx\nconst isEnabled = useIsFeatureEnabled(\"feature-flag-name\");\n```\n\nA feature is enabled when:\n1. The flag is in `user.feature_flags`\n2. `LANGFUSE_ENABLE_EXPERIMENTAL_FEATURES` is set\n3. The user has admin privileges\n\n资料来源：[web/src/features/feature-flags/README.md:1-15]()\n\n### Entitlements System\n\nFeature availability is controlled through entitlements:\n\n- **Plans**: Tiers of features (`oss`, `cloud:pro`, `self-hosted:enterprise`)\n- **Entitlements**: Available features per plan (e.g., `playground`)\n- **EntitlementLimits**: Resource limits (e.g., `annotation-queue-count`)\n\n资料来源：[web/src/features/entitlements/README.md:1-25]()\n\n## Worker Scripts\n\nThe worker module includes utility scripts for data operations:\n\n### Refill Queue Event\n\nBackfill any queue with events from local machines:\n\n```bash\n# 1. Create events file (./worker/events.jsonl)\n{\"projectId\": \"project-123\", \"orgId\": \"org-456\"}\n\n# 2. Configure environment\nREDIS_CONNECTION_STRING=redis://:password@127.0.0.1:6379\nCLICKHOUSE_URL=http://localhost:8123\nCLICKHOUSE_USER=clickhouse\nCLICKHOUSE_PASSWORD=clickhouse\n\n# 3. Run the script\npnpm run --filter=worker refill-queue-event\n```\n\n资料来源：[worker/src/scripts/refillQueueEvent/README.md:1-40]()\n\n### Replay Ingestion Events V2\n\nRe-process S3-stored ingestion events:\n\n```bash\nnpx tsx worker/src/scripts/replayIngestionEventsV2/index.ts \\\n  --input=/path/to/events.csv \\\n  --batch-size=500 \\\n  --concurrency=4\n```\n\n| Parameter | Default | Description |\n|-----------|---------|-------------|\n| `--input` | - | Path to CSV file (required) |\n| `--batch-size` | 500 | Keys per API request |\n| `--concurrency` | 4 | Parallel API requests |\n| `--rate-limit` | 50 | Requests per second |\n| `--dry-run` | false | Validate without sending |\n| `--resume` | false | Continue from checkpoint |\n\n资料来源：[worker/src/scripts/replayIngestionEventsV2/README.md:1-50]()\n\n## Slack Integration Setup\n\nFor local Slack OAuth development, HTTPS is required:\n\n### 1. Generate SSL Certificates\n\n```bash\n# Install mkcert\nbrew install mkcert\nmkcert -install\nmkcert localhost 127.0.0.1\n\n# Move certificates to web directory\nmv localhost+1*.pem web/\n```\n\n### 2. Configure Environment\n\n```bash\nSLACK_CLIENT_ID=your_client_id\nSLACK_CLIENT_SECRET=your_client_secret\nSLACK_STATE_SECRET=your_state_secret\n```\n\n### 3. Start HTTPS Server\n\n```bash\npnpm run dev:https\n```\n\n资料来源：[web/src/features/slack/README.md:1-50]()\n\n## Production Deployment\n\n### Docker Compose Production Mode\n\nFor production, use externalized services:\n\n```yaml\nservices:\n  web:\n    image: langfuse/langfuse-web:latest\n    environment:\n      - DATABASE_URL=${DATABASE_URL}\n      - CLICKHOUSE_URL=${CLICKHOUSE_URL}\n      - REDIS_URL=${REDIS_URL}\n      - NEXTAUTH_SECRET=${NEXTAUTH_SECRET}\n      - S3_ACCESS_KEY=${S3_ACCESS_KEY}\n      - S3_SECRET_KEY=${S3_SECRET_KEY}\n    ports:\n      - \"3000:3000\"\n\n  server:\n    image: langfuse/langfuse-server:latest\n    # Configuration similar to web\n\n  worker:\n    image: langfuse/langfuse-worker:latest\n    depends_on:\n      - redis\n      - postgres\n      - clickhouse\n```\n\n### S3 Event Storage\n\nConfigure S3 bucket for event storage:\n\n```sql\n-- Example: Create external table for S3 access logs\nCREATE EXTERNAL TABLE s3_access_logs (\n  bucketowner STRING,\n  bucket_name STRING,\n  requestdatetime STRING,\n  remoteip STRING,\n  requester STRING,\n  requestid STRING,\n  operation STRING,\n  key STRING,\n  uri STRING,\n  statuscode INT,\n  errorcode STRING,\n  bytessent BIGINT,\n  objectsize BIGINT,\n  totaltime STRING,\n  turnaroundtime STRING\n)\nROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.RegexSerDe'\nWITH SERDEPROPERTIES (\n  'input.regex'='([^ ]*) ([^ ]*) \\\\[(.*?)\\\\] ([^ ]*) ([^ ]*) ...'\n)\nSTORED AS INPUTFORMAT 'org.apache.hadoop.mapred.TextInputFormat'\nLOCATION 's3://your-bucket/logs/'\n```\n\n资料来源：[docker-compose.yml:180-220]()\n\n## Common Issues and Solutions\n\n| Issue | Solution |\n|-------|----------|\n| Stack overflow in tree operations | Use iterative algorithms with explicit stacks |\n| Large dataset performance | Enable virtualization (TanStack Virtual) |\n| Horizontal scroll performance | Avoid wrap mode for wide datasets |\n| Multiple tables in peek view | Share pagination state intentionally |\n\n资料来源：[web/src/components/ui/AdvancedJsonViewer/README.md:40-60]()\n\n## Next Steps\n\nAfter setting up your development environment:\n\n1. **Explore the UI** - Navigate through traces, observations, and evaluations\n2. **Integrate SDK** - Connect your LLM application using [Langfuse Python/JS SDK](https://langfuse.com/docs)\n3. **Configure Features** - Set up feature flags and entitlements for your organization\n4. **Deploy** - Move to production using Docker Compose or Kubernetes\n\n资料来源：[CONTRIBUTING.md:1-50]()\n\n---\n\n<a id='system-architecture'></a>\n\n## System Architecture\n\n### 相关页面\n\n相关主题：[Project Structure](#project-structure), [Database Schema (Prisma)](#database-schema), [Queue System (Redis/BullMQ)](#queue-system)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [packages/shared/src/server/clickhouse/client.ts](https://github.com/langfuse/langfuse/blob/main/packages/shared/src/server/clickhouse/client.ts)\n- [packages/shared/src/server/redis/redis.ts](https://github.com/langfuse/langfuse/blob/main/packages/shared/src/server/redis/redis.ts)\n- [packages/shared/src/db.ts](https://github.com/langfuse/langfuse/blob/main/packages/shared/src/db.ts)\n- [packages/shared/src/server/otel/index.ts](https://github.com/langfuse/langfuse/blob/main/packages/shared/src/server/otel/index.ts)\n- [web/src/components/layouts/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/layouts/README.md)\n- [web/src/components/design-system/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/design-system/README.md)\n- [web/src/components/table/peek/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/table/peek/README.md)\n- [web/src/features/entitlements/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/entitlements/README.md)\n- [packages/shared/src/features/scores/interfaces/README.md](https://github.com/langfuse/langfuse/blob/main/packages/shared/src/features/scores/interfaces/README.md)\n- [worker/src/scripts/replayIngestionEventsV2/README.md](https://github.com/langfuse/langfuse/blob/main/worker/src/scripts/replayIngestionEventsV2/README.md)\n</details>\n\n# System Architecture\n\nLangfuse is a comprehensive observability and analytics platform designed for Large Language Model (LLM) applications. The system architecture is built on a modern, modular design that separates concerns across frontend, backend worker services, and shared infrastructure layers.\n\n## Overview\n\nLangfuse follows a distributed architecture pattern with the following primary components:\n\n| Layer | Technology Stack | Purpose |\n|-------|-----------------|---------|\n| Frontend | Next.js, React, TypeScript | User interface and visualization |\n| Backend Worker | Node.js, BullMQ, TypeScript | Event processing and queue management |\n| Shared Packages | TypeScript | Common utilities, types, and infrastructure clients |\n| Database | PostgreSQL | Primary data storage |\n| Cache/Queue | Redis | Queue management and caching |\n| Analytics | ClickHouse | High-performance analytics queries |\n| Observability | OpenTelemetry | Distributed tracing |\n\n## High-Level Architecture\n\n```mermaid\ngraph TD\n    subgraph Client[\"Frontend (Next.js)\"]\n        UI[User Interface]\n        Pages[Page Components]\n        DesignSystem[Design System]\n    end\n    \n    subgraph Shared[\"Shared Packages\"]\n        DB[(PostgreSQL)]\n        Redis[(Redis)]\n        ClickHouse[(ClickHouse)]\n        Otel[OpenTelemetry]\n    end\n    \n    subgraph Backend[\"Worker Service\"]\n        Queues[Queue Workers]\n        Scripts[Utility Scripts]\n    end\n    \n    Client <-->|tRPC API| Shared\n    Backend <-->|Event Processing| Shared\n    Client -->|Ingestion| Backend\n```\n\n## Infrastructure Layer\n\n### Database Connection\n\nThe PostgreSQL database is the central data store for Langfuse, managed through a shared database client module. The connection is centralized in the `packages/shared/src/db.ts` module, which provides a unified interface for all database operations across the application.\n\n资料来源：[packages/shared/src/db.ts:1-50]()\n\n### Redis Client\n\nRedis serves dual purposes in the Langfuse architecture:\n\n1. **Queue Management**: BullMQ queues for asynchronous event processing\n2. **Caching**: Session and temporary data caching\n\nThe Redis client is configured in `packages/shared/src/server/redis/redis.ts` and is shared across worker services.\n\n资料来源：[packages/shared/src/server/redis/redis.ts:1-30]()\n\n### ClickHouse Integration\n\nClickHouse provides the analytical query engine for high-performance aggregations. The client is initialized in `packages/shared/src/server/clickhouse/client.ts` and is primarily used for:\n\n- Score analytics aggregations\n- Time-series data analysis\n- Large dataset transformations\n\n资料来源：[packages/shared/src/server/clickhouse/client.ts:1-40]()\n\n### OpenTelemetry\n\nThe OpenTelemetry integration (`packages/shared/src/server/otel/index.ts`) provides distributed tracing across all services. This enables:\n\n- Request tracing across frontend and backend\n- Event processing workflow visibility\n- Performance monitoring\n\n资料来源：[packages/shared/src/server/otel/index.ts:1-60]()\n\n## Frontend Architecture\n\n### Page Structure\n\nAll frontend pages use a standardized layout system defined in `web/src/components/layouts/`. The `Page` component is the required wrapper for all application pages, ensuring consistent layout behavior.\n\nKey layout patterns:\n\n| Pattern | Component | Use Case |\n|---------|-----------|----------|\n| Standard Pages | `Page` | Most application pages |\n| Wide Content | `ContainerPage` | Settings, setup pages with wide content |\n\nThe page wrapper provides:\n- Sticky header management\n- Scroll behavior control (`content-scroll` or `page-scroll`)\n- Breadcrumb navigation\n- Custom header actions\n\n资料来源：[web/src/components/layouts/README.md:1-60]()\n\n### Design System\n\nThe design system (`web/src/components/design-system/`) provides primitive, reusable UI components following strict architectural principles:\n\n**Principles:**\n- Presentational only (no business logic)\n- Explicit, strictly typed APIs\n- Props over context (no React Context)\n\n**Component Structure:**\n```\ndesign-system/\n  Button/\n    Button.tsx\n    Button.stories.tsx\n```\n\n**Styling Rules:**\n- No arbitrary CSS values\n- Explicit enums for variants (`size: \"sm\" | \"md\" | \"lg\"`)\n- CVA (Class Variance Authority) for variant management\n- Boolean props use positive naming (`isLoading`, `shouldTruncate`)\n\n资料来源：[web/src/components/design-system/README.md:1-80]()\n\n### State Management Patterns\n\nLangfuse uses a sophisticated state management approach with the Peek Table State system:\n\n```mermaid\ngraph TD\n    A[Page Load] --> B{Peek Context?}\n    B -->|Yes| C[PeekTableStateProvider]\n    B -->|No| D[URL/Session State]\n    C --> E[Table State Preserved]\n    D --> F[Standard State]\n    \n    E --> G[K/J Navigation]\n    G --> H[State Retained ✓]\n```\n\nThe `PeekTableStateProvider` maintains table state (filters, sorting, pagination) across K/J keyboard navigation between items of the same type. State resets only when the peek view closes.\n\n资料来源：[web/src/components/table/peek/README.md:1-100]()\n\n## Feature Modules\n\n### Entitlements System\n\nThe entitlements feature controls feature availability at the organization level:\n\n| Concept | Definition |\n|---------|------------|\n| Plan | Feature tier (OSS, cloud:pro, self-hosted:enterprise) |\n| Entitlement | Available feature (e.g., playground, score analytics) |\n| EntitlementLimit | Resource limits (e.g., annotation-queue-count) |\n\n**Plan Resolution:**\n- Cloud: Added to organization via JWT from NextAuth\n- Self-hosted: From license key or environment configuration\n\n资料来源：[web/src/features/entitlements/README.md:1-50]()\n\n### Score Analytics\n\nThe score analytics feature provides comprehensive statistical analysis of evaluation scores:\n\n**Architecture Components:**\n\n| Component | Location | Responsibility |\n|-----------|----------|----------------|\n| Provider | `ScoreAnalyticsProvider.tsx` | Context management |\n| Hook | `useScoreAnalyticsQuery` | Data fetching and transformation |\n| Transformers | `scoreAnalyticsTransformers.ts` | Data transformation pipeline |\n| Router | `scoreAnalyticsRouter.ts` | tRPC API endpoint |\n\n**Data Flow:**\n```mermaid\ngraph LR\n    A[API Request] --> B[tRPC Router]\n    B --> C[ClickHouse Query]\n    C --> D[Transformers]\n    D --> E[ScoreAnalyticsProvider]\n    E --> F[Chart Components]\n```\n\n资料来源：[packages/shared/src/features/scores/interfaces/README.md:1-80]()\n资料来源：[web/src/features/score-analytics/README.md:1-100]()\n\n### Score Interfaces Architecture\n\nLangfuse maintains a versioned API structure for scores:\n\n```\ninterfaces/\n├── api/\n│   ├── v1/    # Legacy API (trace-focused)\n│   ├── v2/    # Current API (supports traces, sessions)\n│   └── shared.ts\n├── application/\n├── ingestion/\n└── ui/\n```\n\n**API Versioning Strategy:**\n- POST/DELETE APIs: Support all score types across v1 and v2\n- GET APIs:\n  - V1: Requires `traceId`, trace-level only\n  - V2: `traceId` optional, adds `sessionId` support\n\n资料来源：[packages/shared/src/features/scores/interfaces/README.md:1-50]()\n\n## Backend Worker Architecture\n\n### Event Processing\n\nThe worker service processes ingestion events asynchronously using BullMQ queues:\n\n**Queue Types:**\n| Queue | Purpose | Consumer |\n|-------|---------|----------|\n| `IngestionSecondaryQueue` | Standard event processing | Worker |\n| `OtelIngestionQueue` | OpenTelemetry events | Worker |\n\n**Event Flow:**\n```mermaid\ngraph LR\n    A[Ingestion API] --> B{Event Type?}\n    B -->|Standard| C[S3 Key Parse]\n    B -->|OTEL| D[OTEL Key Parse]\n    C --> E[Queue Payload]\n    D --> E\n    E --> F[BullMQ]\n    F --> G[Worker Processing]\n    G --> H[(ClickHouse)]\n    G --> I[(PostgreSQL)]\n```\n\n资料来源：[worker/src/scripts/replayIngestionEventsV2/README.md:1-60]()\n\n### Replay Ingestion Events V2\n\nThe `replayIngestionEventsV2` script enables replaying historical events from S3 storage:\n\n**Key Features:**\n- Batch processing with configurable size\n- Checkpoint/resume capability\n- Rate limiting with exponential backoff\n- Error handling with detailed logging\n\n**Differences from V1:**\n\n| Aspect | V1 | V2 |\n|--------|----|----|\n| Infrastructure | Redis, ClickHouse, PostgreSQL, S3 | Langfuse host URL only |\n| Setup | Full repo clone + `.env` | `npx tsx` + env vars |\n| Event Delivery | BullMQ `addBulk` to Redis | HTTP POST to admin API |\n| Resume | Manual | Built-in checkpoint |\n\n**Event Transformation:**\n- Standard keys: `{projectId}/{type}/{eventBodyId}/{eventId}.json`\n- OTEL keys: `otel/{projectId}/{yyyy}/{mm}/{dd}/{hh}/{mm}/{eventId}.json`\n\n资料来源：[worker/src/scripts/replayIngestionEventsV2/README.md:1-120]()\n\n### Refill Queue Event\n\nThe `refillQueueEvent` utility script backfills queues with events from local files:\n\n**Usage Pattern:**\n```bash\npnpm run --filter=worker refill-queue-event\n```\n\n**Requirements:**\n- `./worker/events.jsonl` file with JSON events\n- Redis connection via `REDIS_CONNECTION_STRING`\n- Supporting services: S3, ClickHouse\n\n资料来源：[worker/src/scripts/refillQueueEvent/README.md:1-60]()\n\n## MCP Server Architecture\n\nLangfuse includes an MCP (Model Context Protocol) server for programmatic prompt management:\n\n**Stateless Design:**\n1. Fresh server instance per request\n2. Authentication context captured in handler closures\n3. Server discarded after request completes\n4. No state between requests\n\n**Available Tools:**\n| Tool | Purpose |\n|------|---------|\n| `getPrompt` | Fetch resolved prompt with dependencies |\n| `getPromptUnresolved` | Fetch raw prompt without resolution |\n| `listPrompts` | List prompts with filtering |\n| `createTextPrompt` | Create text prompt version |\n| `createChatPrompt` | Create chat prompt version |\n| `updatePromptLabels` | Manage prompt labels |\n\n**Prompt Resolution:**\n- Resolved: Recursively replaces `@@@langfusePrompt:...@@@` tags\n- Unresolved: Returns raw content with tags intact\n\n资料来源：[web/src/features/mcp/README.md:1-100]()\n\n## Component Communication Flow\n\n```mermaid\ngraph TD\n    subgraph Pages[\"Page Layer\"]\n        P[Page Component]\n        PC[PeekTableStateProvider]\n    end\n    \n    subgraph Features[\"Feature Layer\"]\n        FP[Feature Provider]\n        FH[Feature Hook]\n        FT[Feature Transformers]\n    end\n    \n    subgraph Services[\"Service Layer\"]\n        TRPC[tRPC Router]\n        API[API Routes]\n    end\n    \n    subgraph Data[\"Data Layer\"]\n        Repo[Repositories]\n        DB[(PostgreSQL)]\n        CH[(ClickHouse)]\n        Redis[(Redis)]\n    end\n    \n    P --> PC\n    PC --> FP\n    FP --> FH\n    FH --> FT\n    FT --> TRPC\n    TRPC --> Repo\n    Repo --> DB\n    Repo --> CH\n    Repo --> Redis\n```\n\n## Configuration Management\n\nLangfuse uses environment-based configuration across layers:\n\n| Environment | Scope | Examples |\n|-------------|-------|----------|\n| `REDIS_CONNECTION_STRING` | Worker, Queue | Redis URL |\n| `CLICKHOUSE_URL` | Analytics | ClickHouse connection |\n| `LANGFUSE_S3_EVENT_UPLOAD_BUCKET` | Storage | S3 bucket name |\n| `ADMIN_API_KEY` | Admin API | Authentication |\n\n## Security Architecture\n\n**Key Security Components:**\n\n1. **JWT Authentication**: Organization and user context embedded in JWT tokens\n2. **API Key Validation**: Admin API uses dedicated key authentication\n3. **Scope-based Authorization**: Project-level access control\n4. **Plan Entitlements**: Feature availability based on subscription tier\n\n**Self-hosted Considerations:**\n- License key validation for enterprise features\n- Environment-based plan override capability\n\n## Performance Optimizations\n\n**Frontend Optimizations:**\n- Memoized transformations in hooks\n- Virtualized table rendering (TanStack Virtual)\n- Iterative algorithms (no recursion, preventing stack overflow)\n\n**Backend Optimizations:**\n- Batch processing for event replay\n- Checkpoint/resume for long-running operations\n- Client-side rate limiting with exponential backoff\n\n## Summary\n\nThe Langfuse architecture demonstrates a well-structured approach to observability platforms:\n\n- **Separation of Concerns**: Clear boundaries between UI, business logic, and data layers\n- **Scalability**: Asynchronous processing via queues enables horizontal scaling\n- **Extensibility**: Feature modules and MCP server support programmatic access\n- **Observability**: Built-in OpenTelemetry integration for distributed tracing\n- **Performance**: ClickHouse for analytics, iterative algorithms, and batch processing\n\n---\n\n<a id='monorepo-structure'></a>\n\n## Monorepo Configuration\n\n### 相关页面\n\n相关主题：[Project Structure](#project-structure), [System Architecture](#system-architecture)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [turbo.json](https://github.com/langfuse/langfuse/blob/main/turbo.json)\n- [packages/config-eslint/index.js](https://github.com/langfuse/langfuse/blob/main/packages/config-eslint/index.js)\n- [packages/config-typescript/base.json](https://github.com/langfuse/langfuse/blob/main/packages/config-typescript/base.json)\n- [packages/shared/tsconfig.json](https://github.com/langfuse/langfuse/blob/main/packages/shared/tsconfig.json)\n- [web/package.json](https://github.com/langfuse/langfuse/blob/main/web/package.json)\n- [worker/src/scripts/replayIngestionEventsV2/README.md](https://github.com/langfuse/langfuse/blob/main/worker/src/scripts/replayIngestionEventsV2/README.md)\n</details>\n\n# Monorepo Configuration\n\nLangfuse uses a **monorepo architecture** managed with [Turborepo](https://turbo.build/), [pnpm](https://pnpm.io/) workspaces, and shared configuration packages. This setup enables efficient builds, consistent code quality standards, and streamlined dependency management across the project's multiple packages.\n\n## Architecture Overview\n\nThe Langfuse repository is organized as a pnpm workspace monorepo with the following core structure:\n\n```yaml\nlangfuse/\n├── web/                    # Next.js frontend application\n├── worker/                 # Background job processing\n├── packages/\n│   ├── shared/            # Shared utilities and types\n│   ├── config-eslint/     # Shared ESLint configuration\n│   └── config-typescript/ # Shared TypeScript configurations\n├── turbo.json             # Turborepo pipeline definition\n└── pnpm-workspace.yaml    # Workspace package definitions\n```\n\n## Turborepo Pipeline Configuration\n\nThe `turbo.json` file defines the build pipeline and task orchestration across packages.\n\n### Core Pipeline Tasks\n\n| Task | Description | Cache Strategy |\n|------|-------------|----------------|\n| `build` | Compiles TypeScript and bundles assets | Enabled |\n| `dev` | Starts development servers | Local only |\n| `test` | Runs unit and integration tests | Enabled |\n| `lint` | ESLint code quality checks | Enabled |\n| `typecheck` | TypeScript type validation | Enabled |\n\n### Task Dependencies\n\nTurborepo automatically resolves dependencies between packages. For example:\n\n```mermaid\ngraph TD\n    A[packages/shared] -->|build| B[Type definitions]\n    B --> C[packages/config-*]\n    C --> D[web]\n    C --> E[worker]\n    D --> F[Build output]\n    E --> F\n```\n\n## Shared ESLint Configuration\n\nThe `packages/config-eslint/index.js` provides standardized ESLint rules across all packages.\n\n### Configuration Features\n\n- **React/Next.js support** for the web application\n- **TypeScript-aware linting** via `@typescript-eslint`\n- **Import ordering** rules for consistent module organization\n- **JSX accessibility** checks\n\n### Usage\n\nPackages extend the shared configuration:\n\n```javascript\n// In package's .eslintrc.js\nmodule.exports = {\n  extends: ['@langfuse/config-eslint'],\n  // Package-specific overrides\n  rules: {\n    // Custom rules\n  }\n};\n```\n\n资料来源：[packages/config-eslint/index.js]()\n\n## Shared TypeScript Configuration\n\nThe `packages/config-typescript/` directory contains base TypeScript configurations.\n\n### Base Configuration (`base.json`)\n\n```json\n{\n  \"compilerOptions\": {\n    \"target\": \"ES2020\",\n    \"module\": \"ESNext\",\n    \"moduleResolution\": \"bundler\",\n    \"strict\": true,\n    \"esModuleInterop\": true,\n    \"skipLibCheck\": true,\n    \"forceConsistentCasingInFileNames\": true\n  }\n}\n```\n\n### Package-Specific Configurations\n\nIndividual packages extend the base configuration:\n\n```json\n// packages/shared/tsconfig.json\n{\n  \"extends\": \"@langfuse/config-typescript/base.json\",\n  \"compilerOptions\": {\n    \"outDir\": \"./dist\",\n    \"rootDir\": \"./src\"\n  },\n  \"include\": [\"src/**/*\"],\n  \"exclude\": [\"node_modules\", \"dist\"]\n}\n```\n\n资料来源：[packages/config-typescript/base.json](), [packages/shared/tsconfig.json]()\n\n## Package Scripts and Commands\n\nEach package defines its own scripts in `package.json`. The web package demonstrates the typical pattern:\n\n### Build Commands\n\n| Command | Purpose |\n|---------|---------|\n| `pnpm build` | Production build with `INLINE_RUNTIME_CHUNK=false` |\n| `pnpm build:check` | Build without emitting (type-checking) |\n| `pnpm dev` | Development server on localhost:3000 |\n| `pnpm dev:http` | HTTPS development server for local testing |\n\n### Quality Assurance Commands\n\n| Command | Purpose |\n|---------|---------|\n| `pnpm lint` | ESLint with caching enabled |\n| `pnpm lint:fix` | Auto-fix linting issues |\n| `pnpm typecheck` | TypeScript validation with incremental compilation |\n| `pnpm test` | Vitest with server and in-source test projects |\n\n资料来源：[web/package.json]()\n\n## Development Workflow\n\n### Starting Development\n\n```bash\n# Install dependencies\npnpm install\n\n# Start all dev servers based on turbo.json\npnpm dev\n\n# Or start a specific package\ncd web && pnpm dev\n```\n\n### Running Tests\n\n```bash\n# All tests\npnpm test\n\n# Client-side tests only (e.g., AdvancedJsonViewer)\npnpm --filter=web run test-client --testPathPattern=\"AdvancedJsonViewer\"\n\n# Server-side tests\npnpm --filter=web run test --project server\n```\n\n### Build Pipeline\n\n```mermaid\ngraph LR\n    A[pnpm build] --> B[turbo build]\n    B --> C{Cache hit?}\n    C -->|Yes| D[Use cached output]\n    C -->|No| E[Build dependencies]\n    E --> F[packages/shared]\n    F --> G[packages/config-*]\n    G --> H[web/worker]\n    H --> I[Save to cache]\n    I --> J[Build artifacts]\n```\n\n## Environment Configuration\n\nThe project uses `.env` files for environment-specific configuration:\n\n| File | Purpose |\n|------|---------|\n| `.env` | Default environment variables |\n| `.env.local` | Local overrides (git-ignored) |\n| `.env.test` | Test environment variables |\n\nScripts use `dotenv` to load these files:\n\n```bash\ndotenv -e ../.env -- next build\ndotenv -e ../.env.test -e ../.env -- vitest run\n```\n\n资料来源：[worker/src/scripts/replayIngestionEventsV2/README.md]()\n\n## Best Practices\n\n### Adding a New Package\n\n1. Create the package under `packages/` or `web/` directories\n2. Extend the shared TypeScript and ESLint configurations\n3. Add the package to `pnpm-workspace.yaml` if needed\n4. Define tasks in `turbo.json` if custom pipeline is required\n5. Add appropriate scripts to `package.json`\n\n### Caching Strategy\n\n- **Build caching**: Enabled by default via Turborepo\n- **Lint caching**: ESLint caches to `.next/cache/eslint/`\n- **TypeScript incremental**: Uses `.tsbuildinfo` files\n\n### CI/CD Integration\n\nIn CI environments, clear caches to ensure fresh builds:\n\n```bash\n# Clear turbo cache\nrm -rf .turbo node_modules/.cache\n\n# Clear ESLint cache\nrm -rf .next/cache/eslint/\n\n# Fresh build\npnpm install --frozen-lockfile\npnpm build\n```\n\n## Key Configuration Files Summary\n\n| File | Purpose |\n|------|---------|\n| `turbo.json` | Task pipeline and dependency graph |\n| `pnpm-workspace.yaml` | Workspace package definitions |\n| `packages/config-eslint/index.js` | Shared ESLint rules |\n| `packages/config-typescript/base.json` | Shared TypeScript base config |\n| `.eslintrc.js` (per package) | Package-specific lint overrides |\n| `tsconfig.json` (per package) | Package-specific TypeScript config |\n\n---\n\n<a id='database-schema'></a>\n\n## Database Schema (Prisma)\n\n### 相关页面\n\n相关主题：[System Architecture](#system-architecture), [ClickHouse Analytics Layer](#clickhouse-analytics)\n\n<details>\n<summary>Relevant Source Files</summary>\n\n以下源码文件用于生成本页说明：\n\n- [packages/shared/prisma/schema.prisma](https://github.com/langfuse/langfuse/blob/main/packages/shared/prisma/schema.prisma)\n- [packages/shared/src/server/repositories/traces.ts](https://packages/shared/src/server/repositories/traces.ts)\n- [packages/shared/src/server/repositories/observations.ts](https://packages/shared/src/server/repositories/observations.ts)\n- [packages/shared/src/server/repositories/scores.ts](https:///packages/shared/src/server/repositories/scores.ts)\n- [packages/shared/src/features/scores/interfaces/README.md](https://github.com/langfuse/langfuse/blob/main/packages/shared/src/features/scores/interfaces/README.md)\n</details>\n\n# Database Schema (Prisma)\n\n## Overview\n\nLangfuse uses Prisma ORM to manage its PostgreSQL database schema. The schema defines the core data models for the application, including organizations, projects, users, traces, observations, and scores. Prisma serves as the primary interface between the application's business logic and the relational database.\n\nThe Prisma schema is located at `packages/shared/prisma/schema.prisma` and is shared across multiple packages in the monorepo structure. This centralized schema approach ensures consistency in data modeling across the web application, worker services, and shared libraries.\n\n### Design Philosophy\n\nThe schema follows several key principles:\n\n- **Normalized relationships**: Related entities are linked through foreign keys with proper cascading behaviors\n- **Soft deletes**: Key entities support soft deletion for data recovery and audit purposes\n- **Audit fields**: Most tables include `createdAt`, `updatedAt`, and `createdBy` fields\n- **Multi-tenancy**: The schema supports multi-tenant architecture with organization and project isolation\n- **Extensible metadata**: JSON fields allow flexible storage of custom attributes\n\n## Core Data Models\n\n### Organization and User Models\n\nThe foundation of Langfuse's multi-tenant architecture begins with the `Organization` model, which represents the top-level tenant entity. Each organization can have multiple users with different roles and permission levels.\n\nThe `User` model stores authentication and profile information, linked to organizations through the `Membership` junction table. This many-to-many relationship enables users to belong to multiple organizations with potentially different roles in each.\n\n```mermaid\nerDiagram\n    Organization ||--o{ User : \"contains\"\n    Organization ||--o{ Project : \"contains\"\n    User ||--o{ Membership : \"has\"\n    Membership }o--|| Organization : \"belongs to\"\n    Membership }o--|| User : \"belongs to\"\n```\n\n### Project Model\n\nProjects serve as the primary container for observability data. Each project belongs to exactly one organization and contains all traces, observations, and scores related to a specific application or use case.\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `id` | `String` | UUID primary key |\n| `name` | `String` | Project display name |\n| `organizationId` | `String` | Foreign key to organization |\n| `createdAt` | `DateTime` | Creation timestamp |\n| `updatedAt` | `DateTime` | Last modification timestamp |\n| `deletedAt` | `DateTime?` | Soft delete timestamp |\n| `settings` | `Json` | Project-specific configuration |\n\n资料来源：[packages/shared/prisma/schema.prisma]()\n\n## Traces\n\nTraces represent the top-level unit of observability in Langfuse. A trace encapsulates a complete interaction or request, typically corresponding to a single LLM call or a multi-step workflow.\n\n### Trace Model Schema\n\n```prisma\nmodel Trace {\n  id            String   @id @default(cuid())\n  name          String?\n  project       Project  @relation(fields: [projectId], references: [id])\n  projectId     String\n  user          String?\n  metadata      Json?\n  sessionId     String?\n  release       String?\n  version       String?\n  tags          String[]\n  \n  // Timestamps\n  createdAt     DateTime @default(now())\n  updatedAt     DateTime @updatedAt\n  \n  // Soft delete\n  deletedAt     DateTime?\n  \n  // Relations\n  observations  Observation[]\n  scores        Score[]\n  \n  @@index([projectId])\n  @@index([sessionId])\n  @@index([createdAt])\n}\n```\n\n资料来源：[packages/shared/prisma/schema.prisma]()\n\n### Key Fields\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `id` | `String` | Unique identifier using CUID algorithm |\n| `name` | `String?` | Optional human-readable trace name |\n| `projectId` | `String` | Reference to parent project |\n| `user` | `String?` | Identifier for the end user |\n| `sessionId` | `String?` | Groups related traces into sessions |\n| `release` | `String?` | Application release version |\n| `version` | `String?` | Trace format version |\n| `tags` | `String[]` | Array of string tags for categorization |\n\n### Repository Pattern\n\nTraces are accessed through the repository pattern defined in `packages/shared/src/server/repositories/traces.ts`. This abstraction provides a clean interface for CRUD operations while encapsulating query logic.\n\n资料来源：[packages/shared/src/server/repositories/traces.ts]()\n\n```typescript\n// Repository interface pattern (simplified)\ninterface ITraceRepository {\n  create(data: CreateTraceInput): Promise<Trace>;\n  getById(id: string, projectId: string): Promise<Trace | null>;\n  list(projectId: string, options?: ListTracesOptions): Promise<Trace[]>;\n  update(id: string, data: UpdateTraceInput): Promise<Trace>;\n  softDelete(id: string): Promise<void>;\n}\n```\n\n## Observations\n\nObservations represent the individual components within a trace, such as LLM calls, retrievals, or custom events. They form a hierarchical structure that can be nested to represent complex workflows.\n\n### Observation Model Schema\n\n```prisma\nmodel Observation {\n  id            String   @id @default(cuid())\n  \n  // Type discrimination\n  type          ObservationType\n  \n  // Relations\n  trace         Trace    @relation(fields: [traceId], references: [id])\n  traceId       String\n  parent        Observation? @relation(\"ObservationHierarchy\", fields: [parentId], references: [id])\n  parentId      String?\n  children      Observation[] @relation(\"ObservationHierarchy\")\n  \n  // Project reference for efficient querying\n  projectId     String\n  \n  // Core data\n  name          String?\n  startTime     DateTime\n  endTime       DateTime?\n  status        String?\n  metadata      Json?\n  \n  // LLM-specific fields\n  model         String?\n  modelId       String?\n  provider      String?\n  promptTokens  Int?\n  completionTokens Int?\n  totalTokens   Int?\n  unitPrice     Float?\n  currency      String?\n  calculatedUnitCost Float?\n  \n  // Retrieval-specific fields\n  input         Json?\n  output        Json?\n  \n  // Timestamps\n  createdAt     DateTime @default(now())\n  updatedAt     DateTime @updatedAt\n  \n  // Soft delete\n  deletedAt     DateTime?\n  \n  @@index([traceId])\n  @@index([projectId])\n  @@index([startTime])\n}\n```\n\n资料来源：[packages/shared/prisma/schema.prisma]()\n资料来源：[packages/shared/src/server/repositories/observations.ts]()\n\n### Observation Types\n\nLangfuse supports several observation types through an enum:\n\n| Type | Description |\n|------|-------------|\n| `CHAT` | Chat completion calls |\n| `GENERATION` | Text generation calls |\n| `RETRIEVAL` | Retrieval augmented generation steps |\n| `EVENT` | Custom events and markers |\n| `TOOL` | Tool/function calls |\n\n### Hierarchical Structure\n\nObservations support nested hierarchies through self-referential relationships. This enables representing complex multi-step workflows where parent observations contain child observations representing sub-tasks or parallel operations.\n\n```mermaid\ngraph TD\n    A[Trace] --> B[Observation: Chat]\n    B --> C[Observation: Retrieval]\n    B --> D[Observation: Generation]\n    C --> E[Observation: Event: Cache Hit]\n    D --> F[Observation: Tool: Calculator]\n    D --> G[Observation: Tool: Search]\n```\n\n资料来源：[packages/shared/prisma/schema.prisma]()\n\n## Scores\n\nScores provide a mechanism for evaluating trace and observation quality. They can be human-generated or automated evaluations attached to specific traces or observations.\n\n### Score Model Schema\n\n```prisma\nmodel Score {\n  id            String   @id @default(cuid())\n  \n  // Target discrimination\n  traceId       String?\n  observationId String?\n  \n  // Project reference\n  projectId     String\n  \n  // Score data\n  name          String\n  value         Float\n  dataType      ScoreDataType\n  comment       String?\n  \n  // Source tracking\n  source        String?\n  \n  // Author\n  authorId      String?\n  \n  // Timestamps\n  createdAt     DateTime @default(now())\n  updatedAt     DateTime @updatedAt\n  \n  // Relations\n  trace         Trace?      @relation(fields: [traceId], references: [id])\n  observation   Observation? @relation(fields: [observationId], references: [id])\n  \n  @@index([projectId])\n  @@index([traceId])\n  @@index([observationId])\n  @@index([name, createdAt])\n}\n```\n\n资料来源：[packages/shared/prisma/schema.prisma]()\n资料来源：[packages/shared/src/server/repositories/scores.ts]()\n\n### Score Data Types\n\nThe `ScoreDataType` enum defines the type of value stored:\n\n| Data Type | Description |\n|-----------|-------------|\n| `NUMERIC` | Continuous numerical value |\n| `CATEGORICAL` | Categorical label or classification |\n| `BOOLEAN` | True/false indicator |\n\n### Score Interfaces Architecture\n\nScores in Langfuse follow a layered interface architecture that separates concerns across different parts of the system:\n\n```mermaid\ngraph LR\n    A[UI Types] --> B[Application Validation]\n    B --> C[Ingestion Validation]\n    C --> D[API v1 Schemas]\n    C --> E[API v2 Schemas]\n    D --> F[Database Models]\n    E --> F\n```\n\n资料来源：[packages/shared/src/features/scores/interfaces/README.md]()\n\n## Indexing Strategy\n\nThe schema defines strategic indexes to optimize common query patterns:\n\n| Table | Indexes | Purpose |\n|-------|---------|---------|\n| `Trace` | `projectId`, `sessionId`, `createdAt` | Fast project filtering and time-based queries |\n| `Observation` | `traceId`, `projectId`, `startTime` | Trace traversal and time-series queries |\n| `Score` | `projectId`, `traceId`, `observationId`, `name, createdAt` | Score lookups and time-series analytics |\n\nThe composite index on `Score(name, createdAt)` specifically supports the score analytics feature's need to retrieve scores by name over time intervals.\n\n资料来源：[packages/shared/prisma/schema.prisma]()\n\n## Prisma Client Usage\n\nPrisma Client is generated from the schema and used throughout the application. The generated client provides type-safe access to all database operations.\n\n### Client Configuration\n\n```typescript\nimport { PrismaClient } from \"@langfuse/shared/prisma\";\n\nconst prisma = new PrismaClient({\n  log: process.env.NODE_ENV === \"development\" ? [\"query\", \"error\"] : [\"error\"],\n});\n```\n\n### Transaction Support\n\nThe schema supports atomic operations through Prisma's transaction API:\n\n```typescript\nawait prisma.$transaction([\n  prisma.trace.create({ data: traceData }),\n  prisma.observation.createMany({ data: observations }),\n  prisma.score.createMany({ data: scores }),\n]);\n```\n\n## Migrations\n\nDatabase migrations are managed through Prisma Migrate. Migration files are stored in `packages/shared/prisma/migrations/` and version-controlled alongside the schema.\n\n### Running Migrations\n\n```bash\n# Apply pending migrations\npnpm --filter=langfuse-prisma migrate deploy\n\n# Create a new migration\npnpm --filter=langfuse-prisma migrate dev --name add_new_field\n```\n\n## Related Components\n\n### Repository Layer\n\nThe repository pattern abstracts database access behind domain-specific interfaces:\n\n| Repository | File | Purpose |\n|------------|------|---------|\n| `TraceRepository` | `repositories/traces.ts` | Trace CRUD and querying |\n| `ObservationRepository` | `repositories/observations.ts` | Observation management |\n| `ScoreRepository` | `repositories/scores.ts` | Score operations |\n\n资料来源：[packages/shared/src/server/repositories/traces.ts]()\n资料来源：[packages/shared/src/server/repositories/scores.ts]()\n\n### ClickHouse Integration\n\nWhile PostgreSQL (via Prisma) stores transactional data like traces and scores, Langfuse also uses ClickHouse for analytics workloads. The Prisma schema defines PostgreSQL models for the primary application data, while ClickHouse handles high-volume analytical queries.\n\n资料来源：[packages/shared/scripts/seeder/utils/README.md]()\n\n## Summary\n\nThe Prisma schema forms the backbone of Langfuse's data layer, defining:\n\n- **Multi-tenant structure**: Organizations, projects, and user memberships\n- **Observability core**: Traces and observations with hierarchical support\n- **Evaluation framework**: Scores with multiple data types and sources\n- **Operational metadata**: Timestamps, soft deletes, and JSON fields for flexibility\n\nThe schema design prioritizes query performance through strategic indexing, data integrity through proper relationships, and extensibility through JSON metadata fields.\n\n---\n\n<a id='clickhouse-analytics'></a>\n\n## ClickHouse Analytics Layer\n\n### 相关页面\n\n相关主题：[Database Schema (Prisma)](#database-schema), [Worker Service](#worker-service)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [packages/shared/clickhouse/migrations/clustered/0001_traces.up.sql](https://github.com/langfuse/langfuse/blob/main/packages/shared/clickhouse/migrations/clustered/0001_traces.up.sql)\n- [packages/shared/src/server/clickhouse/schema.ts](https://github.com/langfuse/langfuse/blob/main/packages/shared/src/server/clickhouse/schema.ts)\n- [packages/shared/src/server/repositories/clickhouse.ts](https://github.com/langfuse/langfuse/blob/main/packages/shared/src/server/repositories/clickhouse.ts)\n- [worker/src/services/ClickhouseWriter/index.ts](https://github.com/langfuse/langfuse/blob/main/worker/src/services/ClickhouseWriter/index.ts)\n- [packages/shared/src/server/repositories/score-analytics.ts](https://github.com/langfuse/langfuse/blob/main/packages/shared/src/server/repositories/score-analytics.ts)\n- [web/src/features/score-analytics/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/score-analytics/README.md)\n- [packages/shared/scripts/seeder/utils/README.md](https://github.com/langfuse/langfuse/blob/main/packages/shared/scripts/seeder/utils/README.md)\n</details>\n\n# ClickHouse Analytics Layer\n\n## Overview\n\nThe ClickHouse Analytics Layer is a core infrastructure component in Langfuse that provides high-performance analytical capabilities for processing and querying large-scale observability data. ClickHouse serves as the primary OLAP (Online Analytical Processing) database for storing traces, observations, and score analytics with optimized columnar storage and efficient aggregation queries.\n\nLangfuse leverages ClickHouse for:\n\n- High-throughput event ingestion during trace collection\n- Complex analytical queries for score comparisons and distributions\n- Time-series analysis with efficient aggregation\n- Large dataset sampling and optimization strategies\n  资料来源：[packages/shared/scripts/seeder/utils/README.md]()\n\n## Architecture Overview\n\n```mermaid\ngraph TD\n    subgraph Ingestion[\"Ingestion Layer\"]\n        W[Worker Service] --> CW[ClickhouseWriter]\n        CW --> CH[ClickHouse Cluster]\n    end\n    \n    subgraph Storage[\"Storage Layer\"]\n        CH --> TS[Traces Table]\n        CH --> OS[Observations Table]\n        CH --> SS[Scores Table]\n    end\n    \n    subgraph Query[\"Query Layer\"]\n        CR[ClickHouse Repository] --> CH\n        SA[Score Analytics] --> CR\n        WEB[Web Frontend] --> SA\n    end\n    \n    subgraph Optimization[\"Optimization Layer\"]\n        CR --> HASH[cityHash64 Sampling]\n        CR --> FINAL[Adaptive FINAL]\n        CR --> INTERVAL[Time Interval Alignment]\n    end\n```\n\n### Components Overview\n\n| Component | Location | Purpose |\n|-----------|----------|---------|\n| ClickhouseWriter | `worker/src/services/ClickhouseWriter/index.ts` | Writes ingestion events to ClickHouse |\n| ClickHouse Repository | `packages/shared/src/server/repositories/clickhouse.ts` | Provides query interface and optimization |\n| Score Analytics | `packages/shared/src/server/repositories/score-analytics.ts` | Specialized analytics queries |\n| Schema Definitions | `packages/shared/src/server/clickhouse/schema.ts` | TypeScript types for ClickHouse data |\n| Migrations | `packages/shared/clickhouse/migrations/clustered/` | Database schema migrations |\n\n资料来源：[worker/src/services/ClickhouseWriter/index.ts]()\n资料来源：[packages/shared/src/server/repositories/clickhouse.ts]()\n\n## Data Schema\n\n### Traces Table\n\nThe traces table stores the fundamental trace records with hierarchical observation data. The clustered migration defines the primary schema with optimized column types for analytical queries.\n\nKey columns include:\n\n| Column | Type | Description |\n|--------|------|-------------|\n| id | UUID | Unique trace identifier |\n| project_id | String | Project association |\n| timestamp | DateTime64 | Event timestamp with millisecond precision |\n| name | String | Trace name |\n| user_id | String | User identifier |\n| metadata | JSON | Flexible metadata storage |\n| tags | Array(String) | Tag-based categorization |\n| input | Text | Input data |\n| output | Text | Output data |\n\n资料来源：[packages/shared/clickhouse/migrations/clustered/0001_traces.up.sql]()\n\n### Observations Table\n\nObservations represent individual events within a trace, storing:\n\n- Model inputs/outputs\n- Function calls\n- Embeddings\n- Generation events\n\nEach observation is linked to its parent trace via `trace_id` and supports nested hierarchies through `parent_observation_id`.\n\n资料来源：[packages/shared/src/server/clickhouse/schema.ts]()\n\n### Scores Table\n\nScores store evaluation metrics associated with traces and observations:\n\n| Column | Type | Purpose |\n|--------|------|---------|\n| trace_id | UUID | Associated trace |\n| observation_id | UUID | Optional observation link |\n| name | String | Score identifier |\n| value | Float64 | Numeric score value |\n| data_type | Enum | NUMERIC, BOOLEAN, or CATEGORICAL |\n| source | String | Score origin (e.g., \"framework-trace\") |\n\n资料来源：[packages/shared/src/server/repositories/score-analytics.ts]()\n\n## Ingestion Pipeline\n\n### Event Flow\n\n```mermaid\nsequenceDiagram\n    participant API as Ingestion API\n    participant Queue as Redis Queue\n    participant Worker as Worker Service\n    participant Writer as ClickhouseWriter\n    participant CH as ClickHouse\n    \n    API->>Queue: Enqueue OtelIngestionEvent\n    Worker->>Queue: Dequeue Event\n    Worker->>Writer: Process Event\n    Writer->>CH: Insert Batch (ClickHouseQueryBuilder)\n    CH-->>Writer: Confirmation\n    Writer->>Worker: Acknowledge\n```\n\n### ClickhouseWriter Service\n\nThe `ClickhouseWriter` handles the actual data insertion into ClickHouse:\n\n```typescript\n// Simplified flow from worker/src/services/ClickhouseWriter/index.ts\nclass ClickhouseWriter {\n  async writeBatch(events: IngestionEvent[]): Promise<void> {\n    const queryBuilder = new ClickHouseQueryBuilder();\n    \n    for (const event of events) {\n      queryBuilder.addEvent(event);\n    }\n    \n    await this.executeQuery(queryBuilder.build());\n  }\n}\n```\n\nKey responsibilities:\n\n1. **Batch Processing**: Aggregates multiple events for efficient insertion\n2. **Schema Validation**: Ensures events match expected schema\n3. **Query Building**: Uses `ClickHouseQueryBuilder` for optimized INSERT queries\n4. **Error Recovery**: Handles failed insertions with retry logic\n\n资料来源：[worker/src/services/ClickhouseWriter/index.ts]()\n\n### ClickHouseQueryBuilder\n\nThe `ClickHouseQueryBuilder` class constructs optimized ClickHouse SQL queries with:\n\n- Proper escaping for special characters\n- Type-aware value formatting\n- Batch insert optimization\n- Efficient column mapping\n\n资料来源：[packages/shared/scripts/seeder/utils/README.md]()\n\n## Query Layer\n\n### Repository Pattern\n\nThe `clickhouse.ts` repository provides a clean interface for all ClickHouse operations:\n\n```typescript\n// packages/shared/src/server/repositories/clickhouse.ts\nclass ClickHouseRepository {\n  // Query execution with automatic connection management\n  async query<T>(sql: string, params?: QueryParams): Promise<T[]>\n  \n  // Stream processing for large result sets\n  async streamQuery(sql: string, handler: (row: T) => void): Promise<void>\n  \n  // Batch inserts with transaction support\n  async insertBatch(table: string, rows: Record<string, unknown>[]): Promise<void>\n}\n```\n\n资料来源：[packages/shared/src/server/repositories/clickhouse.ts]()\n\n### Score Analytics Queries\n\nThe score analytics module provides specialized queries for evaluating model performance:\n\n```typescript\n// packages/shared/src/server/repositories/score-analytics.ts\ninterface ScoreAnalyticsQuery {\n  getScoreIdentifiers(projectId: string): Promise<ScoreIdentifier[]>;\n  \n  estimateScoreComparisonSize(\n    projectId: string,\n    score1Id: string,\n    score2Id?: string\n  ): Promise<QueryEstimate>;\n  \n  getScoreComparisonAnalytics(\n    params: ScoreAnalyticsParams\n  ): Promise<ScoreAnalyticsResult>;\n}\n```\n\n#### Query Estimation\n\nBefore executing expensive analytics queries, the system estimates query size:\n\n| Metric | Description |\n|--------|-------------|\n| scoreCount | Total number of scores matching criteria |\n| matchedCount | Estimated rows that will match |\n| willSample | Whether hash-based sampling is needed |\n| estimatedQueryTime | Predicted query duration |\n\nThis estimation enables adaptive query optimization based on dataset size.\n\n资料来源：[packages/shared/src/server/repositories/score-analytics.ts]()\n资料来源：[web/src/features/score-analytics/README.md]()\n\n## Optimization Strategies\n\n### Hash-Based Sampling\n\nFor large datasets (>100,000 matches), Langfuse uses `cityHash64` for consistent sampling:\n\n```sql\nSELECT * FROM scores\nWHERE cityHash64(trace_id) < 0.1  -- 10% sample\n```\n\nBenefits:\n\n- Consistent sampling across query executions\n- Reproducible results for the same query parameters\n- Reduced query load while maintaining statistical validity\n\n### Adaptive FINAL Optimization\n\nClickHouse's FINAL modifier ensures up-to-date data but adds significant overhead. Langfuse uses adaptive application:\n\n| Dataset Size | FINAL Applied |\n|--------------|---------------|\n| < 70,000 scores | Yes |\n| > 70,000 scores | No |\n\n资料来源：[web/src/features/score-analytics/README.md]()\n\n### Time Interval Alignment\n\nTime series queries use proper interval alignment for accurate aggregation:\n\n```typescript\n// ISO 8601 weeks\nconst weekInterval = \"1W\";\n\n// Calendar months\nconst monthInterval = \"1MONTH\";\n```\n\nProper alignment ensures:\n\n- Consistent bucket boundaries\n- Accurate period-over-period comparisons\n- Correct aggregation across daylight saving time transitions\n\n## Seeding and Testing\n\nThe seeder utility (`packages/shared/scripts/seeder/`) generates realistic test data for ClickHouse:\n\n### Data Types\n\n| Type | Environment | Purpose |\n|------|-------------|---------|\n| Experiment Traces | `langfuse-prompt-experiment` | Realistic traces from actual datasets |\n| Evaluation Data | `langfuse-evaluation` | Metrics and scoring for evaluations |\n| Synthetic Data | `default` | Large-scale hierarchical test data |\n\n### ID Patterns\n\n- Experiment: `trace-dataset-{datasetName}-{itemIndex}-{projectId}-{runNumber}`\n- Evaluation: `trace-eval-{index}-{projectId}`\n- Synthetic: `trace-synthetic-{index}-{projectId}`\n\n资料来源：[packages/shared/scripts/seeder/utils/README.md]()\n\n### DataGenerator\n\nThe `DataGenerator` class creates realistic data for all three types:\n\n| Method | Output |\n|--------|--------|\n| `generateDatasetTrace()` | Traces linked to dataset items |\n| `generateSyntheticTraces()` | Hierarchical traces with scores |\n| `generateEvaluationTraces()` | Evaluation-focused traces |\n\n资料来源：[packages/shared/scripts/seeder/utils/README.md]()\n\n## Framework Traces\n\nFramework traces are real traces produced through official Langfuse framework instrumentation. They can be added to the system for UI testing and demo purposes.\n\n### Adding New Framework Traces\n\n1. Generate a trace using framework instrumentation\n2. Download from UI using the download button\n3. Convert to JSON format via \"Log View (Beta)\"\n4. Merge observations using the provided script:\n   ```bash\n   npx ts-node merge-observations.ts trace-file.json observations.json trace-merged.json\n   ```\n5. Save the merged file with date-based naming\n\n### Discovery\n\nFramework traces use the ID pattern `framework-frameworkName-traceId`. Filter by:\n\n- `source: \"framework-trace\"` in trace table\n- \"All Time\" date range (timestamps not rewritten)\n\n资料来源：[packages/shared/scripts/seeder/utils/framework-traces/README.md]()\n\n## TypeScript Integration\n\n### Schema Types\n\nThe `schema.ts` file provides TypeScript type definitions:\n\n```typescript\n// packages/shared/src/server/clickhouse/schema.ts\ninterface ClickHouseTrace {\n  id: string;\n  project_id: string;\n  timestamp: Date;\n  name: string;\n  user_id?: string;\n  metadata?: Record<string, unknown>;\n  tags?: string[];\n  input?: string;\n  output?: string;\n  session_id?: string;\n}\n\ninterface ClickHouseObservation {\n  id: string;\n  trace_id: string;\n  parent_observation_id?: string;\n  type: ObservationType;\n  timestamp: Date;\n  name?: string;\n  // ... additional fields\n}\n```\n\nThese types ensure compile-time safety when interacting with ClickHouse data.\n\n资料来源：[packages/shared/src/server/clickhouse/schema.ts]()\n\n## Configuration\n\n### Required Environment Variables\n\n| Variable | Description | Example |\n|----------|-------------|---------|\n| `CLICKHOUSE_URL` | ClickHouse server URL | `http://localhost:8123` |\n| `CLICKHOUSE_USER` | Database user | `clickhouse` |\n| `CLICKHOUSE_PASSWORD` | User password | `clickhouse` |\n| `CLICKHOUSE_DATABASE` | Target database | `default` |\n\n### Cluster Configuration\n\nMigrations support clustered deployments:\n\n```bash\n# Clustered migration path\npackages/shared/clickhouse/migrations/clustered/\n```\n\nThe clustered migrations ensure schema consistency across all nodes in a ClickHouse cluster.\n\n资料来源：[packages/shared/clickhouse/migrations/clustered/0001_traces.up.sql]()\n\n## Best Practices\n\n### Query Optimization\n\n1. **Use projections** for frequently accessed columns\n2. **Leverageskipping indexes** for high-cardinality columns\n3. **Batch inserts** to reduce overhead\n4. **Filter early** to minimize data processed\n\n### Data Management\n\n1. **Partition by date** for efficient time-range queries\n2. **Use TTL policies** for automatic data expiration\n3. **Compress data** using ClickHouse's native compression\n\n### Integration Guidelines\n\n1. Always use the repository pattern for query abstraction\n2. Implement query estimation before expensive operations\n3. Use hash-based sampling for large analytical queries\n4. Consider adaptive FINAL optimization for query performance\n\n## See Also\n\n- [Score Analytics Module](../features/score-analytics/README.md)\n- [Ingestion API Documentation](../ingestion/README.md)\n- [Worker Service Documentation](../worker/README.md)\n- [Seeding Utilities](../packages/shared/scripts/seeder/utils/README.md)\n\n---\n\n<a id='queue-system'></a>\n\n## Queue System (Redis/BullMQ)\n\n### 相关页面\n\n相关主题：[System Architecture](#system-architecture), [Worker Service](#worker-service)\n\n<details>\n<summary>Relevant Source Files</summary>\n\n以下源码文件用于生成本页说明：\n\n- [packages/shared/src/server/redis/ingestionQueue.ts](https://github.com/langfuse/langfuse/blob/main/packages/shared/src/server/redis/ingestionQueue.ts)\n- [packages/shared/src/server/redis/evalExecutionQueue.ts](https://github.com/langfuse/langfuse/blob/main/packages/shared/src/server/redis/evalExecutionQueue.ts)\n- [packages/shared/src/server/redis/batchActionQueue.ts](https://github.com/langfuse/langfuse/blob/main/packages/shared/src/server/redis/batchActionQueue.ts)\n- [packages/shared/src/server/redis/webhookQueue.ts](https://github.com/langfuse/langfuse/blob/main/packages/shared/src/server/redis/webhookQueue.ts)\n- [worker/src/queues/workerManager.ts](https://github.com/langfuse/langfuse/blob/main/worker/src/queues/workerManager.ts)\n</details>\n\n# Queue System (Redis/BullMQ)\n\nLangfuse employs a distributed queue system built on **Redis** for storage and **BullMQ** for job orchestration. This architecture enables asynchronous processing of high-volume operations including event ingestion, evaluation execution, batch actions, and webhook delivery.\n\n## Architecture Overview\n\nThe queue system follows a producer-consumer pattern where the web application enqueues jobs and worker processes consume them asynchronously.\n\n```mermaid\ngraph TD\n    subgraph \"Langfuse Web Application\"\n        A[API Request] --> B[Queue Client]\n        B --> C[Redis Queue]\n    end\n    \n    subgraph \"Langfuse Worker\"\n        C --> D[Worker Manager]\n        D --> E1[Ingestion Worker]\n        D --> E2[Eval Worker]\n        D --> E3[Batch Worker]\n        D --> E4[Webhook Worker]\n    end\n    \n    subgraph \"Redis\"\n        C --> F[(Redis Cluster)]\n    end\n    \n    subgraph \"External Services\"\n        E1 --> G[(ClickHouse)]\n        E1 --> H[(PostgreSQL)]\n        E2 --> H\n        E3 --> H\n        E4 --> I[(External APIs)]\n    end\n```\n\n## Queue Types\n\nLangfuse defines multiple specialized queues for different workloads:\n\n| Queue Name | Purpose | Processing Type | Priority |\n|------------|---------|-----------------|----------|\n| `ingestion` | Event ingestion and processing | Async batch | Medium |\n| `evalExecution` | LLM evaluation execution | Async | Medium |\n| `batchAction` | Bulk operations on data | Async batch | Low |\n| `webhook` | Outbound webhook delivery | Async | High |\n| `OtelIngestion` | OpenTelemetry event ingestion | Async | Medium |\n| `IngestionSecondary` | Secondary ingestion processing | Async | Medium |\n\n资料来源：[worker/src/queues/workerManager.ts]()\n\n## Queue Configuration\n\n### Redis Connection\n\nAll queues rely on a Redis connection string configured via environment variables:\n\n```bash\nREDIS_CONNECTION_STRING=redis://:myredissecret@127.0.0.1:6379\n```\n\n### Queue Initialization\n\nEach queue is initialized with specific BullMQ configuration:\n\n```typescript\nconst myQueue = new Queue<T>(queueName, {\n  connection: {\n    host: redisConfig.host,\n    port: redisConfig.port,\n    password: redisConfig.password,\n  },\n  defaultJobOptions: {\n    attempts: 3,\n    backoff: {\n      type: \"exponential\",\n      delay: 1000,\n    },\n    removeOnComplete: true,\n    removeOnFail: false,\n  },\n});\n```\n\n资料来源：[packages/shared/src/server/redis/ingestionQueue.ts]()\n\n## Queue Implementations\n\n### Ingestion Queue\n\nThe ingestion queue handles event processing from SDK clients and the OpenTelemetry protocol.\n\n```mermaid\ngraph LR\n    A[SDK Events] --> B[API Endpoint]\n    B --> C[ingestionQueue]\n    C --> D[Validate Events]\n    D --> E[Parse & Transform]\n    E --> F[(ClickHouse)]\n    E --> G[(PostgreSQL)]\n```\n\n**Key Features:**\n\n- Batch processing with configurable batch size\n- Retry with exponential backoff\n- Event validation against schema\n- S3 file-based storage for large payloads\n\n资料来源：[packages/shared/src/server/redis/ingestionQueue.ts]()\n\n### Evaluation Execution Queue\n\nHandles asynchronous execution of LLM-based evaluations:\n\n```mermaid\ngraph TD\n    A[Create Eval Job] --> B[evalExecutionQueue]\n    B --> C[Worker Pickup]\n    C --> D[Fetch Traces]\n    D --> E[Run LLM Evaluation]\n    E --> F[Store Results]\n    F --> G[(PostgreSQL)]\n```\n\n**Job Options:**\n\n```typescript\n{\n  attempts: 3,\n  backoff: {\n    type: \"exponential\",\n    delay: 2000,\n  },\n  removeOnComplete: 100, // Keep last 100 completed\n  removeOnFail: 1000,   // Keep last 1000 failed\n}\n```\n\n资料来源：[packages/shared/src/server/redis/evalExecutionQueue.ts]()\n\n### Batch Action Queue\n\nProcesses bulk operations such as batch updates and deletions:\n\n| Parameter | Default | Description |\n|-----------|---------|-------------|\n| `batchSize` | 100 | Items per batch |\n| `concurrency` | 5 | Parallel workers |\n| `attempts` | 3 | Retry count |\n| `backoffDelay` | 1000 | Initial backoff ms |\n\n资料来源：[packages/shared/src/server/redis/batchActionQueue.ts]()\n\n### Webhook Queue\n\nManages outbound webhook deliveries with priority handling:\n\n```mermaid\ngraph TD\n    A[Trigger Event] --> B[webhookQueue]\n    B --> C{Has Retry Config?}\n    C -->|Yes| D[Schedule Retry]\n    C -->|No| E[Immediate Delivery]\n    D --> E\n    E --> F{HTTP Response}\n    F -->|2xx| G[Log Success]\n    F -->|4xx| H[Log Failure]\n    F -->|5xx| D\n```\n\n资料来源：[packages/shared/src/server/redis/webhookQueue.ts]()\n\n## Worker Manager\n\nThe `WorkerManager` orchestrates all queue workers within the worker process:\n\n```typescript\nexport class WorkerManager {\n  private workers: Map<string, Worker>;\n\n  async initialize(): Promise<void> {\n    // Initialize all queue workers\n  }\n\n  async gracefulShutdown(): Promise<void> {\n    // Gracefully close all workers\n  }\n}\n```\n\n资料来源：[worker/src/queues/workerManager.ts]()\n\n### Worker Lifecycle\n\n```mermaid\ngraph TD\n    A[Start Worker Process] --> B[Load Configuration]\n    B --> C[Initialize Redis Connection]\n    C --> D[Create Queue Instances]\n    D --> E[Create Worker Instances]\n    E --> F[Register Event Handlers]\n    F --> G[Workers Ready]\n    \n    H[Shutdown Signal] --> I[Close Workers]\n    I --> J[Process Pending Jobs]\n    J --> K[Close Redis Connection]\n    K --> L[Exit]\n```\n\n### Event Handling\n\nWorkers register handlers for job lifecycle events:\n\n| Event | Handler Purpose |\n|-------|------------------|\n| `completed` | Log successful job completion |\n| `failed` | Handle job failures and retries |\n| `progress` | Track job progress updates |\n| `stalled` | Detect and requeue stalled jobs |\n\n## Job Data Flow\n\n### Standard Event Ingestion\n\nEvents flow through the system as follows:\n\n```mermaid\nsequenceDiagram\n    participant SDK\n    participant API\n    participant Redis\n    participant Worker\n    participant DB\n    \n    SDK->>API: POST /api/public/ingestion\n    API->>Redis: Add to IngestionQueue\n    API-->>SDK: 202 Accepted\n    Worker->>Redis: Dequeue Job\n    Worker->>DB: Validate & Store\n    Worker->>Redis: Job Complete\n```\n\n### Event Transformation\n\nThe ingestion endpoint transforms S3 keys into queue payloads:\n\n**Standard format:**\n```json\n{\n  \"authCheck\": {\n    \"validKey\": true,\n    \"scope\": { \"projectId\": \"<projectId>\" }\n  },\n  \"data\": {\n    \"eventBodyId\": \"<eventBodyId>\",\n    \"fileKey\": \"<eventId>\",\n    \"type\": \"<type>-create\"\n  }\n}\n```\n\n**OTEL format:**\n```json\n{\n  \"authCheck\": {\n    \"validKey\": true,\n    \"scope\": { \"projectId\": \"<projectId>\", \"accessLevel\": \"project\" }\n  },\n  \"data\": {\n    \"fileKey\": \"otel/<projectId>/<yyyy>/<mm>/<dd>/<hh>/<mm>/<eventId>.json\"\n  }\n}\n```\n\n资料来源：[worker/src/scripts/replayIngestionEventsV2/README.md]()\n\n## Error Handling and Retries\n\n### Retry Strategy\n\nAll queues implement exponential backoff retry:\n\n```typescript\nconst jobOptions = {\n  attempts: 3,\n  backoff: {\n    type: \"exponential\",\n    delay: 1000, // 1s, 2s, 4s\n  },\n};\n```\n\n### Error Classification\n\n| HTTP Status | Behavior | Retry |\n|-------------|----------|-------|\n| 2xx | Success | No |\n| 429 | Rate limited | Yes (with backoff) |\n| 5xx | Server error | Yes (up to 3 times) |\n| 4xx (not 429) | Client error | No (logged and skipped) |\n\n## Monitoring and Debugging\n\n### Progress Tracking\n\nThe replay scripts provide progress updates:\n\n```\n[1200/45000] 2.7% — 498 queued, 2 skipped\n```\n\n### Checkpoint System\n\nScripts write checkpoints to enable resume after failures:\n\n```bash\n# Checkpoint file location\n./worker/.checkpoint\n\n# Resume from checkpoint\npnpm run --filter=worker replay-ingestion --resume\n```\n\n### Error Logging\n\nFailed jobs are logged to `errors.csv` for manual inspection:\n\n```csv\n\"operation\",\"key\",\"error\"\n\"REST.PUT.OBJECT\",\"projectId/type/eventBodyId/eventId.json\",\"Connection timeout\"\n```\n\n## Admin API for Queue Management\n\n### `POST /api/admin/ingestion-replay`\n\nEnqueues batches of S3 keys for reprocessing:\n\n**Request:**\n```json\n{\n  \"keys\": [\n    \"projectId/trace/eventBodyId/eventId.json\",\n    \"otel/projectId/2025/07/09/14/30/some-uuid.json\"\n  ]\n}\n```\n\n**Response:**\n```json\n{\n  \"queued\": 498,\n  \"skipped\": 2,\n  \"errors\": []\n}\n```\n\n### Authentication\n\nRequires `Authorization: Bearer {ADMIN_API_KEY}` header validated by `AdminApiAuthService`.\n\n## Environment Variables\n\n| Variable | Description | Required |\n|----------|-------------|----------|\n| `REDIS_CONNECTION_STRING` | Redis connection URL | Yes |\n| `LANGFUSE_S3_EVENT_UPLOAD_BUCKET` | S3 bucket for event storage | Yes |\n| `CLICKHOUSE_URL` | ClickHouse connection URL | Yes |\n| `CLICKHOUSE_USER` | ClickHouse username | Yes |\n| `CLICKHOUSE_PASSWORD` | ClickHouse password | Yes |\n| `ADMIN_API_KEY` | Admin API authentication key | Yes (admin endpoints) |\n\n## Utility Scripts\n\n### Replay Ingestion Events V2\n\nA streamlined replacement for v1 with improved features:\n\n| Feature | v1 | v2 |\n|---------|----|----|\n| Infrastructure | Redis, ClickHouse, PostgreSQL, S3 | Langfuse host URL only |\n| Setup | Full repo clone | `npx tsx` + env vars |\n| Event delivery | Direct BullMQ `addBulk` | HTTP POST to admin API |\n| Resume support | Manual | Built-in checkpoint |\n| Rate limiting | None | Client + server side |\n\n### Refill Queue Event\n\nBackfills queues with events from local machines:\n\n```bash\n# 1. Create events file\necho '{\"projectId\": \"project-123\", \"orgId\": \"org-456\"}' > ./worker/events.jsonl\n\n# 2. Configure environment\n# Create .env with REDIS_CONNECTION_STRING and supporting services\n\n# 3. Run the script\npnpm run --filter=worker refill-queue-event\n```\n\n## Best Practices\n\n1. **Connection Pooling**: Reuse Redis connections across queue operations\n2. **Graceful Shutdown**: Always drain active jobs before stopping workers\n3. **Monitoring**: Track queue depth and processing times\n4. **Error Boundaries**: Isolate queue failures to prevent cascade\n5. **Backoff Tuning**: Adjust retry delays based on workload characteristics\n\n## Related Documentation\n\n- [Event Ingestion System](../ingestion/overview)\n- [Evaluation Framework](../evaluation/overview)\n- [Webhook Configuration](../webhooks/setup)\n\n---\n\n<a id='worker-service'></a>\n\n## Worker Service\n\n### 相关页面\n\n相关主题：[System Architecture](#system-architecture), [Queue System (Redis/BullMQ)](#queue-system)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [worker/src/app.ts](https://github.com/langfuse/langfuse/blob/main/worker/src/app.ts)\n- [worker/src/index.ts](https://github.com/langfuse/langfuse/blob/main/worker/src/index.ts)\n- [worker/src/queues/workerManager.ts](https://github.com/langfuse/langfuse/blob/main/worker/src/queues/workerManager.ts)\n- [worker/src/features/evaluation/evalService.ts](https://github.com/langfuse/langfuse/blob/main/worker/src/features/evaluation/evalService.ts)\n- [worker/src/features/batchAction/handleBatchActionJob.ts](https://github.com/langfuse/langfuse/blob/main/worker/src/features/batchAction/handleBatchActionJob.ts)\n</details>\n\n# Worker Service\n\n## Overview\n\nThe Worker Service is a core backend component in Langfuse responsible for asynchronous processing of long-running tasks. It operates as a separate Node.js process that communicates with the main Langfuse server through message queues, primarily using BullMQ backed by Redis.\n\n```mermaid\ngraph TB\n    subgraph \"Langfuse Server\"\n        A[API Endpoints]\n        B[tRPC Routers]\n    end\n    \n    subgraph \"Redis\"\n        C[(Ingestion Queues)]\n        D[(Evaluation Queues)]\n        E[(Batch Action Queues)]\n    end\n    \n    subgraph \"Worker Service\"\n        F[Worker Manager]\n        G[Evaluation Service]\n        H[Batch Action Handler]\n        I[Queue Processors]\n    end\n    \n    A -->|\"Enqueue Jobs\"| C\n    B -->|\"Dispatch Tasks\"| C\n    F -->|\"Process\"| C\n    G -->|\"Execute\"| D\n    H -->|\"Execute\"| E\n    C --> F\n    D --> G\n    E --> H\n```\n\n### Purpose and Scope\n\nThe Worker Service handles the following categories of work:\n\n- **Event Ingestion Processing**: Processing and persisting trace events, observations, and spans from the ingestion queues\n- **Evaluation Execution**: Running LLM-based evaluations on traces and observations\n- **Batch Actions**: Executing bulk operations on datasets, traces, and other resources\n- **Queue Replay**: Replaying historical ingestion events for data recovery or reprocessing\n\n资料来源：[worker/src/app.ts]()\n\n---\n\n## Architecture\n\n### Entry Point\n\nThe worker service is bootstrapped through `worker/src/index.ts`, which initializes the application context and starts the queue processors. The main application logic resides in `worker/src/app.ts`, which sets up the BullMQ workers and registers job handlers.\n\n```typescript\n// Simplified worker initialization flow\nconst app = new WorkerApp();\nawait app.initialize();\nawait app.start();\n```\n\n资料来源：[worker/src/index.ts]()\n\n### Worker Manager\n\nThe `WorkerManager` is the central orchestrator that manages all queue workers. It is responsible for:\n\n- Registering queue processors for different job types\n- Configuring concurrency settings per queue\n- Handling job failures and retries\n- Graceful shutdown coordination\n\n```mermaid\ngraph LR\n    A[Job Enqueued] --> B[Worker Manager]\n    B --> C{Job Type?}\n    C -->|Ingestion| D[Ingestion Processor]\n    C -->|Evaluation| E[Eval Service]\n    C -->|Batch Action| F[Batch Handler]\n    \n    D --> G[Success]\n    E --> G\n    F --> G\n    \n    D --> H[Retry/Fail]\n    E --> H\n    F --> H\n```\n\n资料来源：[worker/src/queues/workerManager.ts]()\n\n### Queue Architecture\n\nLangfuse uses multiple queues for different purposes:\n\n| Queue Name | Purpose | Priority | Concurrency |\n|------------|---------|----------|-------------|\n| `IngestionSecondaryQueue` | Standard event ingestion | Medium | Configurable |\n| `OtelIngestionQueue` | OpenTelemetry-format events | High | Configurable |\n| `EvalQueue` | LLM evaluation jobs | Low | Configurable |\n| `BatchActionQueue` | Bulk operations | Medium | Configurable |\n\n资料来源：[worker/src/app.ts]()\n资料来源：[worker/src/queues/workerManager.ts]()\n\n---\n\n## Core Components\n\n### Evaluation Service\n\nThe Evaluation Service (`evalService.ts`) handles asynchronous evaluation of traces and observations using LLM-based judges. It supports:\n\n- **Trace-level evaluations**: Running multiple evaluation criteria against a complete trace\n- **Observation-level evaluations**: Evaluating individual spans or generations\n- **Dataset-based evaluations**: Running evaluations against dataset items\n- **Configurable retry logic**: Handling transient failures gracefully\n\n```mermaid\ngraph TD\n    A[Evaluation Job Received] --> B[Load Trace/Observation]\n    B --> C[Fetch Eval Config]\n    C --> D[Prepare Prompt]\n    D --> E[Call LLM Provider]\n    E --> F{Success?}\n    F -->|Yes| G[Score Result]\n    F -->|No| H{Retry < 3?}\n    H -->|Yes| E\n    H -->|No| I[Mark Failed]\n    G --> J[Persist Score]\n    J --> K[Job Complete]\n    I --> K\n```\n\n资料来源：[worker/src/features/evaluation/evalService.ts]()\n\n### Batch Action Handler\n\nThe Batch Action Handler processes bulk operations requested through the admin API or scheduled jobs. Common batch actions include:\n\n- Bulk dataset operations (import, export, deletion)\n- Mass updates to traces or observations\n- Batch score calculations\n- Export operations\n\n```typescript\ninterface BatchActionJob {\n  id: string;\n  type: BatchActionType;\n  payload: BatchActionPayload;\n  priority?: number;\n  createdAt: Date;\n}\n```\n\n资料来源：[worker/src/features/batchAction/handleBatchActionJob.ts]()\n\n---\n\n## Queue Processing\n\n### Job Flow\n\n```mermaid\nsequenceDiagram\n    participant API as API Server\n    participant Redis as Redis Queue\n    participant Worker as Worker Service\n    \n    API->>Redis: Enqueue Job\n    Worker->>Redis: Poll for Jobs\n    Redis-->>Worker: Available Jobs\n    Worker->>Worker: Process Job\n    Worker->>Redis: Mark Complete\n    Worker->>API: Update Status (optional)\n```\n\n### Error Handling and Retries\n\nThe worker implements exponential backoff for transient failures:\n\n1. **Transient failures** (network timeouts, rate limits): Retry up to 3 times with exponential backoff\n2. **Permanent failures** (validation errors, missing data): Mark as failed, log error details\n3. **Rate limiting**: Respects server-side rate limits and backs off accordingly\n\n| Error Type | HTTP Code | Retry Behavior |\n|------------|-----------|----------------|\n| Rate Limited | 429 | Exponential backoff |\n| Server Error | 5xx | Retry up to 3 times |\n| Client Error | 4xx (not 429) | No retry, log and skip |\n| Validation | N/A | No retry, mark failed |\n\n资料来源：[worker/src/scripts/replayIngestionEventsV2/README.md]()\n\n### Concurrency Configuration\n\nWorkers can be configured with different concurrency levels per queue:\n\n```typescript\nconst workerConfig = {\n  ingestion: {\n    concurrency: 10,\n    maxRetries: 3,\n  },\n  evaluation: {\n    concurrency: 5,\n    maxRetries: 2,\n  },\n  batchAction: {\n    concurrency: 3,\n    maxRetries: 1,\n  },\n};\n```\n\n资料来源：[worker/src/queues/workerManager.ts]()\n\n---\n\n## Utility Scripts\n\n### Replay Ingestion Events V2\n\nThe replay script allows reprocessing of historical ingestion events from S3 storage.\n\n**Usage:**\n```bash\npnpm --filter=worker run replay-ingestion-events-v2 \\\n  --input ./events.csv \\\n  --batch-size 500 \\\n  --concurrency 4\n```\n\n**Key Features:**\n- Checkpoint/resume support for interrupted runs\n- Configurable batch size and concurrency\n- Rate limiting with exponential backoff\n- Progress tracking with percentage and ETA\n\n| Parameter | Default | Description |\n|-----------|---------|-------------|\n| `--input` | Required | Path to CSV file with S3 keys |\n| `--batch-size` | 500 | Keys per API request |\n| `--concurrency` | 4 | Parallel API requests |\n| `--rate-limit` | 50 | Max requests per second |\n| `--dry-run` | false | Validate without sending |\n| `--resume` | false | Continue from checkpoint |\n\n资料来源：[worker/src/scripts/replayIngestionEventsV2/README.md]()\n\n### Refill Queue Event\n\nThe refill script backfills queues with events from local files for testing and development.\n\n**Requirements:**\n1. Create `./worker/events.jsonl` with JSON events\n2. Configure `.env` with Redis and supporting service credentials\n3. Run: `pnpm run --filter=worker refill-queue-event`\n\n**Event Format:**\n```jsonl\n{\"projectId\": \"project-123\", \"orgId\": \"org-456\"}\n{\"projectId\": \"project-789\", \"orgId\": \"org-101\"}\n```\n\n资料来源：[worker/src/scripts/refillQueueEvent/README.md]()\n\n---\n\n## Environment Configuration\n\n### Required Environment Variables\n\n| Variable | Description | Required |\n|----------|-------------|----------|\n| `REDIS_CONNECTION_STRING` | Redis connection URL | Yes |\n| `LANGFUSE_S3_EVENT_UPLOAD_BUCKET` | S3 bucket for event uploads | Yes |\n| `CLICKHOUSE_URL` | ClickHouse connection URL | Yes |\n| `CLICKHOUSE_USER` | ClickHouse username | Yes |\n| `CLICKHOUSE_PASSWORD` | ClickHouse password | Yes |\n| `ADMIN_API_KEY` | Admin API key for replay scripts | For replay only |\n| `LANGFUSE_HOST` | Target Langfuse instance URL | For replay only |\n\n### Optional Configuration\n\n| Variable | Default | Description |\n|----------|---------|-------------|\n| `WORKER_CONCURRENCY` | 10 | Default queue concurrency |\n| `EVALUATION_CONCURRENCY` | 5 | Evaluation queue concurrency |\n| `BATCH_ACTION_CONCURRENCY` | 3 | Batch action concurrency |\n\n资料来源：[worker/src/scripts/refillQueueEvent/README.md]()\n资料来源：[worker/src/app.ts]()\n\n---\n\n## Health and Monitoring\n\n### Debug Mode\n\nEnable detailed logging for the AdvancedJsonViewer (useful for debugging UI components):\n\n```javascript\nlocalStorage.setItem(\"debug:AdvancedJsonViewer\", \"true\");\n```\n\n### Logging Categories\n\nThe worker service emits structured logs for:\n\n- Queue processing events\n- Job duration and throughput\n- Error rates and failure reasons\n- Resource utilization metrics\n\n### Graceful Shutdown\n\nThe worker service supports graceful shutdown to prevent job loss:\n\n1. Stop accepting new jobs\n2. Wait for in-progress jobs to complete (with timeout)\n3. Release Redis connections\n4. Exit cleanly\n\n---\n\n## Performance Considerations\n\n### Scalability\n\n- Multiple worker instances can run in parallel\n- Each queue can have independent concurrency settings\n- Redis acts as a shared job queue, enabling horizontal scaling\n\n### Memory Management\n\n| Strategy | Implementation |\n|----------|----------------|\n| Iterative Processing | Uses explicit stack-based iteration instead of recursion to prevent stack overflow |\n| Batch Processing | Processes events in configurable batch sizes |\n| Lazy Loading | Loads trace/observation data on-demand within job handlers |\n\n### Known Limitations\n\n1. **No horizontal virtualization in UI**: Wide JSON rows render fully\n2. **Client-side search only**: All matches computed in memory\n3. **Memory constraints**: 1M+ nodes may cause issues despite virtualization\n4. **Wrap mode performance**: Long strings require height measurement\n\n资料来源：[web/src/components/ui/AdvancedJsonViewer/README.md]()\n\n---\n\n## Summary\n\nThe Worker Service is essential to Langfuse's architecture, providing asynchronous processing capabilities that keep the main API server responsive. Key takeaways:\n\n- **BullMQ + Redis**: Provides reliable job queuing with built-in retry logic\n- **Specialized processors**: Dedicated handlers for ingestion, evaluation, and batch actions\n- **Configurable concurrency**: Fine-tune throughput per queue type\n- **Replay capabilities**: Built-in utilities for reprocessing historical events\n- **Horizontal scaling**: Multiple worker instances share work through Redis\n\n---\n\n<a id='api-layer'></a>\n\n## API Layer\n\n### 相关页面\n\n相关主题：[System Architecture](#system-architecture)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [web/src/server/api/root.ts](https://github.com/langfuse/langfuse/blob/main/web/src/server/api/root.ts)\n- [web/src/server/api/routers/traces.ts](https://github.com/langfuse/langfuse/blob/main/web/src/server/api/routers/traces.ts)\n- [web/src/server/api/routers/scores.ts](https://github.com/langfuse/langfuse/blob/main/web/src/server/api/routers/scores.ts)\n- [web/src/server/api/routers/observations.ts](https://github.com/langfuse/langfuse/blob/main/web/src/server/api/routers/observations.ts)\n- [web/src/server/api/trpc.ts](https://github.com/langfuse/langfuse/blob/main/web/src/server/api/trpc.ts)\n- [packages/shared/src/features/scores/interfaces/README.md](https://github.com/langfuse/langfuse/blob/main/packages/shared/src/features/scores/interfaces/README.md)\n- [web/src/features/score-analytics/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/score-analytics/README.md)\n- [web/src/features/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/README.md)\n</details>\n\n# API Layer\n\nThe API Layer is the central communication bridge between the Langfuse frontend and backend services. Built on **tRPC** (TypeScript RPC), it provides end-to-end type safety, enabling the web application to interact with server-side logic through strongly-typed procedure calls.\n\n## Overview\n\nThe API Layer serves multiple critical functions:\n\n- **Type-Safe Communication**: All API calls are fully typed from server to client\n- **Authentication & Authorization**: Every procedure is wrapped with auth middleware\n- **Business Logic Isolation**: Procedures delegate to repository layer for data access\n- **Input Validation**: Zod schemas validate all incoming requests\n- **Feature Organization**: Procedures are grouped by domain (traces, observations, scores)\n\n```mermaid\ngraph TD\n    subgraph Frontend\n        UI[React Components]\n    end\n    \n    subgraph API Layer\n        TRPC[tRPC Client]\n        Procedures[tRPC Procedures]\n        Middleware[Auth Middleware]\n    end\n    \n    subgraph Backend\n        Repositories[Repositories]\n        Database[(Database)]\n    end\n    \n    UI --> TRPC\n    TRPC --> Procedures\n    Procedures --> Middleware\n    Middleware --> Repositories\n    Repositories --> Database\n```\n\n## Architecture\n\n### Core Components\n\n| Component | File | Purpose |\n|-----------|------|---------|\n| tRPC Instance | `trpc.ts` | Initialize tRPC with middleware and context |\n| Root Router | `root.ts` | Register all feature routers |\n| Trace Router | `routers/traces.ts` | Trace CRUD and query operations |\n| Observation Router | `routers/observations.ts` | Span/generation/event operations |\n| Score Router | `routers/scores.ts` | Score management and analytics |\n| Score Analytics | `features/score-analytics/server/scoreAnalyticsRouter.ts` | Score aggregation and statistics |\n\n### Router Registration Flow\n\nThe root router aggregates all feature routers under a namespace:\n\n```typescript\n// Simplified from web/src/server/api/root.ts\nexport const rootRouter = createTRPCRouter({\n  trace: traceRouter,\n  observation: observationRouter,\n  score: scoreRouter,\n  scoreAnalytics: scoreAnalyticsRouter,\n  // ... other routers\n});\n```\n\n资料来源：[web/src/server/api/root.ts:1-50]()\n\n## tRPC Configuration\n\n### Initialization\n\nThe tRPC instance is initialized in `trpc.ts` with:\n\n1. **Context Creation**: Builds request-scoped context with authentication\n2. **Middleware Chain**: Applies auth, rate limiting, and logging\n3. **Error Handling**: Transforms errors into HTTP-compatible responses\n\n```typescript\n// From web/src/server/api/trpc.ts\nexport const createTRPCContext = async (opts: CreateNextContextOptions) => {\n  return {\n    session: await getServerSession(authOptions),\n    // ... additional context\n  };\n};\n\nconst t = initTRPC.context<typeof createTRPCContext>().create();\n```\n\n资料来源：[web/src/server/api/trpc.ts:1-30]()\n\n### Middleware Stack\n\n| Middleware | Purpose |\n|------------|---------|\n| `isAuthed` | Validates user session and project access |\n| `isProjectMember` | Ensures user belongs to the project scope |\n| `isOwnerOrMember` | Allows owner or member roles |\n| `rateLimit` | Prevents abuse with configurable limits |\n\n## API Routers\n\n### Trace Router\n\nHandles all trace-related operations including retrieval, creation, and updates.\n\n**Key Procedures:**\n\n| Procedure | Type | Description |\n|-----------|------|-------------|\n| `getById` | Query | Fetch single trace with full details |\n| `list` | Query | Paginated trace listing with filters |\n| `create` | Mutation | Create new trace record |\n| `update` | Mutation | Update trace metadata/tags |\n| `delete` | Mutation | Soft-delete trace |\n\n资料来源：[web/src/server/api/routers/traces.ts:1-100]()\n\n### Observation Router\n\nManages spans, generations, and events that belong to traces.\n\n**Key Procedures:**\n\n| Procedure | Type | Description |\n|-----------|------|-------------|\n| `getById` | Query | Fetch single observation |\n| `list` | Query | List observations with trace/session filters |\n| `create` | Mutation | Create observation linked to trace |\n| `update` | Mutation | Update observation metadata |\n\n资料来源：[web/src/server/api/routers/observations.ts:1-100]()\n\n### Score Router\n\nProvides score management with support for multiple API versions (v1 and v2).\n\n**API Versioning Strategy:**\n\n| Version | traceId Required | Session Support | Dataset Run Support |\n|---------|------------------|-----------------|---------------------|\n| v1 | Yes | No | No |\n| v2 | Optional | Yes | Yes |\n\nThe Score router supports both trace-level and session-level scores through different API versions.\n\n**Key Procedures:**\n\n| Procedure | Type | Description |\n|-----------|------|-------------|\n| `create` | Mutation | Create score (POST endpoint) |\n| `delete` | Mutation | Delete score |\n| `getById` | Query | Fetch single score |\n| `list` | Query | List scores with filters |\n\n资料来源：[web/src/server/api/routers/scores.ts:1-100]()\n\n### Score Analytics Router\n\nProvides aggregated statistics and time-series data for scores.\n\n```typescript\n// From web/src/features/score-analytics/server/scoreAnalyticsRouter.ts\nexport const scoreAnalyticsRouter = createTRPCRouter({\n  timeSeries: protectedProcedure.query(...),\n  statistics: protectedProcedure.query(...),\n  heatmapData: protectedProcedure.query(...),\n});\n```\n\n**Key Procedures:**\n\n| Procedure | Type | Description |\n|-----------|------|-------------|\n| `timeSeries` | Query | Time-series score data with gap filling |\n| `statistics` | Query | Statistical summaries (count, mean, p50/p95/p99) |\n| `heatmapData` | Query | Heatmap matrix for visualization |\n\n资料来源：[web/src/features/score-analytics/README.md]()\n\n## Request Flow\n\n```mermaid\nsequenceDiagram\n    participant Client\n    participant TRPC as tRPC Server\n    participant Middleware\n    participant Router\n    participant Repository\n    participant DB as Database\n\n    Client->>TRPC: Procedure Call\n    TRPC->>Middleware: Apply Chain\n    Middleware->>Middleware: Auth Check\n    Middleware->>Router: Validated Input\n    Router->>Repository: Domain Operation\n    Repository->>DB: SQL/Query\n    DB-->>Repository: Result\n    Repository-->>Router: Domain Object\n    Router-->>TRPC: Response\n    TRPC-->>Client: Typed Response\n```\n\n## Input Validation\n\nAll procedures use **Zod schemas** for runtime validation:\n\n```typescript\n// Example pattern from routers\nconst createTraceSchema = z.object({\n  name: z.string().optional(),\n  userId: z.string().optional(),\n  metadata: z.record(z.unknown()).optional(),\n  tags: z.array(z.string()).optional(),\n});\n\nprotectedProcedure\n  .input(createTraceSchema)\n  .mutation(async ({ input, ctx }) => {\n    return ctx.repo.trace.create(input);\n  });\n```\n\n## Type Flow\n\nThe API Layer maintains type consistency across the stack:\n\n```mermaid\ngraph LR\n    Client[Client Input] --> InputZ[Zod Schema]\n    InputZ --> InputTS[TypeScript Type]\n    InputTS --> Handler[Procedure Handler]\n    Handler --> Repo[Repository Return]\n    Repo --> OutputZ[Zod Response Schema]\n    OutputZ --> OutputTS[API Response Type]\n    OutputTS --> ClientResponse[Client]\n```\n\n**Type Transformation Points:**\n\n| Stage | Location | Purpose |\n|-------|----------|---------|\n| Input | Routers | Zod validation + type inference |\n| Domain | Repositories | Database models to domain objects |\n| Output | Routers | Zod response schema validation |\n| Client | React Hooks | Full type safety for UI |\n\n## Score Interface Architecture\n\nScores have a multi-layer type system:\n\n| Layer | Location | Purpose |\n|-------|----------|---------|\n| API v1 | `interfaces/api/v1/` | Legacy trace-only scores |\n| API v2 | `interfaces/api/v2/` | Current with session/dataset support |\n| Application | `interfaces/application/` | Internal validation |\n| UI | `interfaces/ui/` | Simplified frontend types |\n\n资料来源：[packages/shared/src/features/scores/interfaces/README.md]()\n\n## Public API Extension\n\nThe Langfuse Public API extends the internal API layer for external consumption:\n\n```typescript\n// From web/src/features/README.md\n// Pattern for adding new public API routes:\n1. Wrap with withMiddleware\n2. Type-safe route with createAuthedAPIRoute\n3. Add Zod types to /features/public-api/types\n4. Use coerce for date handling\n5. Use strict() on response objects\n```\n\n**SDK Generation Pipeline:**\n\n```mermaid\ngraph TD\n    Fern[Fern Definition] --> PythonSDK[Python SDK]\n    Fern --> JSSDK[JS/TS SDK]\n    Fern --> Docs[API Documentation]\n```\n\n## Best Practices\n\n### Procedure Design\n\n- Use `protectedProcedure` for authenticated endpoints\n- Apply input validation at the procedure level\n- Return consistent response structures\n- Handle errors with typed error classes\n\n### Error Handling\n\n| Error Type | HTTP Code | Usage |\n|------------|-----------|-------|\n| `UNAUTHORIZED` | 401 | Missing/invalid session |\n| `FORBIDDEN` | 403 | Insufficient permissions |\n| `NOT_FOUND` | 404 | Resource doesn't exist |\n| `BAD_REQUEST` | 400 | Invalid input |\n| `INTERNAL_SERVER_ERROR` | 500 | Unexpected errors |\n\n### Performance Considerations\n\n- Use cursor-based pagination for large datasets\n- Leverage repository-level caching where applicable\n- Batch database operations in mutations\n- Limit response sizes with maxTake parameters\n\n---\n\n---\n\n## Doramagic 踩坑日志\n\n项目：langfuse/langfuse\n\n摘要：发现 17 个潜在踩坑项，其中 4 个为 high/blocking；最高优先级：安装坑 - 来源证据：bug: Using client with context manager breaks the scoring。\n\n## 1. 安装坑 · 来源证据：bug: Using client with context manager breaks the scoring\n\n- 严重度：high\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：bug: Using client with context manager breaks the scoring\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_5afee24537ba47369cc4621f7fb18122 | https://github.com/langfuse/langfuse/issues/8138 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 2. 安装坑 · 来源证据：bug: unnamed trace name in Langfuse UI\n\n- 严重度：high\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：bug: unnamed trace name in Langfuse UI\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_a219c99fe99c4b7dab002e2b3a6296c2 | https://github.com/langfuse/langfuse/issues/13416 | 来源讨论提到 node 相关条件，需在安装/试用前复核。\n\n## 3. 安全/权限坑 · 来源证据：bug: AsyncStream' object has no attribute 'usage' when integrated with Semantic Kernel and Openlit\n\n- 严重度：high\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：bug: AsyncStream' object has no attribute 'usage' when integrated with Semantic Kernel and Openlit\n- 对用户的影响：可能影响授权、密钥配置或安全边界。\n- 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_8657d86702904e90b9d448770e618256 | https://github.com/langfuse/langfuse/issues/8173 | 来源类型 github_issue 暴露的待验证使用条件。\n\n## 4. 安全/权限坑 · 来源证据：bug: Worker shutdown takes ~1 hour in self hosted kubernetes\n\n- 严重度：high\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：bug: Worker shutdown takes ~1 hour in self hosted kubernetes\n- 对用户的影响：可能影响授权、密钥配置或安全边界。\n- 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_cff1b1d1a1ca4eb892563c33d3aa62e9 | https://github.com/langfuse/langfuse/issues/8156 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 5. 安装坑 · 来源证据：bug: Socket timeout. Expecting data, but didn't receive any in 30000ms on idle BullMQ queues\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：bug: Socket timeout. Expecting data, but didn't receive any in 30000ms on idle BullMQ queues\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_49a69075a1c346789a28db93c9ec6f3f | https://github.com/langfuse/langfuse/issues/13601 | 来源讨论提到 node 相关条件，需在安装/试用前复核。\n\n## 6. 安装坑 · 来源证据：v3.169.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v3.169.0\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_864f213fd7694eba9a4d2fe2bb9267ab | https://github.com/langfuse/langfuse/releases/tag/v3.169.0 | 来源讨论提到 npm 相关条件，需在安装/试用前复核。\n\n## 7. 安装坑 · 来源证据：v3.172.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v3.172.0\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_14588986ba9945eeb40cbc0508e3fed0 | https://github.com/langfuse/langfuse/releases/tag/v3.172.0 | 来源讨论提到 npm 相关条件，需在安装/试用前复核。\n\n## 8. 安装坑 · 来源证据：v3.173.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v3.173.0\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_7560a954846b4f35aedb74de1291c9a4 | https://github.com/langfuse/langfuse/releases/tag/v3.173.0 | 来源讨论提到 docker 相关条件，需在安装/试用前复核。\n\n## 9. 能力坑 · 能力判断依赖假设\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：README/documentation is current enough for a first validation pass.\n- 对用户的影响：假设不成立时，用户拿不到承诺的能力。\n- 建议检查：将假设转成下游验证清单。\n- 防护动作：假设必须转成验证项；没有验证结果前不能写成事实。\n- 证据：capability.assumptions | github_repo:642497346 | https://github.com/langfuse/langfuse | README/documentation is current enough for a first validation pass.\n\n## 10. 维护坑 · 维护活跃度未知\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：未记录 last_activity_observed。\n- 对用户的影响：新项目、停更项目和活跃项目会被混在一起，推荐信任度下降。\n- 建议检查：补 GitHub 最近 commit、release、issue/PR 响应信号。\n- 防护动作：维护活跃度未知时，推荐强度不能标为高信任。\n- 证据：evidence.maintainer_signals | github_repo:642497346 | https://github.com/langfuse/langfuse | last_activity_observed missing\n\n## 11. 安全/权限坑 · 下游验证发现风险项\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：no_demo\n- 对用户的影响：下游已经要求复核，不能在页面中弱化。\n- 建议检查：进入安全/权限治理复核队列。\n- 防护动作：下游风险存在时必须保持 review/recommendation 降级。\n- 证据：downstream_validation.risk_items | github_repo:642497346 | https://github.com/langfuse/langfuse | no_demo; severity=medium\n\n## 12. 安全/权限坑 · 存在评分风险\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：no_demo\n- 对用户的影响：风险会影响是否适合普通用户安装。\n- 建议检查：把风险写入边界卡，并确认是否需要人工复核。\n- 防护动作：评分风险必须进入边界卡，不能只作为内部分数。\n- 证据：risks.scoring_risks | github_repo:642497346 | https://github.com/langfuse/langfuse | no_demo; severity=medium\n\n## 13. 安全/权限坑 · 来源证据：v3.168.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：v3.168.0\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_202b4e8c2c1f4b3790315098d1530297 | https://github.com/langfuse/langfuse/releases/tag/v3.168.0 | 来源讨论提到 node 相关条件，需在安装/试用前复核。\n\n## 14. 安全/权限坑 · 来源证据：v3.170.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：v3.170.0\n- 对用户的影响：可能阻塞安装或首次运行。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_9ed6f994e1424878aa4559a73d72fc52 | https://github.com/langfuse/langfuse/releases/tag/v3.170.0 | 来源讨论提到 docker 相关条件，需在安装/试用前复核。\n\n## 15. 安全/权限坑 · 来源证据：v3.174.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：v3.174.0\n- 对用户的影响：可能影响授权、密钥配置或安全边界。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_f9cb7b7232ff4cce96f0c020fe48c7f4 | https://github.com/langfuse/langfuse/releases/tag/v3.174.0 | 来源讨论提到 api key 相关条件，需在安装/试用前复核。\n\n## 16. 维护坑 · issue/PR 响应质量未知\n\n- 严重度：low\n- 证据强度：source_linked\n- 发现：issue_or_pr_quality=unknown。\n- 对用户的影响：用户无法判断遇到问题后是否有人维护。\n- 建议检查：抽样最近 issue/PR，判断是否长期无人处理。\n- 防护动作：issue/PR 响应未知时，必须提示维护风险。\n- 证据：evidence.maintainer_signals | github_repo:642497346 | https://github.com/langfuse/langfuse | issue_or_pr_quality=unknown\n\n## 17. 维护坑 · 发布节奏不明确\n\n- 严重度：low\n- 证据强度：source_linked\n- 发现：release_recency=unknown。\n- 对用户的影响：安装命令和文档可能落后于代码，用户踩坑概率升高。\n- 建议检查：确认最近 release/tag 和 README 安装命令是否一致。\n- 防护动作：发布节奏未知或过期时，安装说明必须标注可能漂移。\n- 证据：evidence.maintainer_signals | github_repo:642497346 | https://github.com/langfuse/langfuse | release_recency=unknown\n\n<!-- canonical_name: langfuse/langfuse; human_manual_source: deepwiki_human_wiki -->\n",
      "markdown_key": "langfuse",
      "pages": "draft",
      "source_refs": [
        {
          "evidence_id": "github_repo:642497346",
          "kind": "repo",
          "supports_claim_ids": [
            "claim_identity",
            "claim_distribution",
            "claim_capability"
          ],
          "url": "https://github.com/langfuse/langfuse"
        },
        {
          "evidence_id": "art_4db510b3782b4191a485788845d3047b",
          "kind": "docs",
          "supports_claim_ids": [
            "claim_identity",
            "claim_distribution",
            "claim_capability"
          ],
          "url": "https://github.com/langfuse/langfuse#readme"
        }
      ],
      "summary": "DeepWiki/Human Wiki 完整输出，末尾追加 Discovery Agent 踩坑日志。",
      "title": "langfuse 说明书",
      "toc": [
        "https://github.com/langfuse/langfuse 项目说明书",
        "目录",
        "Project Introduction",
        "Overview",
        "Technology Stack",
        "Core Features",
        "Data Flow Architecture",
        "Filtering System",
        "Doramagic 踩坑日志"
      ]
    }
  },
  "quality_gate": {
    "blocking_gaps": [],
    "category_confidence": "medium",
    "compile_status": "ready_for_review",
    "five_assets_present": true,
    "install_sandbox_verified": true,
    "missing_evidence": [],
    "next_action": "publish to Doramagic.ai project surfaces",
    "prompt_preview_boundary_ok": true,
    "publish_status": "publishable",
    "quick_start_verified": true,
    "repo_clone_verified": true,
    "repo_commit": "da7d917597c723c7f659c185b987c667408a2f66",
    "repo_inspection_error": null,
    "repo_inspection_files": [
      "pnpm-lock.yaml",
      "package.json",
      "README.md",
      "docker-compose.yml",
      "packages/eslint-plugin/vitest.config.ts",
      "packages/eslint-plugin/vitest.setup.ts",
      "packages/eslint-plugin/package.json",
      "packages/eslint-plugin/tsconfig.json",
      "packages/shared/AGENTS.md",
      "packages/shared/package.json",
      "packages/shared/tsconfig.json",
      "packages/config-typescript/package.json",
      "packages/config-typescript/nextjs.json",
      "packages/config-typescript/base.json",
      "packages/config-eslint/base.js",
      "packages/config-eslint/index.js",
      "packages/config-eslint/index.d.ts",
      "packages/config-eslint/package.json",
      "packages/config-eslint/next.d.ts",
      "packages/config-eslint/base.d.ts",
      "packages/config-eslint/next.js",
      "packages/eslint-plugin/src/util.ts",
      "packages/eslint-plugin/src/index.ts",
      "packages/eslint-plugin/src/rules/no-tailwind-overflow-scroll.test.ts",
      "packages/eslint-plugin/src/rules/no-in-source-vitest.test.ts",
      "packages/eslint-plugin/src/rules/no-in-source-vitest.ts",
      "packages/eslint-plugin/src/rules/no-tailwind-overflow-scroll.ts",
      "packages/shared/src/eventsTable.ts",
      "packages/shared/src/db.ts",
      "packages/shared/src/constants.ts",
      "packages/shared/src/index.ts",
      "packages/shared/src/env.ts",
      "packages/shared/src/types.ts",
      "packages/shared/src/observationsTable.ts",
      "packages/shared/src/server/logger.ts",
      "packages/shared/src/server/deletionGuard.ts",
      "packages/shared/src/server/orderByToPrisma.ts",
      "packages/shared/src/server/traceDeletionProcessor.ts",
      "packages/shared/src/server/index.ts",
      "packages/shared/src/server/queues.ts"
    ],
    "repo_inspection_verified": true,
    "review_reasons": [],
    "tag_count_ok": true,
    "unsupported_claims": []
  },
  "schema_version": "0.1",
  "user_assets": {
    "ai_context_pack": {
      "asset_id": "ai_context_pack",
      "filename": "AI_CONTEXT_PACK.md",
      "markdown": "# langfuse - Doramagic AI Context Pack\n\n> 定位：安装前体验与判断资产。它帮助宿主 AI 有一个好的开始，但不代表已经安装、执行或验证目标项目。\n\n## 充分原则\n\n- **充分原则，不是压缩原则**：AI Context Pack 应该充分到让宿主 AI 在开工前理解项目价值、能力边界、使用入口、风险和证据来源；它可以分层组织，但不以最短摘要为目标。\n- **压缩策略**：只压缩噪声和重复内容，不压缩会影响判断和开工质量的上下文。\n\n## 给宿主 AI 的使用方式\n\n你正在读取 Doramagic 为 langfuse 编译的 AI Context Pack。请把它当作开工前上下文：帮助用户理解适合谁、能做什么、如何开始、哪些必须安装后验证、风险在哪里。不要声称你已经安装、运行或执行了目标项目。\n\n## Claim 消费规则\n\n- **事实来源**：Repo Evidence + Claim/Evidence Graph；Human Wiki 只提供显著性、术语和叙事结构。\n- **事实最低状态**：`supported`\n- `supported`：可以作为项目事实使用，但回答中必须引用 claim_id 和证据路径。\n- `weak`：只能作为低置信度线索，必须要求用户继续核实。\n- `inferred`：只能用于风险提示或待确认问题，不能包装成项目事实。\n- `unverified`：不得作为事实使用，应明确说证据不足。\n- `contradicted`：必须展示冲突来源，不得替用户强行选择一个版本。\n\n## 它最适合谁\n\n- **希望把专业流程带进宿主 AI 的用户**：仓库包含 Skill 文档。 证据：`.agents/skills/add-model-price/SKILL.md`, `.agents/skills/agent-setup-maintenance/SKILL.md`, `.agents/skills/analyze-cloud-costs/SKILL.md`, `.agents/skills/backend-dev-guidelines/SKILL.md` 等 Claim：`clm_0003` supported 0.86\n\n## 它能做什么\n\n- **AI Skill / Agent 指令资产库**（可做安装前预览）：项目包含可被宿主 AI 读取的 Skill 或 Agent 指令文件，可用于把专业流程带入 Claude、Codex、Cursor 等宿主。 证据：`.agents/skills/add-model-price/SKILL.md`, `.agents/skills/agent-setup-maintenance/SKILL.md`, `.agents/skills/analyze-cloud-costs/SKILL.md`, `.agents/skills/backend-dev-guidelines/SKILL.md` 等 Claim：`clm_0001` supported 0.86\n- **命令行启动或安装流程**（需要安装后验证）：项目文档中存在可执行命令，真实使用需要在本地或宿主环境中运行这些命令。 证据：`README.md` Claim：`clm_0002` supported 0.86\n\n## 怎么开始\n\n- `git clone https://github.com/langfuse/langfuse.git` 证据：`README.md` Claim：`clm_0004` supported 0.86\n- `pip install langfuse openai` 证据：`README.md` Claim：`clm_0005` supported 0.86\n\n## 继续前判断卡\n\n- **当前建议**：先做权限沙盒试用\n- **为什么**：项目存在安装命令、宿主配置或本地写入线索，不建议直接进入主力环境，应先在隔离环境试装。\n\n### 30 秒判断\n\n- **现在怎么做**：先做权限沙盒试用\n- **最小安全下一步**：先跑 Prompt Preview；若仍要安装，只在隔离环境试装\n- **先别相信**：工具权限边界不能在安装前相信。\n- **继续会触碰**：命令执行、宿主 AI 配置、本地环境或项目文件\n\n### 现在可以相信\n\n- **适合人群线索：希望把专业流程带进宿主 AI 的用户**（supported）：有 supported claim 或项目证据支撑，但仍不等于真实安装效果。 证据：`.agents/skills/add-model-price/SKILL.md`, `.agents/skills/agent-setup-maintenance/SKILL.md`, `.agents/skills/analyze-cloud-costs/SKILL.md`, `.agents/skills/backend-dev-guidelines/SKILL.md` 等 Claim：`clm_0003` supported 0.86\n- **能力存在：AI Skill / Agent 指令资产库**（supported）：可以相信项目包含这类能力线索；是否适合你的具体任务仍要试用或安装后验证。 证据：`.agents/skills/add-model-price/SKILL.md`, `.agents/skills/agent-setup-maintenance/SKILL.md`, `.agents/skills/analyze-cloud-costs/SKILL.md`, `.agents/skills/backend-dev-guidelines/SKILL.md` 等 Claim：`clm_0001` supported 0.86\n- **能力存在：命令行启动或安装流程**（supported）：可以相信项目包含这类能力线索；是否适合你的具体任务仍要试用或安装后验证。 证据：`README.md` Claim：`clm_0002` supported 0.86\n- **存在 Quick Start / 安装命令线索**（supported）：可以相信项目文档出现过启动或安装入口；不要因此直接在主力环境运行。 证据：`README.md` Claim：`clm_0004` supported 0.86\n\n### 现在还不能相信\n\n- **工具权限边界不能在安装前相信。**（unverified）：MCP/tool 类项目通常会触碰文件、网络、浏览器或外部 API，必须真实检查权限和日志。\n- **真实输出质量不能在安装前相信。**（unverified）：Prompt Preview 只能展示引导方式，不能证明真实项目中的结果质量。\n- **宿主 AI 版本兼容性不能在安装前相信。**（unverified）：Claude、Cursor、Codex、Gemini 等宿主加载规则和版本差异必须在真实环境验证。\n- **不会污染现有宿主 AI 行为，不能直接相信。**（inferred）：Skill、plugin、AGENTS/CLAUDE/GEMINI 指令可能改变宿主 AI 的默认行为。 证据：`.agents/skills/add-model-price/SKILL.md`, `.agents/skills/agent-setup-maintenance/SKILL.md`, `.agents/skills/analyze-cloud-costs/SKILL.md`, `.agents/skills/backend-dev-guidelines/SKILL.md` 等\n- **可安全回滚不能默认相信。**（unverified）：除非项目明确提供卸载和恢复说明，否则必须先在隔离环境验证。\n- **真实安装后是否与用户当前宿主 AI 版本兼容？**（unverified）：兼容性只能通过实际宿主环境验证。\n- **项目输出质量是否满足用户具体任务？**（unverified）：安装前预览只能展示流程和边界，不能替代真实评测。\n- **安装命令是否需要网络、权限或全局写入？**（unverified）：这影响企业环境和个人环境的安装风险。 证据：`README.md`\n\n### 继续会触碰什么\n\n- **命令执行**：包管理器、网络下载、本地插件目录、项目配置或用户主目录。 原因：运行第一条命令就可能产生环境改动；必须先判断是否值得跑。 证据：`README.md`\n- **宿主 AI 配置**：Claude/Codex/Cursor/Gemini/OpenCode 等宿主的 plugin、Skill 或规则加载配置。 原因：宿主配置会改变 AI 后续工作方式，可能和用户已有规则冲突。 证据：`.agents/skills/add-model-price/SKILL.md`, `.agents/skills/agent-setup-maintenance/SKILL.md`, `.agents/skills/analyze-cloud-costs/SKILL.md`, `.agents/skills/backend-dev-guidelines/SKILL.md` 等\n- **本地环境或项目文件**：安装结果、插件缓存、项目配置或本地依赖目录。 原因：安装前无法证明写入范围和回滚方式，需要隔离验证。 证据：`README.md`\n- **宿主 AI 上下文**：AI Context Pack、Prompt Preview、Skill 路由、风险规则和项目事实。 原因：导入上下文会影响宿主 AI 后续判断，必须避免把未验证项包装成事实。\n\n### 最小安全下一步\n\n- **先跑 Prompt Preview**：用安装前交互式试用判断工作方式是否匹配，不需要授权或改环境。（适用：任何项目都适用，尤其是输出质量未知时。）\n- **只在隔离目录或测试账号试装**：避免安装命令污染主力宿主 AI、真实项目或用户主目录。（适用：存在命令执行、插件配置或本地写入线索时。）\n- **先备份宿主 AI 配置**：Skill、plugin、规则文件可能改变 Claude/Cursor/Codex 的默认行为。（适用：存在插件 manifest、Skill 或宿主规则入口时。）\n- **安装后只验证一个最小任务**：先验证加载、兼容、输出质量和回滚，再决定是否深用。（适用：准备从试用进入真实工作流时。）\n\n### 退出方式\n\n- **保留安装前状态**：记录原始宿主配置和项目状态，后续才能判断是否可恢复。\n- **准备移除宿主 plugin / Skill / 规则入口**：如果试装后行为异常，可以把宿主 AI 恢复到试装前状态。\n- **记录安装命令和写入路径**：没有明确卸载说明时，至少要知道哪些目录或配置需要手动清理。\n- **如果没有回滚路径，不进入主力环境**：不可回滚是继续前阻断项，不应靠信任或运气继续。\n\n## 哪些只能预览\n\n- 解释项目适合谁和能做什么\n- 基于项目文档演示典型对话流程\n- 帮助用户判断是否值得安装或继续研究\n\n## 哪些必须安装后验证\n\n- 真实安装 Skill、插件或 CLI\n- 执行脚本、修改本地文件或访问外部服务\n- 验证真实输出质量、性能和兼容性\n\n## 边界与风险判断卡\n\n- **把安装前预览误认为真实运行**：用户可能高估项目已经完成的配置、权限和兼容性验证。 处理方式：明确区分 prompt_preview_can_do 与 runtime_required。 Claim：`clm_0006` inferred 0.45\n- **命令执行会修改本地环境**：安装命令可能写入用户主目录、宿主插件目录或项目配置。 处理方式：先在隔离环境或测试账号中运行。 证据：`README.md` Claim：`clm_0007` supported 0.86\n- **待确认**：真实安装后是否与用户当前宿主 AI 版本兼容？。原因：兼容性只能通过实际宿主环境验证。\n- **待确认**：项目输出质量是否满足用户具体任务？。原因：安装前预览只能展示流程和边界，不能替代真实评测。\n- **待确认**：安装命令是否需要网络、权限或全局写入？。原因：这影响企业环境和个人环境的安装风险。\n\n## 开工前工作上下文\n\n### 加载顺序\n\n- 先读取 how_to_use.host_ai_instruction，建立安装前判断资产的边界。\n- 读取 claim_graph_summary，确认事实来自 Claim/Evidence Graph，而不是 Human Wiki 叙事。\n- 再读取 intended_users、capabilities 和 quick_start_candidates，判断用户是否匹配。\n- 需要执行具体任务时，优先查 role_skill_index，再查 evidence_index。\n- 遇到真实安装、文件修改、网络访问、性能或兼容性问题时，转入 risk_card 和 boundaries.runtime_required。\n\n### 任务路由\n\n- **AI Skill / Agent 指令资产库**：先基于 role_skill_index / evidence_index 帮用户挑选可用角色、Skill 或工作流。 边界：可做安装前 Prompt 体验。 证据：`.agents/skills/add-model-price/SKILL.md`, `.agents/skills/agent-setup-maintenance/SKILL.md`, `.agents/skills/analyze-cloud-costs/SKILL.md`, `.agents/skills/backend-dev-guidelines/SKILL.md` 等 Claim：`clm_0001` supported 0.86\n- **命令行启动或安装流程**：先说明这是安装后验证能力，再给出安装前检查清单。 边界：必须真实安装或运行后验证。 证据：`README.md` Claim：`clm_0002` supported 0.86\n\n### 上下文规模\n\n- 文件总数：3236\n- 重要文件覆盖：40/3236\n- 证据索引条目：80\n- 角色 / Skill 条目：17\n\n### 证据不足时的处理\n\n- **missing_evidence**：说明证据不足，要求用户提供目标文件、README 段落或安装后验证记录；不要补全事实。\n- **out_of_scope_request**：说明该任务超出当前 AI Context Pack 证据范围，并建议用户先查看 Human Manual 或真实安装后验证。\n- **runtime_request**：给出安装前检查清单和命令来源，但不要替用户执行命令或声称已执行。\n- **source_conflict**：同时展示冲突来源，标记为待核实，不要强行选择一个版本。\n\n## Prompt Recipes\n\n### 适配判断\n\n- 目标：判断这个项目是否适合用户当前任务。\n- 预期输出：适配结论、关键理由、证据引用、安装前可预览内容、必须安装后验证内容、下一步建议。\n\n```text\n请基于 langfuse 的 AI Context Pack，先问我 3 个必要问题，然后判断它是否适合我的任务。回答必须包含：适合谁、能做什么、不能做什么、是否值得安装、证据来自哪里。所有项目事实必须引用 evidence_refs、source_paths 或 claim_id。\n```\n\n### 安装前体验\n\n- 目标：让用户在安装前感受核心工作流，同时避免把预览包装成真实能力或营销承诺。\n- 预期输出：一段带边界标签的体验剧本、安装后验证清单和谨慎建议；不含真实运行承诺或强营销表述。\n\n```text\n请把 langfuse 当作安装前体验资产，而不是已安装工具或真实运行环境。\n\n请严格输出四段：\n1. 先问我 3 个必要问题。\n2. 给出一段“体验剧本”：用 [安装前可预览]、[必须安装后验证]、[证据不足] 三种标签展示它可能如何引导工作流。\n3. 给出安装后验证清单：列出哪些能力只有真实安装、真实宿主加载、真实项目运行后才能确认。\n4. 给出谨慎建议：只能说“值得继续研究/试装”“先补充信息后再判断”或“不建议继续”，不得替项目背书。\n\n硬性边界：\n- 不要声称已经安装、运行、执行测试、修改文件或产生真实结果。\n- 不要写“自动适配”“确保通过”“完美适配”“强烈建议安装”等承诺性表达。\n- 如果描述安装后的工作方式，必须使用“如果安装成功且宿主正确加载 Skill，它可能会……”这种条件句。\n- 体验剧本只能写成“示例台词/假设流程”：使用“可能会询问/可能会建议/可能会展示”，不要写“已写入、已生成、已通过、正在运行、正在生成”。\n- Prompt Preview 不负责给安装命令；如用户准备试装，只能提示先阅读 Quick Start 和 Risk Card，并在隔离环境验证。\n- 所有项目事实必须来自 supported claim、evidence_refs 或 source_paths；inferred/unverified 只能作风险或待确认项。\n\n```\n\n### 角色 / Skill 选择\n\n- 目标：从项目里的角色或 Skill 中挑选最匹配的资产。\n- 预期输出：候选角色或 Skill 列表，每项包含适用场景、证据路径、风险边界和是否需要安装后验证。\n\n```text\n请读取 role_skill_index，根据我的目标任务推荐 3-5 个最相关的角色或 Skill。每个推荐都要说明适用场景、可能输出、风险边界和 evidence_refs。\n```\n\n### 风险预检\n\n- 目标：安装或引入前识别环境、权限、规则冲突和质量风险。\n- 预期输出：环境、权限、依赖、许可、宿主冲突、质量风险和未知项的检查清单。\n\n```text\n请基于 risk_card、boundaries 和 quick_start_candidates，给我一份安装前风险预检清单。不要替我执行命令，只说明我应该检查什么、为什么检查、失败会有什么影响。\n```\n\n### 宿主 AI 开工指令\n\n- 目标：把项目上下文转成一次对话开始前的宿主 AI 指令。\n- 预期输出：一段边界明确、证据引用明确、适合复制给宿主 AI 的开工前指令。\n\n```text\n请基于 langfuse 的 AI Context Pack，生成一段我可以粘贴给宿主 AI 的开工前指令。这段指令必须遵守 not_runtime=true，不能声称项目已经安装、运行或产生真实结果。\n```\n\n\n## 角色 / Skill 索引\n\n- 共索引 17 个角色 / Skill / 项目文档条目。\n\n- **add-model-price**（skill）：Use when editing worker/src/constants/default-model-prices.json, packages/shared/src/server/llm/types.ts, pricing tiers, tokenizer IDs, or matchPattern regexes for OpenAI, Anthropic, Bedrock, Vertex, Azure, or Gemini model pricing. 激活提示：当用户任务与“add-model-price”描述的流程高度相关时，先用它做安装前体验，再决定是否安装。 证据：`.agents/skills/add-model-price/SKILL.md`\n- **agent-setup-maintenance**（skill）： 激活提示：当用户任务与“agent-setup-maintenance”描述的流程高度相关时，先用它做安装前体验，再决定是否安装。 证据：`.agents/skills/agent-setup-maintenance/SKILL.md`\n- **analyze-cloud-costs**（skill）： 激活提示：当用户任务与“analyze-cloud-costs”描述的流程高度相关时，先用它做安装前体验，再决定是否安装。 证据：`.agents/skills/analyze-cloud-costs/SKILL.md`\n- **backend-dev-guidelines**（skill）：Shared backend guide for Langfuse's Next.js, tRPC, BullMQ, and TypeScript monorepo. Use when creating or reviewing tRPC routers, public REST endpoints, BullMQ queue processors, backend services, middleware, Prisma or ClickHouse data access, OpenTelemetry instrumentation, Zod validation, env configuration, or backend tests across web, worker, or packages/shared. 激活提示：当用户任务与“backend-dev-guidelines”描述的流程高度相关时，先用它做安装前体验，再决定是否安装。 证据：`.agents/skills/backend-dev-guidelines/SKILL.md`\n- **changelog-writing**（skill）： 激活提示：当用户任务与“changelog-writing”描述的流程高度相关时，先用它做安装前体验，再决定是否安装。 证据：`.agents/skills/changelog-writing/SKILL.md`\n- **clickhouse-best-practices**（skill）：MUST USE when reviewing ClickHouse schemas, queries, or configurations. Contains 28 rules that MUST be checked before providing recommendations. Always read relevant rule files and cite specific rules in responses. 激活提示：当用户任务与“clickhouse-best-practices”描述的流程高度相关时，先用它做安装前体验，再决定是否安装。 证据：`.agents/skills/clickhouse-best-practices/SKILL.md`\n- **code-review**（skill）： 激活提示：当用户任务与“code-review”描述的流程高度相关时，先用它做安装前体验，再决定是否安装。 证据：`.agents/skills/code-review/SKILL.md`\n- **datadog-query-recipes**（skill）： 激活提示：当用户任务与“datadog-query-recipes”描述的流程高度相关时，先用它做安装前体验，再决定是否安装。 证据：`.agents/skills/datadog-query-recipes/SKILL.md`\n- **debug-issue-with-datadog**（skill）： 激活提示：当用户任务与“debug-issue-with-datadog”描述的流程高度相关时，先用它做安装前体验，再决定是否安装。 证据：`.agents/skills/debug-issue-with-datadog/SKILL.md`\n- **detect-prod-regressions**（skill）： 激活提示：当用户任务与“detect-prod-regressions”描述的流程高度相关时，先用它做安装前体验，再决定是否安装。 证据：`.agents/skills/detect-prod-regressions/SKILL.md`\n- **frontend-browser-review**（skill）： 激活提示：当用户任务与“frontend-browser-review”描述的流程高度相关时，先用它做安装前体验，再决定是否安装。 证据：`.agents/skills/frontend-browser-review/SKILL.md`\n- **linear-bug-triage**（skill）： 激活提示：当用户任务与“linear-bug-triage”描述的流程高度相关时，先用它做安装前体验，再决定是否安装。 证据：`.agents/skills/linear-bug-triage/SKILL.md`\n- **pnpm-upgrade-package**（skill）：Use when upgrading a dependency in this pnpm workspace, including requests to bump a package to a specific version, compare the registry latest version with the latest version installable under the current minimum-release-age window, or decide whether minimumReleaseAgeExclude in pnpm-workspace.yaml must change. Ask the user for the package name or target version when either is missing. 激活提示：当用户任务与“pnpm-upgrade-package”描述的流程高度相关时，先用它做安装前体验，再决定是否安装。 证据：`.agents/skills/pnpm-upgrade-package/SKILL.md`\n- **skill-creator**（skill）：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 Codex's capabilities with specialized knowledge, workflows, or tool integrations. 激活提示：当用户任务与“skill-creator”描述的流程高度相关时，先用它做安装前体验，再决定是否安装。 证据：`.agents/skills/skill-creator/SKILL.md`\n- **turborepo**（skill）： 激活提示：当用户任务与“turborepo”描述的流程高度相关时，先用它做安装前体验，再决定是否安装。 证据：`.agents/skills/turborepo/SKILL.md`\n- **vercel-composition-patterns**（skill）：Composition patterns for building flexible, maintainable React components. Avoid boolean prop proliferation by using compound components, lifting state, and composing internals. These patterns make codebases easier for both humans and AI agents to work with as they scale. 激活提示：当用户任务与“vercel-composition-patterns”描述的流程高度相关时，先用它做安装前体验，再决定是否安装。 证据：`web/.agents/skills/vercel-composition-patterns/SKILL.md`\n- **vercel-react-best-practices**（skill）：React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements. 激活提示：当用户任务与“vercel-react-best-practices”描述的流程高度相关时，先用它做安装前体验，再决定是否安装。 证据：`web/.agents/skills/vercel-react-best-practices/SKILL.md`\n\n## 证据索引\n\n- 共索引 80 条证据。\n\n- **Agent Guidelines for Langfuse**（documentation）：This is the canonical root agent guide for the repo. The root AGENTS.md should remain only as a discovery symlink so tools that require that filename continue to work while .agents/ stays the source of truth. 证据：`.agents/AGENTS.md`\n- **Shared Agent Setup**（documentation）：This directory is the neutral, repo-owned source of truth for agent behavior in Langfuse. 证据：`.agents/README.md`\n- **✨ Core Features**（documentation）：Langfuse Is Doubling Down On Open Source Langfuse Cloud · Self Host · Demo 证据：`README.md`\n- **Codex Guidelines for ee**（documentation）：This file covers package-local guidance for this package. Use root AGENTS.md ../AGENTS.md for monorepo-level rules. 证据：`ee/AGENTS.md`\n- **Enterprise Edition**（documentation）：This folder includes features that are only available in the Enterprise Edition of Langfuse and on Langfuse Cloud. 证据：`ee/README.md`\n- **Codex Guidelines for web**（documentation）：This file covers package-local guidance for this package. Use root AGENTS.md ../AGENTS.md for monorepo-level rules. 证据：`web/AGENTS.md`\n- **CLAUDE.md**（documentation）：Claude Code should treat this file as the package entrypoint for web/ . 证据：`web/CLAUDE.md`\n- **Codex Guidelines for worker**（documentation）：This file covers package-local guidance for this package. Use root AGENTS.md ../AGENTS.md for monorepo-level rules. 证据：`worker/AGENTS.md`\n- **Shared Skills**（documentation）：Shared repo skills for any coding agent working in Langfuse. 证据：`.agents/skills/README.md`\n- **Add Model Price**（documentation）：Guide for adding or updating model pricing entries in Langfuse. Use this when editing worker/src/constants/default-model-prices.json , packages/shared/src/server/llm/types.ts , model matchPattern values, tokenizer IDs, or pricing tiers. 证据：`.agents/skills/add-model-price/AGENTS.md`\n- **Backend Development Guidelines**（documentation）：Establish consistency and best practices across Langfuse's backend packages web , worker , packages/shared using Next.js, tRPC, BullMQ, and TypeScript patterns. Check package manifests such as web/package.json for current framework versions before version-sensitive work. Keep this file as an entrypoint; open reference files only when the task needs their details. 证据：`.agents/skills/backend-dev-guidelines/AGENTS.md`\n- **ClickHouse Best Practices**（documentation）：Start with SKILL.md for the ClickHouse review workflow, rule-selection process, and response format. This file exists as a concise compatibility entrypoint for agents that open AGENTS.md directly. 证据：`.agents/skills/clickhouse-best-practices/AGENTS.md`\n- **ClickHouse Best Practices**（documentation）：Agent skill providing comprehensive ClickHouse guidance for schema design, query optimization, and data ingestion. 证据：`.agents/skills/clickhouse-best-practices/README.md`\n- **PNPM Upgrade Package**（documentation）：Use this workflow when a user wants to upgrade a dependency in the Langfuse pnpm workspace. 证据：`.agents/skills/pnpm-upgrade-package/AGENTS.md`\n- **Codex Guidelines for @langfuse/shared**（documentation）：Codex Guidelines for @langfuse/shared 证据：`packages/shared/AGENTS.md`\n- **Langfuse Seeder System**（documentation）：System for generating test data in ClickHouse and PostgreSQL for Langfuse development and testing. 证据：`packages/shared/scripts/seeder/utils/README.md`\n- **Framework Traces**（documentation）：This folder contains real traces produced through framework instrumentation. Most of them stem from here: https://langfuse.com/integrations/frameworks/agno-agents and so on. 证据：`packages/shared/scripts/seeder/utils/framework-traces/README.md`\n- **Score Interfaces**（documentation）：This directory contains all type definitions, schemas, and validation logic for Langfuse scores. 证据：`packages/shared/src/features/scores/interfaces/README.md`\n- **Instrumentation at Langfuse**（documentation）：Throughout our applications we want to use as much Otel as possible. This helps us to be flexible choosing our observability backend, and we will benefit from features and packages built by the Otel community. 证据：`packages/shared/src/server/instrumentation/README.md`\n- **Repository docs**（documentation）：Guarantees for relating data within Langfuse 证据：`packages/shared/src/server/repositories/README.md`\n- **React Composition Patterns**（documentation）：Version 1.0.0 Engineering January 2026 证据：`web/.agents/skills/vercel-composition-patterns/AGENTS.md`\n- **React Best Practices**（documentation）：Version 1.0.0 Vercel Engineering January 2026 证据：`web/.agents/skills/vercel-react-best-practices/AGENTS.md`\n- **Design System**（documentation）：This folder contains reusable, primitive, presentational UI components . 证据：`web/src/components/design-system/README.md`\n- **📦 Langfuse Layout Components**（documentation）：📌 Overview: Page - Standard Page Wrapper 证据：`web/src/components/layouts/README.md`\n- **Peek View Table State Management**（documentation）：This document describes how table state filters, sorting, pagination, search is managed and persisted in peek views when navigating between items using K/J keyboard shortcuts. 证据：`web/src/components/table/peek/README.md`\n- **Table View Presets**（documentation）：This module provides a flexible and robust way to manage and persist table states across sessions. Users can save, load, and share specific table configurations including column visibility, ordering, filters, and search queries. 证据：`web/src/components/table/table-view-presets/README.md`\n- **AdvancedJsonViewer**（documentation）：A high-performance JSON viewer component built for rendering large datasets 10K+ nodes with virtualization, search, and near-instant expand/collapse operations. 证据：`web/src/components/ui/AdvancedJsonViewer/README.md`\n- **Enterprise Edition**（documentation）：This folder includes features that are only available in the Enterprise Edition of Langfuse and on Langfuse Cloud. 证据：`web/src/ee/README.md`\n- **Billing**（documentation）：Stripe Billing powers subscriptions and usage-based pricing for organizations. We primarily use the new flexible billing model plan + usage and still handle legacy, single-item metered subscriptions during migration. 证据：`web/src/ee/features/billing/README.md`\n- **Public API**（documentation）：- Wrap with withMiddleware - Type-safe and authed API Route with createAuthedAPIRoute - Add zod types to /features/public-api/types folder. 证据：`web/src/features/README.md`\n- **Batch Exports**（documentation）：- Find types in shared - Actual export logic in worker 证据：`web/src/features/batch-exports/README.md`\n- **Dataset Mutations**（documentation）：Always use functions in this directory. Never use direct Prisma calls. 证据：`web/src/features/datasets/server/actions/README.md`\n- **Entitlements**（documentation）：This feature allows to control for availability of features. Entitlements are managed on the organization level. 证据：`web/src/features/entitlements/README.md`\n- **Feature Flags**（documentation）：Configure feature flags in the available-flags.ts file. 证据：`web/src/features/feature-flags/README.md`\n- **Langfuse MCP Server**（documentation）：Model Context Protocol MCP server for Langfuse, enabling AI assistants to interact with your Langfuse prompts programmatically. 证据：`web/src/features/mcp/README.md`\n- **Caching Strategy of Prompts**（documentation）：The caching strategy for prompts is implemented in the PromptService class and is utilized in the createPrompt function. Here is an overview of how the caching mechanism works: 证据：`web/src/features/prompts/README.md`\n- **Prompt Mutations**（documentation）：Always use functions in this directory. Never use direct Prisma calls. 证据：`web/src/features/prompts/server/actions/README.md`\n- **Caching Strategy of API Keys**（documentation）：The cache for API keys is managed using Redis. The cache key looks like the following: api-key: : . The hash is the fastHashedSecretKey from postgres. Hence, we can easily find the key in Redis. 证据：`web/src/features/public-api/README.md`\n- **Score Analytics - Architecture Guide**（documentation）：Score Analytics - Architecture Guide 证据：`web/src/features/score-analytics/README.md`\n- **Slack Integration Setup Guide**（documentation）：This guide walks you through setting up and testing the Langfuse Slack integration for local development. 证据：`web/src/features/slack/README.md`\n- **Telemetry service for Docker deployments**（documentation）：Telemetry service for Docker deployments 证据：`web/src/features/telemetry/README.md`\n- **Readme**（documentation）：These APIs are implemented via the NextJS App router in src/app/api/billing. 证据：`web/src/pages/api/billing/README.md`\n- **otlp-proto**（documentation）：This directory contains compiled opentelemetry protobuf files. Those should correspond to the definitions in https://github.com/open-telemetry/opentelemetry-proto/tree/v1.5.0 and are copied from the generated contents of https://www.npmjs.com/package/@opentelemetry/otlp-transformer. The file was converted from .js to .ts and the export statements were modified to make them Next.js compatible. 证据：`web/src/pages/api/public/otel/otlp-proto/README.md`\n- **ChatML Normalization System**（documentation）：Normalizes LLM provider/framework data traces, observations to ChatML format for display and, partly, playground. In general, provider adapters preprocess data → ChatMlSchema validates → UI renders 证据：`web/src/utils/chatml/README.md`\n- **Readme**（documentation）：Those traces are used to test the chatML adapters. They comes for the various framework intragration examples in Langfuse's doc for example https://langfuse.com/integrations/frameworks/agno-agents . Use download traces.js to generate the files. 证据：`worker/src/__tests__/chatml/framework-traces/README.md`\n- **Background Migrations**（documentation）：Background migrations are longer running jobs that must not be complete before a new application version can be served correctly. They are used to fill new optional columns, migrate data between tables or systems, or perform other actions that would take too long to run in a standard migration. A good threshold is something that takes more than 5 minutes to run or is not an atomic operation. 证据：`worker/src/backgroundMigrations/README.md`\n- **Refill Queue Event**（documentation）：This is a utility script to backfill any queue with events from local machines. It validates events against the queue's schema and processes them in batches for efficient ingestion. 证据：`worker/src/scripts/refillQueueEvent/README.md`\n- **Replay Ingestion Events from S3 v2**（documentation）：Replays failed ingestion events by reading S3 keys from a CSV and submitting them to Langfuse via an admin API endpoint. This replaces the v1 script ../replayIngestionEvents/README.md , which required direct Redis, ClickHouse, and PostgreSQL access plus a full repo clone. 证据：`worker/src/scripts/replayIngestionEventsV2/README.md`\n- **Verify Clickhouse Records**（documentation）：This script is used to compare Clickhouse records to our Postgres records. Per default, it draws a sample of observations, traces, and scores from the Postgres tables and executes single queries on Clickhouse to compare the individual fields. It is possible to overwrite the selection process using the overwriteIds per type. 证据：`worker/src/scripts/verifyClickhouseRecords/README.md`\n- **Package**（package_manifest）：{ \"name\": \"@langfuse/ee\", \"version\": \"1.0.0\", \"private\": true, \"main\": \"./dist/src/index.js\", \"types\": \"./dist/src/index.d.ts\", \"exports\": { \".\": { \"import\": \"./dist/src/index.js\", \"require\": \"./dist/src/index.js\" }, \"./sso\": { \"import\": \"./dist/src/sso/index.js\", \"require\": \"./dist/src/sso/index.js\" } }, \"engines\": { \"node\": \"24\" }, \"scripts\": { \"build\": \"tsc\", \"build:check\": \"tsc\", \"typecheck\": \"dotenv -e ../../.env -- tsgo --noEmit --skipLibCheck --incremental --tsBuildInfoFile .tsbuildinfo\", \"dev\": \"tsc --watch\", \"lint\": \"eslint . --cache --cache-location dist/.eslintcache --max-warnings 0\", \"lint:fix\": \"eslint . --cache --cache-location dist/.eslintcache --fix\" }, \"dependencies\": { \"@l… 证据：`ee/package.json`\n- **Package**（package_manifest）：{ \"name\": \"langfuse\", \"version\": \"3.174.1\", \"author\": \"engineering@langfuse.com\", \"license\": \"MIT\", \"private\": true, \"engines\": { \"node\": \"24\" }, \"scripts\": { \"agents:check\": \"node scripts/agents/sync-agent-shims.mjs --check\", \"agents:sync\": \"node scripts/agents/sync-agent-shims.mjs\", \"postinstall\": \"node -e \\\"const fs = require 'node:fs' ; const cp = require 'node:child process' ; if !fs.existsSync 'scripts/postinstall.sh' { console.log 'Skipping repo postinstall helper: scripts/postinstall.sh is not present in this install context.' ; process.exit 0 ; } cp.execSync 'bash scripts/postinstall.sh', { stdio: 'inherit' } ;\\\"\", \"preinstall\": \"npx only-allow pnpm\", \"infra:dev:up\": \"docker compos… 证据：`package.json`\n- **Package**（package_manifest）：{ \"name\": \"web\", \"version\": \"3.174.1\", \"private\": true, \"license\": \"MIT\", \"engines\": { \"node\": \"24\" }, \"scripts\": { \"build\": \"INLINE RUNTIME CHUNK=false dotenv -e ../.env -- next build\", \"build:check\": \"NEXT DIST DIR=.next-check INLINE RUNTIME CHUNK=false dotenv -e ../.env -- next build\", \"typecheck\": \"dotenv -e ../.env -- tsgo -p tsconfig.build.json --noEmit --skipLibCheck --incremental --tsBuildInfoFile .tsbuildinfo\", \"dev\": \"dotenv -e ../.env -- next dev\", \"dev:http\": \"dotenv -e ../.env -- next dev --experimental-https --experimental-https-key ./localhost+1-key.pem --experimental-https-cert ./localhost+1.pem\", \"lint\": \"dotenv -e ../.env -- eslint . --cache --cache-location .next/cache/es… 证据：`web/package.json`\n- **Package**（package_manifest）：{ \"name\": \"worker\", \"version\": \"3.174.1\", \"description\": \"\", \"license\": \"MIT\", \"private\": true, \"files\": \"dist/ \", \"entrypoint.sh\" , \"engines\": { \"node\": \"24\" }, \"scripts\": { \"test\": \"vitest run\", \"test:exclude-llm-connections\": \"vitest run --exclude ' /llmConnections.test.ts'\", \"test:llm-connections-only\": \"vitest run llmConnections.test.ts\", \"coverage\": \"vitest run --coverage\", \"start\": \"dotenv -e ../.env -- node dist/index.js\", \"build\": \"tsc\", \"build:check\": \"tsc\", \"typecheck\": \"dotenv -e ../.env -- tsgo --noEmit --skipLibCheck --incremental --tsBuildInfoFile .tsbuildinfo\", \"dev\": \"dotenv -e ../.env -- tsx watch --clear-screen=false --include '../packages/shared/dist/ ' src/index.ts\", \"l… 证据：`worker/package.json`\n- **Contributing to Langfuse**（documentation）：! Langfuse GitHub Banner https://github.com/langfuse/langfuse/assets/121163007/6035f0f3-d691-4963-b5d0-10cf506e9d42 证据：`CONTRIBUTING.md`\n- **Package**（package_manifest）：{ \"name\": \"@repo/eslint-config\", \"version\": \"0.0.0\", \"license\": \"MIT\", \"private\": true, \"type\": \"module\", \"exports\": { \".\": \"./index.js\", \"./base\": \"./base.js\", \"./next\": \"./next.js\" }, \"files\": \"index.js\", \"base.js\", \"next.js\" , \"dependencies\": { \"@eslint/js\": \"^9.39.2\", \"@repo/eslint-plugin\": \"workspace: \", \"eslint-config-next\": \"16.2.6\", \"eslint-config-prettier\": \"^10.1.8\", \"eslint-config-turbo\": \"2.9.12\", \"eslint-plugin-only-warn\": \"^1.1.0\", \"eslint-plugin-prettier\": \"^5.5.4\", \"globals\": \"^16.0.0\", \"typescript-eslint\": \"^8.57.1\" }, \"peerDependencies\": { \"eslint\": \"^9.39.0\", \"typescript\": \" =5.0.0\" } } 证据：`packages/config-eslint/package.json`\n- **Package**（package_manifest）：{ \"name\": \"@repo/typescript-config\", \"license\": \"MIT\", \"version\": \"0.0.0\", \"private\": true, \"publishConfig\": { \"access\": \"public\" } } 证据：`packages/config-typescript/package.json`\n- **Package**（package_manifest）：{ \"name\": \"@repo/eslint-plugin\", \"version\": \"0.0.0\", \"license\": \"MIT\", \"private\": true, \"type\": \"module\", \"main\": \"dist/index.js\", \"scripts\": { \"test\": \"vitest run\", \"build\": \"tsc\" }, \"devDependencies\": { \"@repo/typescript-config\": \"workspace: \", \"@types/node\": \"^24.3.0\", \"@typescript-eslint/parser\": \"^8.59.0\", \"@typescript-eslint/rule-tester\": \"^8.59.0\", \"@typescript-eslint/utils\": \"^8.59.0\", \"typescript\": \"^5.9.2\", \"vitest\": \"^4.1.4\" } } 证据：`packages/eslint-plugin/package.json`\n- **Package**（package_manifest）：{ \"name\": \"@langfuse/shared\", \"version\": \"1.0.0\", \"license\": \"MIT\", \"private\": true, \"files\": \"dist/ \", \"prisma/ \", \"clickhouse/ \", \"scripts/cleanup.sql\" , \"main\": \"./dist/src/index.js\", \"types\": \"./dist/src/index.d.ts\", \"engines\": { \"node\": \"24\" }, \"exports\": { \".\": { \"import\": \"./dist/src/index.js\", \"require\": \"./dist/src/index.js\" }, \"./src/db\": { \"import\": \"./dist/src/db.js\", \"require\": \"./dist/src/db.js\" }, \"./src/env\": { \"import\": \"./dist/src/env.js\", \"require\": \"./dist/src/env.js\" }, \"./src/server\": { \"import\": \"./dist/src/server/index.js\", \"require\": \"./dist/src/server/index.js\" }, \"./src/server/auth/apiKeys\": { \"import\": \"./dist/src/server/auth/apiKeys.js\", \"require\": \"./dist/src/s… 证据：`packages/shared/package.json`\n- **Add Model Price**（skill_instruction）：Use this skill for model pricing changes in worker/ and shared LLM type updates in packages/shared/ . 证据：`.agents/skills/add-model-price/SKILL.md`\n- **Agent Setup Maintenance**（skill_instruction）：Use this skill when changing the shared agent setup for the repository. 证据：`.agents/skills/agent-setup-maintenance/SKILL.md`\n- 其余 20 条证据见 `AI_CONTEXT_PACK.json` 或 `EVIDENCE_INDEX.json`。\n\n## 宿主 AI 必须遵守的规则\n\n- **把本资产当作开工前上下文，而不是运行环境。**：AI Context Pack 只包含证据化项目理解，不包含目标项目的可执行状态。 证据：`.agents/AGENTS.md`, `.agents/README.md`, `README.md`\n- **回答用户时区分可预览内容与必须安装后才能验证的内容。**：安装前体验的消费者价值来自降低误装和误判，而不是伪装成真实运行。 证据：`.agents/AGENTS.md`, `.agents/README.md`, `README.md`\n\n## 用户开工前应该回答的问题\n\n- 你准备在哪个宿主 AI 或本地环境中使用它？\n- 你只是想先体验工作流，还是准备真实安装？\n- 你最在意的是安装成本、输出质量、还是和现有规则的冲突？\n\n## 验收标准\n\n- 所有能力声明都能回指到 evidence_refs 中的文件路径。\n- AI_CONTEXT_PACK.md 没有把预览包装成真实运行。\n- 用户能在 3 分钟内看懂适合谁、能做什么、如何开始和风险边界。\n\n---\n\n## Doramagic Context Augmentation\n\n下面内容用于强化 Repomix/AI Context Pack 主体。Human Manual 只提供阅读骨架；踩坑日志会被转成宿主 AI 必须遵守的工作约束。\n\n## Human Manual 骨架\n\n使用规则：这里只是项目阅读路线和显著性信号，不是事实权威。具体事实仍必须回到 repo evidence / Claim Graph。\n\n宿主 AI 硬性规则：\n- 不得把页标题、章节顺序、摘要或 importance 当作项目事实证据。\n- 解释 Human Manual 骨架时，必须明确说它只是阅读路线/显著性信号。\n- 能力、安装、兼容性、运行状态和风险判断必须引用 repo evidence、source path 或 Claim Graph。\n\n- **Project Introduction**：importance `high`\n  - source_paths: README.md, packages/shared/src/constants/VERSION.ts\n- **Project Structure**：importance `high`\n  - source_paths: pnpm-workspace.yaml, turbo.json, packages/shared/package.json, web/package.json, worker/package.json\n- **Quickstart Guide**：importance `high`\n  - source_paths: docker-compose.yml, CONTRIBUTING.md\n- **System Architecture**：importance `high`\n  - source_paths: packages/shared/src/server/clickhouse/client.ts, packages/shared/src/server/redis/redis.ts, packages/shared/src/db.ts, packages/shared/src/server/otel/index.ts\n- **Monorepo Configuration**：importance `medium`\n  - source_paths: turbo.json, packages/config-eslint/index.js, packages/config-typescript/base.json, packages/shared/tsconfig.json\n- **Database Schema (Prisma)**：importance `high`\n  - source_paths: packages/shared/prisma/schema.prisma, packages/shared/src/server/repositories/traces.ts, packages/shared/src/server/repositories/observations.ts, packages/shared/src/server/repositories/scores.ts\n- **ClickHouse Analytics Layer**：importance `high`\n  - source_paths: packages/shared/clickhouse/migrations/clustered/0001_traces.up.sql, packages/shared/src/server/clickhouse/schema.ts, packages/shared/src/server/repositories/clickhouse.ts, worker/src/services/ClickhouseWriter/index.ts\n- **Queue System (Redis/BullMQ)**：importance `high`\n  - source_paths: packages/shared/src/server/redis/ingestionQueue.ts, packages/shared/src/server/redis/evalExecutionQueue.ts, packages/shared/src/server/redis/batchActionQueue.ts, packages/shared/src/server/redis/webhookQueue.ts, worker/src/queues/workerManager.ts\n\n## Repo Inspection Evidence / 源码检查证据\n\n- repo_clone_verified: true\n- repo_inspection_verified: true\n- repo_commit: `da7d917597c723c7f659c185b987c667408a2f66`\n- inspected_files: `pnpm-lock.yaml`, `package.json`, `README.md`, `docker-compose.yml`, `packages/eslint-plugin/vitest.config.ts`, `packages/eslint-plugin/vitest.setup.ts`, `packages/eslint-plugin/package.json`, `packages/eslint-plugin/tsconfig.json`, `packages/shared/AGENTS.md`, `packages/shared/package.json`, `packages/shared/tsconfig.json`, `packages/config-typescript/package.json`, `packages/config-typescript/nextjs.json`, `packages/config-typescript/base.json`, `packages/config-eslint/base.js`, `packages/config-eslint/index.js`, `packages/config-eslint/index.d.ts`, `packages/config-eslint/package.json`, `packages/config-eslint/next.d.ts`, `packages/config-eslint/base.d.ts`\n\n宿主 AI 硬性规则：\n- 没有 repo_clone_verified=true 时，不得声称已经读过源码。\n- 没有 repo_inspection_verified=true 时，不得把 README/docs/package 文件判断写成事实。\n- 没有 quick_start_verified=true 时，不得声称 Quick Start 已跑通。\n\n## Doramagic Pitfall Constraints / 踩坑约束\n\n这些规则来自 Doramagic 发现、验证或编译过程中的项目专属坑点。宿主 AI 必须把它们当作工作约束，而不是普通说明文字。\n\n### Constraint 1: 来源证据：bug: Using client with context manager breaks the scoring\n\n- Trigger: GitHub 社区证据显示该项目存在一个安装相关的待验证问题：bug: Using client with context manager breaks the scoring\n- Host AI rule: 来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- Why it matters: 可能增加新用户试用和生产接入成本。\n- Evidence: community_evidence:github | cevd_5afee24537ba47369cc4621f7fb18122 | https://github.com/langfuse/langfuse/issues/8138 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。\n\n### Constraint 2: 来源证据：bug: unnamed trace name in Langfuse UI\n\n- Trigger: GitHub 社区证据显示该项目存在一个安装相关的待验证问题：bug: unnamed trace name in Langfuse UI\n- Host AI rule: 来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- Why it matters: 可能增加新用户试用和生产接入成本。\n- Evidence: community_evidence:github | cevd_a219c99fe99c4b7dab002e2b3a6296c2 | https://github.com/langfuse/langfuse/issues/13416 | 来源讨论提到 node 相关条件，需在安装/试用前复核。\n- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。\n\n### Constraint 3: 来源证据：bug: AsyncStream' object has no attribute 'usage' when integrated with Semantic Kernel and Openlit\n\n- Trigger: GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：bug: AsyncStream' object has no attribute 'usage' when integrated with Semantic Kernel and Openlit\n- Host AI rule: 来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- Why it matters: 可能影响授权、密钥配置或安全边界。\n- Evidence: community_evidence:github | cevd_8657d86702904e90b9d448770e618256 | https://github.com/langfuse/langfuse/issues/8173 | 来源类型 github_issue 暴露的待验证使用条件。\n- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。\n\n### Constraint 4: 来源证据：bug: Worker shutdown takes ~1 hour in self hosted kubernetes\n\n- Trigger: GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：bug: Worker shutdown takes ~1 hour in self hosted kubernetes\n- Host AI rule: 来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- Why it matters: 可能影响授权、密钥配置或安全边界。\n- Evidence: community_evidence:github | cevd_cff1b1d1a1ca4eb892563c33d3aa62e9 | https://github.com/langfuse/langfuse/issues/8156 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。\n\n### Constraint 5: 来源证据：bug: Socket timeout. Expecting data, but didn't receive any in 30000ms on idle BullMQ queues\n\n- Trigger: GitHub 社区证据显示该项目存在一个安装相关的待验证问题：bug: Socket timeout. Expecting data, but didn't receive any in 30000ms on idle BullMQ queues\n- Host AI rule: 来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- Why it matters: 可能增加新用户试用和生产接入成本。\n- Evidence: community_evidence:github | cevd_49a69075a1c346789a28db93c9ec6f3f | https://github.com/langfuse/langfuse/issues/13601 | 来源讨论提到 node 相关条件，需在安装/试用前复核。\n- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。\n\n### Constraint 6: 来源证据：v3.169.0\n\n- Trigger: GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v3.169.0\n- Host AI rule: 来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- Why it matters: 可能增加新用户试用和生产接入成本。\n- Evidence: community_evidence:github | cevd_864f213fd7694eba9a4d2fe2bb9267ab | https://github.com/langfuse/langfuse/releases/tag/v3.169.0 | 来源讨论提到 npm 相关条件，需在安装/试用前复核。\n- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。\n\n### Constraint 7: 来源证据：v3.172.0\n\n- Trigger: GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v3.172.0\n- Host AI rule: 来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- Why it matters: 可能影响升级、迁移或版本选择。\n- Evidence: community_evidence:github | cevd_14588986ba9945eeb40cbc0508e3fed0 | https://github.com/langfuse/langfuse/releases/tag/v3.172.0 | 来源讨论提到 npm 相关条件，需在安装/试用前复核。\n- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。\n\n### Constraint 8: 来源证据：v3.173.0\n\n- Trigger: GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v3.173.0\n- Host AI rule: 来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- Why it matters: 可能影响升级、迁移或版本选择。\n- Evidence: community_evidence:github | cevd_7560a954846b4f35aedb74de1291c9a4 | https://github.com/langfuse/langfuse/releases/tag/v3.173.0 | 来源讨论提到 docker 相关条件，需在安装/试用前复核。\n- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。\n\n### Constraint 9: 能力判断依赖假设\n\n- Trigger: README/documentation is current enough for a first validation pass.\n- Host AI rule: 将假设转成下游验证清单。\n- Why it matters: 假设不成立时，用户拿不到承诺的能力。\n- Evidence: capability.assumptions | github_repo:642497346 | https://github.com/langfuse/langfuse | README/documentation is current enough for a first validation pass.\n- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。\n\n### Constraint 10: 维护活跃度未知\n\n- Trigger: 未记录 last_activity_observed。\n- Host AI rule: 补 GitHub 最近 commit、release、issue/PR 响应信号。\n- Why it matters: 新项目、停更项目和活跃项目会被混在一起，推荐信任度下降。\n- Evidence: evidence.maintainer_signals | github_repo:642497346 | https://github.com/langfuse/langfuse | last_activity_observed missing\n- Hard boundary: 不要把这个坑点包装成已解决、已验证或可忽略，除非后续验证证据明确证明它已经关闭。\n",
      "summary": "给宿主 AI 的上下文和工作边界。",
      "title": "AI Context Pack / 带给我的 AI"
    },
    "boundary_risk_card": {
      "asset_id": "boundary_risk_card",
      "filename": "BOUNDARY_RISK_CARD.md",
      "markdown": "# Boundary & Risk Card / 安装前决策卡\n\n项目：langfuse/langfuse\n\n## Doramagic 试用结论\n\n当前结论：可以进入发布前推荐检查；首次使用仍应从最小权限、临时目录和可回滚配置开始。\n\n## 用户现在可以做\n\n- 可以先阅读 Human Manual，理解项目目的和主要工作流。\n- 可以复制 Prompt Preview 做安装前体验；这只验证交互感，不代表真实运行。\n- 可以把官方 Quick Start 命令放到隔离环境中验证，不要直接进主力环境。\n\n## 现在不要做\n\n- 不要把 Prompt Preview 当成项目实际运行结果。\n- 不要把 metadata-only validation 当成沙箱安装验证。\n- 不要把未验证能力写成“已支持、已跑通、可放心安装”。\n- 不要在首次试用时交出生产数据、私人文件、真实密钥或主力配置目录。\n\n## 安装前检查\n\n- 宿主 AI 是否匹配：chatgpt\n- 官方安装入口状态：已发现官方入口\n- 是否在临时目录、临时宿主或容器中验证：必须是\n- 是否能回滚配置改动：必须能\n- 是否需要 API Key、网络访问、读写文件或修改宿主配置：未确认前按高风险处理\n- 是否记录了安装命令、实际输出和失败日志：必须记录\n\n## 当前阻塞项\n\n- 无阻塞项。\n\n## 项目专属踩坑\n\n- 来源证据：bug: Using client with context manager breaks the scoring（high）：可能增加新用户试用和生产接入成本。 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 来源证据：bug: unnamed trace name in Langfuse UI（high）：可能增加新用户试用和生产接入成本。 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 来源证据：bug: AsyncStream' object has no attribute 'usage' when integrated with Semantic Kernel and Openlit（high）：可能影响授权、密钥配置或安全边界。 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 来源证据：bug: Worker shutdown takes ~1 hour in self hosted kubernetes（high）：可能影响授权、密钥配置或安全边界。 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 来源证据：bug: Socket timeout. Expecting data, but didn't receive any in 30000ms on idle BullMQ queues（medium）：可能增加新用户试用和生产接入成本。 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n\n## 风险与权限提示\n\n- no_demo: medium\n\n## 证据缺口\n\n- 暂未发现结构化证据缺口。\n",
      "summary": "安装、权限、验证和推荐前风险。",
      "title": "Boundary & Risk Card / 边界与风险卡"
    },
    "human_manual": {
      "asset_id": "human_manual",
      "filename": "HUMAN_MANUAL.md",
      "markdown": "# https://github.com/langfuse/langfuse 项目说明书\n\n生成时间：2026-05-15 10:18:59 UTC\n\n## 目录\n\n- [Project Introduction](#project-introduction)\n- [Project Structure](#project-structure)\n- [Quickstart Guide](#quickstart-guide)\n- [System Architecture](#system-architecture)\n- [Monorepo Configuration](#monorepo-structure)\n- [Database Schema (Prisma)](#database-schema)\n- [ClickHouse Analytics Layer](#clickhouse-analytics)\n- [Queue System (Redis/BullMQ)](#queue-system)\n- [Worker Service](#worker-service)\n- [API Layer](#api-layer)\n\n<a id='project-introduction'></a>\n\n## Project Introduction\n\n### 相关页面\n\n相关主题：[System Architecture](#system-architecture)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [README.md](https://github.com/langfuse/langfuse/blob/main/README.md)\n- [packages/shared/src/constants/VERSION.ts](https://github.com/langfuse/langfuse/blob/main/packages/shared/src/constants/VERSION.ts)\n- [web/src/components/ui/AdvancedJsonViewer/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/ui/AdvancedJsonViewer/README.md)\n- [web/src/components/layouts/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/layouts/README.md)\n- [web/src/features/mcp/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/mcp/README.md)\n- [web/src/features/entitlements/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/entitlements/README.md)\n- [web/src/features/feature-flags/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/feature-flags/README.md)\n- [web/src/components/design-system/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/design-system/README.md)\n</details>\n\n# Project Introduction\n\nLangfuse is an open-source **observability and analytics platform** designed for Large Language Model (LLM) applications. It provides comprehensive tracing, evaluation, and prompt management capabilities that enable developers to monitor, debug, and optimize their AI-powered applications.\n\n## Overview\n\nLangfuse serves as a centralized platform for capturing and analyzing interactions between AI models and end users. The project is MIT licensed and supports both cloud-hosted and self-hosted deployment models, making it accessible for teams of various sizes and requirements.\n\n### Core Purpose\n\nThe platform addresses several critical needs in LLM application development:\n\n- **Observability**: Track and visualize traces, observations, and model interactions in real-time\n- **Evaluation**: Measure and analyze AI application performance through configurable scoring systems\n- **Prompt Management**: Create, version, and manage prompts with support for complex dependency resolution\n- **Collaboration**: Enable team collaboration through commenting and sharing features\n- **Analytics**: Provide insights into AI application behavior through comprehensive analytics dashboards\n\n### High-Level Architecture\n\nLangfuse follows a modern microservices-inspired architecture with clear separation between frontend, backend processing, and data storage components.\n\n```mermaid\ngraph TD\n    subgraph Frontend[\"Frontend (Next.js/React)\"]\n        UI[User Interface]\n        DesignSystem[Design System Components]\n        FeatureFlags[Feature Flags]\n    end\n    \n    subgraph Backend[\"Backend Services\"]\n        API[API Server]\n        MCP[MCP Server]\n        Worker[Worker/Queue Processing]\n    end\n    \n    subgraph Storage[\"Data Layer\"]\n        Postgres[(PostgreSQL)]\n        ClickHouse[(ClickHouse)]\n        Redis[(Redis)]\n        S3[(S3 Storage)]\n    end\n    \n    UI --> API\n    MCP --> API\n    Worker --> API\n    API --> Postgres\n    API --> ClickHouse\n    API --> Redis\n    API --> S3\n```\n\n## Technology Stack\n\nLangfuse is built using a modern technology stack optimized for performance and developer experience.\n\n### Frontend Stack\n\n| Component | Technology | Purpose |\n|-----------|------------|---------|\n| Framework | Next.js | Server-side rendering and routing |\n| UI Library | React | Component-based UI development |\n| State Management | React Context + Hooks | Local and global state |\n| Virtualization | TanStack Virtual | Efficient rendering of large lists |\n| Styling | Tailwind CSS + cva | Utility-first styling with variant handling |\n| Forms | Zod | Schema validation |\n| Data Fetching | tRPC | Type-safe API communication |\n\n资料来源：[web/src/components/design-system/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/design-system/README.md)\n\n### Backend Stack\n\n| Component | Technology | Purpose |\n|-----------|------------|---------|\n| Runtime | Node.js/TypeScript | Server-side logic |\n| Database | PostgreSQL | Primary data storage |\n| Analytics | ClickHouse | High-performance analytics queries |\n| Cache | Redis | Caching and queue management |\n| Queue | BullMQ | Background job processing |\n| Storage | S3-compatible | File and event storage |\n\n### Key Frontend Components\n\nThe frontend architecture is organized around several key systems:\n\n#### Design System\n\nThe design system (`web/src/components/design-system/`) provides reusable, primitive UI components following strict principles:\n\n- **Presentational only**: No business logic in components\n- **Explicit, typed APIs**: Strict TypeScript definitions\n- **No className/style props**: Prevents style leakage\n- **cva for variants**: Consistent variant handling\n\n```mermaid\ngraph LR\n    A[Design System] --> B[Button]\n    A --> C[Input]\n    A --> D[Modal]\n    B --> E[Consistent Styling]\n    C --> E\n    D --> E\n```\n\n资料来源：[web/src/components/design-system/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/design-system/README.md)\n\n#### Layout System\n\nAll pages use a standardized `Page` wrapper component that ensures:\n\n- Consistent layout structure\n- Sticky header behavior\n- Proper scroll management (`\"content-scroll\"` or `\"page-scroll\"`)\n- Breadcrumb navigation support\n- Custom header actions\n\n```mermaid\ngraph TD\n    Page[Page Component] --> Header[Sticky Header]\n    Page --> Content[Scrollable Content]\n    Header --> Breadcrumb[Breadcrumb Navigation]\n    Header --> Actions[Action Buttons]\n```\n\n资料来源：[web/src/components/layouts/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/layouts/README.md)\n\n#### JSON Viewer Component\n\nThe `AdvancedJsonViewer` component provides efficient rendering of large JSON datasets:\n\n- **Virtualization**: Uses TanStack Virtual for row-based rendering\n- **Iterative algorithms**: Explicit stack-based iteration to prevent stack overflow\n- **Client-side search**: In-memory matching with binary search navigation\n- **Theme support**: Customizable JSON syntax highlighting\n\n```mermaid\ngraph TD\n    Input[Large JSON Data] --> Parser[JSON Parser]\n    Parser --> TreeBuilder[Tree Builder]\n    TreeBuilder --> Virtualizer[TanStack Virtual]\n    Virtualizer --> Renderer[Row Renderer]\n    \n    Search[Search Query] --> Matcher[In-Memory Matcher]\n    Matcher --> Navigator[Binary Search Navigator]\n```\n\n资料来源：[web/src/components/ui/AdvancedJsonViewer/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/ui/AdvancedJsonViewer/README.md)\n\n## Core Features\n\n### Tracing and Observability\n\nLangfuse provides comprehensive tracing capabilities that capture the full lifecycle of AI interactions:\n\n- **Traces**: Complete request/response cycles\n- **Observations**: Individual components within a trace (spans, events, generations)\n- **Metadata**: Custom metadata attachment for context\n- **Tree Structure**: Hierarchical representation of nested observations\n\nThe tree-building system uses iterative algorithms to handle millions of observations without stack overflow:\n\n```typescript\n// Iterative traversal pattern\nfunction traverse(rootNode: TreeNode) {\n  const stack = [rootNode];\n  while (stack.length > 0) {\n    const node = stack.pop()!;\n    process(node);\n    node.children.forEach((child) => stack.push(child));\n  }\n}\n```\n\n资料来源：[web/src/components/trace/lib/tree-building.clienttest.ts](https://github.com/langfuse/langfuse/blob/main/web/src/components/trace/lib/tree-building.clienttest.ts)\n\n### Prompt Management\n\nLangfuse supports sophisticated prompt management with dependency resolution:\n\n- **Prompt Stacking**: Compose prompts from multiple sources\n- **Dependency Tags**: Reference other prompts using `@@@langfusePrompt:...@@@` syntax\n- **Resolution Modes**:\n  - `getPromptResolved`: Returns fully resolved prompt with dependencies inlined\n  - `getPromptUnresolved`: Returns raw prompt with tags preserved for analysis\n\n```mermaid\ngraph LR\n    A[Prompt A] -->|references| B[Prompt B]\n    A -->|references| C[Prompt C]\n    B -->|references| D[Prompt D]\n    A -->|resolved| E[Final Prompt]\n```\n\n资料来源：[web/src/features/mcp/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/mcp/README.md)\n\n### Score Analytics\n\nThe scoring system enables quantitative evaluation of AI application performance:\n\n- **Multiple Score Types**: Supports numeric, categorical, and boolean scores\n- **Time Series Analysis**: Track score changes over configurable intervals\n- **Distribution Analysis**: Visualize score distributions with bins and categories\n- **Comparison Mode**: Compare two scores side-by-side\n\nThe analytics layer provides interpretive functions for common metrics:\n\n| Metric | Interpretation | Threshold |\n|--------|----------------|-----------|\n| Agreement (Cohen's Kappa) | Excellent | ≥ 0.9 |\n| Agreement (Cohen's Kappa) | Good | ≥ 0.8 |\n| Agreement (Cohen's Kappa) | Fair | ≥ 0.6 |\n| Agreement (Cohen's Kappa) | Poor | ≥ 0.4 |\n\n资料来源：[web/src/features/score-analytics/lib/statistics-utils.ts](https://github.com/langfuse/langfuse/blob/main/web/src/features/score-analytics/lib/statistics-utils.ts)\n\n### Entitlements System\n\nAccess control is managed through a hierarchical entitlements system:\n\n```mermaid\ngraph TD\n    Plan[Plan] -->|contains| Entitlements[Entitlements]\n    Plan -->|contains| Limits[Entitlement Limits]\n    \n    Entitlements -->|grants| Features[Feature Access]\n    Limits -->|restricts| Resources[Resource Quotas]\n    \n    PlanTypes[Plan Types] --> OSS[OSS]\n    PlanTypes --> CloudPro[Cloud Pro]\n    PlanTypes --> SelfHostedEnterprise[Self-Hosted Enterprise]\n```\n\nAvailable entitlements include:\n\n- **Feature Flags**: Enable/disable features via `useIsFeatureEnabled` hook\n- **Entitlement Limits**: Quotas on resources (e.g., annotation queue count)\n- **Plan-based Access**: Cloud and self-hosted enterprise plans\n\n资料来源：[web/src/features/entitlements/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/entitlements/README.md)\n\n### Feature Flags\n\nFeature flags control feature availability dynamically:\n\n```typescript\nconst isFeatureEnabled = useIsFeatureEnabled(\"feature-flag-name\");\n```\n\nA feature flag is enabled when:\n\n1. Flag is in user's `feature_flags` list\n2. `LANGFUSE_ENABLE_EXPERIMENTAL_FEATURES` environment variable is set\n3. User has admin privileges\n\n资料来源：[web/src/features/feature-flags/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/feature-flags/README.md)\n\n### Collaboration Features\n\nLangfuse includes team collaboration capabilities:\n\n- **Mention Parser**: Extract and resolve user mentions in comments\n- **User References**: Syntax `@[Display Name](user:userId)` for linking users\n- **Sanitization**: Clean user-generated content for safe display\n\n```typescript\n// Mention format: @[Alice](user:alice123)\n// Parser extracts: alice123\n```\n\n资料来源：[web/src/features/comments/lib/mentionParser.clienttest.ts](https://github.com/langfuse/langfuse/blob/main/web/src/features/comments/lib/mentionParser.clienttest.ts)\n\n## Data Flow Architecture\n\n### Ingestion Pipeline\n\nEvents flow through the system in a structured pipeline:\n\n```mermaid\ngraph LR\n    S3[S3 Event Storage] --> Worker[Worker Processing]\n    Worker -->|Standard| IngestionQueue[IngestionSecondaryQueue]\n    Worker -->|OTEL| OtelQueue[OtelIngestionQueue]\n    IngestionQueue --> Postgres[(PostgreSQL)]\n    OtelQueue --> ClickHouse[(ClickHouse)]\n```\n\nEvent processing includes:\n\n- **Checkpointing**: Resume from failures using `.checkpoint` files\n- **Rate Limiting**: Client-side and server-side throttling\n- **Retry Logic**: Exponential backoff with jitter for transient failures\n- **Error Logging**: Failed events appended to `errors.csv`\n\n资料来源：[worker/src/scripts/replayIngestionEventsV2/README.md](https://github.com/langfuse/langfuse/blob/main/worker/src/scripts/replayIngestionEventsV2/README.md)\n\n### API Architecture\n\nLangfuse uses tRPC for type-safe API communication:\n\n- **Server-side validation**: Zod schemas for input validation\n- **tRPC routers**: Organized endpoint handlers\n- **API versioning**: V1 (legacy) and V2 (current) API support\n\n| API Version | GET Support | Notes |\n|-------------|-------------|-------|\n| V1 | `traceId` required | Legacy, trace-focused |\n| V2 | `traceId` optional | Adds `sessionId` support |\n\n资料来源：[packages/shared/src/features/scores/interfaces/README.md](https://github.com/langfuse/langfuse/blob/main/packages/shared/src/features/scores/interfaces/README.md)\n\n### MCP Server Architecture\n\nThe Model Context Protocol (MCP) server provides external access to Langfuse:\n\n- **Stateless per-request**: Fresh server instance for each request\n- **Context via closures**: Authentication captured in handler closures\n- **No session storage**: Request-disposable architecture\n\n```mermaid\ngraph TD\n    Request[MCP Request] --> Instance[New Server Instance]\n    Instance --> Auth[Auth Context Closure]\n    Auth --> Handler[Request Handler]\n    Handler --> Response[Response]\n    Response --> Discard[Instance Discarded]\n```\n\n资料来源：[web/src/features/mcp/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/mcp/README.md)\n\n## Filtering System\n\nLangfuse implements a sophisticated filtering system with type-safe encoding:\n\n### Filter Types\n\n| Type | Description | Example |\n|------|-------------|---------|\n| `string` | Simple string matching | Trace name |\n| `number` | Numeric comparison | Latency values |\n| `datetime` | Date/time filtering | Time ranges |\n| `boolean` | True/false matching | Flag states |\n| `arrayOptions` | Multi-value selection | Tags |\n| `categoryOptions` | Categorical filtering | Status values |\n| `positionInTrace` | Nested location | Span hierarchy |\n\n### State Management\n\nFilters support multiple storage locations:\n\n- **URL**: Persisted in query parameters\n- **Session Storage**: In-memory per session\n- **Peek Context**: Temporary state for preview panels\n\n```typescript\nconst filterOptions: UseSidebarFilterStateOptions = {\n  stateLocation: \"urlAndSessionStorage\",\n  sessionFilterContextId: projectId,\n  implicitDefaultConfig: DEFAULT_SIDEBAR_IMPLICIT_ENVIRONMENT_CONFIG,\n};\n```\n\n资料来源：[web/src/components/table/peek/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/table/peek/README.md)\n\n## Deployment Models\n\nLangfuse supports multiple deployment configurations:\n\n| Model | Plan Options | Authentication | License |\n|-------|--------------|----------------|---------|\n| Cloud | `cloud:pro` | JWT via NextAuth | Proprietary |\n| Self-Hosted | `self-hosted:enterprise` | JWT + License Key | Proprietary |\n| Open Source | `oss` | Basic auth | MIT |\n\n### Self-Hosted Configuration\n\nSelf-hosted deployments require:\n\n- PostgreSQL database\n- ClickHouse for analytics\n- Redis for caching/queues\n- S3-compatible storage for events\n- License key for enterprise features\n\n资料来源：[web/src/features/entitlements/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/entitlements/README.md)\n\n## Performance Considerations\n\n### Large Dataset Handling\n\nLangfuse handles large datasets through several mechanisms:\n\n| Scale | Mechanism | Threshold |\n|-------|-----------|-----------|\n| 10k+ rows | TanStack Virtual | Row-based rendering |\n| 1M+ nodes | Iterative algorithms | No stack overflow |\n| 10k+ search matches | Binary search | Efficient navigation |\n\n### Known Limitations\n\n- No horizontal virtualization for wide rows\n- Client-side search only (can be slow with many matches)\n- Memory constraints at 1M+ nodes\n- Read-only JSON viewer (no inline editing)\n- Wrap mode may cause layout thrashing\n\n资料来源：[web/src/components/ui/AdvancedJsonViewer/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/ui/AdvancedJsonViewer/README.md)\n\n## Development Guidelines\n\n### Testing\n\nThe project uses Jest with custom extensions:\n\n| File Pattern | Purpose | Location |\n|--------------|---------|----------|\n| `.clienttest.ts` | Client-side tests | Colocated with components |\n| `*.test.ts` | Standard unit tests | `__tests__` or inline |\n\n```bash\n# Run client tests\npnpm --filter=web run test-client --testPathPattern=\"ComponentName\"\n```\n\n### Debugging\n\nEnable debug logging via localStorage:\n\n```typescript\nlocalStorage.setItem(\"debug:ComponentName\", \"true\");\n```\n\n## Summary\n\nLangfuse is a comprehensive observability platform that bridges the gap between AI application development and operational monitoring. Its modular architecture, built on proven technologies like PostgreSQL, ClickHouse, and React, provides a scalable foundation for teams to understand, evaluate, and optimize their LLM applications.\n\nThe platform's emphasis on type safety, performance optimization, and developer experience makes it suitable for both small development teams and large-scale enterprise deployments.\n\n---\n\n<a id='project-structure'></a>\n\n## Project Structure\n\n### 相关页面\n\n相关主题：[Monorepo Configuration](#monorepo-structure), [System Architecture](#system-architecture)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [pnpm-workspace.yaml](https://github.com/langfuse/langfuse/blob/main/pnpm-workspace.yaml)\n- [turbo.json](https://github.com/langfuse/langfuse/blob/main/turbo.json)\n- [packages/shared/package.json](https://github.com/langfuse/langfuse/blob/main/packages/shared/package.json)\n- [web/package.json](https://github.com/langfuse/langfuse/blob/main/web/package.json)\n- [worker/package.json](https://github.com/langfuse/langfuse/blob/main/worker/package.json)\n</details>\n\n# Project Structure\n\n## Overview\n\nLangfuse is a comprehensive observability and analytics platform for LLM applications, structured as a **monorepo** using pnpm workspaces and Turborepo for build orchestration. The repository contains multiple packages including the frontend web application, backend worker services, and shared libraries.\n\n## Monorepo Architecture\n\n### Workspace Configuration\n\nLangfuse uses pnpm workspaces defined in `pnpm-workspace.yaml` to manage multiple packages within a single repository.\n\n```yaml\npackages:\n  - \"packages/*\"\n  - \"web\"\n  - \"worker\"\n```\n\n资料来源：[pnpm-workspace.yaml](https://github.com/langfuse/langfuse/blob/main/pnpm-workspace.yaml)\n\n### Build System (Turborepo)\n\nThe project uses Turborepo for efficient incremental builds and task caching. The turbo configuration defines the build pipeline and dependencies between packages.\n\n资料来源：[turbo.json](https://github.com/langfuse/langfuse/blob/main/turbo.json)\n\n## Package Structure\n\n### 1. Web Application (`/web`)\n\nThe frontend application built with Next.js and React, containing the user interface and client-side logic.\n\n| Directory | Purpose |\n|-----------|---------|\n| `src/components/` | Reusable UI components including layouts, tables, and specialized viewers |\n| `src/features/` | Feature-specific modules with their own logic and components |\n| `src/lib/` | Utility functions and helpers |\n| `src/hooks/` | Custom React hooks |\n\n资料来源：[web/package.json](https://github.com/langfuse/langfuse/blob/main/web/package.json)\n\n### 2. Worker Service (`/worker`)\n\nBackend service handling background processing, event ingestion, and queue management.\n\n| Directory | Purpose |\n|-----------|---------|\n| `src/scripts/` | Utility scripts for data operations and migrations |\n| `src/queues/` | Queue handlers for async processing |\n\n资料来源：[worker/package.json](https://github.com/langfuse/langfuse/blob/main/worker/package.json)\n\n### 3. Shared Packages (`/packages/shared`)\n\nCommon utilities, types, and validation schemas shared across web and worker packages.\n\n| Module | Purpose |\n|--------|---------|\n| Validation | Zod schemas for type-safe data validation |\n| Types | Shared TypeScript type definitions |\n| Utilities | Common helper functions |\n\n资料来源：[packages/shared/package.json](https://github.com/langfuse/langfuse/blob/main/packages/shared/package.json)\n\n## Web Application Structure\n\n### Component Architecture\n\n```mermaid\ngraph TD\n    A[Web Application] --> B[Layout Components]\n    A --> C[UI Components]\n    A --> D[Feature Modules]\n    \n    B --> B1[Page Wrapper]\n    B --> B2[ContainerPage]\n    B --> B3[Breadcrumb]\n    \n    C --> C1[AdvancedJsonViewer]\n    C --> C2[Table Components]\n    C --> C3[Peek Components]\n    \n    D --> D1[MCP]\n    D --> D2[Score Analytics]\n    D --> D3[Comments]\n    D --> D4[Filters]\n    D --> D5[Entitlements]\n```\n\n### Layout System\n\nThe `Page` component is the standard wrapper for all pages, providing:\n\n- **Sticky Header**: Consistent header across pages\n- **Scroll Management**: Supports `\"content-scroll\"` and `\"page-scroll\"` modes\n- **Breadcrumb Navigation**: Easy navigation path display\n- **Custom Header Actions**: Flexible button/link placement\n\nFor content that doesn't scale well with page width (e.g., settings pages), use `ContainerPage` instead.\n\n资料来源：[web/src/components/layouts/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/layouts/README.md)\n\n### Key Feature Modules\n\n#### AdvancedJsonViewer\n\nA virtualized JSON tree viewer with the following characteristics:\n\n- **Performance**: Uses TanStack Virtual for rendering large JSON structures\n- **Search**: Client-side search with regex support\n- **Theme Support**: Multiple color themes (GitHub, Monokai, Solarized)\n- **Tree Navigation**: Binary search for efficient node access\n\n资料来源：[web/src/components/ui/AdvancedJsonViewer/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/ui/AdvancedJsonViewer/README.md)\n\n#### Score Analytics\n\nProvides analytics dashboard capabilities for score data:\n\n- **Score Comparison**: Compare two scores over time\n- **Distribution Analysis**: Histogram and heatmap visualizations\n- **Time Series**: Temporal trend analysis with configurable intervals\n- **Data Transformation**: Pure functions for data processing\n\n资料来源：[web/src/features/score-analytics/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/score-analytics/README.md)\n\n#### MCP (Model Context Protocol)\n\nEnables integration with external systems through MCP:\n\n- **Stateless Architecture**: Fresh server instance per request\n- **Prompt Management**: Support for `getPrompt` and `getPromptUnresolved`\n- **Resource Handling**: MCP resources and tool support\n\n资料来源：[web/src/features/mcp/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/mcp/README.md)\n\n#### Entitlements\n\nFeature availability control system:\n\n- **Plan-based Access**: `oss`, `cloud:pro`, `self-hosted:enterprise`\n- **Entitlement Limits**: Resource quotas per plan\n- **Server/Client Support**: Available in both frontend hooks and backend\n\n资料来源：[web/src/features/entitlements/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/entitlements/README.md)\n\n### Table and Peek System\n\n#### PeekTableStateProvider\n\nManages table state for peek views (slide-over panels showing item details):\n\n```mermaid\ngraph LR\n    A[PeekTableStateProvider] --> B[Filters]\n    A --> C[Sorting]\n    A --> D[Pagination]\n    A --> E[Search]\n```\n\n**State Persistence**: Filter, sort, and pagination state persists across K/J navigation between items of the same type.\n\n**State Reset**: State clears when the peek view closes (via X button, Escape, or click outside).\n\n资料来源：[web/src/components/table/peek/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/table/peek/README.md)\n\n## Worker Service Structure\n\n### Scripts\n\nThe worker contains utility scripts for data operations:\n\n| Script | Purpose |\n|--------|---------|\n| `replayIngestionEventsV2` | Replay events from CSV to ingestion queues |\n| `refillQueueEvent` | Backfill queue with events from local files |\n\n#### Replay Ingestion Events V2\n\nReplays S3-stored events back to Langfuse:\n\n- **Batch Processing**: Processes events in configurable batches\n- **Checkpoint Support**: Resume capability via checkpoint files\n- **Rate Limiting**: Respects server-side rate limits with exponential backoff\n- **Error Handling**: Retries transient failures, logs permanent failures\n\n资料来源：[worker/src/scripts/replayIngestionEventsV2/README.md](https://github.com/langfuse/langfuse/blob/main/worker/src/scripts/replayIngestionEventsV2/README.md)\n\n#### Refill Queue Event\n\nBackfills queues with events from local JSONL files:\n\n1. Create `./worker/events.jsonl` with one JSON event per line\n2. Configure Redis connection and supporting services\n3. Run via `pnpm run --filter=worker refill-queue-event`\n\n资料来源：[worker/src/scripts/refillQueueEvent/README.md](https://github.com/langfuse/langfuse/blob/main/worker/src/scripts/refillQueueEvent/README.md)\n\n## Public API Architecture\n\n### Adding New API Routes\n\nThe project follows a structured pattern for public API development:\n\n1. **Implementation**: Wrap routes with `withMiddleware` and `createAuthedAPIRoute`\n2. **Type Definition**: Add Zod types to `/features/public-api/types` using `coerce` for primitives\n3. **Validation**: Use `validateZodSchema` for response validation\n4. **Documentation**: Add to Fern with `docs` attributes\n5. **SDK Updates**: Copy types to Python and JS SDKs\n\n```typescript\n// Response type example\nconst responseSchema = z.object({\n  data: z.string(),\n  timestamp: z.coerce.date(),\n}).strict();\n```\n\n资料来源：[web/src/features/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/README.md)\n\n## Testing Infrastructure\n\n### Client-Side Testing\n\nTests use `.clienttest.ts` extension and are colocated with components:\n\n```bash\npnpm --filter=web run test-client --testPathPattern=\"ComponentName\"\n```\n\nExample: `AdvancedJsonViewer` tests cover tree building, navigation, expansion, and search operations.\n\n资料来源：[web/src/components/ui/AdvancedJsonViewer/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/ui/AdvancedJsonViewer/README.md)\n\n### Trace Tree Building Tests\n\nPerformance tests for large observation sets:\n\n| Scale | Threshold | Structure Types |\n|-------|-----------|-----------------|\n| 10k | 500ms | flat, deep, balanced, realistic |\n| 25k | 2s | flat, realistic |\n| 50k | 5s | flat, realistic |\n| 500k | 60s | realistic |\n\n资料来源：[web/src/components/trace/lib/tree-building.clienttest.ts](https://github.com/langfuse/langfuse/blob/main/web/src/components/trace/lib/tree-building.clienttest.ts)\n\n## Development Workflow\n\n### Component Development Guidelines\n\n1. **Use Page Wrapper**: Always wrap pages with `<Page>` component\n2. **Use ContainerPage**: For settings/setup pages with non-scalable content\n3. **Follow Naming**: Use `.clienttest.ts` for client-side tests\n4. **State Management**: Use `useSidebarFilterState` for filters, `useOrderByState` for sorting\n\n### Prompt Composition\n\nFor MCP prompt features:\n\n- **Resolved Prompt**: Use `getPrompt` for executable prompts with dependencies resolved\n- **Unresolved Prompt**: Use `getPromptUnresolved` for debugging and analysis\n\n资料来源：[web/src/features/mcp/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/mcp/README.md)\n\n## Summary\n\nThe Langfuse project is organized as a well-structured monorepo with clear separation between the frontend web application, backend worker services, and shared packages. The architecture emphasizes:\n\n- **Modularity**: Feature-based organization with isolated modules\n- **Performance**: Virtualization and incremental builds\n- **Type Safety**: Zod schemas and TypeScript throughout\n- **Observability**: Built-in tracing and analytics capabilities\n\n---\n\n<a id='quickstart-guide'></a>\n\n## Quickstart Guide\n\n### 相关页面\n\n相关主题：[Project Introduction](#project-introduction)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [README.md](https://github.com/langfuse/langfuse/blob/main/README.md)\n- [docker-compose.yml](https://github.com/langfuse/langfuse/blob/main/docker-compose.yml)\n- [CONTRIBUTING.md](https://github.com/langfuse/langfuse/blob/main/CONTRIBUTING.md)\n- [web/src/components/layouts/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/layouts/README.md)\n- [worker/src/scripts/refillQueueEvent/README.md](https://github.com/langfuse/langfuse/blob/main/worker/src/scripts/refillQueueEvent/README.md)\n- [web/src/features/slack/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/slack/README.md)\n</details>\n\n# Quickstart Guide\n\nLangfuse is an open-source LLM engineering platform that provides observability, analytics, and prompt management for LLM applications. This guide walks you through setting up a local development environment, understanding the core architecture, and deploying Langfuse for production use.\n\n## Overview\n\nLangfuse supports multiple deployment scenarios:\n\n| Deployment Type | Use Case | Key Components |\n|----------------|----------|----------------|\n| Local Development | Testing and development | Docker Compose with all services |\n| Self-Hosted | Production deployment | Docker/Kubernetes with externalized services |\n| Cloud | Managed SaaS offering | Langfuse-hosted infrastructure |\n\n资料来源：[README.md:1-20]()\n\n## Architecture Overview\n\nLangfuse consists of three main components:\n\n```mermaid\ngraph TD\n    A[Web UI] --> B[Server API]\n    B --> C[(PostgreSQL)]\n    B --> D[(ClickHouse)]\n    B --> E[(Redis)]\n    F[Workers] --> C\n    F --> D\n    F --> E\n    G[S3 Storage] --> F\n```\n\n### Core Components\n\n| Component | Purpose | Technology |\n|-----------|---------|------------|\n| `web/` | Frontend UI application | Next.js, React, TanStack |\n| `server/` | API server and business logic | Node.js, tRPC, Prisma |\n| `worker/` | Background job processing | BullMQ, Redis |\n| `clickhouse/` | Analytics storage | ClickHouse |\n\n资料来源：[docker-compose.yml:1-50]()\n\n## Local Development Setup\n\n### Prerequisites\n\n- Node.js 20+ (using pnpm as package manager)\n- Docker and Docker Compose\n- Git\n\n### 1. Clone the Repository\n\n```bash\ngit clone https://github.com/langfuse/langfuse.git\ncd langfuse\n```\n\n### 2. Environment Configuration\n\nCreate a `.env` file in the root directory with the following required variables:\n\n```bash\n# Database\nDATABASE_URL=postgresql://langfuse:langfuse@localhost:5432/langfuse\n\n# ClickHouse\nCLICKHOUSE_URL=http://localhost:8123\nCLICKHOUSE_USER=langfuse\nCLICKHOUSE_PASSWORD=langfuse\n\n# Redis\nREDIS_URL=redis://localhost:6379\n\n# Auth (NextAuth.js)\nNEXTAUTH_SECRET=your-secret-key\nNEXTAUTH_URL=http://localhost:3000\n\n# S3 Storage (MinIO for local dev)\nS3_ACCESS_KEY=langfuse\nS3_SECRET_KEY=langfuse\nS3_REGION=us-east-1\nS3_ENDPOINT_URL=http://localhost:9000\nS3_EVENT_UPLOAD_BUCKET=langfuse\n```\n\n资料来源：[docker-compose.yml:50-120]()\n\n### 3. Start Infrastructure Services\n\nLaunch all supporting services using Docker Compose:\n\n```bash\ndocker compose up -d\n```\n\nThis starts the following services:\n\n| Service | Port | Purpose |\n|---------|------|---------|\n| postgres | 5432 | Primary database |\n| clickhouse | 8123 | Analytics storage |\n| redis | 6379 | Job queue broker |\n| minio | 9000/9001 | S3-compatible storage |\n\n资料来源：[docker-compose.yml:120-180]()\n\n### 4. Install Dependencies\n\n```bash\npnpm install\n```\n\n### 5. Run Database Migrations\n\n```bash\npnpm db:migrate\n```\n\n### 6. Start Development Servers\n\nLangfuse uses a monorepo structure with multiple development servers:\n\n```bash\n# Start all services in development mode\npnpm run dev\n\n# Or start individual services\npnpm --filter=server run dev    # API server\npnpm --filter=web run dev       # Web UI\npnpm --filter=worker run dev    # Background workers\n```\n\n资料来源：[CONTRIBUTING.md:50-100]()\n\n## Project Structure\n\n```\nlangfuse/\n├── web/                      # Next.js frontend\n│   ├── src/\n│   │   ├── components/       # Reusable UI components\n│   │   ├── features/         # Feature modules\n│   │   ├── pages/            # Next.js pages\n│   │   └── lib/              # Utilities\n│   └── public/               # Static assets\n├── server/                   # API server\n│   ├── src/\n│   │   ├── api/              # tRPC routers\n│   │   ├── services/         # Business logic\n│   │   └── lib/              # Utilities\n├── worker/                   # Background workers\n│   └── src/\n│       ├── workers/          # Queue processors\n│       └── scripts/          # Utility scripts\n├── clickhouse/               # ClickHouse migrations\n└── docker-compose.yml        # Local infrastructure\n```\n\n### Page Component Pattern\n\nThe `Page` component is the standard wrapper for all pages in the application:\n\n```tsx\nimport Page from \"@/src/components/layouts/Page\";\n\nexport default function MyPage() {\n  return (\n    <Page\n      title=\"My Page\"\n      scrollable\n      headerProps={{\n        breadcrumb: [{ name: \"Home\", href: \"/\" }, { name: \"My Page\" }],\n      }}\n    >\n      <div>Content here...</div>\n    </Page>\n  );\n}\n```\n\n**Important**: Every page must be wrapped inside `<Page>`—do not use `<main>` directly.\n\n资料来源：[web/src/components/layouts/README.md:1-40]()\n\n## Development Workflow\n\n### Running Tests\n\nLangfuse uses different test patterns for client and server code:\n\n```bash\n# Run all tests\npnpm run test\n\n# Client-side tests (Vitest with .clienttest.ts extension)\npnpm --filter=web run test-client --testPathPattern=\"ComponentName\"\n\n# Server-side tests (Jest)\npnpm --filter=server run test\n```\n\n#### Client Test Pattern\n\nClient tests use stack-based iteration to avoid stack overflow:\n\n```typescript\n// ✅ Safe for deep trees - iterative approach\nfunction traverse(rootNode: TreeNode) {\n  const stack = [rootNode];\n  while (stack.length > 0) {\n    const node = stack.pop()!;\n    process(node);\n    node.children.forEach((child) => stack.push(child));\n  }\n}\n```\n\n资料来源：[web/src/components/ui/AdvancedJsonViewer/README.md:80-100]()\n\n### Debug Mode\n\nEnable detailed logging for specific components:\n\n```javascript\nlocalStorage.setItem(\"debug:AdvancedJsonViewer\", \"true\");\n```\n\n### Code Quality\n\n```bash\n# Lint code\npnpm run lint\n\n# Format code\npnpm run format\n\n# Type check\npnpm run typecheck\n```\n\n资料来源：[CONTRIBUTING.md:100-150]()\n\n## Feature Modules\n\nLangfuse organizes functionality into feature modules under `web/src/features/`:\n\n| Module | Purpose |\n|--------|---------|\n| `comments/` | User comments and mentions |\n| `entitlements/` | Feature access control |\n| `feature-flags/` | Feature toggle system |\n| `filters/` | Query filtering and search |\n| `mcp/` | Model Context Protocol integration |\n| `score-analytics/` | Score analytics and visualization |\n| `slack/` | Slack integration |\n| `migrations/` | Database migrations |\n\n### Feature Flags\n\nEnable experimental features using the `useIsFeatureEnabled` hook:\n\n```tsx\nconst isEnabled = useIsFeatureEnabled(\"feature-flag-name\");\n```\n\nA feature is enabled when:\n1. The flag is in `user.feature_flags`\n2. `LANGFUSE_ENABLE_EXPERIMENTAL_FEATURES` is set\n3. The user has admin privileges\n\n资料来源：[web/src/features/feature-flags/README.md:1-15]()\n\n### Entitlements System\n\nFeature availability is controlled through entitlements:\n\n- **Plans**: Tiers of features (`oss`, `cloud:pro`, `self-hosted:enterprise`)\n- **Entitlements**: Available features per plan (e.g., `playground`)\n- **EntitlementLimits**: Resource limits (e.g., `annotation-queue-count`)\n\n资料来源：[web/src/features/entitlements/README.md:1-25]()\n\n## Worker Scripts\n\nThe worker module includes utility scripts for data operations:\n\n### Refill Queue Event\n\nBackfill any queue with events from local machines:\n\n```bash\n# 1. Create events file (./worker/events.jsonl)\n{\"projectId\": \"project-123\", \"orgId\": \"org-456\"}\n\n# 2. Configure environment\nREDIS_CONNECTION_STRING=redis://:password@127.0.0.1:6379\nCLICKHOUSE_URL=http://localhost:8123\nCLICKHOUSE_USER=clickhouse\nCLICKHOUSE_PASSWORD=clickhouse\n\n# 3. Run the script\npnpm run --filter=worker refill-queue-event\n```\n\n资料来源：[worker/src/scripts/refillQueueEvent/README.md:1-40]()\n\n### Replay Ingestion Events V2\n\nRe-process S3-stored ingestion events:\n\n```bash\nnpx tsx worker/src/scripts/replayIngestionEventsV2/index.ts \\\n  --input=/path/to/events.csv \\\n  --batch-size=500 \\\n  --concurrency=4\n```\n\n| Parameter | Default | Description |\n|-----------|---------|-------------|\n| `--input` | - | Path to CSV file (required) |\n| `--batch-size` | 500 | Keys per API request |\n| `--concurrency` | 4 | Parallel API requests |\n| `--rate-limit` | 50 | Requests per second |\n| `--dry-run` | false | Validate without sending |\n| `--resume` | false | Continue from checkpoint |\n\n资料来源：[worker/src/scripts/replayIngestionEventsV2/README.md:1-50]()\n\n## Slack Integration Setup\n\nFor local Slack OAuth development, HTTPS is required:\n\n### 1. Generate SSL Certificates\n\n```bash\n# Install mkcert\nbrew install mkcert\nmkcert -install\nmkcert localhost 127.0.0.1\n\n# Move certificates to web directory\nmv localhost+1*.pem web/\n```\n\n### 2. Configure Environment\n\n```bash\nSLACK_CLIENT_ID=your_client_id\nSLACK_CLIENT_SECRET=your_client_secret\nSLACK_STATE_SECRET=your_state_secret\n```\n\n### 3. Start HTTPS Server\n\n```bash\npnpm run dev:https\n```\n\n资料来源：[web/src/features/slack/README.md:1-50]()\n\n## Production Deployment\n\n### Docker Compose Production Mode\n\nFor production, use externalized services:\n\n```yaml\nservices:\n  web:\n    image: langfuse/langfuse-web:latest\n    environment:\n      - DATABASE_URL=${DATABASE_URL}\n      - CLICKHOUSE_URL=${CLICKHOUSE_URL}\n      - REDIS_URL=${REDIS_URL}\n      - NEXTAUTH_SECRET=${NEXTAUTH_SECRET}\n      - S3_ACCESS_KEY=${S3_ACCESS_KEY}\n      - S3_SECRET_KEY=${S3_SECRET_KEY}\n    ports:\n      - \"3000:3000\"\n\n  server:\n    image: langfuse/langfuse-server:latest\n    # Configuration similar to web\n\n  worker:\n    image: langfuse/langfuse-worker:latest\n    depends_on:\n      - redis\n      - postgres\n      - clickhouse\n```\n\n### S3 Event Storage\n\nConfigure S3 bucket for event storage:\n\n```sql\n-- Example: Create external table for S3 access logs\nCREATE EXTERNAL TABLE s3_access_logs (\n  bucketowner STRING,\n  bucket_name STRING,\n  requestdatetime STRING,\n  remoteip STRING,\n  requester STRING,\n  requestid STRING,\n  operation STRING,\n  key STRING,\n  uri STRING,\n  statuscode INT,\n  errorcode STRING,\n  bytessent BIGINT,\n  objectsize BIGINT,\n  totaltime STRING,\n  turnaroundtime STRING\n)\nROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.RegexSerDe'\nWITH SERDEPROPERTIES (\n  'input.regex'='([^ ]*) ([^ ]*) \\\\[(.*?)\\\\] ([^ ]*) ([^ ]*) ...'\n)\nSTORED AS INPUTFORMAT 'org.apache.hadoop.mapred.TextInputFormat'\nLOCATION 's3://your-bucket/logs/'\n```\n\n资料来源：[docker-compose.yml:180-220]()\n\n## Common Issues and Solutions\n\n| Issue | Solution |\n|-------|----------|\n| Stack overflow in tree operations | Use iterative algorithms with explicit stacks |\n| Large dataset performance | Enable virtualization (TanStack Virtual) |\n| Horizontal scroll performance | Avoid wrap mode for wide datasets |\n| Multiple tables in peek view | Share pagination state intentionally |\n\n资料来源：[web/src/components/ui/AdvancedJsonViewer/README.md:40-60]()\n\n## Next Steps\n\nAfter setting up your development environment:\n\n1. **Explore the UI** - Navigate through traces, observations, and evaluations\n2. **Integrate SDK** - Connect your LLM application using [Langfuse Python/JS SDK](https://langfuse.com/docs)\n3. **Configure Features** - Set up feature flags and entitlements for your organization\n4. **Deploy** - Move to production using Docker Compose or Kubernetes\n\n资料来源：[CONTRIBUTING.md:1-50]()\n\n---\n\n<a id='system-architecture'></a>\n\n## System Architecture\n\n### 相关页面\n\n相关主题：[Project Structure](#project-structure), [Database Schema (Prisma)](#database-schema), [Queue System (Redis/BullMQ)](#queue-system)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [packages/shared/src/server/clickhouse/client.ts](https://github.com/langfuse/langfuse/blob/main/packages/shared/src/server/clickhouse/client.ts)\n- [packages/shared/src/server/redis/redis.ts](https://github.com/langfuse/langfuse/blob/main/packages/shared/src/server/redis/redis.ts)\n- [packages/shared/src/db.ts](https://github.com/langfuse/langfuse/blob/main/packages/shared/src/db.ts)\n- [packages/shared/src/server/otel/index.ts](https://github.com/langfuse/langfuse/blob/main/packages/shared/src/server/otel/index.ts)\n- [web/src/components/layouts/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/layouts/README.md)\n- [web/src/components/design-system/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/design-system/README.md)\n- [web/src/components/table/peek/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/components/table/peek/README.md)\n- [web/src/features/entitlements/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/entitlements/README.md)\n- [packages/shared/src/features/scores/interfaces/README.md](https://github.com/langfuse/langfuse/blob/main/packages/shared/src/features/scores/interfaces/README.md)\n- [worker/src/scripts/replayIngestionEventsV2/README.md](https://github.com/langfuse/langfuse/blob/main/worker/src/scripts/replayIngestionEventsV2/README.md)\n</details>\n\n# System Architecture\n\nLangfuse is a comprehensive observability and analytics platform designed for Large Language Model (LLM) applications. The system architecture is built on a modern, modular design that separates concerns across frontend, backend worker services, and shared infrastructure layers.\n\n## Overview\n\nLangfuse follows a distributed architecture pattern with the following primary components:\n\n| Layer | Technology Stack | Purpose |\n|-------|-----------------|---------|\n| Frontend | Next.js, React, TypeScript | User interface and visualization |\n| Backend Worker | Node.js, BullMQ, TypeScript | Event processing and queue management |\n| Shared Packages | TypeScript | Common utilities, types, and infrastructure clients |\n| Database | PostgreSQL | Primary data storage |\n| Cache/Queue | Redis | Queue management and caching |\n| Analytics | ClickHouse | High-performance analytics queries |\n| Observability | OpenTelemetry | Distributed tracing |\n\n## High-Level Architecture\n\n```mermaid\ngraph TD\n    subgraph Client[\"Frontend (Next.js)\"]\n        UI[User Interface]\n        Pages[Page Components]\n        DesignSystem[Design System]\n    end\n    \n    subgraph Shared[\"Shared Packages\"]\n        DB[(PostgreSQL)]\n        Redis[(Redis)]\n        ClickHouse[(ClickHouse)]\n        Otel[OpenTelemetry]\n    end\n    \n    subgraph Backend[\"Worker Service\"]\n        Queues[Queue Workers]\n        Scripts[Utility Scripts]\n    end\n    \n    Client <-->|tRPC API| Shared\n    Backend <-->|Event Processing| Shared\n    Client -->|Ingestion| Backend\n```\n\n## Infrastructure Layer\n\n### Database Connection\n\nThe PostgreSQL database is the central data store for Langfuse, managed through a shared database client module. The connection is centralized in the `packages/shared/src/db.ts` module, which provides a unified interface for all database operations across the application.\n\n资料来源：[packages/shared/src/db.ts:1-50]()\n\n### Redis Client\n\nRedis serves dual purposes in the Langfuse architecture:\n\n1. **Queue Management**: BullMQ queues for asynchronous event processing\n2. **Caching**: Session and temporary data caching\n\nThe Redis client is configured in `packages/shared/src/server/redis/redis.ts` and is shared across worker services.\n\n资料来源：[packages/shared/src/server/redis/redis.ts:1-30]()\n\n### ClickHouse Integration\n\nClickHouse provides the analytical query engine for high-performance aggregations. The client is initialized in `packages/shared/src/server/clickhouse/client.ts` and is primarily used for:\n\n- Score analytics aggregations\n- Time-series data analysis\n- Large dataset transformations\n\n资料来源：[packages/shared/src/server/clickhouse/client.ts:1-40]()\n\n### OpenTelemetry\n\nThe OpenTelemetry integration (`packages/shared/src/server/otel/index.ts`) provides distributed tracing across all services. This enables:\n\n- Request tracing across frontend and backend\n- Event processing workflow visibility\n- Performance monitoring\n\n资料来源：[packages/shared/src/server/otel/index.ts:1-60]()\n\n## Frontend Architecture\n\n### Page Structure\n\nAll frontend pages use a standardized layout system defined in `web/src/components/layouts/`. The `Page` component is the required wrapper for all application pages, ensuring consistent layout behavior.\n\nKey layout patterns:\n\n| Pattern | Component | Use Case |\n|---------|-----------|----------|\n| Standard Pages | `Page` | Most application pages |\n| Wide Content | `ContainerPage` | Settings, setup pages with wide content |\n\nThe page wrapper provides:\n- Sticky header management\n- Scroll behavior control (`content-scroll` or `page-scroll`)\n- Breadcrumb navigation\n- Custom header actions\n\n资料来源：[web/src/components/layouts/README.md:1-60]()\n\n### Design System\n\nThe design system (`web/src/components/design-system/`) provides primitive, reusable UI components following strict architectural principles:\n\n**Principles:**\n- Presentational only (no business logic)\n- Explicit, strictly typed APIs\n- Props over context (no React Context)\n\n**Component Structure:**\n```\ndesign-system/\n  Button/\n    Button.tsx\n    Button.stories.tsx\n```\n\n**Styling Rules:**\n- No arbitrary CSS values\n- Explicit enums for variants (`size: \"sm\" | \"md\" | \"lg\"`)\n- CVA (Class Variance Authority) for variant management\n- Boolean props use positive naming (`isLoading`, `shouldTruncate`)\n\n资料来源：[web/src/components/design-system/README.md:1-80]()\n\n### State Management Patterns\n\nLangfuse uses a sophisticated state management approach with the Peek Table State system:\n\n```mermaid\ngraph TD\n    A[Page Load] --> B{Peek Context?}\n    B -->|Yes| C[PeekTableStateProvider]\n    B -->|No| D[URL/Session State]\n    C --> E[Table State Preserved]\n    D --> F[Standard State]\n    \n    E --> G[K/J Navigation]\n    G --> H[State Retained ✓]\n```\n\nThe `PeekTableStateProvider` maintains table state (filters, sorting, pagination) across K/J keyboard navigation between items of the same type. State resets only when the peek view closes.\n\n资料来源：[web/src/components/table/peek/README.md:1-100]()\n\n## Feature Modules\n\n### Entitlements System\n\nThe entitlements feature controls feature availability at the organization level:\n\n| Concept | Definition |\n|---------|------------|\n| Plan | Feature tier (OSS, cloud:pro, self-hosted:enterprise) |\n| Entitlement | Available feature (e.g., playground, score analytics) |\n| EntitlementLimit | Resource limits (e.g., annotation-queue-count) |\n\n**Plan Resolution:**\n- Cloud: Added to organization via JWT from NextAuth\n- Self-hosted: From license key or environment configuration\n\n资料来源：[web/src/features/entitlements/README.md:1-50]()\n\n### Score Analytics\n\nThe score analytics feature provides comprehensive statistical analysis of evaluation scores:\n\n**Architecture Components:**\n\n| Component | Location | Responsibility |\n|-----------|----------|----------------|\n| Provider | `ScoreAnalyticsProvider.tsx` | Context management |\n| Hook | `useScoreAnalyticsQuery` | Data fetching and transformation |\n| Transformers | `scoreAnalyticsTransformers.ts` | Data transformation pipeline |\n| Router | `scoreAnalyticsRouter.ts` | tRPC API endpoint |\n\n**Data Flow:**\n```mermaid\ngraph LR\n    A[API Request] --> B[tRPC Router]\n    B --> C[ClickHouse Query]\n    C --> D[Transformers]\n    D --> E[ScoreAnalyticsProvider]\n    E --> F[Chart Components]\n```\n\n资料来源：[packages/shared/src/features/scores/interfaces/README.md:1-80]()\n资料来源：[web/src/features/score-analytics/README.md:1-100]()\n\n### Score Interfaces Architecture\n\nLangfuse maintains a versioned API structure for scores:\n\n```\ninterfaces/\n├── api/\n│   ├── v1/    # Legacy API (trace-focused)\n│   ├── v2/    # Current API (supports traces, sessions)\n│   └── shared.ts\n├── application/\n├── ingestion/\n└── ui/\n```\n\n**API Versioning Strategy:**\n- POST/DELETE APIs: Support all score types across v1 and v2\n- GET APIs:\n  - V1: Requires `traceId`, trace-level only\n  - V2: `traceId` optional, adds `sessionId` support\n\n资料来源：[packages/shared/src/features/scores/interfaces/README.md:1-50]()\n\n## Backend Worker Architecture\n\n### Event Processing\n\nThe worker service processes ingestion events asynchronously using BullMQ queues:\n\n**Queue Types:**\n| Queue | Purpose | Consumer |\n|-------|---------|----------|\n| `IngestionSecondaryQueue` | Standard event processing | Worker |\n| `OtelIngestionQueue` | OpenTelemetry events | Worker |\n\n**Event Flow:**\n```mermaid\ngraph LR\n    A[Ingestion API] --> B{Event Type?}\n    B -->|Standard| C[S3 Key Parse]\n    B -->|OTEL| D[OTEL Key Parse]\n    C --> E[Queue Payload]\n    D --> E\n    E --> F[BullMQ]\n    F --> G[Worker Processing]\n    G --> H[(ClickHouse)]\n    G --> I[(PostgreSQL)]\n```\n\n资料来源：[worker/src/scripts/replayIngestionEventsV2/README.md:1-60]()\n\n### Replay Ingestion Events V2\n\nThe `replayIngestionEventsV2` script enables replaying historical events from S3 storage:\n\n**Key Features:**\n- Batch processing with configurable size\n- Checkpoint/resume capability\n- Rate limiting with exponential backoff\n- Error handling with detailed logging\n\n**Differences from V1:**\n\n| Aspect | V1 | V2 |\n|--------|----|----|\n| Infrastructure | Redis, ClickHouse, PostgreSQL, S3 | Langfuse host URL only |\n| Setup | Full repo clone + `.env` | `npx tsx` + env vars |\n| Event Delivery | BullMQ `addBulk` to Redis | HTTP POST to admin API |\n| Resume | Manual | Built-in checkpoint |\n\n**Event Transformation:**\n- Standard keys: `{projectId}/{type}/{eventBodyId}/{eventId}.json`\n- OTEL keys: `otel/{projectId}/{yyyy}/{mm}/{dd}/{hh}/{mm}/{eventId}.json`\n\n资料来源：[worker/src/scripts/replayIngestionEventsV2/README.md:1-120]()\n\n### Refill Queue Event\n\nThe `refillQueueEvent` utility script backfills queues with events from local files:\n\n**Usage Pattern:**\n```bash\npnpm run --filter=worker refill-queue-event\n```\n\n**Requirements:**\n- `./worker/events.jsonl` file with JSON events\n- Redis connection via `REDIS_CONNECTION_STRING`\n- Supporting services: S3, ClickHouse\n\n资料来源：[worker/src/scripts/refillQueueEvent/README.md:1-60]()\n\n## MCP Server Architecture\n\nLangfuse includes an MCP (Model Context Protocol) server for programmatic prompt management:\n\n**Stateless Design:**\n1. Fresh server instance per request\n2. Authentication context captured in handler closures\n3. Server discarded after request completes\n4. No state between requests\n\n**Available Tools:**\n| Tool | Purpose |\n|------|---------|\n| `getPrompt` | Fetch resolved prompt with dependencies |\n| `getPromptUnresolved` | Fetch raw prompt without resolution |\n| `listPrompts` | List prompts with filtering |\n| `createTextPrompt` | Create text prompt version |\n| `createChatPrompt` | Create chat prompt version |\n| `updatePromptLabels` | Manage prompt labels |\n\n**Prompt Resolution:**\n- Resolved: Recursively replaces `@@@langfusePrompt:...@@@` tags\n- Unresolved: Returns raw content with tags intact\n\n资料来源：[web/src/features/mcp/README.md:1-100]()\n\n## Component Communication Flow\n\n```mermaid\ngraph TD\n    subgraph Pages[\"Page Layer\"]\n        P[Page Component]\n        PC[PeekTableStateProvider]\n    end\n    \n    subgraph Features[\"Feature Layer\"]\n        FP[Feature Provider]\n        FH[Feature Hook]\n        FT[Feature Transformers]\n    end\n    \n    subgraph Services[\"Service Layer\"]\n        TRPC[tRPC Router]\n        API[API Routes]\n    end\n    \n    subgraph Data[\"Data Layer\"]\n        Repo[Repositories]\n        DB[(PostgreSQL)]\n        CH[(ClickHouse)]\n        Redis[(Redis)]\n    end\n    \n    P --> PC\n    PC --> FP\n    FP --> FH\n    FH --> FT\n    FT --> TRPC\n    TRPC --> Repo\n    Repo --> DB\n    Repo --> CH\n    Repo --> Redis\n```\n\n## Configuration Management\n\nLangfuse uses environment-based configuration across layers:\n\n| Environment | Scope | Examples |\n|-------------|-------|----------|\n| `REDIS_CONNECTION_STRING` | Worker, Queue | Redis URL |\n| `CLICKHOUSE_URL` | Analytics | ClickHouse connection |\n| `LANGFUSE_S3_EVENT_UPLOAD_BUCKET` | Storage | S3 bucket name |\n| `ADMIN_API_KEY` | Admin API | Authentication |\n\n## Security Architecture\n\n**Key Security Components:**\n\n1. **JWT Authentication**: Organization and user context embedded in JWT tokens\n2. **API Key Validation**: Admin API uses dedicated key authentication\n3. **Scope-based Authorization**: Project-level access control\n4. **Plan Entitlements**: Feature availability based on subscription tier\n\n**Self-hosted Considerations:**\n- License key validation for enterprise features\n- Environment-based plan override capability\n\n## Performance Optimizations\n\n**Frontend Optimizations:**\n- Memoized transformations in hooks\n- Virtualized table rendering (TanStack Virtual)\n- Iterative algorithms (no recursion, preventing stack overflow)\n\n**Backend Optimizations:**\n- Batch processing for event replay\n- Checkpoint/resume for long-running operations\n- Client-side rate limiting with exponential backoff\n\n## Summary\n\nThe Langfuse architecture demonstrates a well-structured approach to observability platforms:\n\n- **Separation of Concerns**: Clear boundaries between UI, business logic, and data layers\n- **Scalability**: Asynchronous processing via queues enables horizontal scaling\n- **Extensibility**: Feature modules and MCP server support programmatic access\n- **Observability**: Built-in OpenTelemetry integration for distributed tracing\n- **Performance**: ClickHouse for analytics, iterative algorithms, and batch processing\n\n---\n\n<a id='monorepo-structure'></a>\n\n## Monorepo Configuration\n\n### 相关页面\n\n相关主题：[Project Structure](#project-structure), [System Architecture](#system-architecture)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [turbo.json](https://github.com/langfuse/langfuse/blob/main/turbo.json)\n- [packages/config-eslint/index.js](https://github.com/langfuse/langfuse/blob/main/packages/config-eslint/index.js)\n- [packages/config-typescript/base.json](https://github.com/langfuse/langfuse/blob/main/packages/config-typescript/base.json)\n- [packages/shared/tsconfig.json](https://github.com/langfuse/langfuse/blob/main/packages/shared/tsconfig.json)\n- [web/package.json](https://github.com/langfuse/langfuse/blob/main/web/package.json)\n- [worker/src/scripts/replayIngestionEventsV2/README.md](https://github.com/langfuse/langfuse/blob/main/worker/src/scripts/replayIngestionEventsV2/README.md)\n</details>\n\n# Monorepo Configuration\n\nLangfuse uses a **monorepo architecture** managed with [Turborepo](https://turbo.build/), [pnpm](https://pnpm.io/) workspaces, and shared configuration packages. This setup enables efficient builds, consistent code quality standards, and streamlined dependency management across the project's multiple packages.\n\n## Architecture Overview\n\nThe Langfuse repository is organized as a pnpm workspace monorepo with the following core structure:\n\n```yaml\nlangfuse/\n├── web/                    # Next.js frontend application\n├── worker/                 # Background job processing\n├── packages/\n│   ├── shared/            # Shared utilities and types\n│   ├── config-eslint/     # Shared ESLint configuration\n│   └── config-typescript/ # Shared TypeScript configurations\n├── turbo.json             # Turborepo pipeline definition\n└── pnpm-workspace.yaml    # Workspace package definitions\n```\n\n## Turborepo Pipeline Configuration\n\nThe `turbo.json` file defines the build pipeline and task orchestration across packages.\n\n### Core Pipeline Tasks\n\n| Task | Description | Cache Strategy |\n|------|-------------|----------------|\n| `build` | Compiles TypeScript and bundles assets | Enabled |\n| `dev` | Starts development servers | Local only |\n| `test` | Runs unit and integration tests | Enabled |\n| `lint` | ESLint code quality checks | Enabled |\n| `typecheck` | TypeScript type validation | Enabled |\n\n### Task Dependencies\n\nTurborepo automatically resolves dependencies between packages. For example:\n\n```mermaid\ngraph TD\n    A[packages/shared] -->|build| B[Type definitions]\n    B --> C[packages/config-*]\n    C --> D[web]\n    C --> E[worker]\n    D --> F[Build output]\n    E --> F\n```\n\n## Shared ESLint Configuration\n\nThe `packages/config-eslint/index.js` provides standardized ESLint rules across all packages.\n\n### Configuration Features\n\n- **React/Next.js support** for the web application\n- **TypeScript-aware linting** via `@typescript-eslint`\n- **Import ordering** rules for consistent module organization\n- **JSX accessibility** checks\n\n### Usage\n\nPackages extend the shared configuration:\n\n```javascript\n// In package's .eslintrc.js\nmodule.exports = {\n  extends: ['@langfuse/config-eslint'],\n  // Package-specific overrides\n  rules: {\n    // Custom rules\n  }\n};\n```\n\n资料来源：[packages/config-eslint/index.js]()\n\n## Shared TypeScript Configuration\n\nThe `packages/config-typescript/` directory contains base TypeScript configurations.\n\n### Base Configuration (`base.json`)\n\n```json\n{\n  \"compilerOptions\": {\n    \"target\": \"ES2020\",\n    \"module\": \"ESNext\",\n    \"moduleResolution\": \"bundler\",\n    \"strict\": true,\n    \"esModuleInterop\": true,\n    \"skipLibCheck\": true,\n    \"forceConsistentCasingInFileNames\": true\n  }\n}\n```\n\n### Package-Specific Configurations\n\nIndividual packages extend the base configuration:\n\n```json\n// packages/shared/tsconfig.json\n{\n  \"extends\": \"@langfuse/config-typescript/base.json\",\n  \"compilerOptions\": {\n    \"outDir\": \"./dist\",\n    \"rootDir\": \"./src\"\n  },\n  \"include\": [\"src/**/*\"],\n  \"exclude\": [\"node_modules\", \"dist\"]\n}\n```\n\n资料来源：[packages/config-typescript/base.json](), [packages/shared/tsconfig.json]()\n\n## Package Scripts and Commands\n\nEach package defines its own scripts in `package.json`. The web package demonstrates the typical pattern:\n\n### Build Commands\n\n| Command | Purpose |\n|---------|---------|\n| `pnpm build` | Production build with `INLINE_RUNTIME_CHUNK=false` |\n| `pnpm build:check` | Build without emitting (type-checking) |\n| `pnpm dev` | Development server on localhost:3000 |\n| `pnpm dev:http` | HTTPS development server for local testing |\n\n### Quality Assurance Commands\n\n| Command | Purpose |\n|---------|---------|\n| `pnpm lint` | ESLint with caching enabled |\n| `pnpm lint:fix` | Auto-fix linting issues |\n| `pnpm typecheck` | TypeScript validation with incremental compilation |\n| `pnpm test` | Vitest with server and in-source test projects |\n\n资料来源：[web/package.json]()\n\n## Development Workflow\n\n### Starting Development\n\n```bash\n# Install dependencies\npnpm install\n\n# Start all dev servers based on turbo.json\npnpm dev\n\n# Or start a specific package\ncd web && pnpm dev\n```\n\n### Running Tests\n\n```bash\n# All tests\npnpm test\n\n# Client-side tests only (e.g., AdvancedJsonViewer)\npnpm --filter=web run test-client --testPathPattern=\"AdvancedJsonViewer\"\n\n# Server-side tests\npnpm --filter=web run test --project server\n```\n\n### Build Pipeline\n\n```mermaid\ngraph LR\n    A[pnpm build] --> B[turbo build]\n    B --> C{Cache hit?}\n    C -->|Yes| D[Use cached output]\n    C -->|No| E[Build dependencies]\n    E --> F[packages/shared]\n    F --> G[packages/config-*]\n    G --> H[web/worker]\n    H --> I[Save to cache]\n    I --> J[Build artifacts]\n```\n\n## Environment Configuration\n\nThe project uses `.env` files for environment-specific configuration:\n\n| File | Purpose |\n|------|---------|\n| `.env` | Default environment variables |\n| `.env.local` | Local overrides (git-ignored) |\n| `.env.test` | Test environment variables |\n\nScripts use `dotenv` to load these files:\n\n```bash\ndotenv -e ../.env -- next build\ndotenv -e ../.env.test -e ../.env -- vitest run\n```\n\n资料来源：[worker/src/scripts/replayIngestionEventsV2/README.md]()\n\n## Best Practices\n\n### Adding a New Package\n\n1. Create the package under `packages/` or `web/` directories\n2. Extend the shared TypeScript and ESLint configurations\n3. Add the package to `pnpm-workspace.yaml` if needed\n4. Define tasks in `turbo.json` if custom pipeline is required\n5. Add appropriate scripts to `package.json`\n\n### Caching Strategy\n\n- **Build caching**: Enabled by default via Turborepo\n- **Lint caching**: ESLint caches to `.next/cache/eslint/`\n- **TypeScript incremental**: Uses `.tsbuildinfo` files\n\n### CI/CD Integration\n\nIn CI environments, clear caches to ensure fresh builds:\n\n```bash\n# Clear turbo cache\nrm -rf .turbo node_modules/.cache\n\n# Clear ESLint cache\nrm -rf .next/cache/eslint/\n\n# Fresh build\npnpm install --frozen-lockfile\npnpm build\n```\n\n## Key Configuration Files Summary\n\n| File | Purpose |\n|------|---------|\n| `turbo.json` | Task pipeline and dependency graph |\n| `pnpm-workspace.yaml` | Workspace package definitions |\n| `packages/config-eslint/index.js` | Shared ESLint rules |\n| `packages/config-typescript/base.json` | Shared TypeScript base config |\n| `.eslintrc.js` (per package) | Package-specific lint overrides |\n| `tsconfig.json` (per package) | Package-specific TypeScript config |\n\n---\n\n<a id='database-schema'></a>\n\n## Database Schema (Prisma)\n\n### 相关页面\n\n相关主题：[System Architecture](#system-architecture), [ClickHouse Analytics Layer](#clickhouse-analytics)\n\n<details>\n<summary>Relevant Source Files</summary>\n\n以下源码文件用于生成本页说明：\n\n- [packages/shared/prisma/schema.prisma](https://github.com/langfuse/langfuse/blob/main/packages/shared/prisma/schema.prisma)\n- [packages/shared/src/server/repositories/traces.ts](https://packages/shared/src/server/repositories/traces.ts)\n- [packages/shared/src/server/repositories/observations.ts](https://packages/shared/src/server/repositories/observations.ts)\n- [packages/shared/src/server/repositories/scores.ts](https:///packages/shared/src/server/repositories/scores.ts)\n- [packages/shared/src/features/scores/interfaces/README.md](https://github.com/langfuse/langfuse/blob/main/packages/shared/src/features/scores/interfaces/README.md)\n</details>\n\n# Database Schema (Prisma)\n\n## Overview\n\nLangfuse uses Prisma ORM to manage its PostgreSQL database schema. The schema defines the core data models for the application, including organizations, projects, users, traces, observations, and scores. Prisma serves as the primary interface between the application's business logic and the relational database.\n\nThe Prisma schema is located at `packages/shared/prisma/schema.prisma` and is shared across multiple packages in the monorepo structure. This centralized schema approach ensures consistency in data modeling across the web application, worker services, and shared libraries.\n\n### Design Philosophy\n\nThe schema follows several key principles:\n\n- **Normalized relationships**: Related entities are linked through foreign keys with proper cascading behaviors\n- **Soft deletes**: Key entities support soft deletion for data recovery and audit purposes\n- **Audit fields**: Most tables include `createdAt`, `updatedAt`, and `createdBy` fields\n- **Multi-tenancy**: The schema supports multi-tenant architecture with organization and project isolation\n- **Extensible metadata**: JSON fields allow flexible storage of custom attributes\n\n## Core Data Models\n\n### Organization and User Models\n\nThe foundation of Langfuse's multi-tenant architecture begins with the `Organization` model, which represents the top-level tenant entity. Each organization can have multiple users with different roles and permission levels.\n\nThe `User` model stores authentication and profile information, linked to organizations through the `Membership` junction table. This many-to-many relationship enables users to belong to multiple organizations with potentially different roles in each.\n\n```mermaid\nerDiagram\n    Organization ||--o{ User : \"contains\"\n    Organization ||--o{ Project : \"contains\"\n    User ||--o{ Membership : \"has\"\n    Membership }o--|| Organization : \"belongs to\"\n    Membership }o--|| User : \"belongs to\"\n```\n\n### Project Model\n\nProjects serve as the primary container for observability data. Each project belongs to exactly one organization and contains all traces, observations, and scores related to a specific application or use case.\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `id` | `String` | UUID primary key |\n| `name` | `String` | Project display name |\n| `organizationId` | `String` | Foreign key to organization |\n| `createdAt` | `DateTime` | Creation timestamp |\n| `updatedAt` | `DateTime` | Last modification timestamp |\n| `deletedAt` | `DateTime?` | Soft delete timestamp |\n| `settings` | `Json` | Project-specific configuration |\n\n资料来源：[packages/shared/prisma/schema.prisma]()\n\n## Traces\n\nTraces represent the top-level unit of observability in Langfuse. A trace encapsulates a complete interaction or request, typically corresponding to a single LLM call or a multi-step workflow.\n\n### Trace Model Schema\n\n```prisma\nmodel Trace {\n  id            String   @id @default(cuid())\n  name          String?\n  project       Project  @relation(fields: [projectId], references: [id])\n  projectId     String\n  user          String?\n  metadata      Json?\n  sessionId     String?\n  release       String?\n  version       String?\n  tags          String[]\n  \n  // Timestamps\n  createdAt     DateTime @default(now())\n  updatedAt     DateTime @updatedAt\n  \n  // Soft delete\n  deletedAt     DateTime?\n  \n  // Relations\n  observations  Observation[]\n  scores        Score[]\n  \n  @@index([projectId])\n  @@index([sessionId])\n  @@index([createdAt])\n}\n```\n\n资料来源：[packages/shared/prisma/schema.prisma]()\n\n### Key Fields\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `id` | `String` | Unique identifier using CUID algorithm |\n| `name` | `String?` | Optional human-readable trace name |\n| `projectId` | `String` | Reference to parent project |\n| `user` | `String?` | Identifier for the end user |\n| `sessionId` | `String?` | Groups related traces into sessions |\n| `release` | `String?` | Application release version |\n| `version` | `String?` | Trace format version |\n| `tags` | `String[]` | Array of string tags for categorization |\n\n### Repository Pattern\n\nTraces are accessed through the repository pattern defined in `packages/shared/src/server/repositories/traces.ts`. This abstraction provides a clean interface for CRUD operations while encapsulating query logic.\n\n资料来源：[packages/shared/src/server/repositories/traces.ts]()\n\n```typescript\n// Repository interface pattern (simplified)\ninterface ITraceRepository {\n  create(data: CreateTraceInput): Promise<Trace>;\n  getById(id: string, projectId: string): Promise<Trace | null>;\n  list(projectId: string, options?: ListTracesOptions): Promise<Trace[]>;\n  update(id: string, data: UpdateTraceInput): Promise<Trace>;\n  softDelete(id: string): Promise<void>;\n}\n```\n\n## Observations\n\nObservations represent the individual components within a trace, such as LLM calls, retrievals, or custom events. They form a hierarchical structure that can be nested to represent complex workflows.\n\n### Observation Model Schema\n\n```prisma\nmodel Observation {\n  id            String   @id @default(cuid())\n  \n  // Type discrimination\n  type          ObservationType\n  \n  // Relations\n  trace         Trace    @relation(fields: [traceId], references: [id])\n  traceId       String\n  parent        Observation? @relation(\"ObservationHierarchy\", fields: [parentId], references: [id])\n  parentId      String?\n  children      Observation[] @relation(\"ObservationHierarchy\")\n  \n  // Project reference for efficient querying\n  projectId     String\n  \n  // Core data\n  name          String?\n  startTime     DateTime\n  endTime       DateTime?\n  status        String?\n  metadata      Json?\n  \n  // LLM-specific fields\n  model         String?\n  modelId       String?\n  provider      String?\n  promptTokens  Int?\n  completionTokens Int?\n  totalTokens   Int?\n  unitPrice     Float?\n  currency      String?\n  calculatedUnitCost Float?\n  \n  // Retrieval-specific fields\n  input         Json?\n  output        Json?\n  \n  // Timestamps\n  createdAt     DateTime @default(now())\n  updatedAt     DateTime @updatedAt\n  \n  // Soft delete\n  deletedAt     DateTime?\n  \n  @@index([traceId])\n  @@index([projectId])\n  @@index([startTime])\n}\n```\n\n资料来源：[packages/shared/prisma/schema.prisma]()\n资料来源：[packages/shared/src/server/repositories/observations.ts]()\n\n### Observation Types\n\nLangfuse supports several observation types through an enum:\n\n| Type | Description |\n|------|-------------|\n| `CHAT` | Chat completion calls |\n| `GENERATION` | Text generation calls |\n| `RETRIEVAL` | Retrieval augmented generation steps |\n| `EVENT` | Custom events and markers |\n| `TOOL` | Tool/function calls |\n\n### Hierarchical Structure\n\nObservations support nested hierarchies through self-referential relationships. This enables representing complex multi-step workflows where parent observations contain child observations representing sub-tasks or parallel operations.\n\n```mermaid\ngraph TD\n    A[Trace] --> B[Observation: Chat]\n    B --> C[Observation: Retrieval]\n    B --> D[Observation: Generation]\n    C --> E[Observation: Event: Cache Hit]\n    D --> F[Observation: Tool: Calculator]\n    D --> G[Observation: Tool: Search]\n```\n\n资料来源：[packages/shared/prisma/schema.prisma]()\n\n## Scores\n\nScores provide a mechanism for evaluating trace and observation quality. They can be human-generated or automated evaluations attached to specific traces or observations.\n\n### Score Model Schema\n\n```prisma\nmodel Score {\n  id            String   @id @default(cuid())\n  \n  // Target discrimination\n  traceId       String?\n  observationId String?\n  \n  // Project reference\n  projectId     String\n  \n  // Score data\n  name          String\n  value         Float\n  dataType      ScoreDataType\n  comment       String?\n  \n  // Source tracking\n  source        String?\n  \n  // Author\n  authorId      String?\n  \n  // Timestamps\n  createdAt     DateTime @default(now())\n  updatedAt     DateTime @updatedAt\n  \n  // Relations\n  trace         Trace?      @relation(fields: [traceId], references: [id])\n  observation   Observation? @relation(fields: [observationId], references: [id])\n  \n  @@index([projectId])\n  @@index([traceId])\n  @@index([observationId])\n  @@index([name, createdAt])\n}\n```\n\n资料来源：[packages/shared/prisma/schema.prisma]()\n资料来源：[packages/shared/src/server/repositories/scores.ts]()\n\n### Score Data Types\n\nThe `ScoreDataType` enum defines the type of value stored:\n\n| Data Type | Description |\n|-----------|-------------|\n| `NUMERIC` | Continuous numerical value |\n| `CATEGORICAL` | Categorical label or classification |\n| `BOOLEAN` | True/false indicator |\n\n### Score Interfaces Architecture\n\nScores in Langfuse follow a layered interface architecture that separates concerns across different parts of the system:\n\n```mermaid\ngraph LR\n    A[UI Types] --> B[Application Validation]\n    B --> C[Ingestion Validation]\n    C --> D[API v1 Schemas]\n    C --> E[API v2 Schemas]\n    D --> F[Database Models]\n    E --> F\n```\n\n资料来源：[packages/shared/src/features/scores/interfaces/README.md]()\n\n## Indexing Strategy\n\nThe schema defines strategic indexes to optimize common query patterns:\n\n| Table | Indexes | Purpose |\n|-------|---------|---------|\n| `Trace` | `projectId`, `sessionId`, `createdAt` | Fast project filtering and time-based queries |\n| `Observation` | `traceId`, `projectId`, `startTime` | Trace traversal and time-series queries |\n| `Score` | `projectId`, `traceId`, `observationId`, `name, createdAt` | Score lookups and time-series analytics |\n\nThe composite index on `Score(name, createdAt)` specifically supports the score analytics feature's need to retrieve scores by name over time intervals.\n\n资料来源：[packages/shared/prisma/schema.prisma]()\n\n## Prisma Client Usage\n\nPrisma Client is generated from the schema and used throughout the application. The generated client provides type-safe access to all database operations.\n\n### Client Configuration\n\n```typescript\nimport { PrismaClient } from \"@langfuse/shared/prisma\";\n\nconst prisma = new PrismaClient({\n  log: process.env.NODE_ENV === \"development\" ? [\"query\", \"error\"] : [\"error\"],\n});\n```\n\n### Transaction Support\n\nThe schema supports atomic operations through Prisma's transaction API:\n\n```typescript\nawait prisma.$transaction([\n  prisma.trace.create({ data: traceData }),\n  prisma.observation.createMany({ data: observations }),\n  prisma.score.createMany({ data: scores }),\n]);\n```\n\n## Migrations\n\nDatabase migrations are managed through Prisma Migrate. Migration files are stored in `packages/shared/prisma/migrations/` and version-controlled alongside the schema.\n\n### Running Migrations\n\n```bash\n# Apply pending migrations\npnpm --filter=langfuse-prisma migrate deploy\n\n# Create a new migration\npnpm --filter=langfuse-prisma migrate dev --name add_new_field\n```\n\n## Related Components\n\n### Repository Layer\n\nThe repository pattern abstracts database access behind domain-specific interfaces:\n\n| Repository | File | Purpose |\n|------------|------|---------|\n| `TraceRepository` | `repositories/traces.ts` | Trace CRUD and querying |\n| `ObservationRepository` | `repositories/observations.ts` | Observation management |\n| `ScoreRepository` | `repositories/scores.ts` | Score operations |\n\n资料来源：[packages/shared/src/server/repositories/traces.ts]()\n资料来源：[packages/shared/src/server/repositories/scores.ts]()\n\n### ClickHouse Integration\n\nWhile PostgreSQL (via Prisma) stores transactional data like traces and scores, Langfuse also uses ClickHouse for analytics workloads. The Prisma schema defines PostgreSQL models for the primary application data, while ClickHouse handles high-volume analytical queries.\n\n资料来源：[packages/shared/scripts/seeder/utils/README.md]()\n\n## Summary\n\nThe Prisma schema forms the backbone of Langfuse's data layer, defining:\n\n- **Multi-tenant structure**: Organizations, projects, and user memberships\n- **Observability core**: Traces and observations with hierarchical support\n- **Evaluation framework**: Scores with multiple data types and sources\n- **Operational metadata**: Timestamps, soft deletes, and JSON fields for flexibility\n\nThe schema design prioritizes query performance through strategic indexing, data integrity through proper relationships, and extensibility through JSON metadata fields.\n\n---\n\n<a id='clickhouse-analytics'></a>\n\n## ClickHouse Analytics Layer\n\n### 相关页面\n\n相关主题：[Database Schema (Prisma)](#database-schema), [Worker Service](#worker-service)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [packages/shared/clickhouse/migrations/clustered/0001_traces.up.sql](https://github.com/langfuse/langfuse/blob/main/packages/shared/clickhouse/migrations/clustered/0001_traces.up.sql)\n- [packages/shared/src/server/clickhouse/schema.ts](https://github.com/langfuse/langfuse/blob/main/packages/shared/src/server/clickhouse/schema.ts)\n- [packages/shared/src/server/repositories/clickhouse.ts](https://github.com/langfuse/langfuse/blob/main/packages/shared/src/server/repositories/clickhouse.ts)\n- [worker/src/services/ClickhouseWriter/index.ts](https://github.com/langfuse/langfuse/blob/main/worker/src/services/ClickhouseWriter/index.ts)\n- [packages/shared/src/server/repositories/score-analytics.ts](https://github.com/langfuse/langfuse/blob/main/packages/shared/src/server/repositories/score-analytics.ts)\n- [web/src/features/score-analytics/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/score-analytics/README.md)\n- [packages/shared/scripts/seeder/utils/README.md](https://github.com/langfuse/langfuse/blob/main/packages/shared/scripts/seeder/utils/README.md)\n</details>\n\n# ClickHouse Analytics Layer\n\n## Overview\n\nThe ClickHouse Analytics Layer is a core infrastructure component in Langfuse that provides high-performance analytical capabilities for processing and querying large-scale observability data. ClickHouse serves as the primary OLAP (Online Analytical Processing) database for storing traces, observations, and score analytics with optimized columnar storage and efficient aggregation queries.\n\nLangfuse leverages ClickHouse for:\n\n- High-throughput event ingestion during trace collection\n- Complex analytical queries for score comparisons and distributions\n- Time-series analysis with efficient aggregation\n- Large dataset sampling and optimization strategies\n  资料来源：[packages/shared/scripts/seeder/utils/README.md]()\n\n## Architecture Overview\n\n```mermaid\ngraph TD\n    subgraph Ingestion[\"Ingestion Layer\"]\n        W[Worker Service] --> CW[ClickhouseWriter]\n        CW --> CH[ClickHouse Cluster]\n    end\n    \n    subgraph Storage[\"Storage Layer\"]\n        CH --> TS[Traces Table]\n        CH --> OS[Observations Table]\n        CH --> SS[Scores Table]\n    end\n    \n    subgraph Query[\"Query Layer\"]\n        CR[ClickHouse Repository] --> CH\n        SA[Score Analytics] --> CR\n        WEB[Web Frontend] --> SA\n    end\n    \n    subgraph Optimization[\"Optimization Layer\"]\n        CR --> HASH[cityHash64 Sampling]\n        CR --> FINAL[Adaptive FINAL]\n        CR --> INTERVAL[Time Interval Alignment]\n    end\n```\n\n### Components Overview\n\n| Component | Location | Purpose |\n|-----------|----------|---------|\n| ClickhouseWriter | `worker/src/services/ClickhouseWriter/index.ts` | Writes ingestion events to ClickHouse |\n| ClickHouse Repository | `packages/shared/src/server/repositories/clickhouse.ts` | Provides query interface and optimization |\n| Score Analytics | `packages/shared/src/server/repositories/score-analytics.ts` | Specialized analytics queries |\n| Schema Definitions | `packages/shared/src/server/clickhouse/schema.ts` | TypeScript types for ClickHouse data |\n| Migrations | `packages/shared/clickhouse/migrations/clustered/` | Database schema migrations |\n\n资料来源：[worker/src/services/ClickhouseWriter/index.ts]()\n资料来源：[packages/shared/src/server/repositories/clickhouse.ts]()\n\n## Data Schema\n\n### Traces Table\n\nThe traces table stores the fundamental trace records with hierarchical observation data. The clustered migration defines the primary schema with optimized column types for analytical queries.\n\nKey columns include:\n\n| Column | Type | Description |\n|--------|------|-------------|\n| id | UUID | Unique trace identifier |\n| project_id | String | Project association |\n| timestamp | DateTime64 | Event timestamp with millisecond precision |\n| name | String | Trace name |\n| user_id | String | User identifier |\n| metadata | JSON | Flexible metadata storage |\n| tags | Array(String) | Tag-based categorization |\n| input | Text | Input data |\n| output | Text | Output data |\n\n资料来源：[packages/shared/clickhouse/migrations/clustered/0001_traces.up.sql]()\n\n### Observations Table\n\nObservations represent individual events within a trace, storing:\n\n- Model inputs/outputs\n- Function calls\n- Embeddings\n- Generation events\n\nEach observation is linked to its parent trace via `trace_id` and supports nested hierarchies through `parent_observation_id`.\n\n资料来源：[packages/shared/src/server/clickhouse/schema.ts]()\n\n### Scores Table\n\nScores store evaluation metrics associated with traces and observations:\n\n| Column | Type | Purpose |\n|--------|------|---------|\n| trace_id | UUID | Associated trace |\n| observation_id | UUID | Optional observation link |\n| name | String | Score identifier |\n| value | Float64 | Numeric score value |\n| data_type | Enum | NUMERIC, BOOLEAN, or CATEGORICAL |\n| source | String | Score origin (e.g., \"framework-trace\") |\n\n资料来源：[packages/shared/src/server/repositories/score-analytics.ts]()\n\n## Ingestion Pipeline\n\n### Event Flow\n\n```mermaid\nsequenceDiagram\n    participant API as Ingestion API\n    participant Queue as Redis Queue\n    participant Worker as Worker Service\n    participant Writer as ClickhouseWriter\n    participant CH as ClickHouse\n    \n    API->>Queue: Enqueue OtelIngestionEvent\n    Worker->>Queue: Dequeue Event\n    Worker->>Writer: Process Event\n    Writer->>CH: Insert Batch (ClickHouseQueryBuilder)\n    CH-->>Writer: Confirmation\n    Writer->>Worker: Acknowledge\n```\n\n### ClickhouseWriter Service\n\nThe `ClickhouseWriter` handles the actual data insertion into ClickHouse:\n\n```typescript\n// Simplified flow from worker/src/services/ClickhouseWriter/index.ts\nclass ClickhouseWriter {\n  async writeBatch(events: IngestionEvent[]): Promise<void> {\n    const queryBuilder = new ClickHouseQueryBuilder();\n    \n    for (const event of events) {\n      queryBuilder.addEvent(event);\n    }\n    \n    await this.executeQuery(queryBuilder.build());\n  }\n}\n```\n\nKey responsibilities:\n\n1. **Batch Processing**: Aggregates multiple events for efficient insertion\n2. **Schema Validation**: Ensures events match expected schema\n3. **Query Building**: Uses `ClickHouseQueryBuilder` for optimized INSERT queries\n4. **Error Recovery**: Handles failed insertions with retry logic\n\n资料来源：[worker/src/services/ClickhouseWriter/index.ts]()\n\n### ClickHouseQueryBuilder\n\nThe `ClickHouseQueryBuilder` class constructs optimized ClickHouse SQL queries with:\n\n- Proper escaping for special characters\n- Type-aware value formatting\n- Batch insert optimization\n- Efficient column mapping\n\n资料来源：[packages/shared/scripts/seeder/utils/README.md]()\n\n## Query Layer\n\n### Repository Pattern\n\nThe `clickhouse.ts` repository provides a clean interface for all ClickHouse operations:\n\n```typescript\n// packages/shared/src/server/repositories/clickhouse.ts\nclass ClickHouseRepository {\n  // Query execution with automatic connection management\n  async query<T>(sql: string, params?: QueryParams): Promise<T[]>\n  \n  // Stream processing for large result sets\n  async streamQuery(sql: string, handler: (row: T) => void): Promise<void>\n  \n  // Batch inserts with transaction support\n  async insertBatch(table: string, rows: Record<string, unknown>[]): Promise<void>\n}\n```\n\n资料来源：[packages/shared/src/server/repositories/clickhouse.ts]()\n\n### Score Analytics Queries\n\nThe score analytics module provides specialized queries for evaluating model performance:\n\n```typescript\n// packages/shared/src/server/repositories/score-analytics.ts\ninterface ScoreAnalyticsQuery {\n  getScoreIdentifiers(projectId: string): Promise<ScoreIdentifier[]>;\n  \n  estimateScoreComparisonSize(\n    projectId: string,\n    score1Id: string,\n    score2Id?: string\n  ): Promise<QueryEstimate>;\n  \n  getScoreComparisonAnalytics(\n    params: ScoreAnalyticsParams\n  ): Promise<ScoreAnalyticsResult>;\n}\n```\n\n#### Query Estimation\n\nBefore executing expensive analytics queries, the system estimates query size:\n\n| Metric | Description |\n|--------|-------------|\n| scoreCount | Total number of scores matching criteria |\n| matchedCount | Estimated rows that will match |\n| willSample | Whether hash-based sampling is needed |\n| estimatedQueryTime | Predicted query duration |\n\nThis estimation enables adaptive query optimization based on dataset size.\n\n资料来源：[packages/shared/src/server/repositories/score-analytics.ts]()\n资料来源：[web/src/features/score-analytics/README.md]()\n\n## Optimization Strategies\n\n### Hash-Based Sampling\n\nFor large datasets (>100,000 matches), Langfuse uses `cityHash64` for consistent sampling:\n\n```sql\nSELECT * FROM scores\nWHERE cityHash64(trace_id) < 0.1  -- 10% sample\n```\n\nBenefits:\n\n- Consistent sampling across query executions\n- Reproducible results for the same query parameters\n- Reduced query load while maintaining statistical validity\n\n### Adaptive FINAL Optimization\n\nClickHouse's FINAL modifier ensures up-to-date data but adds significant overhead. Langfuse uses adaptive application:\n\n| Dataset Size | FINAL Applied |\n|--------------|---------------|\n| < 70,000 scores | Yes |\n| > 70,000 scores | No |\n\n资料来源：[web/src/features/score-analytics/README.md]()\n\n### Time Interval Alignment\n\nTime series queries use proper interval alignment for accurate aggregation:\n\n```typescript\n// ISO 8601 weeks\nconst weekInterval = \"1W\";\n\n// Calendar months\nconst monthInterval = \"1MONTH\";\n```\n\nProper alignment ensures:\n\n- Consistent bucket boundaries\n- Accurate period-over-period comparisons\n- Correct aggregation across daylight saving time transitions\n\n## Seeding and Testing\n\nThe seeder utility (`packages/shared/scripts/seeder/`) generates realistic test data for ClickHouse:\n\n### Data Types\n\n| Type | Environment | Purpose |\n|------|-------------|---------|\n| Experiment Traces | `langfuse-prompt-experiment` | Realistic traces from actual datasets |\n| Evaluation Data | `langfuse-evaluation` | Metrics and scoring for evaluations |\n| Synthetic Data | `default` | Large-scale hierarchical test data |\n\n### ID Patterns\n\n- Experiment: `trace-dataset-{datasetName}-{itemIndex}-{projectId}-{runNumber}`\n- Evaluation: `trace-eval-{index}-{projectId}`\n- Synthetic: `trace-synthetic-{index}-{projectId}`\n\n资料来源：[packages/shared/scripts/seeder/utils/README.md]()\n\n### DataGenerator\n\nThe `DataGenerator` class creates realistic data for all three types:\n\n| Method | Output |\n|--------|--------|\n| `generateDatasetTrace()` | Traces linked to dataset items |\n| `generateSyntheticTraces()` | Hierarchical traces with scores |\n| `generateEvaluationTraces()` | Evaluation-focused traces |\n\n资料来源：[packages/shared/scripts/seeder/utils/README.md]()\n\n## Framework Traces\n\nFramework traces are real traces produced through official Langfuse framework instrumentation. They can be added to the system for UI testing and demo purposes.\n\n### Adding New Framework Traces\n\n1. Generate a trace using framework instrumentation\n2. Download from UI using the download button\n3. Convert to JSON format via \"Log View (Beta)\"\n4. Merge observations using the provided script:\n   ```bash\n   npx ts-node merge-observations.ts trace-file.json observations.json trace-merged.json\n   ```\n5. Save the merged file with date-based naming\n\n### Discovery\n\nFramework traces use the ID pattern `framework-frameworkName-traceId`. Filter by:\n\n- `source: \"framework-trace\"` in trace table\n- \"All Time\" date range (timestamps not rewritten)\n\n资料来源：[packages/shared/scripts/seeder/utils/framework-traces/README.md]()\n\n## TypeScript Integration\n\n### Schema Types\n\nThe `schema.ts` file provides TypeScript type definitions:\n\n```typescript\n// packages/shared/src/server/clickhouse/schema.ts\ninterface ClickHouseTrace {\n  id: string;\n  project_id: string;\n  timestamp: Date;\n  name: string;\n  user_id?: string;\n  metadata?: Record<string, unknown>;\n  tags?: string[];\n  input?: string;\n  output?: string;\n  session_id?: string;\n}\n\ninterface ClickHouseObservation {\n  id: string;\n  trace_id: string;\n  parent_observation_id?: string;\n  type: ObservationType;\n  timestamp: Date;\n  name?: string;\n  // ... additional fields\n}\n```\n\nThese types ensure compile-time safety when interacting with ClickHouse data.\n\n资料来源：[packages/shared/src/server/clickhouse/schema.ts]()\n\n## Configuration\n\n### Required Environment Variables\n\n| Variable | Description | Example |\n|----------|-------------|---------|\n| `CLICKHOUSE_URL` | ClickHouse server URL | `http://localhost:8123` |\n| `CLICKHOUSE_USER` | Database user | `clickhouse` |\n| `CLICKHOUSE_PASSWORD` | User password | `clickhouse` |\n| `CLICKHOUSE_DATABASE` | Target database | `default` |\n\n### Cluster Configuration\n\nMigrations support clustered deployments:\n\n```bash\n# Clustered migration path\npackages/shared/clickhouse/migrations/clustered/\n```\n\nThe clustered migrations ensure schema consistency across all nodes in a ClickHouse cluster.\n\n资料来源：[packages/shared/clickhouse/migrations/clustered/0001_traces.up.sql]()\n\n## Best Practices\n\n### Query Optimization\n\n1. **Use projections** for frequently accessed columns\n2. **Leverageskipping indexes** for high-cardinality columns\n3. **Batch inserts** to reduce overhead\n4. **Filter early** to minimize data processed\n\n### Data Management\n\n1. **Partition by date** for efficient time-range queries\n2. **Use TTL policies** for automatic data expiration\n3. **Compress data** using ClickHouse's native compression\n\n### Integration Guidelines\n\n1. Always use the repository pattern for query abstraction\n2. Implement query estimation before expensive operations\n3. Use hash-based sampling for large analytical queries\n4. Consider adaptive FINAL optimization for query performance\n\n## See Also\n\n- [Score Analytics Module](../features/score-analytics/README.md)\n- [Ingestion API Documentation](../ingestion/README.md)\n- [Worker Service Documentation](../worker/README.md)\n- [Seeding Utilities](../packages/shared/scripts/seeder/utils/README.md)\n\n---\n\n<a id='queue-system'></a>\n\n## Queue System (Redis/BullMQ)\n\n### 相关页面\n\n相关主题：[System Architecture](#system-architecture), [Worker Service](#worker-service)\n\n<details>\n<summary>Relevant Source Files</summary>\n\n以下源码文件用于生成本页说明：\n\n- [packages/shared/src/server/redis/ingestionQueue.ts](https://github.com/langfuse/langfuse/blob/main/packages/shared/src/server/redis/ingestionQueue.ts)\n- [packages/shared/src/server/redis/evalExecutionQueue.ts](https://github.com/langfuse/langfuse/blob/main/packages/shared/src/server/redis/evalExecutionQueue.ts)\n- [packages/shared/src/server/redis/batchActionQueue.ts](https://github.com/langfuse/langfuse/blob/main/packages/shared/src/server/redis/batchActionQueue.ts)\n- [packages/shared/src/server/redis/webhookQueue.ts](https://github.com/langfuse/langfuse/blob/main/packages/shared/src/server/redis/webhookQueue.ts)\n- [worker/src/queues/workerManager.ts](https://github.com/langfuse/langfuse/blob/main/worker/src/queues/workerManager.ts)\n</details>\n\n# Queue System (Redis/BullMQ)\n\nLangfuse employs a distributed queue system built on **Redis** for storage and **BullMQ** for job orchestration. This architecture enables asynchronous processing of high-volume operations including event ingestion, evaluation execution, batch actions, and webhook delivery.\n\n## Architecture Overview\n\nThe queue system follows a producer-consumer pattern where the web application enqueues jobs and worker processes consume them asynchronously.\n\n```mermaid\ngraph TD\n    subgraph \"Langfuse Web Application\"\n        A[API Request] --> B[Queue Client]\n        B --> C[Redis Queue]\n    end\n    \n    subgraph \"Langfuse Worker\"\n        C --> D[Worker Manager]\n        D --> E1[Ingestion Worker]\n        D --> E2[Eval Worker]\n        D --> E3[Batch Worker]\n        D --> E4[Webhook Worker]\n    end\n    \n    subgraph \"Redis\"\n        C --> F[(Redis Cluster)]\n    end\n    \n    subgraph \"External Services\"\n        E1 --> G[(ClickHouse)]\n        E1 --> H[(PostgreSQL)]\n        E2 --> H\n        E3 --> H\n        E4 --> I[(External APIs)]\n    end\n```\n\n## Queue Types\n\nLangfuse defines multiple specialized queues for different workloads:\n\n| Queue Name | Purpose | Processing Type | Priority |\n|------------|---------|-----------------|----------|\n| `ingestion` | Event ingestion and processing | Async batch | Medium |\n| `evalExecution` | LLM evaluation execution | Async | Medium |\n| `batchAction` | Bulk operations on data | Async batch | Low |\n| `webhook` | Outbound webhook delivery | Async | High |\n| `OtelIngestion` | OpenTelemetry event ingestion | Async | Medium |\n| `IngestionSecondary` | Secondary ingestion processing | Async | Medium |\n\n资料来源：[worker/src/queues/workerManager.ts]()\n\n## Queue Configuration\n\n### Redis Connection\n\nAll queues rely on a Redis connection string configured via environment variables:\n\n```bash\nREDIS_CONNECTION_STRING=redis://:myredissecret@127.0.0.1:6379\n```\n\n### Queue Initialization\n\nEach queue is initialized with specific BullMQ configuration:\n\n```typescript\nconst myQueue = new Queue<T>(queueName, {\n  connection: {\n    host: redisConfig.host,\n    port: redisConfig.port,\n    password: redisConfig.password,\n  },\n  defaultJobOptions: {\n    attempts: 3,\n    backoff: {\n      type: \"exponential\",\n      delay: 1000,\n    },\n    removeOnComplete: true,\n    removeOnFail: false,\n  },\n});\n```\n\n资料来源：[packages/shared/src/server/redis/ingestionQueue.ts]()\n\n## Queue Implementations\n\n### Ingestion Queue\n\nThe ingestion queue handles event processing from SDK clients and the OpenTelemetry protocol.\n\n```mermaid\ngraph LR\n    A[SDK Events] --> B[API Endpoint]\n    B --> C[ingestionQueue]\n    C --> D[Validate Events]\n    D --> E[Parse & Transform]\n    E --> F[(ClickHouse)]\n    E --> G[(PostgreSQL)]\n```\n\n**Key Features:**\n\n- Batch processing with configurable batch size\n- Retry with exponential backoff\n- Event validation against schema\n- S3 file-based storage for large payloads\n\n资料来源：[packages/shared/src/server/redis/ingestionQueue.ts]()\n\n### Evaluation Execution Queue\n\nHandles asynchronous execution of LLM-based evaluations:\n\n```mermaid\ngraph TD\n    A[Create Eval Job] --> B[evalExecutionQueue]\n    B --> C[Worker Pickup]\n    C --> D[Fetch Traces]\n    D --> E[Run LLM Evaluation]\n    E --> F[Store Results]\n    F --> G[(PostgreSQL)]\n```\n\n**Job Options:**\n\n```typescript\n{\n  attempts: 3,\n  backoff: {\n    type: \"exponential\",\n    delay: 2000,\n  },\n  removeOnComplete: 100, // Keep last 100 completed\n  removeOnFail: 1000,   // Keep last 1000 failed\n}\n```\n\n资料来源：[packages/shared/src/server/redis/evalExecutionQueue.ts]()\n\n### Batch Action Queue\n\nProcesses bulk operations such as batch updates and deletions:\n\n| Parameter | Default | Description |\n|-----------|---------|-------------|\n| `batchSize` | 100 | Items per batch |\n| `concurrency` | 5 | Parallel workers |\n| `attempts` | 3 | Retry count |\n| `backoffDelay` | 1000 | Initial backoff ms |\n\n资料来源：[packages/shared/src/server/redis/batchActionQueue.ts]()\n\n### Webhook Queue\n\nManages outbound webhook deliveries with priority handling:\n\n```mermaid\ngraph TD\n    A[Trigger Event] --> B[webhookQueue]\n    B --> C{Has Retry Config?}\n    C -->|Yes| D[Schedule Retry]\n    C -->|No| E[Immediate Delivery]\n    D --> E\n    E --> F{HTTP Response}\n    F -->|2xx| G[Log Success]\n    F -->|4xx| H[Log Failure]\n    F -->|5xx| D\n```\n\n资料来源：[packages/shared/src/server/redis/webhookQueue.ts]()\n\n## Worker Manager\n\nThe `WorkerManager` orchestrates all queue workers within the worker process:\n\n```typescript\nexport class WorkerManager {\n  private workers: Map<string, Worker>;\n\n  async initialize(): Promise<void> {\n    // Initialize all queue workers\n  }\n\n  async gracefulShutdown(): Promise<void> {\n    // Gracefully close all workers\n  }\n}\n```\n\n资料来源：[worker/src/queues/workerManager.ts]()\n\n### Worker Lifecycle\n\n```mermaid\ngraph TD\n    A[Start Worker Process] --> B[Load Configuration]\n    B --> C[Initialize Redis Connection]\n    C --> D[Create Queue Instances]\n    D --> E[Create Worker Instances]\n    E --> F[Register Event Handlers]\n    F --> G[Workers Ready]\n    \n    H[Shutdown Signal] --> I[Close Workers]\n    I --> J[Process Pending Jobs]\n    J --> K[Close Redis Connection]\n    K --> L[Exit]\n```\n\n### Event Handling\n\nWorkers register handlers for job lifecycle events:\n\n| Event | Handler Purpose |\n|-------|------------------|\n| `completed` | Log successful job completion |\n| `failed` | Handle job failures and retries |\n| `progress` | Track job progress updates |\n| `stalled` | Detect and requeue stalled jobs |\n\n## Job Data Flow\n\n### Standard Event Ingestion\n\nEvents flow through the system as follows:\n\n```mermaid\nsequenceDiagram\n    participant SDK\n    participant API\n    participant Redis\n    participant Worker\n    participant DB\n    \n    SDK->>API: POST /api/public/ingestion\n    API->>Redis: Add to IngestionQueue\n    API-->>SDK: 202 Accepted\n    Worker->>Redis: Dequeue Job\n    Worker->>DB: Validate & Store\n    Worker->>Redis: Job Complete\n```\n\n### Event Transformation\n\nThe ingestion endpoint transforms S3 keys into queue payloads:\n\n**Standard format:**\n```json\n{\n  \"authCheck\": {\n    \"validKey\": true,\n    \"scope\": { \"projectId\": \"<projectId>\" }\n  },\n  \"data\": {\n    \"eventBodyId\": \"<eventBodyId>\",\n    \"fileKey\": \"<eventId>\",\n    \"type\": \"<type>-create\"\n  }\n}\n```\n\n**OTEL format:**\n```json\n{\n  \"authCheck\": {\n    \"validKey\": true,\n    \"scope\": { \"projectId\": \"<projectId>\", \"accessLevel\": \"project\" }\n  },\n  \"data\": {\n    \"fileKey\": \"otel/<projectId>/<yyyy>/<mm>/<dd>/<hh>/<mm>/<eventId>.json\"\n  }\n}\n```\n\n资料来源：[worker/src/scripts/replayIngestionEventsV2/README.md]()\n\n## Error Handling and Retries\n\n### Retry Strategy\n\nAll queues implement exponential backoff retry:\n\n```typescript\nconst jobOptions = {\n  attempts: 3,\n  backoff: {\n    type: \"exponential\",\n    delay: 1000, // 1s, 2s, 4s\n  },\n};\n```\n\n### Error Classification\n\n| HTTP Status | Behavior | Retry |\n|-------------|----------|-------|\n| 2xx | Success | No |\n| 429 | Rate limited | Yes (with backoff) |\n| 5xx | Server error | Yes (up to 3 times) |\n| 4xx (not 429) | Client error | No (logged and skipped) |\n\n## Monitoring and Debugging\n\n### Progress Tracking\n\nThe replay scripts provide progress updates:\n\n```\n[1200/45000] 2.7% — 498 queued, 2 skipped\n```\n\n### Checkpoint System\n\nScripts write checkpoints to enable resume after failures:\n\n```bash\n# Checkpoint file location\n./worker/.checkpoint\n\n# Resume from checkpoint\npnpm run --filter=worker replay-ingestion --resume\n```\n\n### Error Logging\n\nFailed jobs are logged to `errors.csv` for manual inspection:\n\n```csv\n\"operation\",\"key\",\"error\"\n\"REST.PUT.OBJECT\",\"projectId/type/eventBodyId/eventId.json\",\"Connection timeout\"\n```\n\n## Admin API for Queue Management\n\n### `POST /api/admin/ingestion-replay`\n\nEnqueues batches of S3 keys for reprocessing:\n\n**Request:**\n```json\n{\n  \"keys\": [\n    \"projectId/trace/eventBodyId/eventId.json\",\n    \"otel/projectId/2025/07/09/14/30/some-uuid.json\"\n  ]\n}\n```\n\n**Response:**\n```json\n{\n  \"queued\": 498,\n  \"skipped\": 2,\n  \"errors\": []\n}\n```\n\n### Authentication\n\nRequires `Authorization: Bearer {ADMIN_API_KEY}` header validated by `AdminApiAuthService`.\n\n## Environment Variables\n\n| Variable | Description | Required |\n|----------|-------------|----------|\n| `REDIS_CONNECTION_STRING` | Redis connection URL | Yes |\n| `LANGFUSE_S3_EVENT_UPLOAD_BUCKET` | S3 bucket for event storage | Yes |\n| `CLICKHOUSE_URL` | ClickHouse connection URL | Yes |\n| `CLICKHOUSE_USER` | ClickHouse username | Yes |\n| `CLICKHOUSE_PASSWORD` | ClickHouse password | Yes |\n| `ADMIN_API_KEY` | Admin API authentication key | Yes (admin endpoints) |\n\n## Utility Scripts\n\n### Replay Ingestion Events V2\n\nA streamlined replacement for v1 with improved features:\n\n| Feature | v1 | v2 |\n|---------|----|----|\n| Infrastructure | Redis, ClickHouse, PostgreSQL, S3 | Langfuse host URL only |\n| Setup | Full repo clone | `npx tsx` + env vars |\n| Event delivery | Direct BullMQ `addBulk` | HTTP POST to admin API |\n| Resume support | Manual | Built-in checkpoint |\n| Rate limiting | None | Client + server side |\n\n### Refill Queue Event\n\nBackfills queues with events from local machines:\n\n```bash\n# 1. Create events file\necho '{\"projectId\": \"project-123\", \"orgId\": \"org-456\"}' > ./worker/events.jsonl\n\n# 2. Configure environment\n# Create .env with REDIS_CONNECTION_STRING and supporting services\n\n# 3. Run the script\npnpm run --filter=worker refill-queue-event\n```\n\n## Best Practices\n\n1. **Connection Pooling**: Reuse Redis connections across queue operations\n2. **Graceful Shutdown**: Always drain active jobs before stopping workers\n3. **Monitoring**: Track queue depth and processing times\n4. **Error Boundaries**: Isolate queue failures to prevent cascade\n5. **Backoff Tuning**: Adjust retry delays based on workload characteristics\n\n## Related Documentation\n\n- [Event Ingestion System](../ingestion/overview)\n- [Evaluation Framework](../evaluation/overview)\n- [Webhook Configuration](../webhooks/setup)\n\n---\n\n<a id='worker-service'></a>\n\n## Worker Service\n\n### 相关页面\n\n相关主题：[System Architecture](#system-architecture), [Queue System (Redis/BullMQ)](#queue-system)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [worker/src/app.ts](https://github.com/langfuse/langfuse/blob/main/worker/src/app.ts)\n- [worker/src/index.ts](https://github.com/langfuse/langfuse/blob/main/worker/src/index.ts)\n- [worker/src/queues/workerManager.ts](https://github.com/langfuse/langfuse/blob/main/worker/src/queues/workerManager.ts)\n- [worker/src/features/evaluation/evalService.ts](https://github.com/langfuse/langfuse/blob/main/worker/src/features/evaluation/evalService.ts)\n- [worker/src/features/batchAction/handleBatchActionJob.ts](https://github.com/langfuse/langfuse/blob/main/worker/src/features/batchAction/handleBatchActionJob.ts)\n</details>\n\n# Worker Service\n\n## Overview\n\nThe Worker Service is a core backend component in Langfuse responsible for asynchronous processing of long-running tasks. It operates as a separate Node.js process that communicates with the main Langfuse server through message queues, primarily using BullMQ backed by Redis.\n\n```mermaid\ngraph TB\n    subgraph \"Langfuse Server\"\n        A[API Endpoints]\n        B[tRPC Routers]\n    end\n    \n    subgraph \"Redis\"\n        C[(Ingestion Queues)]\n        D[(Evaluation Queues)]\n        E[(Batch Action Queues)]\n    end\n    \n    subgraph \"Worker Service\"\n        F[Worker Manager]\n        G[Evaluation Service]\n        H[Batch Action Handler]\n        I[Queue Processors]\n    end\n    \n    A -->|\"Enqueue Jobs\"| C\n    B -->|\"Dispatch Tasks\"| C\n    F -->|\"Process\"| C\n    G -->|\"Execute\"| D\n    H -->|\"Execute\"| E\n    C --> F\n    D --> G\n    E --> H\n```\n\n### Purpose and Scope\n\nThe Worker Service handles the following categories of work:\n\n- **Event Ingestion Processing**: Processing and persisting trace events, observations, and spans from the ingestion queues\n- **Evaluation Execution**: Running LLM-based evaluations on traces and observations\n- **Batch Actions**: Executing bulk operations on datasets, traces, and other resources\n- **Queue Replay**: Replaying historical ingestion events for data recovery or reprocessing\n\n资料来源：[worker/src/app.ts]()\n\n---\n\n## Architecture\n\n### Entry Point\n\nThe worker service is bootstrapped through `worker/src/index.ts`, which initializes the application context and starts the queue processors. The main application logic resides in `worker/src/app.ts`, which sets up the BullMQ workers and registers job handlers.\n\n```typescript\n// Simplified worker initialization flow\nconst app = new WorkerApp();\nawait app.initialize();\nawait app.start();\n```\n\n资料来源：[worker/src/index.ts]()\n\n### Worker Manager\n\nThe `WorkerManager` is the central orchestrator that manages all queue workers. It is responsible for:\n\n- Registering queue processors for different job types\n- Configuring concurrency settings per queue\n- Handling job failures and retries\n- Graceful shutdown coordination\n\n```mermaid\ngraph LR\n    A[Job Enqueued] --> B[Worker Manager]\n    B --> C{Job Type?}\n    C -->|Ingestion| D[Ingestion Processor]\n    C -->|Evaluation| E[Eval Service]\n    C -->|Batch Action| F[Batch Handler]\n    \n    D --> G[Success]\n    E --> G\n    F --> G\n    \n    D --> H[Retry/Fail]\n    E --> H\n    F --> H\n```\n\n资料来源：[worker/src/queues/workerManager.ts]()\n\n### Queue Architecture\n\nLangfuse uses multiple queues for different purposes:\n\n| Queue Name | Purpose | Priority | Concurrency |\n|------------|---------|----------|-------------|\n| `IngestionSecondaryQueue` | Standard event ingestion | Medium | Configurable |\n| `OtelIngestionQueue` | OpenTelemetry-format events | High | Configurable |\n| `EvalQueue` | LLM evaluation jobs | Low | Configurable |\n| `BatchActionQueue` | Bulk operations | Medium | Configurable |\n\n资料来源：[worker/src/app.ts]()\n资料来源：[worker/src/queues/workerManager.ts]()\n\n---\n\n## Core Components\n\n### Evaluation Service\n\nThe Evaluation Service (`evalService.ts`) handles asynchronous evaluation of traces and observations using LLM-based judges. It supports:\n\n- **Trace-level evaluations**: Running multiple evaluation criteria against a complete trace\n- **Observation-level evaluations**: Evaluating individual spans or generations\n- **Dataset-based evaluations**: Running evaluations against dataset items\n- **Configurable retry logic**: Handling transient failures gracefully\n\n```mermaid\ngraph TD\n    A[Evaluation Job Received] --> B[Load Trace/Observation]\n    B --> C[Fetch Eval Config]\n    C --> D[Prepare Prompt]\n    D --> E[Call LLM Provider]\n    E --> F{Success?}\n    F -->|Yes| G[Score Result]\n    F -->|No| H{Retry < 3?}\n    H -->|Yes| E\n    H -->|No| I[Mark Failed]\n    G --> J[Persist Score]\n    J --> K[Job Complete]\n    I --> K\n```\n\n资料来源：[worker/src/features/evaluation/evalService.ts]()\n\n### Batch Action Handler\n\nThe Batch Action Handler processes bulk operations requested through the admin API or scheduled jobs. Common batch actions include:\n\n- Bulk dataset operations (import, export, deletion)\n- Mass updates to traces or observations\n- Batch score calculations\n- Export operations\n\n```typescript\ninterface BatchActionJob {\n  id: string;\n  type: BatchActionType;\n  payload: BatchActionPayload;\n  priority?: number;\n  createdAt: Date;\n}\n```\n\n资料来源：[worker/src/features/batchAction/handleBatchActionJob.ts]()\n\n---\n\n## Queue Processing\n\n### Job Flow\n\n```mermaid\nsequenceDiagram\n    participant API as API Server\n    participant Redis as Redis Queue\n    participant Worker as Worker Service\n    \n    API->>Redis: Enqueue Job\n    Worker->>Redis: Poll for Jobs\n    Redis-->>Worker: Available Jobs\n    Worker->>Worker: Process Job\n    Worker->>Redis: Mark Complete\n    Worker->>API: Update Status (optional)\n```\n\n### Error Handling and Retries\n\nThe worker implements exponential backoff for transient failures:\n\n1. **Transient failures** (network timeouts, rate limits): Retry up to 3 times with exponential backoff\n2. **Permanent failures** (validation errors, missing data): Mark as failed, log error details\n3. **Rate limiting**: Respects server-side rate limits and backs off accordingly\n\n| Error Type | HTTP Code | Retry Behavior |\n|------------|-----------|----------------|\n| Rate Limited | 429 | Exponential backoff |\n| Server Error | 5xx | Retry up to 3 times |\n| Client Error | 4xx (not 429) | No retry, log and skip |\n| Validation | N/A | No retry, mark failed |\n\n资料来源：[worker/src/scripts/replayIngestionEventsV2/README.md]()\n\n### Concurrency Configuration\n\nWorkers can be configured with different concurrency levels per queue:\n\n```typescript\nconst workerConfig = {\n  ingestion: {\n    concurrency: 10,\n    maxRetries: 3,\n  },\n  evaluation: {\n    concurrency: 5,\n    maxRetries: 2,\n  },\n  batchAction: {\n    concurrency: 3,\n    maxRetries: 1,\n  },\n};\n```\n\n资料来源：[worker/src/queues/workerManager.ts]()\n\n---\n\n## Utility Scripts\n\n### Replay Ingestion Events V2\n\nThe replay script allows reprocessing of historical ingestion events from S3 storage.\n\n**Usage:**\n```bash\npnpm --filter=worker run replay-ingestion-events-v2 \\\n  --input ./events.csv \\\n  --batch-size 500 \\\n  --concurrency 4\n```\n\n**Key Features:**\n- Checkpoint/resume support for interrupted runs\n- Configurable batch size and concurrency\n- Rate limiting with exponential backoff\n- Progress tracking with percentage and ETA\n\n| Parameter | Default | Description |\n|-----------|---------|-------------|\n| `--input` | Required | Path to CSV file with S3 keys |\n| `--batch-size` | 500 | Keys per API request |\n| `--concurrency` | 4 | Parallel API requests |\n| `--rate-limit` | 50 | Max requests per second |\n| `--dry-run` | false | Validate without sending |\n| `--resume` | false | Continue from checkpoint |\n\n资料来源：[worker/src/scripts/replayIngestionEventsV2/README.md]()\n\n### Refill Queue Event\n\nThe refill script backfills queues with events from local files for testing and development.\n\n**Requirements:**\n1. Create `./worker/events.jsonl` with JSON events\n2. Configure `.env` with Redis and supporting service credentials\n3. Run: `pnpm run --filter=worker refill-queue-event`\n\n**Event Format:**\n```jsonl\n{\"projectId\": \"project-123\", \"orgId\": \"org-456\"}\n{\"projectId\": \"project-789\", \"orgId\": \"org-101\"}\n```\n\n资料来源：[worker/src/scripts/refillQueueEvent/README.md]()\n\n---\n\n## Environment Configuration\n\n### Required Environment Variables\n\n| Variable | Description | Required |\n|----------|-------------|----------|\n| `REDIS_CONNECTION_STRING` | Redis connection URL | Yes |\n| `LANGFUSE_S3_EVENT_UPLOAD_BUCKET` | S3 bucket for event uploads | Yes |\n| `CLICKHOUSE_URL` | ClickHouse connection URL | Yes |\n| `CLICKHOUSE_USER` | ClickHouse username | Yes |\n| `CLICKHOUSE_PASSWORD` | ClickHouse password | Yes |\n| `ADMIN_API_KEY` | Admin API key for replay scripts | For replay only |\n| `LANGFUSE_HOST` | Target Langfuse instance URL | For replay only |\n\n### Optional Configuration\n\n| Variable | Default | Description |\n|----------|---------|-------------|\n| `WORKER_CONCURRENCY` | 10 | Default queue concurrency |\n| `EVALUATION_CONCURRENCY` | 5 | Evaluation queue concurrency |\n| `BATCH_ACTION_CONCURRENCY` | 3 | Batch action concurrency |\n\n资料来源：[worker/src/scripts/refillQueueEvent/README.md]()\n资料来源：[worker/src/app.ts]()\n\n---\n\n## Health and Monitoring\n\n### Debug Mode\n\nEnable detailed logging for the AdvancedJsonViewer (useful for debugging UI components):\n\n```javascript\nlocalStorage.setItem(\"debug:AdvancedJsonViewer\", \"true\");\n```\n\n### Logging Categories\n\nThe worker service emits structured logs for:\n\n- Queue processing events\n- Job duration and throughput\n- Error rates and failure reasons\n- Resource utilization metrics\n\n### Graceful Shutdown\n\nThe worker service supports graceful shutdown to prevent job loss:\n\n1. Stop accepting new jobs\n2. Wait for in-progress jobs to complete (with timeout)\n3. Release Redis connections\n4. Exit cleanly\n\n---\n\n## Performance Considerations\n\n### Scalability\n\n- Multiple worker instances can run in parallel\n- Each queue can have independent concurrency settings\n- Redis acts as a shared job queue, enabling horizontal scaling\n\n### Memory Management\n\n| Strategy | Implementation |\n|----------|----------------|\n| Iterative Processing | Uses explicit stack-based iteration instead of recursion to prevent stack overflow |\n| Batch Processing | Processes events in configurable batch sizes |\n| Lazy Loading | Loads trace/observation data on-demand within job handlers |\n\n### Known Limitations\n\n1. **No horizontal virtualization in UI**: Wide JSON rows render fully\n2. **Client-side search only**: All matches computed in memory\n3. **Memory constraints**: 1M+ nodes may cause issues despite virtualization\n4. **Wrap mode performance**: Long strings require height measurement\n\n资料来源：[web/src/components/ui/AdvancedJsonViewer/README.md]()\n\n---\n\n## Summary\n\nThe Worker Service is essential to Langfuse's architecture, providing asynchronous processing capabilities that keep the main API server responsive. Key takeaways:\n\n- **BullMQ + Redis**: Provides reliable job queuing with built-in retry logic\n- **Specialized processors**: Dedicated handlers for ingestion, evaluation, and batch actions\n- **Configurable concurrency**: Fine-tune throughput per queue type\n- **Replay capabilities**: Built-in utilities for reprocessing historical events\n- **Horizontal scaling**: Multiple worker instances share work through Redis\n\n---\n\n<a id='api-layer'></a>\n\n## API Layer\n\n### 相关页面\n\n相关主题：[System Architecture](#system-architecture)\n\n<details>\n<summary>相关源码文件</summary>\n\n以下源码文件用于生成本页说明：\n\n- [web/src/server/api/root.ts](https://github.com/langfuse/langfuse/blob/main/web/src/server/api/root.ts)\n- [web/src/server/api/routers/traces.ts](https://github.com/langfuse/langfuse/blob/main/web/src/server/api/routers/traces.ts)\n- [web/src/server/api/routers/scores.ts](https://github.com/langfuse/langfuse/blob/main/web/src/server/api/routers/scores.ts)\n- [web/src/server/api/routers/observations.ts](https://github.com/langfuse/langfuse/blob/main/web/src/server/api/routers/observations.ts)\n- [web/src/server/api/trpc.ts](https://github.com/langfuse/langfuse/blob/main/web/src/server/api/trpc.ts)\n- [packages/shared/src/features/scores/interfaces/README.md](https://github.com/langfuse/langfuse/blob/main/packages/shared/src/features/scores/interfaces/README.md)\n- [web/src/features/score-analytics/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/score-analytics/README.md)\n- [web/src/features/README.md](https://github.com/langfuse/langfuse/blob/main/web/src/features/README.md)\n</details>\n\n# API Layer\n\nThe API Layer is the central communication bridge between the Langfuse frontend and backend services. Built on **tRPC** (TypeScript RPC), it provides end-to-end type safety, enabling the web application to interact with server-side logic through strongly-typed procedure calls.\n\n## Overview\n\nThe API Layer serves multiple critical functions:\n\n- **Type-Safe Communication**: All API calls are fully typed from server to client\n- **Authentication & Authorization**: Every procedure is wrapped with auth middleware\n- **Business Logic Isolation**: Procedures delegate to repository layer for data access\n- **Input Validation**: Zod schemas validate all incoming requests\n- **Feature Organization**: Procedures are grouped by domain (traces, observations, scores)\n\n```mermaid\ngraph TD\n    subgraph Frontend\n        UI[React Components]\n    end\n    \n    subgraph API Layer\n        TRPC[tRPC Client]\n        Procedures[tRPC Procedures]\n        Middleware[Auth Middleware]\n    end\n    \n    subgraph Backend\n        Repositories[Repositories]\n        Database[(Database)]\n    end\n    \n    UI --> TRPC\n    TRPC --> Procedures\n    Procedures --> Middleware\n    Middleware --> Repositories\n    Repositories --> Database\n```\n\n## Architecture\n\n### Core Components\n\n| Component | File | Purpose |\n|-----------|------|---------|\n| tRPC Instance | `trpc.ts` | Initialize tRPC with middleware and context |\n| Root Router | `root.ts` | Register all feature routers |\n| Trace Router | `routers/traces.ts` | Trace CRUD and query operations |\n| Observation Router | `routers/observations.ts` | Span/generation/event operations |\n| Score Router | `routers/scores.ts` | Score management and analytics |\n| Score Analytics | `features/score-analytics/server/scoreAnalyticsRouter.ts` | Score aggregation and statistics |\n\n### Router Registration Flow\n\nThe root router aggregates all feature routers under a namespace:\n\n```typescript\n// Simplified from web/src/server/api/root.ts\nexport const rootRouter = createTRPCRouter({\n  trace: traceRouter,\n  observation: observationRouter,\n  score: scoreRouter,\n  scoreAnalytics: scoreAnalyticsRouter,\n  // ... other routers\n});\n```\n\n资料来源：[web/src/server/api/root.ts:1-50]()\n\n## tRPC Configuration\n\n### Initialization\n\nThe tRPC instance is initialized in `trpc.ts` with:\n\n1. **Context Creation**: Builds request-scoped context with authentication\n2. **Middleware Chain**: Applies auth, rate limiting, and logging\n3. **Error Handling**: Transforms errors into HTTP-compatible responses\n\n```typescript\n// From web/src/server/api/trpc.ts\nexport const createTRPCContext = async (opts: CreateNextContextOptions) => {\n  return {\n    session: await getServerSession(authOptions),\n    // ... additional context\n  };\n};\n\nconst t = initTRPC.context<typeof createTRPCContext>().create();\n```\n\n资料来源：[web/src/server/api/trpc.ts:1-30]()\n\n### Middleware Stack\n\n| Middleware | Purpose |\n|------------|---------|\n| `isAuthed` | Validates user session and project access |\n| `isProjectMember` | Ensures user belongs to the project scope |\n| `isOwnerOrMember` | Allows owner or member roles |\n| `rateLimit` | Prevents abuse with configurable limits |\n\n## API Routers\n\n### Trace Router\n\nHandles all trace-related operations including retrieval, creation, and updates.\n\n**Key Procedures:**\n\n| Procedure | Type | Description |\n|-----------|------|-------------|\n| `getById` | Query | Fetch single trace with full details |\n| `list` | Query | Paginated trace listing with filters |\n| `create` | Mutation | Create new trace record |\n| `update` | Mutation | Update trace metadata/tags |\n| `delete` | Mutation | Soft-delete trace |\n\n资料来源：[web/src/server/api/routers/traces.ts:1-100]()\n\n### Observation Router\n\nManages spans, generations, and events that belong to traces.\n\n**Key Procedures:**\n\n| Procedure | Type | Description |\n|-----------|------|-------------|\n| `getById` | Query | Fetch single observation |\n| `list` | Query | List observations with trace/session filters |\n| `create` | Mutation | Create observation linked to trace |\n| `update` | Mutation | Update observation metadata |\n\n资料来源：[web/src/server/api/routers/observations.ts:1-100]()\n\n### Score Router\n\nProvides score management with support for multiple API versions (v1 and v2).\n\n**API Versioning Strategy:**\n\n| Version | traceId Required | Session Support | Dataset Run Support |\n|---------|------------------|-----------------|---------------------|\n| v1 | Yes | No | No |\n| v2 | Optional | Yes | Yes |\n\nThe Score router supports both trace-level and session-level scores through different API versions.\n\n**Key Procedures:**\n\n| Procedure | Type | Description |\n|-----------|------|-------------|\n| `create` | Mutation | Create score (POST endpoint) |\n| `delete` | Mutation | Delete score |\n| `getById` | Query | Fetch single score |\n| `list` | Query | List scores with filters |\n\n资料来源：[web/src/server/api/routers/scores.ts:1-100]()\n\n### Score Analytics Router\n\nProvides aggregated statistics and time-series data for scores.\n\n```typescript\n// From web/src/features/score-analytics/server/scoreAnalyticsRouter.ts\nexport const scoreAnalyticsRouter = createTRPCRouter({\n  timeSeries: protectedProcedure.query(...),\n  statistics: protectedProcedure.query(...),\n  heatmapData: protectedProcedure.query(...),\n});\n```\n\n**Key Procedures:**\n\n| Procedure | Type | Description |\n|-----------|------|-------------|\n| `timeSeries` | Query | Time-series score data with gap filling |\n| `statistics` | Query | Statistical summaries (count, mean, p50/p95/p99) |\n| `heatmapData` | Query | Heatmap matrix for visualization |\n\n资料来源：[web/src/features/score-analytics/README.md]()\n\n## Request Flow\n\n```mermaid\nsequenceDiagram\n    participant Client\n    participant TRPC as tRPC Server\n    participant Middleware\n    participant Router\n    participant Repository\n    participant DB as Database\n\n    Client->>TRPC: Procedure Call\n    TRPC->>Middleware: Apply Chain\n    Middleware->>Middleware: Auth Check\n    Middleware->>Router: Validated Input\n    Router->>Repository: Domain Operation\n    Repository->>DB: SQL/Query\n    DB-->>Repository: Result\n    Repository-->>Router: Domain Object\n    Router-->>TRPC: Response\n    TRPC-->>Client: Typed Response\n```\n\n## Input Validation\n\nAll procedures use **Zod schemas** for runtime validation:\n\n```typescript\n// Example pattern from routers\nconst createTraceSchema = z.object({\n  name: z.string().optional(),\n  userId: z.string().optional(),\n  metadata: z.record(z.unknown()).optional(),\n  tags: z.array(z.string()).optional(),\n});\n\nprotectedProcedure\n  .input(createTraceSchema)\n  .mutation(async ({ input, ctx }) => {\n    return ctx.repo.trace.create(input);\n  });\n```\n\n## Type Flow\n\nThe API Layer maintains type consistency across the stack:\n\n```mermaid\ngraph LR\n    Client[Client Input] --> InputZ[Zod Schema]\n    InputZ --> InputTS[TypeScript Type]\n    InputTS --> Handler[Procedure Handler]\n    Handler --> Repo[Repository Return]\n    Repo --> OutputZ[Zod Response Schema]\n    OutputZ --> OutputTS[API Response Type]\n    OutputTS --> ClientResponse[Client]\n```\n\n**Type Transformation Points:**\n\n| Stage | Location | Purpose |\n|-------|----------|---------|\n| Input | Routers | Zod validation + type inference |\n| Domain | Repositories | Database models to domain objects |\n| Output | Routers | Zod response schema validation |\n| Client | React Hooks | Full type safety for UI |\n\n## Score Interface Architecture\n\nScores have a multi-layer type system:\n\n| Layer | Location | Purpose |\n|-------|----------|---------|\n| API v1 | `interfaces/api/v1/` | Legacy trace-only scores |\n| API v2 | `interfaces/api/v2/` | Current with session/dataset support |\n| Application | `interfaces/application/` | Internal validation |\n| UI | `interfaces/ui/` | Simplified frontend types |\n\n资料来源：[packages/shared/src/features/scores/interfaces/README.md]()\n\n## Public API Extension\n\nThe Langfuse Public API extends the internal API layer for external consumption:\n\n```typescript\n// From web/src/features/README.md\n// Pattern for adding new public API routes:\n1. Wrap with withMiddleware\n2. Type-safe route with createAuthedAPIRoute\n3. Add Zod types to /features/public-api/types\n4. Use coerce for date handling\n5. Use strict() on response objects\n```\n\n**SDK Generation Pipeline:**\n\n```mermaid\ngraph TD\n    Fern[Fern Definition] --> PythonSDK[Python SDK]\n    Fern --> JSSDK[JS/TS SDK]\n    Fern --> Docs[API Documentation]\n```\n\n## Best Practices\n\n### Procedure Design\n\n- Use `protectedProcedure` for authenticated endpoints\n- Apply input validation at the procedure level\n- Return consistent response structures\n- Handle errors with typed error classes\n\n### Error Handling\n\n| Error Type | HTTP Code | Usage |\n|------------|-----------|-------|\n| `UNAUTHORIZED` | 401 | Missing/invalid session |\n| `FORBIDDEN` | 403 | Insufficient permissions |\n| `NOT_FOUND` | 404 | Resource doesn't exist |\n| `BAD_REQUEST` | 400 | Invalid input |\n| `INTERNAL_SERVER_ERROR` | 500 | Unexpected errors |\n\n### Performance Considerations\n\n- Use cursor-based pagination for large datasets\n- Leverage repository-level caching where applicable\n- Batch database operations in mutations\n- Limit response sizes with maxTake parameters\n\n---\n\n---\n\n## Doramagic 踩坑日志\n\n项目：langfuse/langfuse\n\n摘要：发现 17 个潜在踩坑项，其中 4 个为 high/blocking；最高优先级：安装坑 - 来源证据：bug: Using client with context manager breaks the scoring。\n\n## 1. 安装坑 · 来源证据：bug: Using client with context manager breaks the scoring\n\n- 严重度：high\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：bug: Using client with context manager breaks the scoring\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_5afee24537ba47369cc4621f7fb18122 | https://github.com/langfuse/langfuse/issues/8138 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 2. 安装坑 · 来源证据：bug: unnamed trace name in Langfuse UI\n\n- 严重度：high\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：bug: unnamed trace name in Langfuse UI\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_a219c99fe99c4b7dab002e2b3a6296c2 | https://github.com/langfuse/langfuse/issues/13416 | 来源讨论提到 node 相关条件，需在安装/试用前复核。\n\n## 3. 安全/权限坑 · 来源证据：bug: AsyncStream' object has no attribute 'usage' when integrated with Semantic Kernel and Openlit\n\n- 严重度：high\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：bug: AsyncStream' object has no attribute 'usage' when integrated with Semantic Kernel and Openlit\n- 对用户的影响：可能影响授权、密钥配置或安全边界。\n- 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_8657d86702904e90b9d448770e618256 | https://github.com/langfuse/langfuse/issues/8173 | 来源类型 github_issue 暴露的待验证使用条件。\n\n## 4. 安全/权限坑 · 来源证据：bug: Worker shutdown takes ~1 hour in self hosted kubernetes\n\n- 严重度：high\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：bug: Worker shutdown takes ~1 hour in self hosted kubernetes\n- 对用户的影响：可能影响授权、密钥配置或安全边界。\n- 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_cff1b1d1a1ca4eb892563c33d3aa62e9 | https://github.com/langfuse/langfuse/issues/8156 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 5. 安装坑 · 来源证据：bug: Socket timeout. Expecting data, but didn't receive any in 30000ms on idle BullMQ queues\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：bug: Socket timeout. Expecting data, but didn't receive any in 30000ms on idle BullMQ queues\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_49a69075a1c346789a28db93c9ec6f3f | https://github.com/langfuse/langfuse/issues/13601 | 来源讨论提到 node 相关条件，需在安装/试用前复核。\n\n## 6. 安装坑 · 来源证据：v3.169.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v3.169.0\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_864f213fd7694eba9a4d2fe2bb9267ab | https://github.com/langfuse/langfuse/releases/tag/v3.169.0 | 来源讨论提到 npm 相关条件，需在安装/试用前复核。\n\n## 7. 安装坑 · 来源证据：v3.172.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v3.172.0\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_14588986ba9945eeb40cbc0508e3fed0 | https://github.com/langfuse/langfuse/releases/tag/v3.172.0 | 来源讨论提到 npm 相关条件，需在安装/试用前复核。\n\n## 8. 安装坑 · 来源证据：v3.173.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v3.173.0\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_7560a954846b4f35aedb74de1291c9a4 | https://github.com/langfuse/langfuse/releases/tag/v3.173.0 | 来源讨论提到 docker 相关条件，需在安装/试用前复核。\n\n## 9. 能力坑 · 能力判断依赖假设\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：README/documentation is current enough for a first validation pass.\n- 对用户的影响：假设不成立时，用户拿不到承诺的能力。\n- 建议检查：将假设转成下游验证清单。\n- 防护动作：假设必须转成验证项；没有验证结果前不能写成事实。\n- 证据：capability.assumptions | github_repo:642497346 | https://github.com/langfuse/langfuse | README/documentation is current enough for a first validation pass.\n\n## 10. 维护坑 · 维护活跃度未知\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：未记录 last_activity_observed。\n- 对用户的影响：新项目、停更项目和活跃项目会被混在一起，推荐信任度下降。\n- 建议检查：补 GitHub 最近 commit、release、issue/PR 响应信号。\n- 防护动作：维护活跃度未知时，推荐强度不能标为高信任。\n- 证据：evidence.maintainer_signals | github_repo:642497346 | https://github.com/langfuse/langfuse | last_activity_observed missing\n\n## 11. 安全/权限坑 · 下游验证发现风险项\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：no_demo\n- 对用户的影响：下游已经要求复核，不能在页面中弱化。\n- 建议检查：进入安全/权限治理复核队列。\n- 防护动作：下游风险存在时必须保持 review/recommendation 降级。\n- 证据：downstream_validation.risk_items | github_repo:642497346 | https://github.com/langfuse/langfuse | no_demo; severity=medium\n\n## 12. 安全/权限坑 · 存在评分风险\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：no_demo\n- 对用户的影响：风险会影响是否适合普通用户安装。\n- 建议检查：把风险写入边界卡，并确认是否需要人工复核。\n- 防护动作：评分风险必须进入边界卡，不能只作为内部分数。\n- 证据：risks.scoring_risks | github_repo:642497346 | https://github.com/langfuse/langfuse | no_demo; severity=medium\n\n## 13. 安全/权限坑 · 来源证据：v3.168.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：v3.168.0\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_202b4e8c2c1f4b3790315098d1530297 | https://github.com/langfuse/langfuse/releases/tag/v3.168.0 | 来源讨论提到 node 相关条件，需在安装/试用前复核。\n\n## 14. 安全/权限坑 · 来源证据：v3.170.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：v3.170.0\n- 对用户的影响：可能阻塞安装或首次运行。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_9ed6f994e1424878aa4559a73d72fc52 | https://github.com/langfuse/langfuse/releases/tag/v3.170.0 | 来源讨论提到 docker 相关条件，需在安装/试用前复核。\n\n## 15. 安全/权限坑 · 来源证据：v3.174.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：v3.174.0\n- 对用户的影响：可能影响授权、密钥配置或安全边界。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_f9cb7b7232ff4cce96f0c020fe48c7f4 | https://github.com/langfuse/langfuse/releases/tag/v3.174.0 | 来源讨论提到 api key 相关条件，需在安装/试用前复核。\n\n## 16. 维护坑 · issue/PR 响应质量未知\n\n- 严重度：low\n- 证据强度：source_linked\n- 发现：issue_or_pr_quality=unknown。\n- 对用户的影响：用户无法判断遇到问题后是否有人维护。\n- 建议检查：抽样最近 issue/PR，判断是否长期无人处理。\n- 防护动作：issue/PR 响应未知时，必须提示维护风险。\n- 证据：evidence.maintainer_signals | github_repo:642497346 | https://github.com/langfuse/langfuse | issue_or_pr_quality=unknown\n\n## 17. 维护坑 · 发布节奏不明确\n\n- 严重度：low\n- 证据强度：source_linked\n- 发现：release_recency=unknown。\n- 对用户的影响：安装命令和文档可能落后于代码，用户踩坑概率升高。\n- 建议检查：确认最近 release/tag 和 README 安装命令是否一致。\n- 防护动作：发布节奏未知或过期时，安装说明必须标注可能漂移。\n- 证据：evidence.maintainer_signals | github_repo:642497346 | https://github.com/langfuse/langfuse | release_recency=unknown\n\n<!-- canonical_name: langfuse/langfuse; human_manual_source: deepwiki_human_wiki -->\n",
      "summary": "DeepWiki/Human Wiki 完整输出，末尾追加 Discovery Agent 踩坑日志。",
      "title": "Human Manual / 人类版说明书"
    },
    "pitfall_log": {
      "asset_id": "pitfall_log",
      "filename": "PITFALL_LOG.md",
      "markdown": "# Pitfall Log / 踩坑日志\n\n项目：langfuse/langfuse\n\n摘要：发现 17 个潜在踩坑项，其中 4 个为 high/blocking；最高优先级：安装坑 - 来源证据：bug: Using client with context manager breaks the scoring。\n\n## 1. 安装坑 · 来源证据：bug: Using client with context manager breaks the scoring\n\n- 严重度：high\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：bug: Using client with context manager breaks the scoring\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_5afee24537ba47369cc4621f7fb18122 | https://github.com/langfuse/langfuse/issues/8138 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 2. 安装坑 · 来源证据：bug: unnamed trace name in Langfuse UI\n\n- 严重度：high\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：bug: unnamed trace name in Langfuse UI\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_a219c99fe99c4b7dab002e2b3a6296c2 | https://github.com/langfuse/langfuse/issues/13416 | 来源讨论提到 node 相关条件，需在安装/试用前复核。\n\n## 3. 安全/权限坑 · 来源证据：bug: AsyncStream' object has no attribute 'usage' when integrated with Semantic Kernel and Openlit\n\n- 严重度：high\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：bug: AsyncStream' object has no attribute 'usage' when integrated with Semantic Kernel and Openlit\n- 对用户的影响：可能影响授权、密钥配置或安全边界。\n- 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_8657d86702904e90b9d448770e618256 | https://github.com/langfuse/langfuse/issues/8173 | 来源类型 github_issue 暴露的待验证使用条件。\n\n## 4. 安全/权限坑 · 来源证据：bug: Worker shutdown takes ~1 hour in self hosted kubernetes\n\n- 严重度：high\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：bug: Worker shutdown takes ~1 hour in self hosted kubernetes\n- 对用户的影响：可能影响授权、密钥配置或安全边界。\n- 建议检查：来源问题仍为 open，Pack Agent 需要复核是否仍影响当前版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_cff1b1d1a1ca4eb892563c33d3aa62e9 | https://github.com/langfuse/langfuse/issues/8156 | 来源讨论提到 python 相关条件，需在安装/试用前复核。\n\n## 5. 安装坑 · 来源证据：bug: Socket timeout. Expecting data, but didn't receive any in 30000ms on idle BullMQ queues\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：bug: Socket timeout. Expecting data, but didn't receive any in 30000ms on idle BullMQ queues\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_49a69075a1c346789a28db93c9ec6f3f | https://github.com/langfuse/langfuse/issues/13601 | 来源讨论提到 node 相关条件，需在安装/试用前复核。\n\n## 6. 安装坑 · 来源证据：v3.169.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v3.169.0\n- 对用户的影响：可能增加新用户试用和生产接入成本。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_864f213fd7694eba9a4d2fe2bb9267ab | https://github.com/langfuse/langfuse/releases/tag/v3.169.0 | 来源讨论提到 npm 相关条件，需在安装/试用前复核。\n\n## 7. 安装坑 · 来源证据：v3.172.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v3.172.0\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_14588986ba9945eeb40cbc0508e3fed0 | https://github.com/langfuse/langfuse/releases/tag/v3.172.0 | 来源讨论提到 npm 相关条件，需在安装/试用前复核。\n\n## 8. 安装坑 · 来源证据：v3.173.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：v3.173.0\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_7560a954846b4f35aedb74de1291c9a4 | https://github.com/langfuse/langfuse/releases/tag/v3.173.0 | 来源讨论提到 docker 相关条件，需在安装/试用前复核。\n\n## 9. 能力坑 · 能力判断依赖假设\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：README/documentation is current enough for a first validation pass.\n- 对用户的影响：假设不成立时，用户拿不到承诺的能力。\n- 建议检查：将假设转成下游验证清单。\n- 防护动作：假设必须转成验证项；没有验证结果前不能写成事实。\n- 证据：capability.assumptions | github_repo:642497346 | https://github.com/langfuse/langfuse | README/documentation is current enough for a first validation pass.\n\n## 10. 维护坑 · 维护活跃度未知\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：未记录 last_activity_observed。\n- 对用户的影响：新项目、停更项目和活跃项目会被混在一起，推荐信任度下降。\n- 建议检查：补 GitHub 最近 commit、release、issue/PR 响应信号。\n- 防护动作：维护活跃度未知时，推荐强度不能标为高信任。\n- 证据：evidence.maintainer_signals | github_repo:642497346 | https://github.com/langfuse/langfuse | last_activity_observed missing\n\n## 11. 安全/权限坑 · 下游验证发现风险项\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：no_demo\n- 对用户的影响：下游已经要求复核，不能在页面中弱化。\n- 建议检查：进入安全/权限治理复核队列。\n- 防护动作：下游风险存在时必须保持 review/recommendation 降级。\n- 证据：downstream_validation.risk_items | github_repo:642497346 | https://github.com/langfuse/langfuse | no_demo; severity=medium\n\n## 12. 安全/权限坑 · 存在评分风险\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：no_demo\n- 对用户的影响：风险会影响是否适合普通用户安装。\n- 建议检查：把风险写入边界卡，并确认是否需要人工复核。\n- 防护动作：评分风险必须进入边界卡，不能只作为内部分数。\n- 证据：risks.scoring_risks | github_repo:642497346 | https://github.com/langfuse/langfuse | no_demo; severity=medium\n\n## 13. 安全/权限坑 · 来源证据：v3.168.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：v3.168.0\n- 对用户的影响：可能影响升级、迁移或版本选择。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_202b4e8c2c1f4b3790315098d1530297 | https://github.com/langfuse/langfuse/releases/tag/v3.168.0 | 来源讨论提到 node 相关条件，需在安装/试用前复核。\n\n## 14. 安全/权限坑 · 来源证据：v3.170.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：v3.170.0\n- 对用户的影响：可能阻塞安装或首次运行。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_9ed6f994e1424878aa4559a73d72fc52 | https://github.com/langfuse/langfuse/releases/tag/v3.170.0 | 来源讨论提到 docker 相关条件，需在安装/试用前复核。\n\n## 15. 安全/权限坑 · 来源证据：v3.174.0\n\n- 严重度：medium\n- 证据强度：source_linked\n- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：v3.174.0\n- 对用户的影响：可能影响授权、密钥配置或安全边界。\n- 建议检查：来源显示可能已有修复、规避或版本变化，说明书中必须标注适用版本。\n- 防护动作：不得脱离来源链接放大为确定性结论；需要标注适用版本和复核状态。\n- 证据：community_evidence:github | cevd_f9cb7b7232ff4cce96f0c020fe48c7f4 | https://github.com/langfuse/langfuse/releases/tag/v3.174.0 | 来源讨论提到 api key 相关条件，需在安装/试用前复核。\n\n## 16. 维护坑 · issue/PR 响应质量未知\n\n- 严重度：low\n- 证据强度：source_linked\n- 发现：issue_or_pr_quality=unknown。\n- 对用户的影响：用户无法判断遇到问题后是否有人维护。\n- 建议检查：抽样最近 issue/PR，判断是否长期无人处理。\n- 防护动作：issue/PR 响应未知时，必须提示维护风险。\n- 证据：evidence.maintainer_signals | github_repo:642497346 | https://github.com/langfuse/langfuse | issue_or_pr_quality=unknown\n\n## 17. 维护坑 · 发布节奏不明确\n\n- 严重度：low\n- 证据强度：source_linked\n- 发现：release_recency=unknown。\n- 对用户的影响：安装命令和文档可能落后于代码，用户踩坑概率升高。\n- 建议检查：确认最近 release/tag 和 README 安装命令是否一致。\n- 防护动作：发布节奏未知或过期时，安装说明必须标注可能漂移。\n- 证据：evidence.maintainer_signals | github_repo:642497346 | https://github.com/langfuse/langfuse | release_recency=unknown\n",
      "summary": "用户实践前最可能遇到的身份、安装、配置、运行和安全坑。",
      "title": "Pitfall Log / 踩坑日志"
    },
    "prompt_preview": {
      "asset_id": "prompt_preview",
      "filename": "PROMPT_PREVIEW.md",
      "markdown": "# langfuse - Prompt Preview\n\n> Copy the prompt below into your AI host before installing anything.\n> Its purpose is to let you safely feel the project's workflow, not to claim the project has already run.\n\n## Copy this prompt\n\n```text\nYou are using an independent Doramagic capability pack for langfuse/langfuse.\n\nProject:\n- Name: langfuse\n- Repository: https://github.com/langfuse/langfuse\n- Summary: 🪢 Open source LLM engineering platform: LLM Observability, metrics, evals, prompt management, playground, datasets. Integrates with OpenTelemetry, Langchain, OpenAI SDK, LiteLLM, and more. 🍊YC W23\n- Host target: ChatGPT, Claude, Codex, Cursor\n\nGoal:\nHelp me evaluate this project for the following task without installing it yet: I want to evaluate whether this project fits a real AI workflow before installing it.\n\nBefore taking action:\n1. Restate my task, success standard, and boundary.\n2. Identify whether the next step requires tools, browser access, network access, filesystem access, credentials, package installation, or host configuration.\n3. Use only the Doramagic Project Pack, the upstream repository, and the source-linked evidence listed below.\n4. If a real command, install step, API call, file write, or host integration is required, mark it as \"requires post-install verification\" and ask for approval first.\n5. If evidence is missing, say \"evidence is missing\" instead of filling the gap.\n\nPreviewable capabilities:\n- Capability 1: Use the source-backed project context to guide one small, checkable workflow step.\n\nCapabilities that require post-install verification:\n- Capability 1: Use the source-backed project context to guide one small, checkable workflow step.\n\nCore service flow:\n1. project-introduction: Project Introduction. Produce one small intermediate artifact and wait for confirmation.\n2. project-structure: Project Structure. Produce one small intermediate artifact and wait for confirmation.\n3. quickstart-guide: Quickstart Guide. Produce one small intermediate artifact and wait for confirmation.\n4. system-architecture: System Architecture. Produce one small intermediate artifact and wait for confirmation.\n5. database-schema: Database Schema (Prisma). Produce one small intermediate artifact and wait for confirmation.\n\nSource-backed evidence to keep in mind:\n- https://github.com/langfuse/langfuse\n- https://github.com/langfuse/langfuse#readme\n- .agents/skills/add-model-price/SKILL.md\n- .agents/skills/agent-setup-maintenance/SKILL.md\n- .agents/skills/analyze-cloud-costs/SKILL.md\n- .agents/skills/backend-dev-guidelines/SKILL.md\n- .agents/skills/changelog-writing/SKILL.md\n- .agents/skills/clickhouse-best-practices/SKILL.md\n- .agents/skills/code-review/SKILL.md\n- .agents/skills/datadog-query-recipes/SKILL.md\n\nFirst response rules:\n1. Start Step 1 only.\n2. Explain the one service action you will perform first.\n3. Ask exactly three questions about my target workflow, success standard, and sandbox boundary.\n4. Stop and wait for my answers.\n\nStep 1 follow-up protocol:\n- After I answer the first three questions, stay in Step 1.\n- Produce six parts only: clarified task, success standard, boundary conditions, two or three options, tradeoffs for each option, and one recommendation.\n- End by asking whether I confirm the recommendation.\n- Do not move to Step 2 until I explicitly confirm.\n\nConversation rules:\n- Advance one step at a time and wait for confirmation after each small artifact.\n- Write outputs as recommendations or planned checks, not as completed execution.\n- Do not claim tests passed, files changed, commands ran, APIs were called, or the project was installed.\n- If the user asks for execution, first provide the sandbox setup, expected output, rollback, and approval checkpoint.\n```\n",
      "summary": "A safe pre-install prompt generated for the English Project Pack.",
      "title": "Prompt Preview"
    },
    "quick_start": {
      "asset_id": "quick_start",
      "filename": "QUICK_START.md",
      "markdown": "# Quick Start / 官方入口\n\n项目：langfuse/langfuse\n\n## 官方安装入口\n\n### Python / pip · 官方安装入口\n\n```bash\npip install langfuse\n```\n\n来源：https://github.com/langfuse/langfuse#readme\n\n## 来源\n\n- repo: https://github.com/langfuse/langfuse\n- docs: https://github.com/langfuse/langfuse#readme\n",
      "summary": "从项目官方 README 或安装文档提取的开工入口。",
      "title": "Quick Start / 官方入口"
    }
  },
  "validation_id": "dval_8c486efe87fd4ad990dc77cbf338b160"
}
