fix(sentry): disable error tracking in dev and preview environments#510
Conversation
Only enable Sentry in production to reduce noise from development and preview environment errors. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
📝 WalkthroughWalkthroughModifies Sentry initialization enablement across multiple applications to activate only in production environments, replacing the previous DSN-presence check. Additionally, standardizes tracesSampleRate values and enforces dual production environment gating in desktop clients. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 6
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/docs/src/instrumentation-client.ts (1)
26-34: Verify thatNEXT_PUBLIC_SENTRY_DSN_DOCSis configured in production deployments.The
NEXT_PUBLIC_SENTRY_DSN_DOCSvariable is optional per the environment schema, so Sentry could be enabled in production without a valid DSN. However, the environment-based gating pattern (enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production") is consistent with the approach used inapps/web,apps/marketing, andapps/api. Ensure production deployments always provide the DSN, or this will silently fail to send events.
🧹 Nitpick comments (4)
apps/docs/sentry.server.config.ts (1)
8-8: Consider adding DSN validation to the enabled check.The change correctly implements production-only enablement. However, since
NEXT_PUBLIC_SENTRY_DSN_DOCSis optional, Sentry could initialize in production without a valid DSN, leading to silent failure of error tracking.🔎 Suggested defensive check
- enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production", + enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production" && !!env.NEXT_PUBLIC_SENTRY_DSN_DOCS,This ensures Sentry only initializes when both the environment is production AND a DSN is configured, preventing silent configuration errors.
apps/web/src/instrumentation-client.ts (1)
29-29: Consider adding DSN validation to the enabled check.The production-only enablement aligns with the PR objectives. However, with
NEXT_PUBLIC_SENTRY_DSN_WEBbeing optional, there's a risk of Sentry initializing in production without a valid DSN, resulting in no error tracking without any warnings.🔎 Suggested defensive check
- enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production", + enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production" && !!env.NEXT_PUBLIC_SENTRY_DSN_WEB,This dual check ensures Sentry initializes only when properly configured.
apps/docs/sentry.edge.config.ts (1)
8-8: Consider adding DSN validation to the enabled check.While the production-only gating correctly implements the PR objectives, the optional
NEXT_PUBLIC_SENTRY_DSN_DOCScould lead to Sentry initializing in production without a DSN, causing silent error tracking failure.🔎 Suggested defensive check
- enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production", + enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production" && !!env.NEXT_PUBLIC_SENTRY_DSN_DOCS,This prevents misconfiguration where production is set but DSN is forgotten.
apps/marketing/sentry.server.config.ts (1)
8-8: Consider adding DSN validation to the enabled check.The change achieves the PR goal of production-only Sentry enablement. However, since
NEXT_PUBLIC_SENTRY_DSN_MARKETINGis optional, Sentry might initialize in production without a valid DSN, leading to undetected error tracking failures.🔎 Suggested defensive check
- enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production", + enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production" && !!env.NEXT_PUBLIC_SENTRY_DSN_MARKETING,This dual condition guards against configuration mistakes in production.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (13)
apps/api/sentry.edge.config.tsapps/api/sentry.server.config.tsapps/desktop/src/main/lib/sentry.tsapps/desktop/src/renderer/lib/sentry.tsapps/docs/sentry.edge.config.tsapps/docs/sentry.server.config.tsapps/docs/src/instrumentation-client.tsapps/marketing/sentry.edge.config.tsapps/marketing/sentry.server.config.tsapps/marketing/src/instrumentation-client.tsapps/web/sentry.edge.config.tsapps/web/sentry.server.config.tsapps/web/src/instrumentation-client.ts
🧰 Additional context used
📓 Path-based instructions (6)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Avoid using any type in TypeScript - maintain type safety unless absolutely necessary
Files:
apps/marketing/src/instrumentation-client.tsapps/marketing/sentry.server.config.tsapps/web/sentry.server.config.tsapps/docs/src/instrumentation-client.tsapps/docs/sentry.server.config.tsapps/web/src/instrumentation-client.tsapps/docs/sentry.edge.config.tsapps/desktop/src/renderer/lib/sentry.tsapps/api/sentry.edge.config.tsapps/api/sentry.server.config.tsapps/marketing/sentry.edge.config.tsapps/desktop/src/main/lib/sentry.tsapps/web/sentry.edge.config.ts
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
Run Biome for formatting, linting, import organization, and safe fixes at the root level using bun run lint:fix
Files:
apps/marketing/src/instrumentation-client.tsapps/marketing/sentry.server.config.tsapps/web/sentry.server.config.tsapps/docs/src/instrumentation-client.tsapps/docs/sentry.server.config.tsapps/web/src/instrumentation-client.tsapps/docs/sentry.edge.config.tsapps/desktop/src/renderer/lib/sentry.tsapps/api/sentry.edge.config.tsapps/api/sentry.server.config.tsapps/marketing/sentry.edge.config.tsapps/desktop/src/main/lib/sentry.tsapps/web/sentry.edge.config.ts
apps/desktop/src/renderer/**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Never import Node.js modules in renderer process or shared code - use only in main process (src/main/)
Files:
apps/desktop/src/renderer/lib/sentry.ts
apps/desktop/src/{main,renderer,preload}/**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use type-safe IPC communication - define channel types in apps/desktop/src/shared/ipc-channels.ts before implementing handlers
Files:
apps/desktop/src/renderer/lib/sentry.tsapps/desktop/src/main/lib/sentry.ts
apps/desktop/**/*.{ts,tsx}
📄 CodeRabbit inference engine (apps/desktop/AGENTS.md)
apps/desktop/**/*.{ts,tsx}: For Electron interprocess communication, ALWAYS use tRPC as defined insrc/lib/trpc
Use alias as defined intsconfig.jsonwhen possible
Prefer zustand for state management if it makes sense. Do not use effect unless absolutely necessary.
For tRPC subscriptions with trpc-electron, ALWAYS use the observable pattern from@trpc/server/observableinstead of async generators, as the library explicitly checksisObservable(result)and throws an error otherwise
Files:
apps/desktop/src/renderer/lib/sentry.tsapps/desktop/src/main/lib/sentry.ts
apps/desktop/src/main/**/*.ts
📄 CodeRabbit inference engine (AGENTS.md)
Accept object parameters in IPC handlers - do not use positional parameters in ipcMain.handle()
Files:
apps/desktop/src/main/lib/sentry.ts
🧬 Code graph analysis (13)
apps/marketing/src/instrumentation-client.ts (1)
apps/marketing/src/env.ts (1)
env(5-42)
apps/marketing/sentry.server.config.ts (1)
apps/marketing/src/env.ts (1)
env(5-42)
apps/web/sentry.server.config.ts (3)
apps/docs/src/env.ts (1)
env(5-36)apps/marketing/src/env.ts (1)
env(5-42)apps/web/src/env.ts (1)
env(5-53)
apps/docs/src/instrumentation-client.ts (1)
apps/docs/src/env.ts (1)
env(5-36)
apps/docs/sentry.server.config.ts (1)
apps/docs/src/env.ts (1)
env(5-36)
apps/web/src/instrumentation-client.ts (1)
apps/web/src/env.ts (1)
env(5-53)
apps/docs/sentry.edge.config.ts (5)
apps/api/src/env.ts (1)
env(4-41)apps/admin/src/env.ts (1)
env(5-48)apps/docs/src/env.ts (1)
env(5-36)apps/marketing/src/env.ts (1)
env(5-42)apps/web/src/env.ts (1)
env(5-53)
apps/desktop/src/renderer/lib/sentry.ts (2)
apps/desktop/src/main/env.main.ts (1)
env(12-44)apps/desktop/src/renderer/env.renderer.ts (1)
env(45-47)
apps/api/sentry.edge.config.ts (3)
apps/api/src/env.ts (1)
env(4-41)apps/docs/src/env.ts (1)
env(5-36)apps/web/src/env.ts (1)
env(5-53)
apps/api/sentry.server.config.ts (2)
apps/api/src/env.ts (1)
env(4-41)apps/docs/src/env.ts (1)
env(5-36)
apps/marketing/sentry.edge.config.ts (1)
apps/marketing/src/env.ts (1)
env(5-42)
apps/desktop/src/main/lib/sentry.ts (2)
apps/desktop/src/main/env.main.ts (1)
env(12-44)apps/desktop/src/renderer/env.renderer.ts (1)
env(45-47)
apps/web/sentry.edge.config.ts (3)
apps/docs/src/env.ts (1)
env(5-36)apps/marketing/src/env.ts (1)
env(5-42)apps/web/src/env.ts (1)
env(5-53)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: Deploy API
- GitHub Check: Deploy Web
- GitHub Check: Deploy Marketing
- GitHub Check: Deploy Docs
- GitHub Check: Deploy Admin
- GitHub Check: Build
🔇 Additional comments (4)
apps/desktop/src/main/lib/sentry.ts (2)
8-10: Good defensive gating for Sentry initialization.The dual check ensures Sentry only initializes when both the DSN is present AND the environment is production. This is safer than checking environment alone, as it prevents initialization with missing credentials.
19-19: tracesSampleRate simplification is appropriate.Since Sentry now only initializes in production (Line 8), the constant value of 0.1 is correct and eliminates unnecessary conditional logic. This aligns with the PR objective to simplify desktop configuration.
apps/desktop/src/renderer/lib/sentry.ts (2)
8-10: Good defensive gating for Sentry initialization.Consistent with the main process, this dual check ensures Sentry only initializes when both the DSN is present AND the environment is production, preventing initialization issues in non-production or misconfigured environments.
19-19: tracesSampleRate simplification is appropriate.Since initialization is now production-only (Line 8), the constant 0.1 value removes unnecessary branching logic while maintaining the intended production sampling rate.
| dsn: env.NEXT_PUBLIC_SENTRY_DSN_API, | ||
| environment: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT, | ||
| enabled: !!env.NEXT_PUBLIC_SENTRY_DSN_API, | ||
| enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production", |
There was a problem hiding this comment.
Consider defensive check: verify DSN presence before enabling.
The enabled flag should verify both the environment and DSN presence to prevent enabling Sentry without a valid DSN in production.
🔎 Suggested defensive fix
- enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production",
+ enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production" && !!env.NEXT_PUBLIC_SENTRY_DSN_API,📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production", | |
| enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production" && !!env.NEXT_PUBLIC_SENTRY_DSN_API, |
🤖 Prompt for AI Agents
In apps/api/sentry.edge.config.ts around line 8, the enabled flag currently only
checks for production but can be true without a valid DSN; change the logic to
require both production environment and a non-empty Sentry DSN (e.g.
process.env.SENTRY_DSN or process.env.NEXT_PUBLIC_SENTRY_DSN as appropriate)
before enabling Sentry, performing a defensive truthiness check (trim/length) so
Sentry is only enabled when running in production AND a valid DSN exists.
| dsn: env.NEXT_PUBLIC_SENTRY_DSN_API, | ||
| environment: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT, | ||
| enabled: !!env.NEXT_PUBLIC_SENTRY_DSN_API, | ||
| enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production", |
There was a problem hiding this comment.
Consider defensive check: verify DSN presence before enabling.
The enabled flag should verify both the environment and DSN presence to prevent enabling Sentry without valid credentials in production.
🔎 Suggested defensive fix
- enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production",
+ enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production" && !!env.NEXT_PUBLIC_SENTRY_DSN_API,📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production", | |
| enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production" && !!env.NEXT_PUBLIC_SENTRY_DSN_API, |
🤖 Prompt for AI Agents
In apps/api/sentry.server.config.ts around line 8, the enabled flag only checks
the environment and may enable Sentry in production even when no DSN is
provided; update the enabled calculation to require both production environment
AND a present, non-empty DSN (e.g., check process.env.SENTRY_DSN or
process.env.NEXT_PUBLIC_SENTRY_DSN with a trim() truthy check) so Sentry is only
enabled when credentials exist.
| dsn: env.NEXT_PUBLIC_SENTRY_DSN_MARKETING, | ||
| environment: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT, | ||
| enabled: !!env.NEXT_PUBLIC_SENTRY_DSN_MARKETING, | ||
| enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production", |
There was a problem hiding this comment.
Consider defensive check: verify DSN presence before enabling.
The enabled flag should verify both the environment and DSN presence to avoid runtime issues if the DSN is missing in production.
🔎 Suggested defensive fix
- enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production",
+ enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production" && !!env.NEXT_PUBLIC_SENTRY_DSN_MARKETING,📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production", | |
| enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production" && !!env.NEXT_PUBLIC_SENTRY_DSN_MARKETING, |
🤖 Prompt for AI Agents
In apps/marketing/sentry.edge.config.ts around line 8, the enabled flag
currently only checks the environment and should also verify that the Sentry DSN
is present; change the logic to enable Sentry only when
env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production" AND a non-empty
env.NEXT_PUBLIC_SENTRY_DSN exists (e.g., check
Boolean(env.NEXT_PUBLIC_SENTRY_DSN) or trim and length > 0) so production
without a DSN does not try to initialize Sentry.
| dsn: env.NEXT_PUBLIC_SENTRY_DSN_MARKETING, | ||
| environment: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT, | ||
| enabled: !!env.NEXT_PUBLIC_SENTRY_DSN_MARKETING, | ||
| enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production", |
There was a problem hiding this comment.
Consider defensive check: verify DSN presence before enabling.
Similar to other configs, the enabled flag now depends only on the production environment. If NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production" but NEXT_PUBLIC_SENTRY_DSN_MARKETING is undefined, Sentry will be enabled without a valid DSN.
🔎 Suggested defensive fix
- enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production",
+ enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production" && !!env.NEXT_PUBLIC_SENTRY_DSN_MARKETING,📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production", | |
| enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production" && !!env.NEXT_PUBLIC_SENTRY_DSN_MARKETING, |
🤖 Prompt for AI Agents
In apps/marketing/src/instrumentation-client.ts around line 35, the Sentry
enabled flag currently checks only for production environment; update it so it
also verifies that process.env.NEXT_PUBLIC_SENTRY_DSN_MARKETING (or
env.NEXT_PUBLIC_SENTRY_DSN_MARKETING depending on how env is referenced in this
file) is defined and non-empty before enabling. Change the logic to set enabled
to true only when environment === "production" AND the DSN string exists
(trimmed and non-empty), otherwise set enabled false, and ensure any downstream
initialization respects this combined check.
| dsn: env.NEXT_PUBLIC_SENTRY_DSN_WEB, | ||
| environment: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT, | ||
| enabled: !!env.NEXT_PUBLIC_SENTRY_DSN_WEB, | ||
| enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production", |
There was a problem hiding this comment.
Consider defensive check: verify DSN presence before enabling.
The enabled flag now depends solely on the production environment, but the DSN is optional and may be undefined. If NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production" but NEXT_PUBLIC_SENTRY_DSN_WEB is missing, Sentry will be enabled without a valid DSN, potentially causing runtime warnings or silent failures.
🔎 Suggested defensive fix
- enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production",
+ enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production" && !!env.NEXT_PUBLIC_SENTRY_DSN_WEB,📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production", | |
| enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production" && !!env.NEXT_PUBLIC_SENTRY_DSN_WEB, |
🤖 Prompt for AI Agents
In apps/web/sentry.edge.config.ts around line 8, the enabled flag currently only
checks NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production" which can enable Sentry
even when NEXT_PUBLIC_SENTRY_DSN_WEB is missing; update the logic to verify the
DSN exists too by checking env.NEXT_PUBLIC_SENTRY_DSN_WEB (or its proper config
key) alongside the environment before setting enabled, so Sentry is only enabled
when both environment === "production" and a non-empty DSN is present.
| dsn: env.NEXT_PUBLIC_SENTRY_DSN_WEB, | ||
| environment: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT, | ||
| enabled: !!env.NEXT_PUBLIC_SENTRY_DSN_WEB, | ||
| enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production", |
There was a problem hiding this comment.
Consider defensive check: verify DSN presence before enabling.
The enabled flag should verify both the environment and DSN presence to prevent enabling Sentry without a valid DSN.
🔎 Suggested defensive fix
- enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production",
+ enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production" && !!env.NEXT_PUBLIC_SENTRY_DSN_WEB,📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production", | |
| enabled: env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production" && !!env.NEXT_PUBLIC_SENTRY_DSN_WEB, |
🤖 Prompt for AI Agents
In apps/web/sentry.server.config.ts around line 8, the enabled flag currently
only checks the environment; update it to also verify the Sentry DSN exists and
is non-empty before enabling. Change the logic so enabled is true only when
env.NEXT_PUBLIC_SENTRY_ENVIRONMENT === "production" AND a truthy
env.NEXT_PUBLIC_SENTRY_DSN (e.g., check for non-empty string or trim() length),
ensuring you read the correct env var name and treat missing/empty DSN as
disabled.
Summary
Test plan
NEXT_PUBLIC_SENTRY_ENVIRONMENT !== "production"🤖 Generated with Claude Code
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.