Skip to content

Commit

Permalink
feat: load sentry DSN from env
Browse files Browse the repository at this point in the history
The implementation should support
Sentry credentials being supplied via the
environment.

This allows us to use seperate Sentry projects
for individual installs and eventually remove
the credentials from our codebase entirely
instead moving this key to be supplied via
CI environment variables.

In addition to this change we are adding
support for Sentry's concept of environments.
We are using the `siteVariant` to acheive this.

This allows us to filter the errors and understand
how our production environment is performing compared
to our various staging and development environment.
  • Loading branch information
thisislawatts committed Nov 20, 2021
1 parent 21e6db5 commit 6707ff9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/common/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export const initErrorHandler = () => {
location.search.indexOf('noSentry=true') !== -1 ||
location.hostname === 'localhost'
) {
console.log('No error handler for this environment')
return
}

// please check https://docs.sentry.io/error-reporting/configuration/?platform=javascript for options
Sentry.init({
dsn: SENTRY_CONFIG.dsn,
})
Sentry.init(SENTRY_CONFIG)
}
12 changes: 8 additions & 4 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ import { UserRole } from 'src/models'
Dev/Staging
/********************************************************************************************** */

let sentryConfig: ISentryConfig = {
dsn: 'https://8c1f7eb4892e48b18956af087bdfa3ac@sentry.io/1399729',
}
// note - algolia lets you have multiple apps which can serve different purposes
// (and all have their own free quotas)
let algoliaSearchConfig: IAlgoliaConfig = {
Expand Down Expand Up @@ -166,7 +163,13 @@ export const DEV_SITE_ROLE = devSiteRole
export const FIREBASE_CONFIG = firebaseConfigs[siteVariant]
export const ALGOLIA_SEARCH_CONFIG = algoliaSearchConfig
export const ALGOLIA_PLACES_CONFIG = algoliaPlacesConfig
export const SENTRY_CONFIG = sentryConfig
export const SENTRY_CONFIG: ISentryConfig = {
dsn:
process.env.REACT_APP_SENTRY_DSN ||
'https://8c1f7eb4892e48b18956af087bdfa3ac@sentry.io/1399729',
environment: siteVariant,
}

export const VERSION = require('../../package.json').version
export const GA_TRACKING_ID = process.env.REACT_APP_GA_TRACKING_ID

Expand All @@ -184,6 +187,7 @@ interface IFirebaseConfig {
}
interface ISentryConfig {
dsn: string
environment: string
}
interface IAlgoliaConfig {
searchOnlyAPIKey: string
Expand Down

0 comments on commit 6707ff9

Please sign in to comment.