Repository navigation
refactor(sentry): give every server report one capture body - #1102
Conversation
Five sites each had their own idea of what a message capture attaches: two spelled the level by hand, one left it off so Sentry defaulted to `info`, two built a scope through `withScope`, and three mirrored the message to `payload.logger.warn` beside the capture while two did not. Nothing held them in step, so a field added to one reached none of the others. `captureMessage` is the body they now share, the twin of `captureFailure` for anything that is not an exception. It defaults the level to `warning`, never throws — most of its sites report from a path that is otherwise succeeding, so a telemetry error there would fail a working operation — and takes the logger when a site wants the mirror. `captureTags` is what both bodies read their tags from, so neither can tag a deployment the other leaves untagged. Two decisions the ticket asked for. The logger mirror is opt-in, because the abuse-milestone task logs one aggregate line for a whole run of reports and the mail adapter's own line carries detail the report deliberately omits; passing a logger is how the other two stop writing both halves by hand. And `deliverProposal` keeps `info`: the system contact is the last rung of its routing ladder rather than a failure of it, and the admin home already lists a proposal that reached it. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjYvvk73ifTAQh9uxHz
The per-site specs each drive one caller, so none of them can see what a site leaves out. These cover the defaults, the mirror's level mapping, and a transport that throws while the caller is mid-success. `endpoint-guard-credential-rejected.spec.ts` now reads the capture context the way its throwing-path twin already does, rather than five scope setters. The last case is the ticket's own `rg` made permanent: nothing but the body may call `Sentry.captureMessage`, since the defaults and the mirror are invisible to a site that reaches the SDK itself. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjYvvk73ifTAQh9uxHz
… pass The review pass found three fields carrying no weight. `contexts` served one site, and its own doc warned readers off it, so the abuse-milestone report sends plain extras instead — the named card is the one thing an operator sees differently. `user` was only ever given an address, so the body takes `ip` and builds the field itself, keeping the ⚠ that says why an IP may not be an extra. `CaptureMessageArgs` is no longer exported; nothing imported it. `tags.ts` no longer credits the tag with closing #733. `Sentry.init` sets the event's own `environment` field on every event, so the tag is the searchable copy beside it, not the thing that makes a preview's errors legible — and nothing should read that comment as a reason it cannot be removed. The module also says it is server-side only, since `deploymentEnvironment` reads an environment a browser bundle never carries. `capturedFrom` replaces four copies of the same reader, two of which had already drifted apart in how they typed `tags`. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjYvvk73ifTAQh9uxHz
… report A logger that throws was taking the Sentry event with it, which is the one thing `describeRejectedCredential` already guards its own WARN line against and `docs/architecture.md` states as a rule. The two guards are siblings now, and a spec drives a throwing destination. `index.ts` also speaks for both bodies, since `src/AGENTS.md` now points there for why neither is in the barrel. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjYvvk73ifTAQh9uxHz
|
🚅 Deployed to the SahajCloud-pr-1102 environment in sahajcloud
1 service not affected by this PR
|
sydevs-bot
left a comment
There was a problem hiding this comment.
2 questions for the reviewer, one per thread.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
|
🤖 no session running recent dispatchesWritten by the sydevs dispatcher. Sessions never edit this comment. |
Four conflicts, all Markdown, all the same figure. Both sides raised the unit lane's recorded counts from the merge base's 242 / 3143 — this branch to 243 / 3155 for the spec it adds, main to 251 / 3382 across nine files — so neither side's number describes the merged tree. `perf-figures-pinned.spec.ts` pins the file count to what is on disk and holds every consumer doc to PERF.md, so the counts are re-measured here rather than chosen: 252 files, 3407 tests, from this tree's own gate run. That also corrects main's new sentence in `testing-reqs.md`, which git merged in clean and which states the same pair. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjUsAuvKB1ezkDBghp9
The merged tree runs 3407 unit tests, not the 3394 that adding both sides' new cases to main's figure predicts. `perf-figures-pinned.spec.ts` pins only the file count to disk, so a wrong test count stays green as long as all four consumer docs agree on it — which is exactly how the figure it governs drifted before (#990). Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjUsAuvKB1ezkDBghp9
|
Merged So neither side's number describes the merged tree, and I took neither. 3407 is 13 above the 3394 that adding both sides' new cases predicts. The spec pins only the file count, so a derived test count would have stayed green and wrong. No code conflict. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
This PR is the size of #1100, no larger. Seven call sites and two new modules; the ticket's own rg criterion pulls in the three sites beyond its four. tags.ts earns its file under src/AGENTS.md:43 — two callers, beside them. Correctness reads clean: the tag filter drops nothing the if (value) setTag loop sent (RejectedCredentialContext.tags is all string | undefined), and the new edge into deploymentEnvironment adds no client-bundle hazard.
Both architectural calls already sit in question threads — whether the environment tag should exist, and message-vs-exception versus one body. I raise neither again. No contract surface is touched, so there is no consumer side to read.
Findings
should-fix— the body takes the SDK's own export name, where its twin avoids it.captureMessage.ts:41.should-fix—tagsis typed wider than anything it keeps.captureMessage.ts:38.should-fix—## Test resultsquotes the pre-merge run, 243 files / 3155 tests. This branch's docs now record 252 / 3407, re-measured after themainmerge. Refresh it.
What was checked
- #1100's four criteria against the diff. All four hold, and
sentry-capture-message.spec.tsguards criterion 2 across.tsand.tsx. - Read whole on the branch: both capture bodies,
tags.ts,credentialRejection.ts,deploymentEnvironment.ts, all seven call sites. - Ladder:
captureMessage.tsis the ticket's ask,tags.tsthesrc/AGENTS.md:43rule,tests/utils/sentryCapture.tsreplaces four inline copies. - Client bundle:
deploymentEnvironment.tsis not inclient-bundle-safety.spec.ts'sSERVER_ONLY, andclientDeploymentEnvironment(named attags.ts:11) exists. - Counts: 252 unit spec files here, 251 on
main; the diff adds 12 cases. - Preview: the host answers 200, and no page shows a Sentry change.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
#1087 moved the unit lane's recorded counts again. Both sides had raised them from the merge base, so neither figure describes the merged tree; these are re-measured in the next commit, from this tree's own gate run. No code conflict. #1087's own files and this branch's do not overlap. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjVR6JWLAcsDvjpUicx
`captureFailure` deliberately avoids the SDK's `captureException`; the message body took `captureMessage` and lost that. `resendAdapter.ts` is where it cost something — ours sat ten lines from a real `Sentry.captureException`, under a name the SDK also exports. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjVR6JWLAcsDvjpUicx
The body accepted `Record<string, unknown>` and silently dropped everything that was not a string, so `usage/tasks.ts` forgetting its `String(report.clientId)` would have lost the tag naming the abusing client with no compiler error. `RejectedCredentialContext.tags` already carries the narrow type, and every caller satisfies it. `captureTags` keeps the wide argument, because `captureFailure` passes it a job id. Its non-string filter is therefore only reachable from that side, and is pinned there instead. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjVR6JWLAcsDvjpUicx
255 files and 3445 tests, from this tree's own gate run. #1087 raised main's figures while this branch raised its own, so the merge left all four consumer docs stating a pair that described neither side. `perf-figures-pinned.spec.ts` pins the file count to disk, so only that half could go red; the test count is held by the four docs agreeing, which is how the figure drifted before (#990). Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjVR6JWLAcsDvjpUicx
3450 tests, from this tree's own gate run; 255 files is unchanged, so `perf-figures-pinned.spec.ts` could not have caught the drift — nothing but the four consumer docs agreeing holds the test count. `tests/COVERAGE.md` gains the row for `sentry-capture.spec.ts`, beside the three Sentry rows already there. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjZShQHAHuZbzeMYzrf
The branch-level security sweep found no invariant breached — no value newly reaches an extra, a tag, a message or `user`, the caller IP stays on `user.ip_address`, and only the truncated key fingerprint is emitted. It raised three accuracy points, each fixed here. **The three per-item job reports stay at `error`.** Passing `level: 'warning'` would have matched their log lines, but the Sentry level was load-bearing in a way neither half showed: a sweep that catches per-item failures *succeeds*, so `jobCapture`'s final-attempt capture never fires, and those per-item events were the only `error`-level signal a night of total failure produced. `sendInvitations` already reports the same shape — a per-item failure inside a continuing loop — at `error` with a matching `logger.error`, so matching it keeps the Sentry level untouched and makes the four consistent. **`captureFailure` really never throws now.** `status = errorStatus(error)` was a parameter default, evaluated before the body's `try`, and `errorStatus` reads the error's own `status` — so a throwing getter escaped the guard. Resolved inside the `try` instead, and pinned. **The log mirror's comment no longer reasons from pino.** This repo's one logger is `workerSafeLogger`, which has no serializers and no `redact` and reduces an Error under any key. The stack is still what the `err` key buys; pino's rules are not what buys it. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjZShQHAHuZbzeMYzrf
|
Both question threads answered and built. Pushed
What decided the recommendation: six sites captured inline with no Look at: every Sentry level is unchanged; three log lines move Gate ✓ 255 files / 3451 tests. 8 int specs ✓. Security sweep ✓ — no invariant breached, three accuracy points fixed in 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Three doc conflicts, all one figure: the unit lane's file and test counts. Both sides moved 254/3431 independently — this branch to 255/3451, main to 255/3457 — so neither number describes the merged tree. Re-measured here: 256 files, 3478 tests. AGENTS.md states the file count too and never conflicted, because both sides said 255; perf-figures-pinned.spec.ts checks it against disk, so it would have gone red on either side taken whole. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjWo4RQkAJtqPe72vrB
#1108 renamed Clients.name to label; #1106 landed after it with two new scripts still reading name. The two touch different files, so GitHub merged #1106 without a conflict and main has not typechecked since: tsc --noEmit on e543e6a reports the same three errors this branch inherited on merging it. Both scripts are operator audits printing an internal identifier, so label is the right half of the split rather than the public title. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjWo4RQkAJtqPe72vrB
|
Merged Both sides moved
Lean gate green on the merged tree: lint, format, typecheck, typecheck:tests, 256 files / 3478 tests, 134 s. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
…er-contacts Four conflicts. Three are one fact again: the unit lane's file and test counts, in docs/rules/testing-reqs.md, tests/AGENTS.md and tests/PERF.md. main's #1102 and this branch each added a spec file since the seventh merge, so neither side's number describes the merged tree. Measured instead: 257 files, 3488 tests. AGENTS.md states the file count too and merged clean at the stale 256, so it is corrected here — tests/unit/perf-figures-pinned.spec.ts pins all four against the tree. The fourth is an import line in src/plugins/login/invitations.ts, where this branch added selfOrAdminFieldAccess and #1102 added capture. Both are used, so both are kept. main added no migration, so the chain and its snapshot stand as the seventh merge left them. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjYptMd7SiHURhD6ufY
Five Markdown conflicts and one semantic conflict no marker showed. Four of the five are the same fact twice: both sides recounted the unit lane from 255 / 3457. Measured on the merged tree rather than added up — 262 files and 3530 tests. `tests/PERF.md` takes this run as its forty-seventh row; `AGENTS.md`, `docs/rules/testing-reqs.md` and `tests/AGENTS.md` quote the same pair. The fifth is `docs/architecture.md`'s Sentry paragraph. #1102 rewrote it from "the `environment` tag" to "the `environment` FIELD", adding why no capture sets a tag beside it; this branch had only renamed `next.config.mjs` to `next.config.ts` in it, twice. Resolved as main's prose carrying this branch's two renames. **The semantic conflict is `tests/unit/submission-deliverers.spec.ts`, which git merged clean and which then failed.** #1102 added a mock factory for `@/lib/env/deploymentEnvironment` declaring `deploymentEnvironment` alone — complete against `main`, where that module exports nothing else a deliverer reaches. On this branch `getServerUrl()` reads `railwayEnvironmentName()` from the same module, and a factory replaces the module whole, so the review link's `adminDocUrl()` threw vitest's missing-export error inside `deliverProposal`'s try, which reported it as a retryable delivery failure and sent no email. The factory now declares both exports, the second off-Railway to match the `'test'` name beside it. Neither side is wrong, and neither could have seen it: the mock is complete on `main` and the import is correct here. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjXTetkJdxYxxUHBYFi
Summary
capture, now reports every server event — an exception as well as a message. It is the only place insrc/that reachesSentry.captureExceptionorSentry.captureMessage, and a spec fails any other spelling. Fifteen sites stop spelling the level, the tags, the log mirror and the never-throw guard themselves.captureFailurekeeps its closed field list and its exclusions, but now only classifies a routed failure and reports through that body.environmenttag. Every event already names its deployment in its ownenvironmentfield, whichSentry.initsets — so refactor(sentry): give a reported warning one capture body, with the environment tag #1100's criterion 1 asked for a copy, not a capability.capturedFromreplaces four copies of the same spec reader, two of which had already drifted in how they typedtags.Change outline
Files — one body, and one classifier above it
Neither takes the SDK's own export name, so a reader cannot mistake one for
Sentry.captureMessagesitting beside it.Flow — a per-item failure inside a run written to continue
⚠ Those four
catchblocks exist so the run continues, and the capture inside them had notry. A Sentry transport error there aborted exactly the run that was written not to abort. That is the defect this answers, and it is why the second question thread's answer is "one body" rather than "consistency is nicer".Behaviour — the six reports the one body reached
Every Sentry level is unchanged, and all six now cannot throw. Three of them had their Sentry level (
error, the SDK's default) and their log line (warn) disagreeing; this body gives a report one level for both, anderroris the half that was kept — § Detail says why that was the load-bearing one.Types — a report with no subject does not compile
The wide
Record<string, unknown>is gone from both sides. The earlier body of this PR saidcaptureFailureneeds it for a numericjob_id; that was wrong —jobCapture.ts:81passesString(args.job.id), so nothing ever handed it a non-string.Preview
https://sahajcloud-sahajcloud-pr-1102.up.railway.appif a reviewer wants to trigger a report — the event'senvironmentfield readspr-1102there, which is the whole of what the deleted tag was copying.Email previews
src/plugins/email/resendAdapter.tschanges only on its three failure paths, and the preview scripts post through Mailpit's own adapter, so no rendered message differs.tests/unit/resend-adapter.spec.tsdrives the two drop paths.Test results
.claude/skills/pr-prep/check.sh— lint, format, typecheck, typecheck:tests, test:unit (255 files / 3451 tests), 122 sexpire-events.int,digests.int,session-reminders.int,user-submissions-repeat-registration.int,admin-write-capture.int,manager-signin-page.int,meditationFrames.int,atlas-submission-routing.intsrc/collections/UserSubmissions/hooks/, so the conditional sweep ran. It diffed all ten moved or renamed sites against their pre-change form and found no value newly reaching anextra, a tag, a message, a fingerprint oruser; confirmed the caller IP cannot reach anextraon any path, including throughcaptureFailure'srejected; confirmed only the truncated key fingerprint is still emitted; and read[email protected]'s ownfetchRequestto confirm the one reachable throw atresendAdapter.ts:160cannot carry a recipient, subject or body. It raised three accuracy points, all fixed inae727f8— the job levels,captureFailure's status default, and the mirror's comment. It also notes that nowithScope/setTag/setExtra/setContextsurvives anywhere insrc/, so there is no cross-request scope-bleed surface leftEvery new assertion was watched failing against its defect: a message routed to
captureException, one level default for both kinds, a mirror that drops the exception, an IP outranking the acting user, the never-throw guard removed, a site reaching the SDK itself, theenvironmenttag restored, the per-event tag dropped fromExpireEvents, andcaptureFailure's status default moved back outside itstry.Manual verification
environmentfield, which is untouched — but that is the premise the tag's removal rests on, and only Sentry can show it.Notes for reviewer
environmenttag): B is built, infaee06c.tags.tshad already gone incbb28d2— once one body owned the send, its filter had one caller rather than two — so B itself landed as one line. refactor(sentry): give a reported warning one capture body, with the environment tag #1100's criterion 1 is retracted on the ticket, with the replacement in its place.cbb28d2. The recommendation turns on the reliability half of your three words, not the consistency half: four of the six inline sites sit in acatchthat exists so a run continues, and a throwing capture there aborted it. Consistency is what the two SDK spellings cost; this is what they cost that a reader cannot see.scope.setContext(...)named card becomes plain extras, forExpireEvents,SendSessionReminders,SendDigestsandframes.ts— on top of the abuse-milestoneabuse_detailscard already declared.warntoerror: the per-item failures inExpireEvents,SendSessionRemindersandSendDigests. Their Sentry level was alreadyerror, and one level now drives both halves.sendInvitationsreports the identical shape aterror/erroralready.error: <message>;invitations.tsalready passed the error.usage/tasks.tskeeps its ownNEXT_PUBLIC_SENTRY_DSNgate, which the body deliberately does not have — removing it would stop its aggregate log line on a deployment with no DSN. AndcaptureFailurekeeps its own outertry: the three readers it classifies from run beforecaptureis reached, and one of them turned out to be reachable before anytryat all (ae727f8).tags.tsback (the file is gone), and deleting a tag case from the body's spec as redundant (thecaptureTags(undefined)case it protected is nowcapture's own "adds no deployment tag" case).Detail
Why
captureFailureis still a separate function. Its inputs are an error plus one of fourCaptureSourcevalues, and its job is deriving a level, tags, extras, a fingerprint and a user from aPayloadRequest. That derivation is one caller shape's classification, not policy shared by all fifteen reports — theafterErrorhook, the Local API wrapper, the job runner and the two sign-in paths are infrastructure seams rather than call sites. Folding it into the one public body would put a closedsourceunion in front of every ordinary site that has no source. So: one body that sends, one classifier above it for the routed-failure shape.Why the three browser reporters stay out. Their exclusion used to rest on
captureTagsbeing unable to read the deployment in a browser. That reason is gone with the tag, so here is the one that is left.clientLogger.erroris the browser's own mirror-and-capture body — the client-side equivalent ofcapture, not one of its callers — andErrorBoundarybranches onSentry.getClient() !== undefinedto fall back toconsole.error, which no server site wants. One body carrying both a pino logger and a console mirror, with agetClient()check only one caller reads, would be less streamlined than two.ErrorBoundaryalso passescontexts.react.componentStack, which Sentry's React integration renders in its own pane; flattening it to an extra would be a reporting regression, not a simplification.Why the three job sites kept
errorrather thanwarning. Matching theirwarnlog line was the first answer, and it was wrong. A sweep that catches per-item failures so the run continues succeeds — sojobCapture's final-attempt capture never fires, and those per-item events are the onlyerror-level signal a night of total failure produces: a bad migration, a dead Resend key, an expired Mapbox token. Dropping them towarningwould have removed the one thing alevel:erroralert could see.sendInvitationsalready reports the identical shape aterrorwith a matchinglogger.error, so keepingerrorboth preserves every Sentry level and makes the four consistent. The log lines move instead, which adds noise and loses nothing.Why the mirror is opt-in, still. Three of the four sites #1100 listed wrote
logger.warn({ msg, ...extra })beside the capture; the abuse-milestone task logs one aggregate line for a whole run instead. Passing a logger is how a site stops writing both halves by hand; leaving it out is how that task keeps the one line it wants.Why
deliverProposalkeepsinfo. The system contact is the last rung of its routing ladder, not a failure of it — the function's own docblock says so — andadminProposalsWhere(src/lib/atlasOverview/openItems.ts) already puts a proposal that reached it on the admin home. The level is now explicit rather than Sentry's default, with the reason beside it.Where #733's breadcrumb went. It used to sit on the
environmenttag, crediting it with a fix that belongs tosentry.server.config.tsandinstrumentation-client.ts. It now sits ondeploymentEnvironment()itself, which is what those twoinitcalls read.docs/architecture.mdsaid "tag" in three places where it meant "field" — that wording is what put criterion 1 on the ticket, so it is corrected rather than left for the next reader.The unit lane's figures. 255 files and 3451 tests, re-measured from this tree's own gate run. The file count did not move, so
perf-figures-pinned.spec.tscould not have caught the test count drifting — nothing but the four consumer docs agreeing holds that half.Closes #1100
Generated by Claude Code