Skip to content

πŸͺ’ Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

chore(agent-dx): add debug-issue-with-datadog skill (#13375)

Steffen Schmitz8e275fbdc525
diff --git a/.agents/AGENTS.md b/.agents/AGENTS.md
index 4bf0a118b0..62d9da098e 100644
--- a/.agents/AGENTS.md
+++ b/.agents/AGENTS.md
@@ -34,6 +34,9 @@ evaluating, and debugging AI applications.
[`skills/add-model-price/SKILL.md`](skills/add-model-price/SKILL.md)
- Code review tasks:
[`skills/code-review/SKILL.md`](skills/code-review/SKILL.md)
+- Debugging a Linear issue, GitHub issue, or incident report using Datadog
+ (APM, logs, metrics) to establish a root cause:
+ [`skills/debug-issue-with-datadog/SKILL.md`](skills/debug-issue-with-datadog/SKILL.md)
- Changelog drafting for completed feature branches:
[`skills/changelog-writing/SKILL.md`](skills/changelog-writing/SKILL.md)
- ClickHouse schema/query review:
diff --git a/.agents/skills/debug-issue-with-datadog/SKILL.md b/.agents/skills/debug-issue-with-datadog/SKILL.md
new file mode 100644
index 0000000000..a5b340318b
--- /dev/null
+++ b/.agents/skills/debug-issue-with-datadog/SKILL.md
@@ -0,0 +1,115 @@
+---
+name: debug-issue-with-datadog
+description: |
+ Debug a user-reported issue, Linear ticket, or incident report by combining
+ Datadog (APM, logs, metrics) with the Langfuse repo to establish a
+ root cause. Use when given a Linear issue URL/ID (e.g. LFE-XXXX), a GitHub
+ issue, or a pasted error/report and asked to investigate, root-cause, or
+ triage. Produces a structured analysis β€” error breakdown, hypothesis-by-class,
+ suggested patches with code references.
+---
+
+# Debug Issue with Datadog
+
+Use this skill whenever the task is **investigative** rather than
+implementational: a user, customer, or oncall has surfaced a problem and you
+need to figure out *what is actually happening in production* and *where in the
+code it lives*. The deliverable is an analysis, not a patch β€” though the
+analysis should make the right patch obvious.
+
+## When to Apply
+
+- A Linear issue (typically with an `LFE-XXXX` ID) describes a production
+ failure, error spike, or customer report.
+- A GitHub issue or pasted incident/error report needs triage.
+- A monitor alerted and you need to understand *why* before deciding what to
+ fix.
+- Existing tickets under the "Make monitoring useful again" project (parent
+ `LFE-8837`) and similar β€” these expect the structured analysis output below.
+
+If the task is "implement this fix" rather than "figure out what's broken",
+this is the wrong skill β€” go to `backend-dev-guidelines` or the relevant
+package guide.
+
+## Workflow
+
+Read the inputs first, then plan the Datadog sweep, then read the code, then
+write the analysis. Do not skip ahead to suggested patches before the data
+supports them.
+
+1. **Intake.** Pull every signal already available in the report. See
+ [`references/intake.md`](references/intake.md). For a Linear URL/ID, fetch
+ the issue *and* its comments via the Linear MCP β€” the description is often
+ updated inline as triage proceeds. For a GitHub issue, use `gh issue view`.
+ For pasted text, treat it as the description.
+
+2. **Scope the sweep.** From the intake, pick the affected subsystem and time
+ window. Use [`references/repo-debug-map.md`](references/repo-debug-map.md)
+ to translate "PostHog integration", "ingestion failures", "evals stuck",
+ etc. into the Datadog filters and source files you should be looking at.
+
+3. **Run the broad Datadog sweep.** Default to the full sweep in
+ [`references/datadog-playbook.md`](references/datadog-playbook.md): APM
+ spans, error logs, metrics, and monitors β€” split across `prod-eu`
+ and `prod-us` (and `prod-hipaa` / `prod-jp` when relevant). Always check
+ regional disparity first; it usually rules whole hypotheses in or out.
+
+4. **Cluster the errors.** Group by `(projectId, error.message)` or
+ `(error.type, error.message)`. Treat each distinct cluster as its own
+ hypothesis β€” Langfuse incidents commonly have *multiple* coexisting root
+ causes, not one.
+
+5. **Map clusters to code.** For each cluster, open the relevant handler file
+ from the repo-debug map and read enough of it to confirm or refute the
+ hypothesis. Cite specific files and line ranges in the output.
+
+6. **Write the analysis** using
+ [`references/output-template.md`](references/output-template.md).
+
+7. **Deliver.** Default: print the analysis in chat. If the user asked for it,
+ also save under the workflow they specified (file, Linear comment via, etc.).
+
+## Datadog MCP Usage Notes
+
+Two Datadog MCP servers are typically available β€” one bound to the EU site
+(`datadoghq.eu`) and one to the US site (`datadoghq.com`). Always run
+region-relevant queries against **both** unless intake clearly localizes the
+incident. The `prod-eu` / `prod-us` env tags live on each side respectively.
+
+- Span search filter pattern:
+ `service:worker resource_name:"process posthog-integration-project" status:error`
+- Log search filter pattern:
+ `service:worker env:prod-eu @langfuse.project.id:cm1r6u… status:error`
+- For high-volume queries, prefer `aggregate_spans` / `aggregate_events`
+ grouped by `(error.message, projectId)` over fetching individual traces.
+- Always link to the Datadog UI for the queries you ran (final section of the
+ output template).
+
+See [`references/datadog-playbook.md`](references/datadog-playbook.md) for the
+full set of starter queries and parameter shapes.
+
+## Output Expectations
+
+From the output template:
+
+- Header: data source, time window, region split (EU vs US table).
+- Hotspots: per-`projectId` (or per-cluster) error counts.
+- Root cause by error class: each cluster gets a short hypothesis with
+ reasoning, distinguishing primary causes from symptoms.
+- Suggested patches: P0/P1/P2 grouped, with concrete file paths and short code
+ sketches. Reference the actual handler in `worker/src/features/**` or
+ `web/src/**`.
+- Dashboards: paste the Datadog query URLs at the end.
+
+Findings come first, recommendations last. If the data is thin, say so
+explicitly and propose what would need to be true to confirm each hypothesis β€”
+do not invent root causes.
+
+## Cross-References
+
+- Backend layout, queue contracts, instrumentation patterns:
+ [`backend-dev-guidelines`](../backend-dev-guidelines/SKILL.md)
+- ClickHouse-related findings (memory ceilings, JOIN spills, slow queries):
+ [`clickhouse-best-practices`](../clickhouse-best-practices/SKILL.md)
+- Once a fix is identified and you switch to implementation, hand off to the
+ package `AGENTS.md` for the affected directory.
diff --git a/.agents/skills/debug-issue-with-datadog/references/datadog-playbook.md b/.agents/skills/debug-issue-with-datadog/references/datadog-playbook.md
new file mode 100644
index 0000000000..a34781a22c
--- /dev/null
+++ b/.agents/skills/debug-issue-with-datadog/references/datadog-playbook.md
@@ -0,0 +1,133 @@
+# Datadog Query Playbook
+
+The default for this skill is the **broad sweep**: APM spans + logs + metrics
++ monitors + incidents, run against both EU and US sites unless intake clearly
+localizes. Cluster results before drilling in.
+
+Two MCP servers are typically connected β€” one for `datadoghq.eu`, one for
+`datadoghq.com`. Run the same query on both and compare. The contrast itself
+is often the most informative finding (e.g. LFE-9475's 23.5% EU vs 0.7% US
+error rate immediately ruled out PostHog Cloud as the global cause).
+
+## Tag Vocabulary
+
+- **Site:** `datadoghq.eu` for EU, `datadoghq.com` for US.
+- **Region tag (`env`):** `prod-eu`, `prod-us`, `prod-hipaa`, `prod-jp`.
+- **Service:** `worker` (default in `worker/src/env.ts`) or `web` (default in
+ `web/src/env.mjs`). Some deployments override to `langfuse`.
+- **Span resource names** for worker async jobs follow the pattern
+ `process <queue-name>` β€” see `repo-debug-map.md`.
+
+## 1. APM Span Sweep β€” find the failing handler
+
+Use `aggregate_spans` first; only fetch individual traces once a cluster is
+identified.
+
+Starter shape (rename the resource for the relevant subsystem):
+
+```text
+service:worker resource_name:"process posthog-integration-project" status:error
+```
+
+Aggregations to run, in order:
+
+1. Count by `env` β€” confirms region split.
+2. Count by `error.message` β€” primary error classes.
+3. Count by `(projectId, error.message)` β€” which tenants are affected, by
+ class. `projectId` lives on span tags as `@projectId` for log search and as
+ a tag for spans (depends on instrumentation site).
+4. p50 / p95 / p99 duration by region β€” fingerprints timeouts vs. crashes vs.
+ slow successes.
+
+If `aggregate_spans` returns no results, check:
+
+- the resource name is right (case-sensitive, see `repo-debug-map.md`);
+- the time window covers when the issue was actually firing;
+- the region tag matches reality (the EU MCP only sees EU traces).
+
+## 2. Log Sweep β€” read what the handler said
+
+Logs are the right tool for *messages* the handler emitted. Spans are the
+right tool for *which handler invocations failed*.
+
+Starter shapes:
+
+```text
+service:worker env:prod-eu @projectId:cm1r6u1iq00ccfvrkoy8vg3ms status:error
+service:worker env:prod-eu "[POSTHOG]" status:error
+```
+
+Useful log facets:
+
+- `@projectId` or `@langfuse.project.id` β€” Langfuse project (cuid).
+- `@error.kind` / `@error.message` / `@error.stack` β€” when the Winston logger
+ serialized an Error.
+- `@queue` / `@jobName` β€” when set by BullMQ instrumentation.
+
+For high-volume subsystems (`ingestion-queue`, `otel-ingestion-queue`),
+prefer `analyze_datadog_logs` with grouping over `search_datadog_logs` β€” the
+raw matches are too noisy.
+
+## 3. Metric Sweep β€” confirm the trend
+
+Pick 2–3 metrics that match the subsystem. Common ones:
+
+- `trace.bullmq.process.errors` and `trace.bullmq.process.duration` β€”
+ per-queue health from the BullMQ OTel instrumentation. Filter by
+ `resource_name:"process <queue-name>"`.
+- `trace.http_request.errors` and `trace.http_request.duration` for HTTP
+ handlers (`service:web`).
+- ClickHouse: cluster-level `clickhouse.query.duration`,
+ `clickhouse.memory_usage` β€” the worker doesn't emit these directly, they
+ come from the `clickhouse` integration in the infra repo.
+- Postgres: `aurora.databaseconnections`, `aurora.deadlocks` β€” relevant when
+ the symptom is `connection_limit` / `connection pool` errors.
+
+If the subsystem isn't already known, run `search_datadog_metrics` for the
+subsystem name and pick the obvious counter / gauge / histogram triplet.
+
+## 4. Monitors & Incidents
+
+- `search_datadog_monitors` for the subsystem name β€” tells you what alerts
+ *would* have fired and what their thresholds are. A muted monitor on the
+ affected subsystem is itself a finding (see LFE-9475: "EU alert muted for
+ a week").
+- `search_datadog_incidents` for the time window β€” links any pre-existing
+ incident the user may not have referenced.
+
+## 5. RUM / Frontend (only when the symptom is user-facing)
+
+Skip unless the issue is "page broken" / "slow load". Then:
+
+- `search_datadog_rum_events` filtered by `@view.url:` patterns matching the
+ affected route.
+- Cross-reference with `service:web` API errors at the same time.
+
+## 6. Trace Drill-Down
+
+Once a cluster is identified, fetch one or two representative traces with
+`get_datadog_trace` to read the actual stack and confirm where in the handler
+the throw originates. This is what lets you point at a specific file and
+line range in the analysis.
+
+## Anti-Patterns
+
+- Don't fetch individual logs/traces before aggregating. You'll burn context
+ on noise and miss the cluster pattern.
+- Don't trust a single-region query as global. Always compare EU and US.
+- Don't read an `error.message` literally if it goes through a custom error
+ wrapper β€” `validateWebhookURL` rejections, for example, are re-logged as
+ "DNS lookup failed" but are actually validator rejections.
+- Don't assume monitors are firing just because errors exist β€” check if the
+ monitor is muted.
+
+## Linking Out
+
+End the analysis with the actual Datadog UI URLs you queried, e.g.:
+
+```text
+https://app.datadoghq.eu/apm/traces?query=resource_name%3A%22process+posthog-integration-project%22+status%3Aerror
+https://app.datadoghq.com/apm/traces?query=resource_name%3A%22process+posthog-integration-project%22+status%3Aerror
+```
+
+so the human reader can re-run the same query.
diff --git a/.agents/skills/debug-issue-with-datadog/references/intake.md b/.agents/skills/debug-issue-with-datadog/references/intake.md
new file mode 100644
index 0000000000..e5f5d94663
--- /dev/null
+++ b/.agents/skills/debug-issue-with-datadog/references/intake.md
@@ -0,0 +1,72 @@
+# Intake β€” What Are We Actually Investigating?
+
+Goal: extract every signal from the input *before* you touch Datadog. Cheap
+to do, expensive to skip β€” the wrong time window or wrong service tag can
+hide the real cause.
+
+## Source-by-Source Recipes
+
+### Linear issue (URL or `LFE-XXXX` ID)
+
+1. Fetch the issue via the Linear MCP:
+ `mcp__d39d26f2-…__get_issue` with `id: "LFE-XXXX"` and
+ `includeRelations: true`.
+2. Fetch comments separately:
+ `mcp__d39d26f2-…__list_comments` with the same `issueId`.
+3. Note: Langfuse triages **inside the issue description**. The description
+ often grows reaction sections (`projectId: <one-line note>`) as oncall
+ investigates. Treat both description and comments as authoritative state.
+4. Pull `attachments` for linked PRs/commits β€” these show what's already been
+ tried. Reading the diff of a half-merged fix often reveals the original
+ theory of the bug.
+5. Pull labels (`integration-posthog`, `feat-exports`, etc.) β€” they map
+ directly to the subsystem clusters in `repo-debug-map.md`.
+
+### GitHub issue
+
+1. `gh issue view <url-or-number> --json title,body,labels,comments,assignees`.
+2. If there's a stack trace in the issue body, copy the top frames into your
+ notes β€” those frames usually map straight to a handler file.
+
+### Pasted error / incident text
+
+1. Treat as the issue description. If it's a stack trace, identify:
+ - the throwing module (handler vs. SDK vs. infra),
+ - whether it looks like a *user-input* failure (HTTP 4xx, validation, auth)
+ or an *infra* failure (5xx, timeout, OOM, DNS, pool exhaustion),
+ - the error class (`Error`, `TypeError`, `PrismaClientKnownRequestError`,
+ etc.).
+2. If a `projectId` appears, that's gold β€” anchor every Datadog query on it.
+3. If a `traceId` (Datadog's, not Langfuse's) appears, jump straight to
+ `get_datadog_trace`.
+
+## Extract The Following Before Querying
+
+Build a small notes block. If a value is missing, mark it `?` rather than
+guessing β€” Datadog will tell you what's missing.
+
+- **Subsystem.** PostHog integration, blob-storage export, evaluation
+ execution, OTel ingestion, batch action, webhook delivery, etc. Map to
+ `repo-debug-map.md`.
+- **Region(s).** `prod-eu` / `prod-us` / `prod-hipaa` / `prod-jp`. If unknown,
+ query both EU and US.
+- **Service.** Most issues are `service:worker`; UI/API timeouts are
+ `service:web`. Check for both when unsure.
+- **Time window.** Default to 7 days back from the issue's `createdAt`. If
+ the issue references a specific incident or alert, use that window Β±1 day.
+- **`projectId`(s).** Project IDs in Langfuse are `cuid`-shaped
+ (`cl…` / `cm…`, 25 chars). The reaction blocks in Linear descriptions
+ often *are* lists of affected project IDs.
+- **Error message fragments.** Exact substrings to grep for in DD logs:
+ `Header overflow`, `Timeout error.`, `HTTP 403`, `DNS lookup failed`,
+ `Cannot write to canceled buffer`, `connection pool`, etc.
+- **Already-attempted fixes.** Linked PRs/commits on the issue. Read their
+ diffs β€” your analysis must not re-recommend something that's already
+ shipped.
+
+## Output Of The Intake Step
+
+A short bullet list (not yet formatted as the final analysis) with each of
+the above filled in. The remaining steps key off this β€” `datadog-playbook.md`
+expects subsystem + region + window, `repo-debug-map.md` expects subsystem,
+and the output template wants the affected projects.
diff --git a/.agents/skills/debug-issue-with-datadog/references/output-template.md b/.agents/skills/debug-issue-with-datadog/references/output-template.md
new file mode 100644
index 0000000000..e0947b1b13
--- /dev/null
+++ b/.agents/skills/debug-issue-with-datadog/references/output-template.md
@@ -0,0 +1,127 @@
+# Output Template
+
+The analysis should be structured so it can be pasted directly as the first
+investigative comment on the Linear issue. The example to anchor on is the
+first comment on `LFE-9475` (PostHog Integration Processing Failures).
+
+Findings come first, recommendations last. If the data doesn't support a
+hypothesis, say so β€” do not invent root causes to fill the template.
+
+## Section Order
+
+1. **Header** β€” data source, time window, scope of sweep.
+2. **Volume & error-rate split** β€” table by region (always).
+3. **Hotspots** β€” table by `(projectId, dominant cause)` or by cluster.
+4. **Root cause by error class** β€” one numbered subsection per cluster.
+5. **Suggested patches** β€” P0 / P1 / P2, each with file paths and a short
+ code sketch.
+6. **Dashboards** β€” Datadog UI URLs for the queries you ran.
+
+## Skeleton (fill in with your findings)
+
+````markdown
+## Datadog APM + log analysis (<N>-day window, <YYYY-MM-DD> β†’ <YYYY-MM-DD>)
+
+Source: APM spans with `resource_name:"process <queue-name>"` across EU and US.
+
+### Volume & error rate β€” <one-line summary of regional split>
+
+| Region | Total spans | Errors | Error rate |
+|---|---|---|---|
+| EU (`prod-eu`) | <n> | <n> | **<pct>%** |
+| US (`prod-us`) | <n> | <n> | **<pct>%** |
+
+<One sentence explaining where the noise actually lives.>
+
+### Hotspots β€” concentrated on ~<N> <region> projects
+
+<Region> errors break down by `(projectId, error.message)`:
+
+| ProjectId | Errors | Dominant cause |
+|---|---|---|
+| `<projectId>` | <n> | `<error message>` (<n>) + others |
+| ... | ... | ... |
+
+<Optional: contrast with another subsystem if relevant β€” e.g.
+"Unlike blob storage, PostHog has multiple distinct root causes β€” not one
+hotspot pattern.">
+
+## Root cause by error class
+
+### 1. `<error message>` β€” <n> errors, <n> projects
+<2–4 sentences explaining what this error class actually is at the
+implementation level (which library, which call site). Then list candidate
+causes in order of likelihood. Mark which ones are confirmed by the data
+vs. speculative.>
+
+### 2. `<error message>` β€” <n> errors, mostly <n> projects
+<Same pattern.>
+
+### 3. <next class>
+<...>
+
+### <N>. <Symptom of upstream failure>
+<Use this slot when a class is a *symptom* of another class rather than an
+independent bug β€” call it out so suggested patches don't double-count.>
+
+## Suggested patches
+
+### P0 β€” <one-line summary, e.g. "Auto-disable integrations on persistent
+auth failures">
+<Why this is P0 β€” what noise it kills, what data it stops corrupting, what
+unblocks downstream work.>
+
+```ts
+// <relative path from repo root>
+// Short code sketch (5–20 lines). It does not need to compile β€”
+// it must communicate the shape of the change.
+```
+
+### P0 β€” <next P0>
+<...>
+
+### P1 β€” <smaller / less urgent fix>
+<Same shape.>
+
+### P2 β€” <separate-but-surfaced finding>
+<E.g. a Prisma pool sizing issue surfaced incidentally by this analysis but
+not the original bug. Call it out with its own section so it doesn't get
+lost.>
+
+### Regional split explanation (only if relevant)
+<One paragraph explaining why EU vs. US asymmetry exists β€” usually not an
+infra bug, just where the affected tenants happen to live.>
+
+Dashboards:
+- EU APM: <url>
+- US APM: <url>
+- (logs / metrics / monitor links as relevant)
+````
+
+## Style Rules
+
+- Lead with numbers, not adjectives. "23.5% error rate" beats "very noisy".
+- Distinguish **primary causes** from **symptoms** explicitly. Symptoms
+ shouldn't get their own P0 patch.
+- Always cite specific files when proposing a code change. A patch
+ recommendation without `worker/src/features/<…>/<file>.ts` is unfinished.
+- Code sketches are illustrative β€” clearly mark them as sketches if they
+ hand-wave types. The next agent / human will write the real diff.
+- If the analysis surfaces a finding *outside* the original ticket scope
+ (e.g. a Prisma pool issue while debugging PostHog), include it as a P2
+ with a sentence explaining it's separate.
+- If the data refuses to converge on a single root cause, say so. The
+ template handles N classes β€” use as many subsections as the data warrants.
+
+## When To Skip Sections
+
+- **Single-region deployments:** if the issue clearly affects only one
+ region, you can replace the "Volume & error rate" table with a single-row
+ variant, but still note that the other region was checked and clean.
+- **No code change recommended:** if the only finding is "the affected
+ tenants have misconfigured credentials and we should reach out", the
+ Suggested-patches section can be a single sentence β€” but still include
+ the dashboards.
+- **Aborted investigation:** if Datadog access fails or the data is
+ insufficient, write what you tried, what was missing, and what would let
+ the next investigator pick it up.
diff --git a/.agents/skills/debug-issue-with-datadog/references/repo-debug-map.md b/.agents/skills/debug-issue-with-datadog/references/repo-debug-map.md
new file mode 100644
index 0000000000..b1302f2d07
--- /dev/null
+++ b/.agents/skills/debug-issue-with-datadog/references/repo-debug-map.md
@@ -0,0 +1,89 @@
+# Repo Debug Map β€” Subsystem β†’ Code β†’ Datadog Filters
+
+For each subsystem we ship monitors and incidents on, this is the canonical
+map between the symptom, the Datadog query that surfaces it, and the source
+files where the bug almost certainly lives.
+
+When intake gives you a subsystem (PostHog, evals, exports, etc.), start
+here to pick the right Datadog filters and the right files to read.
+
+## Worker Async Jobs
+
+Worker handlers are wrapped by `instrumentAsync` in their queue file. The
+span resource name follows the pattern `process <queue-name>`. Queue and job
+name constants live in
+`packages/shared/src/server/queues.ts`
+(`QueueName` and `QueueJobs` enums).
+
+| Subsystem | Queue file | Handler dir | Span `resource_name` | Log prefix |
+| --- | --- | --- | --- | --- |
+| PostHog integration | `worker/src/queues/postHogIntegrationQueue.ts` | `worker/src/features/posthog/` | `process posthog-integration-project` | `[POSTHOG]` |
+| Mixpanel integration | `worker/src/queues/mixpanelIntegrationQueue.ts` | `worker/src/features/mixpanel/` | `process mixpanel-integration-project` | `[MIXPANEL]` |
+| Blob storage export | `worker/src/queues/blobStorageIntegrationQueue.ts` | `worker/src/features/blobstorage/` | `process blob-storage-project` | `[BLOBSTORAGE]` |
+| Data retention | `worker/src/queues/dataRetentionQueue.ts` | `worker/src/features/batch-data-retention-cleaner/` | `process data-retention-project` | n/a |
+| Event propagation | `worker/src/queues/eventPropagationQueue.ts` | `worker/src/features/eventPropagation/` | `process event-propagation` | n/a |
+| Cloud usage metering | `worker/src/queues/cloudUsageMeteringQueue.ts` | `worker/src/ee/` (cloud-only) | `process cloud-usage-metering` | n/a |
+| Free-tier usage threshold | `worker/src/queues/cloudFreeTierUsageThresholdQueue.ts` | `worker/src/ee/usageThresholds/` | `process cloud-free-tier-usage-threshold` | n/a |
+| Ingestion (single event) | `worker/src/queues/ingestionQueue.ts` | `worker/src/features/ingestion/` (and `IngestionService`) | BullMQ default span | n/a |
+| OTel ingestion | `worker/src/queues/otelIngestionQueue.ts` | `worker/src/features/otel/` | BullMQ default span | n/a |
+| Evaluation execution | `worker/src/queues/evalQueue.ts` | `worker/src/features/evaluation/` | BullMQ default span | n/a |
+| Batch export | `worker/src/queues/batchExportQueue.ts` | `worker/src/features/batchExport/` | BullMQ default span | n/a |
+| Webhook delivery | `worker/src/queues/webhooks.ts` | `worker/src/features/webhooks/` | BullMQ default span | n/a |
+| Trace / score / dataset / project delete | `worker/src/queues/{traceDelete,scoreDelete,datasetDelete,projectDelete}.ts` | `worker/src/features/traces/`, `…/scores/`, `…/datasets/` | BullMQ default span | n/a |
+
+For queues using BullMQ default spans (no `instrumentAsync` wrapper), search
+APM with `service:worker operation_name:bullmq.process` filtered by
+`bullmq.queue:<queue-name>`.
+
+## Web (Next.js / tRPC / public API)
+
+| Subsystem | Code | Span / log filter |
+| --- | --- | --- |
+| Public REST API | `web/src/pages/api/public/**` | `service:web resource_name:"GET /api/public/<path>"` |
+| tRPC procedures | `web/src/server/api/routers/**` | `service:web resource_name:"POST /api/trpc/<router>.<proc>"` |
+| Auth / API key verification | `web/src/features/public-api/server/apiAuth.ts` | look for `verifyAuthHeaderAndReturnScope` spans |
+| Stripe billing | `web/src/ee/features/billing/server/stripeBillingService.ts` | wrapped in `instrumentAsync`; spans named after the method |
+
+## Shared Layers
+
+These are not subsystems on their own, but are *frequently the actual cause*
+behind a worker subsystem failure.
+
+| Layer | Location | Common failure modes |
+| --- | --- | --- |
+| ClickHouse access | `packages/shared/src/server/clickhouse/`, `packages/shared/src/server/repositories/` | OOM (`Code: 241`), buffer cancel (`Code: 734`), JOIN spills, slow queries on un-pre-filtered traces |
+| Prisma access | `packages/shared/src/db.ts` and per-feature repos | `connection pool timeout` (worker default `connection_limit=5`), N+1 queries |
+| Queue contracts | `packages/shared/src/server/queues.ts` | wrong queue name, missing schema validation |
+| Logger / instrumentation | `packages/shared/src/server/logger.ts`, `packages/shared/src/server/instrumentation.ts` | log silently dropped because `LANGFUSE_LOG_LEVEL` set wrong, or span missing because handler doesn't call `instrumentAsync` |
+| Webhook URL validation | `packages/shared/src/server/validateWebhookURL.ts` | rejects with messages that *look* like DNS errors but are SSRF guard rejections |
+| Encryption | `packages/shared/encryption` | bad keys β†’ 403/auth-style failures masquerading as upstream errors |
+
+## Common Symptoms β†’ First Files To Read
+
+- **"403 from upstream":** check the per-integration credentials table in
+ Postgres (`PostHogIntegration`, `BlobStorageIntegration`, `WebhookConfig`,
+ etc.) and the encryption layer.
+- **"Timeout":** check the SDK timeout default and the per-stream
+ flush/batch size in the handler. Worker async jobs default to long-running
+ but the upstream SDK does not.
+- **"DNS lookup failed":** distinguish actual DNS from `validateWebhookURL`
+ rejection. The error message wrapping is misleading on purpose.
+- **"Cannot write to canceled buffer" (CH):** ClickHouse stream wasn't
+ aborted when the downstream consumer threw. Look for an `AbortController`
+ threaded through the handler.
+- **"Connection pool timeout" (Prisma):** worker `connection_limit` is set
+ in the connection string; jobs doing per-row `findFirst()` exhaust it.
+ Check whether the integration row could be cached in closure scope.
+- **"memory limit exceeded" (CH):** look for unbounded JOINs without a
+ pre-filter CTE, especially in analytics integrations.
+- **"Header overflow":** Node HTTP parser's default 80 KB ceiling. Either
+ raise `--max-http-header-size` for the worker, or replace the SDK's HTTP
+ client.
+
+## Where to Look for Already-Shipped Fixes
+
+Before recommending a patch, confirm it isn't already merged or in flight:
+
+- `attachments` on the Linear issue (PRs and commits are auto-linked).
+- `git log --oneline --since=<recent-window> -- <handler-path>`.
+- Open PRs touching the file via `gh pr list --search "<filename>"`.