Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 13, 2025

Overview

This PR implements conditional Sentry initialization that ensures error tracking is only active in production environments, preventing development errors from being sent to Sentry when running on localhost.

Problem

Previously, Sentry was initialized unconditionally whenever the VITE_SENTRY_DSN environment variable was set:

Sentry.init({
  dsn: import.meta.env.VITE_SENTRY_DSN,
})

This meant that:

  • Development errors on localhost would be sent to the production Sentry project
  • Developers would clutter error logs with test/development data
  • No way to differentiate between production and development errors

Solution

Implemented environment-aware Sentry initialization that checks the hostname before initializing:

const sentryDsn = import.meta.env.VITE_SENTRY_DSN
if (shouldInitializeSentry(sentryDsn)) {
  Sentry.init({
    dsn: sentryDsn,
  })
}

New Utility Functions (src/lib/sentry.ts)

// Check if running in production (not localhost)
export const isProduction = (): boolean => {
  const hostname = window.location.hostname
  return hostname !== 'localhost' && hostname !== '127.0.0.1'
}

// Determine if Sentry should be initialized
export const shouldInitializeSentry = (dsn: string | undefined): boolean => {
  return Boolean(dsn) && isProduction()
}

Behavior

Environment DSN Set Sentry Initialized?
localhost ❌ No
127.0.0.1 ❌ No
arkade.money ✅ Yes
dev.arkade.money ✅ Yes
next.arkade.money ✅ Yes
(any domain) ❌ No

Sentry will initialize only when:

  • VITE_SENTRY_DSN environment variable is set
  • AND the application is NOT running on localhost or 127.0.0.1

Changes

  • src/lib/sentry.ts (NEW): Added utility functions for environment detection and Sentry initialization logic
  • src/index.tsx: Updated Sentry initialization to be conditional based on environment
  • src/vite-env.d.ts: Added TypeScript type definitions for environment variables (VITE_SENTRY_DSN, VITE_ARK_SERVER, VITE_BOLTZ_URL); removed deprecated VITE_IS_RIGA
  • src/test/lib/sentry.test.ts (NEW): Added 11 comprehensive test cases covering all scenarios
  • README.md: Updated documentation to clarify that Sentry only works in production

Merge with Master

This PR includes a merge with the latest master branch (commit fce53cf - "Cleanup #156"), which includes:

  • Removal of IframeProvider and related iframe functionality
  • Removal of deprecated isRiga constant from src/lib/constants.ts
  • Deletion of unused files: src/components/Minimal.tsx, src/lib/alerts.ts, src/providers/iframe.tsx
  • Various cleanup updates across multiple screen components

Testing

111 tests pass (including 11 new Sentry-specific tests)

  • Tests for isProduction() with various hostnames (localhost, 127.0.0.1, production domains)
  • Tests for shouldInitializeSentry() with different DSN and hostname combinations

All quality checks pass:

  • Linting: No errors
  • TypeScript compilation: No errors
  • Build: Successful
  • CodeQL security scan: 0 alerts

Usage

Development

# Sentry will NOT initialize on localhost
pnpm run start

Production

# Set the DSN, build, and deploy to production
VITE_SENTRY_DSN=https://your-dsn@sentry.io/project pnpm run build
# Sentry will initialize when accessed from production domains

Benefits

  • 🛡️ Cleaner development experience: No Sentry errors during local development
  • 🎯 Environment-aware: Automatically detects production vs development
  • 🔒 Secure: Prevents development errors from reaching production Sentry
  • Well-tested: 11 comprehensive test cases ensure correctness
  • 📝 Documented: Clear README and inline documentation
  • 🔧 Type-safe: Full TypeScript support
  • 🧹 Up-to-date: Merged with latest master cleanup changes
Original prompt

Make sure SENTRY DSN can be passed via ENV VARS and be used only when the build is in production (ie. not localhost)


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 13, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Oct 13, 2025

Deploying wallet-signet with  Cloudflare Pages  Cloudflare Pages

Latest commit: 12e0515
Status: ✅  Deploy successful!
Preview URL: https://f11fb835.wallet-23u.pages.dev
Branch Preview URL: https://copilot-add-sentry-dsn-env-s.wallet-23u.pages.dev

View logs

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Oct 13, 2025

Deploying wallet-mutinynet with  Cloudflare Pages  Cloudflare Pages

Latest commit: 12e0515
Status: ✅  Deploy successful!
Preview URL: https://b17a83a6.arkade-wallet.pages.dev
Branch Preview URL: https://copilot-add-sentry-dsn-env-s.arkade-wallet.pages.dev

View logs

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Oct 13, 2025

Deploying wallet-bitcoin-v8 with  Cloudflare Pages  Cloudflare Pages

Latest commit: 12e0515
Status: ✅  Deploy successful!
Preview URL: https://2d921f1b.wallet-v8.pages.dev
Branch Preview URL: https://copilot-add-sentry-dsn-env-s.wallet-v8.pages.dev

View logs

Copilot AI and others added 2 commits October 13, 2025 12:23
Co-authored-by: tiero <3596602+tiero@users.noreply.github.com>
Co-authored-by: tiero <3596602+tiero@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for passing SENTRY DSN via environment variables Add conditional Sentry initialization based on environment (production only) Oct 13, 2025
Copilot AI requested a review from tiero October 13, 2025 12:31
@tiero
Copy link
Member

tiero commented Oct 13, 2025

@copilot merge master, solve conflicts and remove VITE_IS_RIGA as in master we have cleaned up

Co-authored-by: tiero <3596602+tiero@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 13, 2025

@copilot merge master, solve conflicts and remove VITE_IS_RIGA as in master we have cleaned up

Done! Successfully merged master branch and removed VITE_IS_RIGA from TypeScript definitions. All conflicts resolved automatically, tests pass, and build succeeds. Commit: ea4ae40 → (merge commit will be created)

@cloudflare-workers-and-pages
Copy link

Deploying wallet-bitcoin with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8ee174a
Status: ✅  Deploy successful!
Preview URL: https://9ace442a.wallet-bitcoin.pages.dev
Branch Preview URL: https://copilot-add-sentry-dsn-env-s.wallet-bitcoin.pages.dev

View logs

Signed-off-by: Marco Argentieri <3596602+tiero@users.noreply.github.com>
@tiero tiero marked this pull request as ready for review October 13, 2025 15:57
@tiero tiero requested a review from bordalix October 13, 2025 15:58
Copy link
Collaborator

@bordalix bordalix left a comment

Choose a reason for hiding this comment

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

ACK

@tiero tiero merged commit 0d98259 into master Oct 14, 2025
5 checks passed
@bordalix bordalix deleted the copilot/add-sentry-dsn-env-support branch November 26, 2025 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants