Browse Source

wip sentry logs

master
Anastasia Poupeney 7 years ago
parent
commit
55387b06c4
  1. 2
      src/helpers/db.js
  2. 15
      src/helpers/user.js
  3. 6
      src/init-sentry.js
  4. 2
      src/main/index.js
  5. 19
      src/middlewares/sentry.js
  6. 3
      src/reducers/settings.js
  7. 4
      src/renderer/createStore.js
  8. 4
      src/renderer/index.js
  9. 3
      src/renderer/init.js
  10. 19
      src/renderer/sentry/browser.js
  11. 0
      src/renderer/sentry/node.js

2
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 = {}

15
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
}

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

2
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'))

19
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) {
//
// }
}
}

3
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)

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

4
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')

3
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)

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

0
src/renderer/sentry/node.js

Loading…
Cancel
Save