From a75615707b1b93565e15755873e5d08120df669c Mon Sep 17 00:00:00 2001 From: Hannu Lyytikainen Date: Thu, 28 Sep 2017 17:18:27 +0300 Subject: [PATCH] Remove Sentry config from logger setup functions The Sentry DSN key and environment are read from environment parameters/config in the logger modules. --- server/index.js | 6 ++---- server/log.js | 14 ++++++-------- src/index.js | 2 +- src/util/log.js | 9 ++++----- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/server/index.js b/server/index.js index 14a5d983..0e13a50b 100644 --- a/server/index.js +++ b/server/index.js @@ -31,21 +31,19 @@ const fs = require('fs'); const log = require('./log'); const buildPath = path.resolve(__dirname, '..', 'build'); -const ENV = process.env.NODE_ENV; +const dev = process.env.NODE_ENV !== 'production'; const PORT = process.env.PORT || 4000; const CLIENT_ID = process.env.REACT_APP_SHARETRIBE_SDK_CLIENT_ID || '08ec69f6-d37e-414d-83eb-324e94afddf0'; const BASE_URL = process.env.REACT_APP_SHARETRIBE_SDK_BASE_URL || 'http://localhost:8088'; const ENFORCE_SSL = process.env.SERVER_SHARETRIBE_ENFORCE_SSL === 'true'; const TRUST_PROXY = process.env.SERVER_SHARETRIBE_TRUST_PROXY || null; -const SENTRY_DSN = process.env.SERVER_SENTRY_DSN; -const dev = ENV !== 'production'; const app = express(); const errorPage = fs.readFileSync(path.join(buildPath, '500.html'), 'utf-8'); // Setup error logger -log.setup(SENTRY_DSN, ENV); +log.setup(); // Add logger request handler. In case Sentry is set up // request information is added to error context when sent // to Sentry. diff --git a/server/log.js b/server/log.js index 52d15e9b..a274bbff 100644 --- a/server/log.js +++ b/server/log.js @@ -6,23 +6,21 @@ const Raven = require('raven'); -// Sentry client key -let SENTRY_DSN; +const ENV = process.env.NODE_ENV; +const SENTRY_DSN = process.env.SERVER_SENTRY_DSN; /** * Set up error loggin. If a Sentry DSN is defined * Sentry client is configured. */ -exports.setup = (sentryDsn, env) => { - if (sentryDsn) { - Raven.config(sentryDsn, { - environment: env, +exports.setup = () => { + if (SENTRY_DSN) { + Raven.config(SENTRY_DSN, { + environment: ENV, autoBreadcrumbs: { http: true, }, }).install(); - - SENTRY_DSN = sentryDsn; } }; diff --git a/src/index.js b/src/index.js index d3695e1f..416f40f2 100644 --- a/src/index.js +++ b/src/index.js @@ -56,7 +56,7 @@ const setupStripe = () => { // If we're in a browser already, render the client application. if (typeof window !== 'undefined') { // set up logger with Sentry DSN client key and environment - log.setup(config.sentryDsn, config.env); + log.setup(); // eslint-disable-next-line no-underscore-dangle const preloadedState = window.__PRELOADED_STATE__ || '{}'; diff --git a/src/util/log.js b/src/util/log.js index ed1c1caf..00492202 100644 --- a/src/util/log.js +++ b/src/util/log.js @@ -7,16 +7,15 @@ */ import Raven from 'raven-js'; +import config from '../config'; /** * Set up error handling. If a Sentry DSN is * provided a Sentry client will be installed. - * - * @param {String} sentryDsn A public Sentry DSN */ -export const setup = (sentryDsn, env) => { - if (sentryDsn !== undefined) { - Raven.config(sentryDsn, { environment: env }).install(); +export const setup = () => { + if (config.sentryDsn !== undefined) { + Raven.config(config.sentryDsn, { environment: config.env }).install(); } };