Browse Source

connect Sentry to main & internal processes

master
Gaëtan Renaudeau 7 years ago
parent
commit
070ae1c532
  1. 8
      src/commands/testCrash.js
  2. 7
      src/init-sentry.js
  3. 9
      src/internals/index.js
  4. 21
      src/main/bridge.js
  5. 1
      src/main/index.js
  6. 17
      src/middlewares/sentry.js
  7. 11
      src/renderer/index.js
  8. 5
      src/renderer/init.js
  9. 19
      src/renderer/sentry/browser.js
  10. 0
      src/renderer/sentry/node.js
  11. 9
      src/sentry/browser.js
  12. 26
      src/sentry/install.js
  13. 8
      src/sentry/node.js

8
src/commands/testCrash.js

@ -8,10 +8,10 @@ import { createCommand, Command } from 'helpers/ipc'
type Input = void type Input = void
type Result = void type Result = void
const cmd: Command<Input, Result> = createCommand('testCrash', () => const cmd: Command<Input, Result> = createCommand('testCrash', () => {
Observable.create(() => { return Observable.create(() => {
process.exit(1) process.exit(1)
}), })
) })
export default cmd export default cmd

7
src/init-sentry.js

@ -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()
}

9
src/internals/index.js

@ -3,14 +3,18 @@ import commands from 'commands'
import logger from 'logger' import logger from 'logger'
import uuid from 'uuid/v4' import uuid from 'uuid/v4'
import { setImplementation } from 'api/network' import { setImplementation } from 'api/network'
import sentry from 'sentry/node'
require('../env') require('../env')
require('../init-sentry')
process.title = 'Internal' process.title = 'Internal'
const defers = {} const defers = {}
let sentryEnabled = process.env.INITIAL_SENTRY_ENABLED || false
sentry(() => sentryEnabled, process.env.SENTRY_USER_ID)
if (process.env.DEBUG_NETWORK) { if (process.env.DEBUG_NETWORK) {
setImplementation(networkArg => { setImplementation(networkArg => {
const id = uuid() const id = uuid()
@ -92,6 +96,9 @@ process.on('message', m => {
} else { } else {
defer.reject(payload.error) defer.reject(payload.error)
} }
} else if (m.type === 'sentryLogsChanged') {
const { payload } = m
sentryEnabled = payload.value
} }
}) })

21
src/main/bridge.js

@ -7,6 +7,8 @@ import { ipcMain, app } from 'electron'
import { ipcMainListenReceiveCommands } from 'helpers/ipc' import { ipcMainListenReceiveCommands } from 'helpers/ipc'
import path from 'path' import path from 'path'
import logger from 'logger' import logger from 'logger'
import sentry from 'sentry/node'
import user from 'helpers/user'
import setupAutoUpdater, { quitAndInstall } from './autoUpdate' import setupAutoUpdater, { quitAndInstall } from './autoUpdate'
@ -17,6 +19,11 @@ const LEDGER_LIVE_SQLITE_PATH = path.resolve(app.getPath('userData'), 'sqlite')
let internalProcess let internalProcess
let sentryEnabled = false
const userId = user().id
sentry(() => sentryEnabled, userId)
const killInternalProcess = () => { const killInternalProcess = () => {
if (internalProcess) { if (internalProcess) {
logger.log('killing internal process...') logger.log('killing internal process...')
@ -30,7 +37,12 @@ const forkBundlePath = path.resolve(__dirname, `${__DEV__ ? '../../' : './'}dist
const bootInternalProcess = () => { const bootInternalProcess = () => {
logger.log('booting internal process...') logger.log('booting internal process...')
internalProcess = fork(forkBundlePath, { 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('message', handleGlobalInternalMessage)
internalProcess.on('exit', code => { internalProcess.on('exit', code => {
@ -102,6 +114,13 @@ ipcMain.on('executeHttpQueryPayload', (event, payload) => {
p.send({ type: 'executeHttpQueryPayload', 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 // TODO move this to "command" pattern
ipcMain.on('updater', (event, { type, data }) => { ipcMain.on('updater', (event, { type, data }) => {
const handler = { const handler = {

1
src/main/index.js

@ -4,7 +4,6 @@ process.setMaxListeners(0)
require('../env') require('../env')
require('../globals') require('../globals')
// require('../init-sentry')
require('./app') require('./app')
setImmediate(() => require('./bridge')) setImmediate(() => require('./bridge'))

17
src/middlewares/sentry.js

@ -1,19 +1,14 @@
const Raven = require('raven-js') import { ipcRenderer } from 'electron'
require('../env')
import { sentryLogsBooleanSelector } from 'reducers/settings' import { sentryLogsBooleanSelector } from 'reducers/settings'
const { SENTRY_URL } = process.env
let isSentryInstalled = false let isSentryInstalled = false
export default store => next => action => { export default store => next => action => {
next(action) next(action)
if (__PROD__ && SENTRY_URL) { const state = store.getState()
const state = store.getState() const sentryLogs = sentryLogsBooleanSelector(state)
const sentryLogs = sentryLogsBooleanSelector(state) if (sentryLogs !== isSentryInstalled) {
// if (sentryLogs !== isSentryInstalled) { isSentryInstalled = sentryLogs
// ipcRenderer.send('sentryLogsChanged', { value: sentryLogs })
// }
} }
} }

11
src/renderer/index.js

@ -1,14 +1,3 @@
require('@babel/polyfill') require('@babel/polyfill')
const Raven = require('raven-js')
require('../env') 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') require('./init')

5
src/renderer/init.js

@ -14,8 +14,7 @@ import events from 'renderer/events'
import { fetchAccounts } from 'actions/accounts' import { fetchAccounts } from 'actions/accounts'
import { fetchSettings } from 'actions/settings' import { fetchSettings } from 'actions/settings'
import { isLocked } from 'reducers/application' import { isLocked } from 'reducers/application'
import { getLanguage } from 'reducers/settings' import { getLanguage, sentryLogsBooleanSelector } from 'reducers/settings'
import { sentryLogsBooleanSelector } from 'reducers/settings'
import libcoreGetVersion from 'commands/libcoreGetVersion' import libcoreGetVersion from 'commands/libcoreGetVersion'
import db from 'helpers/db' import db from 'helpers/db'
@ -23,7 +22,7 @@ import dbMiddleware from 'middlewares/db'
import CounterValues from 'helpers/countervalues' import CounterValues from 'helpers/countervalues'
import hardReset from 'helpers/hardReset' import hardReset from 'helpers/hardReset'
import sentry from 'renderer/sentry/browser' import sentry from 'sentry/browser'
import App from 'components/App' import App from 'components/App'
import 'styles/global' import 'styles/global'

19
src/renderer/sentry/browser.js

@ -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()
}

0
src/renderer/sentry/node.js

9
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)
}

26
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()
}

8
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)
}
Loading…
Cancel
Save