From a4e5b05656c6440a424bfa04b06538924c8ef78b Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 14 Jan 2022 14:40:15 -0600 Subject: [PATCH] Make Sentry DSN configurable --- app/soapbox/actions/soapbox.js | 1 + app/soapbox/features/soapbox_config/index.js | 10 ++++++++++ app/soapbox/main.js | 6 ++++-- app/soapbox/monitoring.js | 6 +++--- app/soapbox/reducers/soapbox.js | 8 ++++++++ 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/app/soapbox/actions/soapbox.js b/app/soapbox/actions/soapbox.js index d85bd0f0f..34dd32ae3 100644 --- a/app/soapbox/actions/soapbox.js +++ b/app/soapbox/actions/soapbox.js @@ -59,6 +59,7 @@ export const makeDefaultConfig = features => { }), aboutPages: ImmutableMap(), authenticatedProfile: true, + sentryDsn: '', }); }; diff --git a/app/soapbox/features/soapbox_config/index.js b/app/soapbox/features/soapbox_config/index.js index 5ec7f0b39..139c18009 100644 --- a/app/soapbox/features/soapbox_config/index.js +++ b/app/soapbox/features/soapbox_config/index.js @@ -38,6 +38,8 @@ const messages = defineMessages({ heading: { id: 'column.soapbox_config', defaultMessage: 'Soapbox config' }, saved: { id: 'soapbox_config.saved', defaultMessage: 'Soapbox config saved!' }, copyrightFooterLabel: { id: 'soapbox_config.copyright_footer.meta_fields.label_placeholder', defaultMessage: 'Copyright footer' }, + sentryDsnLabel: { id: 'soapbox_config.sentry_dsn_label', defaultMessage: 'Sentry DSN' }, + sentryDsnHint: { id: 'soapbox_config.sentry_dsn_hint', defaultMessage: 'Enable error monitoring with a Sentry-compatible DSN.' }, promoItemIcon: { id: 'soapbox_config.promo_panel.meta_fields.icon_placeholder', defaultMessage: 'Icon' }, promoItemLabel: { id: 'soapbox_config.promo_panel.meta_fields.label_placeholder', defaultMessage: 'Label' }, promoItemURL: { id: 'soapbox_config.promo_panel.meta_fields.url_placeholder', defaultMessage: 'URL' }, @@ -264,6 +266,14 @@ class SoapboxConfig extends ImmutablePureComponent { value={soapbox.get('copyright')} onChange={this.handleChange(['copyright'], (e) => e.target.value)} /> + e.target.value)} + /> { const mountNode = document.getElementById('soapbox'); diff --git a/app/soapbox/monitoring.js b/app/soapbox/monitoring.js index adb99a891..a069679c0 100644 --- a/app/soapbox/monitoring.js +++ b/app/soapbox/monitoring.js @@ -1,12 +1,12 @@ -import { NODE_ENV, SENTRY_DSN } from 'soapbox/build_config'; +import { NODE_ENV } from 'soapbox/build_config'; -export const start = () => { +export const start = (dsn) => { Promise.all([ import(/* webpackChunkName: "error" */'@sentry/react'), import(/* webpackChunkName: "error" */'@sentry/tracing'), ]).then(([Sentry, { Integrations: Integrations }]) => { Sentry.init({ - dsn: SENTRY_DSN, + dsn, environment: NODE_ENV, debug: false, integrations: [new Integrations.BrowserTracing()], diff --git a/app/soapbox/reducers/soapbox.js b/app/soapbox/reducers/soapbox.js index a208b4301..a1b9bb116 100644 --- a/app/soapbox/reducers/soapbox.js +++ b/app/soapbox/reducers/soapbox.js @@ -1,6 +1,7 @@ import { Map as ImmutableMap, fromJS } from 'immutable'; import { PLEROMA_PRELOAD_IMPORT } from 'soapbox/actions/preload'; +import * as monitoring from 'soapbox/monitoring'; import KVStore from 'soapbox/storage/kv_store'; import { ConfigDB } from 'soapbox/utils/config_db'; @@ -46,7 +47,14 @@ const persistSoapboxConfig = (soapboxConfig, host) => { }; const importSoapboxConfig = (state, soapboxConfig, host) => { + const sentryDsn = soapboxConfig.get('sentryDsn'); + persistSoapboxConfig(soapboxConfig, host); + + if (sentryDsn) { + monitoring.start(sentryDsn); + } + return soapboxConfig; };