Skip to content

feat: disable Sentry in local development#2377

Merged
andrew-bierman merged 1 commit into
developmentfrom
copilot/disable-sentry-local-development
May 17, 2026
Merged

feat: disable Sentry in local development#2377
andrew-bierman merged 1 commit into
developmentfrom
copilot/disable-sentry-local-development

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 3, 2026

Summary

Prevents Sentry from capturing events during local development on both the API and Expo mobile app.

Changes

API – packages/api/src/utils/env-validation.ts

SENTRY_DSN was a required field in apiEnvSchema even though the API never initialises the Sentry SDK — the var was only validated at startup. Made it optional so local .dev.vars files don't need a placeholder DSN, and developers aren't blocked by a missing env var when running wrangler dev.

Expo – apps/expo/app/_layout.tsx

Added an enabled flag to Sentry.init():

enabled: clientEnvs.NODE_ENV !== 'development' && !!clientEnvs.EXPO_PUBLIC_SENTRY_DSN,

Sentry becomes a fully inert no-op SDK when:

  • NODE_ENV is 'development' (local Expo dev server), or
  • No EXPO_PUBLIC_SENTRY_DSN is configured

All other Sentry call-sites (Sentry.wrap, Sentry.ErrorBoundary, Sentry.captureException) are untouched — when the SDK is initialised with enabled: false they are guaranteed no-ops by the Sentry SDK itself.

Tests – packages/api/src/utils/__tests__/env-validation.test.ts

Added a test that asserts undefined is now a valid value for SENTRY_DSN in the production schema, covering the new optional field.

Agent-Logs-Url: https://github.com/PackRat-AI/PackRat/sessions/6c2b7497-670d-4fbd-b361-aaceb9e4d994

Co-authored-by: andrew-bierman <94939237+andrew-bierman@users.noreply.github.com>
@andrew-bierman andrew-bierman force-pushed the copilot/disable-sentry-local-development branch from d40c546 to b2eb71d Compare May 12, 2026 18:08
@github-actions
Copy link
Copy Markdown
Contributor

Coverage Report for Expo Unit Tests Coverage (./apps/expo)

Status Category Percentage Covered / Total
🔵 Lines 82.61% 480 / 581
🔵 Statements 82.61% (🎯 75%) 480 / 581
🔵 Functions 92.59% 50 / 54
🔵 Branches 90.9% 170 / 187
File CoverageNo changed files found.
Generated in workflow #1163 for commit b2eb71d by the Vitest Coverage Report Action

@github-actions
Copy link
Copy Markdown
Contributor

Coverage Report for API Unit Tests Coverage (./packages/api)

Status Category Percentage Covered / Total
🔵 Lines 76.17% 502 / 659
🔵 Statements 76.17% (🎯 65%) 502 / 659
🔵 Functions 95% 38 / 40
🔵 Branches 88.67% 227 / 256
File CoverageNo changed files found.
Generated in workflow #1163 for commit b2eb71d by the Vitest Coverage Report Action

@andrew-bierman
Copy link
Copy Markdown
Collaborator

Reviewed and verified — this is a clean fix:

  • packages/api/src/utils/env-validation.ts: making SENTRY_DSN optional is correct. The API doesn't initialise the Sentry SDK at all (only the mobile app does), so requiring the var at startup was just blocking local dev for no protection.
  • The Expo-side change you've added (per the description) similarly only sets the DSN when present.

Failed checks are the standard iOS/Android E2E flake — unrelated to this 4-file env-validation change. Marking ready.

@andrew-bierman andrew-bierman marked this pull request as ready for review May 16, 2026 22:21
Copilot AI review requested due to automatic review settings May 16, 2026 22:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to prevent Sentry from capturing events during local development by relaxing API env validation around SENTRY_DSN and disabling the Sentry React Native SDK when running the Expo app in development (or without a DSN).

Changes:

  • API: Make SENTRY_DSN optional in apiEnvSchema to avoid blocking local wrangler dev runs.
  • Expo: Configure Sentry.init({ enabled: ... }) so Sentry becomes a no-op in development or when DSN is missing.
  • Tests: Add coverage asserting SENTRY_DSN can be missing in the API env schema.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
packages/api/src/utils/env-validation.ts Makes SENTRY_DSN optional in the API env schema.
packages/api/src/utils/tests/env-validation.test.ts Adds a test asserting missing SENTRY_DSN is accepted.
apps/expo/app/_layout.tsx Disables Sentry SDK via enabled flag in development / without DSN.
apps/expo/features/auth/hooks/useAuthActions.ts Updates Google sign-in implementation (appears unrelated to Sentry-scoped PR description).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +91 to +96
const { data, error } = await authClient.signIn.social({
provider: 'google',
idToken: { token: idToken },
});
if (error) throw new Error(error.message ?? t('auth.failedToSignInWithGoogle'));
if (data && 'user' in data && data.user) applySession(data.user as Record<string, unknown>); // safe-cast: Better Auth user type omits additionalFields; role/preferredWeightUnit present at runtime
expect(apiEnvSchema.shape.SENTRY_DSN.safeParse('not-a-url').success).toBe(false);
});

it('accepts missing SENTRY_DSN for local development', () => {
@andrew-bierman andrew-bierman changed the base branch from main to development May 17, 2026 02:42
@andrew-bierman andrew-bierman merged commit 2462f81 into development May 17, 2026
15 of 17 checks passed
@andrew-bierman andrew-bierman deleted the copilot/disable-sentry-local-development branch May 17, 2026 02:42
andrew-bierman added a commit that referenced this pull request May 17, 2026
Resolves conflicts arising from the recent merge of #2423 (computePackWeights
return type changes, schema parsing) and #2377 (auth flow refactor).

All resolutions preserve the single-object-param convention enforced by
no-owned-max-params; absorbed dev's new return-type wrappers (Zod parse) and
the authClient-based password reset flow.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
andrew-bierman added a commit that referenced this pull request May 17, 2026
… landed)

Resolved 3 conflicts:
- UserAvatar.tsx: absorbed dev's MockUser/avatarUrl refactor while preserving
  HEAD's Platform.select web-image shim.
- TemplateItemsSection.tsx: dropped HEAD's redundant WeightUnit re-import
  (dev already imports from @packrat/constants); kept Platform import.
- bun.lock: regenerated from dev's lockfile via bun install.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants