Prevent local errors from reaching production Sentry - #1882
Conversation
|
🤖 Review skipped: Repository rate limit exceeded. Free accounts are limited to 2 reviews per 4 hours per repository. Upgrade to a paid plan for unlimited reviews. |
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
Warning Review limit reached
Next review available in: 43 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (10)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Storybook previews for This comment updates automatically on each PR push. |
Greptile SummaryThis PR centralizes Sentry initialization behind an
Confidence Score: 5/5Safe to merge — the change is purely additive and reduces surface area: local processes can no longer reach production Sentry even when they inherit the DSN. Both issues flagged in earlier review rounds (absent idempotency guard in the shared helper and missing test for an unset DEPLOY_ENVIRONMENT) are addressed in this revision. The shared initializer correctly sequences its guards, the server and worker delegation paths preserve skipOpenTelemetrySetup, the stack.yml default is intentional and documented, and the five new unit tests provide direct regression coverage for the core guard being added. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Server: initSentry] --> B{server initialized?}
B -- yes --> Z[return no-op]
B -- no --> C[set server initialized = true]
C --> D[initProductionSentry dsn]
W[Worker module load] --> D
D --> E{shared initialized?}
E -- yes --> Z
E -- no --> F{DSN present?}
F -- no --> Z
F -- yes --> G{DEPLOY_ENVIRONMENT == prod or production?}
G -- no --> Z
G -- yes --> H[Sentry.init with environment production and skipOpenTelemetrySetup true]
H --> I[set shared initialized = true]
style H fill:#2d9,color:#fff
style Z fill:#ccc
Reviews (2): Last reviewed commit: "fix: make Sentry initialization idempote..." | Re-trigger Greptile |
|
🤖 Review skipped: Repository rate limit exceeded. Free accounts are limited to 2 reviews per 4 hours per repository. Upgrade to a paid plan for unlimited reviews. |
…tion worker.test.ts assigned DEPLOY_ENVIRONMENT="prod" and SENTRY_DSN directly on process.env inside vi.hoisted() and never restored them. The "prod" classification persisted for the entire vitest fork, defeating the production-only guard in initProductionSentry() for every module in that fork — the same failure mode 7eba92d (#1882) fixed for Sentry. Any un-mocked telemetry sink wired to that guard would then ship local test-fixture errors to production error tracking. - Use tracked vi.stubEnv and restore with vi.unstubAllEnvs() in afterAll so the classification cannot outlive the test file within a reused fork. - Add an explicit non-production DEPLOY_ENVIRONMENT="test" default to the shared test env so no test run is ever classified as a production deployment unless it opts in. - Record the recurrence in docs/production-incident-baseline.md. Generated-By: PostHog Code Task-Id: 0fd126a1-18dd-4b16-a4cc-a990b91ce4aa
…tion (#2348) * fix(test): stop worker test from classifying the whole fork as production worker.test.ts assigned DEPLOY_ENVIRONMENT="prod" and SENTRY_DSN directly on process.env inside vi.hoisted() and never restored them. The "prod" classification persisted for the entire vitest fork, defeating the production-only guard in initProductionSentry() for every module in that fork — the same failure mode 7eba92d (#1882) fixed for Sentry. Any un-mocked telemetry sink wired to that guard would then ship local test-fixture errors to production error tracking. - Use tracked vi.stubEnv and restore with vi.unstubAllEnvs() in afterAll so the classification cannot outlive the test file within a reused fork. - Add an explicit non-production DEPLOY_ENVIRONMENT="test" default to the shared test env so no test run is ever classified as a production deployment unless it opts in. - Record the recurrence in docs/production-incident-baseline.md. Generated-By: PostHog Code Task-Id: 0fd126a1-18dd-4b16-a4cc-a990b91ce4aa * fix(ci): merge main and repair report/sync regressions blocking checks Bring the branch up to date with main and fix downstream breakages from the report empty-state work and provider sync refactor that were failing lint, typecheck, unit, and mobile tests in CI. Co-authored-by: Cursor <cursoragent@cursor.com> * chore(dev): use MISE_LOCKED=1 instead of mise trust for installs Replace mise trust with explicit MISE_LOCKED=1 on install commands so pinned tool versions are enforced without relying on mise.toml settings. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(ci): repair unit, integration, e2e, and iOS build failures Align withings timeout expectations with ProviderRequestTimeoutError, pass endDate in monthly report integration tests, lowercase GHCR cache refs for fork repos, and defer HealthKit observer coordinator init to avoid self capture in Swift. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(web): align report fixtures with MonthlyReportData types Remove recovery fields from component stories and tests since web UI consumes repository data shapes, not router results. Delete the unused report-data fixture that was breaking Knip, coverage, and Stryker. Co-authored-by: Cursor <cursoragent@cursor.com> * docs: cite Vitest sources in worker env leak incident entry Add primary-source links for vi.hoisted, fork worker env sharing, vi.stubEnv, vi.unstubAllEnvs, and module mocking per review feedback. Also use "unmocked". Co-authored-by: Cursor <cursoragent@cursor.com> * fix(test): restore only worker env stubs in afterAll Use targeted vi.stubEnv calls instead of vi.unstubAllEnvs so future tests in worker.test.ts can stub other env vars without implicit teardown. Co-authored-by: Cursor <cursoragent@cursor.com> * docs: cite Sentry and PostHog SDKs in env leak incident entry Add official SDK documentation links for @sentry/node and posthog-node claims to satisfy third-party citation compliance in the incident baseline. Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: posthog[bot] <206114724+posthog[bot]@users.noreply.github.com> Co-authored-by: Asher Cohen <asherlc@asherlc.com> Co-authored-by: Cursor <cursoragent@cursor.com>
Summary
Centralize Sentry initialization and require an explicit
prodorproductiondeployment environment, preventing local processes that inherit the production DSN from reporting errors.Pass the existing deployment environment into production web and worker containers, explicitly tag their events as
production, and document the operational contract and incident findings.Add regression coverage for local suppression, production initialization, server delegation, and worker startup.
Testing
pnpm lint; root, server, and web TypeScript checks;pnpm test(13,131 passed, 21 skipped).Summary by cubic
Prevents local processes from sending errors to production Sentry by centralizing Sentry init, gating it on
DEPLOY_ENVIRONMENT, and ensuring it only initializes once. Productionwebandworkernow tag events with theproductionenvironment.Bug Fixes
initProductionSentry(src/lib/sentry.ts) that initializes only when a DSN is present andDEPLOY_ENVIRONMENTisprodorproduction, setsenvironment: "production", and is idempotent.dofek/lib/sentry; replaced direct@sentry/nodeinit in the worker; added tests for local suppression, production init, idempotency, and worker startup; exported./lib/sentryinpackage.json.DEPLOY_ENVIRONMENTtowebandworkerindeploy/stack.yml(defaultproduction); clarified behavior indeploy/README.mdand documented the incident indocs/production-incident-baseline.md.Migration
deploy/stack.yml, setDEPLOY_ENVIRONMENT=productionfor any productionweb/worker. Leave it unset or non-prod for local and staging.Written for commit 64a8f24. Summary will update on new commits.