Skip to content

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

9.1 KB
Raw Blame

Sentry capture contract β€” depth reference

Load when authoring a beforeSend/denylist rule, hardening a capture path, or triaging a noise family. Read the SKILL.md first β€” this file is the detail behind its rules.

Contents

Where Sentry is wired

  • The only Sentry.init is web/instrumentation-client.ts β€” client-side only. It configures beforeSend, captureConsoleIntegration({ levels: ["error"] }), httpClientIntegration(), replayIntegration(...) (unconditional masking), and denyUrls (browser-extension origins).
  • The worker and web server have no Sentry SDK β€” backend signal lives in the server-side observability/APM stack, not Sentry. Do not assume a backend error reaches Sentry; it does not. (Treat "Sentry = frontend-only" until a decision says otherwise.)
  • Filter predicates live in web/src/utils/sentryFilters.ts with unit tests in sentryFilters.clienttest.ts; beforeSend only calls these named predicates and holds no inline checks (the former invalid-href and React-devtools inline checks were removed / migrated to isReactDevtoolsInternalEvent in #15276). Add new filters only as predicates here, never inline.
  • The tRPC seam is handleTrpcError in web/src/utils/api.ts: every query/mutation error flows through it β€” the single place to classify. PR #15243 drops expected data.codes (NOT_FOUND / FORBIDDEN / UNAUTHORIZED) there with a breadcrumb and tags the rest (trpc.code / trpc.path).

PII and the HIPAA compliance boundary

ALL cloud regions β€” including HIPAA β€” report to the same US Sentry org. Two mechanisms keep user content (prompts, traces, PII/PHI) out of it, and they cover different channels. Do not conflate them.

  1. Session Replay β†’ the unconditional mask. instrumentation-client.ts configures replayIntegration({ maskAllText, maskAllInputs, blockAllMedia }) so replays are fully masked in every deployment. The mask must never be removed or weakened, and it must be covered by a CI regression test that executes the real module per region and fails on any change to the options (the mask-guard instrumentation-client-replay-mask.clienttest.ts; landing with #15802). A diff that trips that guard is a compliance change, not a broken test; a diff that touches Replay masking without the guard passing must be rejected.
  2. Error events β†’ the capture discipline (SKILL rule 7). The mask covers Session Replay ONLY. Error-event payloads β€” message, breadcrumbs, extra, tags β€” are not masked in any region. The rule "no user content in messages/extra/tags" IS the compliance boundary for error events; there is no downstream scrub to catch a leak. sendDefaultPii stays unset (false), so the SDK attaches no cookies, headers, request/response bodies, or user IP.

Reviewer checklist β€” any diff touching instrumentation-client.ts or the replay integration:

  • maskAllText, maskAllInputs, and blockAllMedia remain true in every deployment, and the mask-guard clienttest (landing with #15802) asserts against the real module β€” not a copy of the config or an uncalled predicate.
  • No new replay option weakens masking (e.g. maskAllInputs: false, unmask/unblock selectors).
  • sendDefaultPii remains unset/false; no integration starts attaching bodies, headers, or cookies.
  • Changes to the mask-guard test itself (skipped cases, loosened assertions, region list edits) are reviewed as compliance changes.

The shared capture helpers

Prefer these over a raw captureException:

// A caught value of unknown shape (catch block, rejected promise, event handler).
captureUnknownError("io-parse", value, { traceId }); // real Error passes through; else synthesized. tags:{area}, warns (no double-capture)

// A Web Worker onerror ErrorEvent (script failed to load / threw during init).
reportParserWorkerError("useJsonParse", event); // extracts message/filename/lineno; tags:{area:"io-parse-worker"}

Both log via console.warn (not console.error) on purpose β€” console.error would be re-captured by captureConsoleIntegration as a second, opaque event.

If you must capture directly: pass a real Error, add { tags: { area }, extra }, keep the message static, and log any companion console line at warn.

beforeSend / denylist authoring protocol

A suppression rule is a loaded gun aimed at your own signal. Every rule:

  1. Is a named predicate in sentryFilters.ts (e.g. isNoisyHttpClientPollEvent), never an inline check in beforeSend.
  2. Keys on an unambiguous signature β€” the Sentry-set exception mechanism.type, a whole-message match, or a startsWith-anchored prefix. Never a loose includes that could match a real error.
  3. Reads the right event field. Exception events carry text on event.exception.values[0].value; message events (console captures, benign strings, [next-auth] logs, Invalid href …) carry it on event.message or event.logentry.message. A predicate must coalesce all three (exception value ?? event.message ?? event.logentry?.message) or it silently never fires on message events β€” the exact bug that left the original invalid-href filter dead.
  4. Has a written rationale in a comment: why this signature cannot represent a real, actionable error, and where the real signal still lives (usually server-side).
  5. Has a NEGATIVE fixture in sentryFilters.clienttest.ts proving a real error still passes β€” a 5xx / unknown code / genuine thrown Error must return false from the predicate.

Prefer root-causing the emission over a filter whenever the source is a small, identifiable set of call sites (see Rule 5 / the invalid-href case).

Fingerprinting, tagging, messages

  • Static message β†’ correct grouping. Sentry groups by message; an interpolated id (Trace ${id} not found) mints a new fingerprint per id. Keep the message constant; put variability in extra.
  • area tag on every real capture (tags: { area: "io-parse-worker" }) so issues route/group by surface. The tRPC seam adds trpc.code / trpc.path.
  • Explicit fingerprint only when a message legitimately must vary and you still want one group β€” set it on the scope; do not rely on the default.

Known noise families

The recurring shapes and their correct disposition:

  • Expected tRPC codes β€” Trace not found (NOT_FOUND), not a member (FORBIDDEN), expired session (UNAUTHORIZED). β†’ dropped at the seam (#15243).
  • Transport / next-auth β€” Failed to fetch, [next-auth] CLIENT_FETCH_ERROR, poll 5xx. β†’ server owns the signal; scoped/denylisted (#15145, #15238).
  • Opaque non-Error captures β€” [object Object], [object ErrorEvent], "Object captured as exception". β†’ capture a real Error via the helpers (#15173, #15175).
  • User-content URL validation β€” Invalid href … passed to next/router. β†’ render user URLs as native <a>, not a framework <Link> (#15245).
  • Perf detectors / third-party β€” N+1, HTTP-overhead info issues, browser extensions, crawlers. β†’ Sentry project settings (inbound filters, detectors), not code. Stackless Chrome chrome.runtime lastError (Could not establish connection. Receiving end does not exist) is the exception: denyUrls cannot match with no frames, so a named predicate drops it (LANGFUSE-614).
  • Stale-deploy β€” chunk 404s, importScripts failures, version-skew. β†’ a reload-on-new-version prompt + release-aware handling (open work).

Workstream levers (case studies)

Each row names the PR that established the pattern; verify a cited symbol/swap against the current tree before relying on it.

PR Family Lever
#15145 418 httpClient poll 5xx (~44k→8/24h) isNoisyHttpClientPollEvent (mechanism + path)
#15173 parse-worker [object ErrorEvent] reportParserWorkerError (real Error)
#15174 JSON-viewer meta-root offsets (456) fingerprint/render fix
#15175 opaque non-Error captures (5EX) captureUnknownError (real Error)
#15238 transport / next-auth / benign (~1.9k/24h) isDenylistedNoiseEvent in sentryFilters.ts β€” reads all event fields, negative fixtures
#15243 expected tRPC codes (54F #2, ~30k) handleTrpcError classify + breadcrumb + tags
#15245 Invalid href (5DZ/5EA/5ER, ~40k) native <a> at the source

Each is a worked example of one rule: prefer real Errors, prefer root-cause over filter, read the right field, keep a negative fixture, verify in the browser.