From e412d9b5329cb3f39d423c1fa953a065174d9718 Mon Sep 17 00:00:00 2001 From: Anastasia Poupeney Date: Wed, 13 Jun 2018 15:13:21 +0200 Subject: [PATCH] wip sentry logs --- src/helpers/db.js | 2 +- src/helpers/user.js | 15 +++++++++++++++ src/init-sentry.js | 6 +++--- src/main/index.js | 2 +- src/middlewares/sentry.js | 19 +++++++++++++++++++ src/reducers/settings.js | 3 ++- src/renderer/createStore.js | 4 ++-- src/renderer/index.js | 4 ++-- src/renderer/init.js | 3 +++ src/renderer/sentry/browser.js | 19 +++++++++++++++++++ src/renderer/sentry/node.js | 0 11 files changed, 67 insertions(+), 10 deletions(-) create mode 100644 src/helpers/user.js create mode 100644 src/middlewares/sentry.js create mode 100644 src/renderer/sentry/browser.js create mode 100644 src/renderer/sentry/node.js diff --git a/src/helpers/db.js b/src/helpers/db.js index 19968185..fb1dfa65 100644 --- a/src/helpers/db.js +++ b/src/helpers/db.js @@ -6,7 +6,7 @@ import get from 'lodash/get' import { decodeAccountsModel, encodeAccountsModel } from 'reducers/accounts' -type DBKey = 'settings' | 'accounts' | 'countervalues' +type DBKey = 'settings' | 'accounts' | 'countervalues' | 'user' const encryptionKey = {} diff --git a/src/helpers/user.js b/src/helpers/user.js new file mode 100644 index 00000000..15a8b7cb --- /dev/null +++ b/src/helpers/user.js @@ -0,0 +1,15 @@ +// @flow + +import db from 'helpers/db' +import uuid from 'uuid/v4' + +// a user is an anonymous way to identify a same instance of the app + +export default () => { + let user = db.get('user') + if (!user) { + user = { id: uuid() } + db.set('user', user) + } + return user +} diff --git a/src/init-sentry.js b/src/init-sentry.js index 1af0c815..663c6840 100644 --- a/src/init-sentry.js +++ b/src/init-sentry.js @@ -1,7 +1,7 @@ const { SENTRY_URL } = process.env if (__PROD__ && SENTRY_URL) { - const Raven = require('raven') - const ravenConfig = { captureUnhandledRejections: true } - Raven.config(SENTRY_URL, ravenConfig).install() + // const Raven = require('raven') + // const ravenConfig = { captureUnhandledRejections: true } + // Raven.config(SENTRY_URL, ravenConfig).install() } diff --git a/src/main/index.js b/src/main/index.js index c0d18749..3670ac42 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -4,7 +4,7 @@ process.setMaxListeners(0) require('../env') require('../globals') -require('../init-sentry') +// require('../init-sentry') require('./app') setImmediate(() => require('./bridge')) diff --git a/src/middlewares/sentry.js b/src/middlewares/sentry.js new file mode 100644 index 00000000..479be983 --- /dev/null +++ b/src/middlewares/sentry.js @@ -0,0 +1,19 @@ +const Raven = require('raven-js') +require('../env') + +import { sentryLogsBooleanSelector } from 'reducers/settings' + +const { SENTRY_URL } = process.env + +let isSentryInstalled = false + +export default store => next => action => { + next(action) + if (__PROD__ && SENTRY_URL) { + const state = store.getState() + const sentryLogs = sentryLogsBooleanSelector(state) + // if (sentryLogs !== isSentryInstalled) { + // + // } + } +} diff --git a/src/reducers/settings.js b/src/reducers/settings.js index fbe330f6..fc1aa1ca 100644 --- a/src/reducers/settings.js +++ b/src/reducers/settings.js @@ -73,7 +73,7 @@ const INITIAL_STATE: SettingsState = { developerMode: !!process.env.__DEV__, loaded: false, shareAnalytics: false, - sentryLogs: false, + sentryLogs: true, lastUsedVersion: __APP_VERSION__, } @@ -214,5 +214,6 @@ export const exchangeSettingsForAccountSelector: ESFAS = createSelector( ) export const marketIndicatorSelector = (state: State) => state.settings.marketIndicator +export const sentryLogsBooleanSelector = (state: State) => state.settings.sentryLogs export default handleActions(handlers, INITIAL_STATE) diff --git a/src/renderer/createStore.js b/src/renderer/createStore.js index 6e14fa5e..75f46711 100644 --- a/src/renderer/createStore.js +++ b/src/renderer/createStore.js @@ -6,7 +6,7 @@ import thunk from 'redux-thunk' import createHistory from 'history/createHashHistory' import type { HashHistory } from 'history' import logger from 'middlewares/logger' - +import sentry from 'middlewares/sentry' import reducers from 'reducers' type Props = { @@ -20,7 +20,7 @@ export default ({ state, history, dbMiddleware }: Props) => { if (!history) { history = createHistory() } - const middlewares = [routerMiddleware(history), thunk, logger] + const middlewares = [routerMiddleware(history), thunk, logger, sentry] if (dbMiddleware) { middlewares.push(dbMiddleware) } diff --git a/src/renderer/index.js b/src/renderer/index.js index d65ad8bf..5ae7edce 100644 --- a/src/renderer/index.js +++ b/src/renderer/index.js @@ -7,8 +7,8 @@ require('../env') const { SENTRY_URL } = process.env if (__PROD__ && SENTRY_URL) { - Raven.config(SENTRY_URL, { allowSecretKey: true }).install() - window.addEventListener('unhandledrejection', event => Raven.captureException(event.reason)) + // Raven.config(SENTRY_URL, { allowSecretKey: true }).install() + // window.addEventListener('unhandledrejection', event => Raven.captureException(event.reason)) } require('./init') diff --git a/src/renderer/init.js b/src/renderer/init.js index 6ef76a10..7bc6fe3d 100644 --- a/src/renderer/init.js +++ b/src/renderer/init.js @@ -15,6 +15,7 @@ import { fetchAccounts } from 'actions/accounts' import { fetchSettings } from 'actions/settings' import { isLocked } from 'reducers/application' import { getLanguage } from 'reducers/settings' +import { sentryLogsBooleanSelector } from 'reducers/settings' import libcoreGetVersion from 'commands/libcoreGetVersion' import db from 'helpers/db' @@ -22,6 +23,7 @@ import dbMiddleware from 'middlewares/db' import CounterValues from 'helpers/countervalues' import hardReset from 'helpers/hardReset' +import sentry from 'renderer/sentry/browser' import App from 'components/App' import 'styles/global' @@ -50,6 +52,7 @@ async function init() { const state = store.getState() const language = getLanguage(state) const locked = isLocked(state) + sentry(() => sentryLogsBooleanSelector(store.getState())) moment.locale(language) diff --git a/src/renderer/sentry/browser.js b/src/renderer/sentry/browser.js new file mode 100644 index 00000000..9ee54b29 --- /dev/null +++ b/src/renderer/sentry/browser.js @@ -0,0 +1,19 @@ +const Raven = require('raven-js') +require('../../env') +import user from 'helpers/user' + +const { SENTRY_URL } = process.env + +export default shouldSendCallback => { + Raven.config(SENTRY_URL, { + allowSecretKey: true, + release: __APP_VERSION__, + environment: __DEV__ ? 'development' : 'production', + shouldSendCallback, + }) + .setUserContext({ + ip_address: null, + id: user().id, + }) + .install() +} diff --git a/src/renderer/sentry/node.js b/src/renderer/sentry/node.js new file mode 100644 index 00000000..e69de29b