From 55387b06c444357893310c5bbc7d6a0543f6e162 Mon Sep 17 00:00:00 2001 From: Anastasia Poupeney Date: Wed, 13 Jun 2018 15:13:21 +0200 Subject: [PATCH 01/14] 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 From 070ae1c5322a8cd3165df96245589407b9c2ba6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Wed, 13 Jun 2018 15:53:06 +0200 Subject: [PATCH 02/14] connect Sentry to main & internal processes --- src/commands/testCrash.js | 8 ++++---- src/init-sentry.js | 7 ------- src/internals/index.js | 9 ++++++++- src/main/bridge.js | 21 ++++++++++++++++++++- src/main/index.js | 1 - src/middlewares/sentry.js | 17 ++++++----------- src/renderer/index.js | 11 ----------- src/renderer/init.js | 5 ++--- src/renderer/sentry/browser.js | 19 ------------------- src/renderer/sentry/node.js | 0 src/sentry/browser.js | 9 +++++++++ src/sentry/install.js | 26 ++++++++++++++++++++++++++ src/sentry/node.js | 8 ++++++++ 13 files changed, 83 insertions(+), 58 deletions(-) delete mode 100644 src/init-sentry.js delete mode 100644 src/renderer/sentry/browser.js delete mode 100644 src/renderer/sentry/node.js create mode 100644 src/sentry/browser.js create mode 100644 src/sentry/install.js create mode 100644 src/sentry/node.js diff --git a/src/commands/testCrash.js b/src/commands/testCrash.js index 0725988a..5675a1ee 100644 --- a/src/commands/testCrash.js +++ b/src/commands/testCrash.js @@ -8,10 +8,10 @@ import { createCommand, Command } from 'helpers/ipc' type Input = void type Result = void -const cmd: Command = createCommand('testCrash', () => - Observable.create(() => { +const cmd: Command = createCommand('testCrash', () => { + return Observable.create(() => { process.exit(1) - }), -) + }) +}) export default cmd diff --git a/src/init-sentry.js b/src/init-sentry.js deleted file mode 100644 index 663c6840..00000000 --- a/src/init-sentry.js +++ /dev/null @@ -1,7 +0,0 @@ -const { SENTRY_URL } = process.env - -if (__PROD__ && SENTRY_URL) { - // const Raven = require('raven') - // const ravenConfig = { captureUnhandledRejections: true } - // Raven.config(SENTRY_URL, ravenConfig).install() -} diff --git a/src/internals/index.js b/src/internals/index.js index 94601aaa..f2879c08 100644 --- a/src/internals/index.js +++ b/src/internals/index.js @@ -3,14 +3,18 @@ import commands from 'commands' import logger from 'logger' import uuid from 'uuid/v4' import { setImplementation } from 'api/network' +import sentry from 'sentry/node' require('../env') -require('../init-sentry') process.title = 'Internal' const defers = {} +let sentryEnabled = process.env.INITIAL_SENTRY_ENABLED || false + +sentry(() => sentryEnabled, process.env.SENTRY_USER_ID) + if (process.env.DEBUG_NETWORK) { setImplementation(networkArg => { const id = uuid() @@ -92,6 +96,9 @@ process.on('message', m => { } else { defer.reject(payload.error) } + } else if (m.type === 'sentryLogsChanged') { + const { payload } = m + sentryEnabled = payload.value } }) diff --git a/src/main/bridge.js b/src/main/bridge.js index ff9af1ab..bd118629 100644 --- a/src/main/bridge.js +++ b/src/main/bridge.js @@ -7,6 +7,8 @@ import { ipcMain, app } from 'electron' import { ipcMainListenReceiveCommands } from 'helpers/ipc' import path from 'path' import logger from 'logger' +import sentry from 'sentry/node' +import user from 'helpers/user' import setupAutoUpdater, { quitAndInstall } from './autoUpdate' @@ -17,6 +19,11 @@ const LEDGER_LIVE_SQLITE_PATH = path.resolve(app.getPath('userData'), 'sqlite') let internalProcess +let sentryEnabled = false +const userId = user().id + +sentry(() => sentryEnabled, userId) + const killInternalProcess = () => { if (internalProcess) { logger.log('killing internal process...') @@ -30,7 +37,12 @@ const forkBundlePath = path.resolve(__dirname, `${__DEV__ ? '../../' : './'}dist const bootInternalProcess = () => { logger.log('booting internal process...') internalProcess = fork(forkBundlePath, { - env: { ...process.env, LEDGER_LIVE_SQLITE_PATH }, + env: { + ...process.env, + LEDGER_LIVE_SQLITE_PATH, + INITIAL_SENTRY_ENABLED: sentryEnabled, + SENTRY_USER_ID: userId, + }, }) internalProcess.on('message', handleGlobalInternalMessage) internalProcess.on('exit', code => { @@ -102,6 +114,13 @@ ipcMain.on('executeHttpQueryPayload', (event, payload) => { p.send({ type: 'executeHttpQueryPayload', payload }) }) +ipcMain.on('sentryLogsChanged', (event, payload) => { + sentryEnabled = payload.value + const p = internalProcess + if (!p) return + p.send({ type: 'sentryLogsChanged', payload }) +}) + // TODO move this to "command" pattern ipcMain.on('updater', (event, { type, data }) => { const handler = { diff --git a/src/main/index.js b/src/main/index.js index 3670ac42..65952b72 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -4,7 +4,6 @@ process.setMaxListeners(0) require('../env') require('../globals') -// require('../init-sentry') require('./app') setImmediate(() => require('./bridge')) diff --git a/src/middlewares/sentry.js b/src/middlewares/sentry.js index 479be983..212764c6 100644 --- a/src/middlewares/sentry.js +++ b/src/middlewares/sentry.js @@ -1,19 +1,14 @@ -const Raven = require('raven-js') -require('../env') - +import { ipcRenderer } from 'electron' 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) { - // - // } + const state = store.getState() + const sentryLogs = sentryLogsBooleanSelector(state) + if (sentryLogs !== isSentryInstalled) { + isSentryInstalled = sentryLogs + ipcRenderer.send('sentryLogsChanged', { value: sentryLogs }) } } diff --git a/src/renderer/index.js b/src/renderer/index.js index 5ae7edce..5164fc17 100644 --- a/src/renderer/index.js +++ b/src/renderer/index.js @@ -1,14 +1,3 @@ require('@babel/polyfill') - -const Raven = require('raven-js') - 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)) -} - require('./init') diff --git a/src/renderer/init.js b/src/renderer/init.js index 7bc6fe3d..c9e77136 100644 --- a/src/renderer/init.js +++ b/src/renderer/init.js @@ -14,8 +14,7 @@ import events from 'renderer/events' 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 { getLanguage, sentryLogsBooleanSelector } from 'reducers/settings' import libcoreGetVersion from 'commands/libcoreGetVersion' import db from 'helpers/db' @@ -23,7 +22,7 @@ import dbMiddleware from 'middlewares/db' import CounterValues from 'helpers/countervalues' import hardReset from 'helpers/hardReset' -import sentry from 'renderer/sentry/browser' +import sentry from 'sentry/browser' import App from 'components/App' import 'styles/global' diff --git a/src/renderer/sentry/browser.js b/src/renderer/sentry/browser.js deleted file mode 100644 index 9ee54b29..00000000 --- a/src/renderer/sentry/browser.js +++ /dev/null @@ -1,19 +0,0 @@ -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 deleted file mode 100644 index e69de29b..00000000 diff --git a/src/sentry/browser.js b/src/sentry/browser.js new file mode 100644 index 00000000..ac5fc55c --- /dev/null +++ b/src/sentry/browser.js @@ -0,0 +1,9 @@ +// @flow + +import Raven from 'raven-js' +import user from 'helpers/user' +import install from './install' + +export default (shouldSendCallback: () => boolean) => { + install(Raven, shouldSendCallback, user().id) +} diff --git a/src/sentry/install.js b/src/sentry/install.js new file mode 100644 index 00000000..acfb33e0 --- /dev/null +++ b/src/sentry/install.js @@ -0,0 +1,26 @@ +// @flow + +require('../env') + +const { SENTRY_URL } = process.env + +export default (Raven: any, shouldSendCallback: () => boolean, userId: string) => { + if (!SENTRY_URL) return + let r = Raven.config(SENTRY_URL, { + captureUnhandledRejections: true, + allowSecretKey: true, + release: __APP_VERSION__, + environment: __DEV__ ? 'development' : 'production', + shouldSendCallback, + }) + const user = { + ip_address: null, + id: userId, + } + if (r.setUserContext) { + r = r.setUserContext(user) + } else if (r.setContext) { + r = r.setContext({ user }) + } + r.install() +} diff --git a/src/sentry/node.js b/src/sentry/node.js new file mode 100644 index 00000000..a617487b --- /dev/null +++ b/src/sentry/node.js @@ -0,0 +1,8 @@ +// @flow + +import Raven from 'raven' +import install from './install' + +export default (shouldSendCallback: () => boolean, userId: string) => { + install(Raven, shouldSendCallback, userId) +} From 99aa530d11c7f8c35ac641304440676f52c522ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Wed, 13 Jun 2018 16:41:06 +0200 Subject: [PATCH 03/14] should fix Sentry to work in prod --- src/sentry/install.js | 6 ++---- webpack/plugins.js | 3 ++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/sentry/install.js b/src/sentry/install.js index acfb33e0..d556339f 100644 --- a/src/sentry/install.js +++ b/src/sentry/install.js @@ -2,11 +2,9 @@ require('../env') -const { SENTRY_URL } = process.env - export default (Raven: any, shouldSendCallback: () => boolean, userId: string) => { - if (!SENTRY_URL) return - let r = Raven.config(SENTRY_URL, { + if (!__SENTRY_URL__) return + let r = Raven.config(__SENTRY_URL__, { captureUnhandledRejections: true, allowSecretKey: true, release: __APP_VERSION__, diff --git a/webpack/plugins.js b/webpack/plugins.js index af1b4b64..a19bfd87 100644 --- a/webpack/plugins.js +++ b/webpack/plugins.js @@ -3,7 +3,7 @@ const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer') const pkg = require('../package.json') require('../src/globals') -const { BUNDLE_ANALYZER } = process.env +const { BUNDLE_ANALYZER, SENTRY_URL } = process.env module.exports = type => { const plugins = [ @@ -12,6 +12,7 @@ module.exports = type => { __GLOBAL_STYLES__: JSON.stringify(__GLOBAL_STYLES__), __DEV__, __PROD__, + __SENTRY_URL__: SENTRY_URL, 'process.env.NODE_ENV': JSON.stringify(__ENV__), }), ] From 9a421c4754b8fbbe9c2e06e56dbadc6cc1b5246c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Wed, 13 Jun 2018 16:54:53 +0200 Subject: [PATCH 04/14] fix build --- webpack/plugins.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webpack/plugins.js b/webpack/plugins.js index a19bfd87..e1bfb18d 100644 --- a/webpack/plugins.js +++ b/webpack/plugins.js @@ -12,7 +12,7 @@ module.exports = type => { __GLOBAL_STYLES__: JSON.stringify(__GLOBAL_STYLES__), __DEV__, __PROD__, - __SENTRY_URL__: SENTRY_URL, + __SENTRY_URL__: JSON.stringify(SENTRY_URL || null), 'process.env.NODE_ENV': JSON.stringify(__ENV__), }), ] From e412d9b5329cb3f39d423c1fa953a065174d9718 Mon Sep 17 00:00:00 2001 From: Anastasia Poupeney Date: Wed, 13 Jun 2018 15:13:21 +0200 Subject: [PATCH 05/14] 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 From beba014abdfd905b5caa08d312b3686559c0150c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Wed, 13 Jun 2018 15:53:06 +0200 Subject: [PATCH 06/14] connect Sentry to main & internal processes --- src/commands/testCrash.js | 8 ++++---- src/init-sentry.js | 7 ------- src/internals/index.js | 9 ++++++++- src/main/bridge.js | 21 ++++++++++++++++++++- src/main/index.js | 1 - src/middlewares/sentry.js | 17 ++++++----------- src/renderer/index.js | 11 ----------- src/renderer/init.js | 5 ++--- src/renderer/sentry/browser.js | 19 ------------------- src/renderer/sentry/node.js | 0 src/sentry/browser.js | 9 +++++++++ src/sentry/install.js | 26 ++++++++++++++++++++++++++ src/sentry/node.js | 8 ++++++++ 13 files changed, 83 insertions(+), 58 deletions(-) delete mode 100644 src/init-sentry.js delete mode 100644 src/renderer/sentry/browser.js delete mode 100644 src/renderer/sentry/node.js create mode 100644 src/sentry/browser.js create mode 100644 src/sentry/install.js create mode 100644 src/sentry/node.js diff --git a/src/commands/testCrash.js b/src/commands/testCrash.js index 0725988a..5675a1ee 100644 --- a/src/commands/testCrash.js +++ b/src/commands/testCrash.js @@ -8,10 +8,10 @@ import { createCommand, Command } from 'helpers/ipc' type Input = void type Result = void -const cmd: Command = createCommand('testCrash', () => - Observable.create(() => { +const cmd: Command = createCommand('testCrash', () => { + return Observable.create(() => { process.exit(1) - }), -) + }) +}) export default cmd diff --git a/src/init-sentry.js b/src/init-sentry.js deleted file mode 100644 index 663c6840..00000000 --- a/src/init-sentry.js +++ /dev/null @@ -1,7 +0,0 @@ -const { SENTRY_URL } = process.env - -if (__PROD__ && SENTRY_URL) { - // const Raven = require('raven') - // const ravenConfig = { captureUnhandledRejections: true } - // Raven.config(SENTRY_URL, ravenConfig).install() -} diff --git a/src/internals/index.js b/src/internals/index.js index 94601aaa..f2879c08 100644 --- a/src/internals/index.js +++ b/src/internals/index.js @@ -3,14 +3,18 @@ import commands from 'commands' import logger from 'logger' import uuid from 'uuid/v4' import { setImplementation } from 'api/network' +import sentry from 'sentry/node' require('../env') -require('../init-sentry') process.title = 'Internal' const defers = {} +let sentryEnabled = process.env.INITIAL_SENTRY_ENABLED || false + +sentry(() => sentryEnabled, process.env.SENTRY_USER_ID) + if (process.env.DEBUG_NETWORK) { setImplementation(networkArg => { const id = uuid() @@ -92,6 +96,9 @@ process.on('message', m => { } else { defer.reject(payload.error) } + } else if (m.type === 'sentryLogsChanged') { + const { payload } = m + sentryEnabled = payload.value } }) diff --git a/src/main/bridge.js b/src/main/bridge.js index ff9af1ab..bd118629 100644 --- a/src/main/bridge.js +++ b/src/main/bridge.js @@ -7,6 +7,8 @@ import { ipcMain, app } from 'electron' import { ipcMainListenReceiveCommands } from 'helpers/ipc' import path from 'path' import logger from 'logger' +import sentry from 'sentry/node' +import user from 'helpers/user' import setupAutoUpdater, { quitAndInstall } from './autoUpdate' @@ -17,6 +19,11 @@ const LEDGER_LIVE_SQLITE_PATH = path.resolve(app.getPath('userData'), 'sqlite') let internalProcess +let sentryEnabled = false +const userId = user().id + +sentry(() => sentryEnabled, userId) + const killInternalProcess = () => { if (internalProcess) { logger.log('killing internal process...') @@ -30,7 +37,12 @@ const forkBundlePath = path.resolve(__dirname, `${__DEV__ ? '../../' : './'}dist const bootInternalProcess = () => { logger.log('booting internal process...') internalProcess = fork(forkBundlePath, { - env: { ...process.env, LEDGER_LIVE_SQLITE_PATH }, + env: { + ...process.env, + LEDGER_LIVE_SQLITE_PATH, + INITIAL_SENTRY_ENABLED: sentryEnabled, + SENTRY_USER_ID: userId, + }, }) internalProcess.on('message', handleGlobalInternalMessage) internalProcess.on('exit', code => { @@ -102,6 +114,13 @@ ipcMain.on('executeHttpQueryPayload', (event, payload) => { p.send({ type: 'executeHttpQueryPayload', payload }) }) +ipcMain.on('sentryLogsChanged', (event, payload) => { + sentryEnabled = payload.value + const p = internalProcess + if (!p) return + p.send({ type: 'sentryLogsChanged', payload }) +}) + // TODO move this to "command" pattern ipcMain.on('updater', (event, { type, data }) => { const handler = { diff --git a/src/main/index.js b/src/main/index.js index 3670ac42..65952b72 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -4,7 +4,6 @@ process.setMaxListeners(0) require('../env') require('../globals') -// require('../init-sentry') require('./app') setImmediate(() => require('./bridge')) diff --git a/src/middlewares/sentry.js b/src/middlewares/sentry.js index 479be983..212764c6 100644 --- a/src/middlewares/sentry.js +++ b/src/middlewares/sentry.js @@ -1,19 +1,14 @@ -const Raven = require('raven-js') -require('../env') - +import { ipcRenderer } from 'electron' 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) { - // - // } + const state = store.getState() + const sentryLogs = sentryLogsBooleanSelector(state) + if (sentryLogs !== isSentryInstalled) { + isSentryInstalled = sentryLogs + ipcRenderer.send('sentryLogsChanged', { value: sentryLogs }) } } diff --git a/src/renderer/index.js b/src/renderer/index.js index 5ae7edce..5164fc17 100644 --- a/src/renderer/index.js +++ b/src/renderer/index.js @@ -1,14 +1,3 @@ require('@babel/polyfill') - -const Raven = require('raven-js') - 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)) -} - require('./init') diff --git a/src/renderer/init.js b/src/renderer/init.js index 7bc6fe3d..c9e77136 100644 --- a/src/renderer/init.js +++ b/src/renderer/init.js @@ -14,8 +14,7 @@ import events from 'renderer/events' 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 { getLanguage, sentryLogsBooleanSelector } from 'reducers/settings' import libcoreGetVersion from 'commands/libcoreGetVersion' import db from 'helpers/db' @@ -23,7 +22,7 @@ import dbMiddleware from 'middlewares/db' import CounterValues from 'helpers/countervalues' import hardReset from 'helpers/hardReset' -import sentry from 'renderer/sentry/browser' +import sentry from 'sentry/browser' import App from 'components/App' import 'styles/global' diff --git a/src/renderer/sentry/browser.js b/src/renderer/sentry/browser.js deleted file mode 100644 index 9ee54b29..00000000 --- a/src/renderer/sentry/browser.js +++ /dev/null @@ -1,19 +0,0 @@ -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 deleted file mode 100644 index e69de29b..00000000 diff --git a/src/sentry/browser.js b/src/sentry/browser.js new file mode 100644 index 00000000..ac5fc55c --- /dev/null +++ b/src/sentry/browser.js @@ -0,0 +1,9 @@ +// @flow + +import Raven from 'raven-js' +import user from 'helpers/user' +import install from './install' + +export default (shouldSendCallback: () => boolean) => { + install(Raven, shouldSendCallback, user().id) +} diff --git a/src/sentry/install.js b/src/sentry/install.js new file mode 100644 index 00000000..acfb33e0 --- /dev/null +++ b/src/sentry/install.js @@ -0,0 +1,26 @@ +// @flow + +require('../env') + +const { SENTRY_URL } = process.env + +export default (Raven: any, shouldSendCallback: () => boolean, userId: string) => { + if (!SENTRY_URL) return + let r = Raven.config(SENTRY_URL, { + captureUnhandledRejections: true, + allowSecretKey: true, + release: __APP_VERSION__, + environment: __DEV__ ? 'development' : 'production', + shouldSendCallback, + }) + const user = { + ip_address: null, + id: userId, + } + if (r.setUserContext) { + r = r.setUserContext(user) + } else if (r.setContext) { + r = r.setContext({ user }) + } + r.install() +} diff --git a/src/sentry/node.js b/src/sentry/node.js new file mode 100644 index 00000000..a617487b --- /dev/null +++ b/src/sentry/node.js @@ -0,0 +1,8 @@ +// @flow + +import Raven from 'raven' +import install from './install' + +export default (shouldSendCallback: () => boolean, userId: string) => { + install(Raven, shouldSendCallback, userId) +} From fdfff4e10fb7ffda8a74915003bc1c0eb811cc28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Wed, 13 Jun 2018 16:41:06 +0200 Subject: [PATCH 07/14] should fix Sentry to work in prod --- src/sentry/install.js | 6 ++---- webpack/plugins.js | 3 ++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/sentry/install.js b/src/sentry/install.js index acfb33e0..d556339f 100644 --- a/src/sentry/install.js +++ b/src/sentry/install.js @@ -2,11 +2,9 @@ require('../env') -const { SENTRY_URL } = process.env - export default (Raven: any, shouldSendCallback: () => boolean, userId: string) => { - if (!SENTRY_URL) return - let r = Raven.config(SENTRY_URL, { + if (!__SENTRY_URL__) return + let r = Raven.config(__SENTRY_URL__, { captureUnhandledRejections: true, allowSecretKey: true, release: __APP_VERSION__, diff --git a/webpack/plugins.js b/webpack/plugins.js index af1b4b64..a19bfd87 100644 --- a/webpack/plugins.js +++ b/webpack/plugins.js @@ -3,7 +3,7 @@ const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer') const pkg = require('../package.json') require('../src/globals') -const { BUNDLE_ANALYZER } = process.env +const { BUNDLE_ANALYZER, SENTRY_URL } = process.env module.exports = type => { const plugins = [ @@ -12,6 +12,7 @@ module.exports = type => { __GLOBAL_STYLES__: JSON.stringify(__GLOBAL_STYLES__), __DEV__, __PROD__, + __SENTRY_URL__: SENTRY_URL, 'process.env.NODE_ENV': JSON.stringify(__ENV__), }), ] From c2a5ae5ea5f05411df580e502d063128d2ae2cbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Wed, 13 Jun 2018 16:54:53 +0200 Subject: [PATCH 08/14] fix build --- webpack/plugins.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webpack/plugins.js b/webpack/plugins.js index a19bfd87..e1bfb18d 100644 --- a/webpack/plugins.js +++ b/webpack/plugins.js @@ -12,7 +12,7 @@ module.exports = type => { __GLOBAL_STYLES__: JSON.stringify(__GLOBAL_STYLES__), __DEV__, __PROD__, - __SENTRY_URL__: SENTRY_URL, + __SENTRY_URL__: JSON.stringify(SENTRY_URL || null), 'process.env.NODE_ENV': JSON.stringify(__ENV__), }), ] From 468946f4ec59bd548adfcca45b12ffbe05cd6f4b Mon Sep 17 00:00:00 2001 From: Anastasia Poupeney Date: Wed, 13 Jun 2018 17:00:12 +0200 Subject: [PATCH 09/14] remove not needed changes --- src/commands/testCrash.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/commands/testCrash.js b/src/commands/testCrash.js index 5675a1ee..0725988a 100644 --- a/src/commands/testCrash.js +++ b/src/commands/testCrash.js @@ -8,10 +8,10 @@ import { createCommand, Command } from 'helpers/ipc' type Input = void type Result = void -const cmd: Command = createCommand('testCrash', () => { - return Observable.create(() => { +const cmd: Command = createCommand('testCrash', () => + Observable.create(() => { process.exit(1) - }) -}) + }), +) export default cmd From 85ae87f6717735219a28c21311c27d40015bd0fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Wed, 13 Jun 2018 17:41:26 +0200 Subject: [PATCH 10/14] fix empty exchange section to appear in settings! --- src/components/SettingsPage/sections/Display.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/components/SettingsPage/sections/Display.js b/src/components/SettingsPage/sections/Display.js index a57892f9..55d13b3f 100644 --- a/src/components/SettingsPage/sections/Display.js +++ b/src/components/SettingsPage/sections/Display.js @@ -173,10 +173,6 @@ class TabProfile extends PureComponent { /> - Date: Wed, 13 Jun 2018 17:43:36 +0200 Subject: [PATCH 11/14] fix ci error --- src/commands/testCrash.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/commands/testCrash.js b/src/commands/testCrash.js index 5675a1ee..72695e53 100644 --- a/src/commands/testCrash.js +++ b/src/commands/testCrash.js @@ -8,10 +8,8 @@ import { createCommand, Command } from 'helpers/ipc' type Input = void type Result = void -const cmd: Command = createCommand('testCrash', () => { - return Observable.create(() => { +const cmd: Command = createCommand('testCrash', () => Observable.create(() => { process.exit(1) - }) -}) + })) export default cmd From 2163bf6b1fe23f16311f0b98ee022cce518de3e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Wed, 13 Jun 2018 17:36:13 +0200 Subject: [PATCH 12/14] add TopGradient for MainSideBar --- src/components/MainSideBar/TopGradient.js | 19 +++++++++++++++++++ src/components/MainSideBar/index.js | 2 ++ 2 files changed, 21 insertions(+) create mode 100644 src/components/MainSideBar/TopGradient.js diff --git a/src/components/MainSideBar/TopGradient.js b/src/components/MainSideBar/TopGradient.js new file mode 100644 index 00000000..3cf0e899 --- /dev/null +++ b/src/components/MainSideBar/TopGradient.js @@ -0,0 +1,19 @@ +// @flow + +import React from 'react' +import styled from 'styled-components' + +const TopGradientBox = styled.div` + width: 100%; + height: 80px; + position: absolute; + top: 0; + left: 0; + background: linear-gradient(#ffffff 40%, rgba(255, 255, 255, 0)); + z-index: 2; + pointer-events: none; +` + +const el = + +export default () => el diff --git a/src/components/MainSideBar/index.js b/src/components/MainSideBar/index.js index b8a0688d..a55a1466 100644 --- a/src/components/MainSideBar/index.js +++ b/src/components/MainSideBar/index.js @@ -32,6 +32,7 @@ import IconExchange from 'icons/Exchange' import AccountListItem from './AccountListItem' import AddAccountButton from './AddAccountButton' +import TopGradient from './TopGradient' const mapStateToProps = state => ({ accounts: accountsSelector(state), @@ -84,6 +85,7 @@ class MainSideBar extends PureComponent { return ( + From ef303c042f5873ee74af115904ccd712c6c5e7e5 Mon Sep 17 00:00:00 2001 From: Anastasia Poupeney Date: Wed, 13 Jun 2018 18:34:20 +0200 Subject: [PATCH 13/14] merge issues fix --- src/commands/testCrash.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/commands/testCrash.js b/src/commands/testCrash.js index 72695e53..0725988a 100644 --- a/src/commands/testCrash.js +++ b/src/commands/testCrash.js @@ -8,8 +8,10 @@ import { createCommand, Command } from 'helpers/ipc' type Input = void type Result = void -const cmd: Command = createCommand('testCrash', () => Observable.create(() => { +const cmd: Command = createCommand('testCrash', () => + Observable.create(() => { process.exit(1) - })) + }), +) export default cmd From a132bb250c06b2193945e5545ded92f6b877a6a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Wed, 13 Jun 2018 18:39:53 +0200 Subject: [PATCH 14/14] fix jsx code --- src/components/SettingsPage/sections/Display.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/SettingsPage/sections/Display.js b/src/components/SettingsPage/sections/Display.js index 81fcb5e2..1945e034 100644 --- a/src/components/SettingsPage/sections/Display.js +++ b/src/components/SettingsPage/sections/Display.js @@ -173,7 +173,6 @@ class TabProfile extends PureComponent { /> -