From 0441eea7d7fbfbc3382f63e431a1aca15ed48625 Mon Sep 17 00:00:00 2001 From: meriadec Date: Mon, 22 Jan 2018 15:49:03 +0100 Subject: [PATCH] Integrate sentry - main and renderer side --- .eslintrc | 1 + .gitignore | 1 + README.md | 10 +++++++++- flow-defs/globals.js | 3 +++ package.json | 9 +++++++++ src/main/index.js | 6 ++++++ src/renderer/index.js | 6 ++++++ webpack/main.config.js | 7 +++++++ webpack/plugins.js | 4 +++- yarn.lock | 38 ++++++++++++++++++++++++++++++++------ 10 files changed, 77 insertions(+), 8 deletions(-) create mode 100644 webpack/main.config.js diff --git a/.eslintrc b/.eslintrc index 9cac6933..1049b3ec 100644 --- a/.eslintrc +++ b/.eslintrc @@ -6,6 +6,7 @@ "__ENV__": false, "__DEV__": false, "__PROD__": false, + "__SENTRY_URL__": false, "__static": false, "window": false, }, diff --git a/.gitignore b/.gitignore index d516939f..2df01008 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ /static/ /storybook-static/ thumbs.db +/.env diff --git a/README.md b/README.md index 8e1052f5..fcdc491d 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,15 @@ * nodejs v8.x (https://nodejs.org/en/) * yarn latest (https://yarnpkg.com/fr/docs/install) -## Installation +## Setup + +#### Create .env file and complete it, if you want main & renderer errors to be tracked + +``` +SENTRY_URL=http://... +``` + +#### Install dependencies ``` yarn diff --git a/flow-defs/globals.js b/flow-defs/globals.js index ee6bc5da..661e2fe8 100644 --- a/flow-defs/globals.js +++ b/flow-defs/globals.js @@ -1,4 +1,7 @@ +/* eslint-disable */ + declare var __DEV__: boolean declare var __PROD__: boolean declare var __ENV__: string +declare var __SENTRY_URL__: string declare var __static: string diff --git a/package.json b/package.json index 97e241d8..dca3ead3 100644 --- a/package.json +++ b/package.json @@ -29,8 +29,14 @@ "electronWebpack": { "renderer": { "webpackConfig": "./webpack/renderer.config.js" + }, + "main": { + "webpackConfig": "./webpack/main.config.js" } }, + "resolutions": { + "webpack-sources": "1.0.1" + }, "dependencies": { "@ledgerhq/hw-app-btc": "^1.1.2-beta.068e2a14", "@ledgerhq/hw-app-eth": "^1.1.2-beta.068e2a14", @@ -49,6 +55,8 @@ "ledger-wallet-common": "github:LedgerHQ/ledger-wallet-common", "lodash": "^4.17.4", "object-path": "^0.11.4", + "raven": "^2.3.0", + "raven-js": "^3.22.1", "react": "^16.2.0", "react-dom": "^16.2.0", "react-i18next": "^7.3.1", @@ -81,6 +89,7 @@ "babel-preset-react": "^6.24.1", "babel-preset-stage-0": "^6.24.1", "concurrently": "^3.5.1", + "dotenv": "^4.0.0", "electron": "1.7.10", "electron-builder": "^19.54.0", "electron-devtools-installer": "^2.2.3", diff --git a/src/main/index.js b/src/main/index.js index 9ad87886..75e8269b 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -3,3 +3,9 @@ require('../globals') require('./bridge') require('./app') + +if (__PROD__ && __SENTRY_URL__) { + const Raven = require('raven') // eslint-disable-line global-require + const ravenConfig = { captureUnhandledRejections: true } + Raven.config(__SENTRY_URL__, ravenConfig).install() +} diff --git a/src/renderer/index.js b/src/renderer/index.js index b3ea74f3..f31608fe 100644 --- a/src/renderer/index.js +++ b/src/renderer/index.js @@ -1,6 +1,7 @@ // @flow import React from 'react' +import Raven from 'raven-js' import { render } from 'react-dom' import { AppContainer } from 'react-hot-loader' import createHistory from 'history/createHashHistory' @@ -16,6 +17,11 @@ import App from 'components/App' import 'styles/global' +if (__PROD__ && __SENTRY_URL__) { + Raven.config(__SENTRY_URL__).install() + window.addEventListener('unhandledrejection', event => Raven.captureException(event.reason)) +} + const history = createHistory() const store = createStore(history) const rootNode = document.getElementById('app') diff --git a/webpack/main.config.js b/webpack/main.config.js new file mode 100644 index 00000000..40819492 --- /dev/null +++ b/webpack/main.config.js @@ -0,0 +1,7 @@ +const plugins = require('./plugins') + +const config = { + plugins, +} + +module.exports = config diff --git a/webpack/plugins.js b/webpack/plugins.js index 472e924d..973c4577 100644 --- a/webpack/plugins.js +++ b/webpack/plugins.js @@ -1,3 +1,4 @@ +require('dotenv').config() const webpack = require('webpack') require('../src/globals') @@ -6,6 +7,7 @@ module.exports = [ new webpack.DefinePlugin({ __DEV__, __PROD__, - 'process.env.NODE_ENV': `"${__ENV__}"`, + __SENTRY_URL__: JSON.stringify(process.env.SENTRY_URL), + 'process.env.NODE_ENV': JSON.stringify(__ENV__), }), ] diff --git a/yarn.lock b/yarn.lock index ddd2614e..7573862e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5667,6 +5667,10 @@ lru-cache@^4.0.1, lru-cache@^4.1.1: pseudomap "^1.0.2" yallist "^2.1.2" +lsmod@1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/lsmod/-/lsmod-1.0.0.tgz#9a00f76dca36eb23fa05350afe1b585d4299e64b" + macaddress@^0.2.8: version "0.2.8" resolved "https://registry.yarnpkg.com/macaddress/-/macaddress-0.2.8.tgz#5904dc537c39ec6dbefeae902327135fa8511f12" @@ -7146,6 +7150,20 @@ range-parser@^1.0.3, range-parser@~1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.0.tgz#f49be6b487894ddc40dcc94a322f611092e00d5e" +raven-js@^3.22.1: + version "3.22.1" + resolved "https://registry.yarnpkg.com/raven-js/-/raven-js-3.22.1.tgz#1117f00dfefaa427ef6e1a7d50bbb1fb998a24da" + +raven@^2.3.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/raven/-/raven-2.3.0.tgz#96f15346bdaa433b3b6d47130804506155833d69" + dependencies: + cookie "0.3.1" + lsmod "1.0.0" + stack-trace "0.0.9" + timed-out "4.0.1" + uuid "3.0.0" + raw-body@2.3.2: version "2.3.2" resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.3.2.tgz#bcd60c77d3eb93cde0050295c3f379389bc88f89" @@ -8196,7 +8214,7 @@ source-map@0.5.6: version "0.5.6" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.6.tgz#75ce38f52bf0733c5a7f0c118d81334a2bb5f412" -source-map@0.5.x, source-map@^0.5.3, source-map@^0.5.6, source-map@~0.5.0, source-map@~0.5.1: +source-map@0.5.x, source-map@^0.5.3, source-map@^0.5.6, source-map@~0.5.0, source-map@~0.5.1, source-map@~0.5.3: version "0.5.7" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc" @@ -8285,6 +8303,10 @@ ssri@^5.0.0: dependencies: safe-buffer "^5.1.0" +stack-trace@0.0.9: + version "0.0.9" + resolved "https://registry.yarnpkg.com/stack-trace/-/stack-trace-0.0.9.tgz#a8f6eaeca90674c333e7c43953f275b451510695" + stackframe@^0.3.1: version "0.3.1" resolved "https://registry.yarnpkg.com/stackframe/-/stackframe-0.3.1.tgz#33aa84f1177a5548c8935533cbfeb3420975f5a4" @@ -8659,7 +8681,7 @@ time-stamp@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/time-stamp/-/time-stamp-2.0.0.tgz#95c6a44530e15ba8d6f4a3ecb8c3a3fac46da357" -timed-out@^4.0.0: +timed-out@4.0.1, timed-out@^4.0.0: version "4.0.1" resolved "https://registry.yarnpkg.com/timed-out/-/timed-out-4.0.1.tgz#f32eacac5a175bea25d7fab565ab3ed8741ef56f" @@ -9013,6 +9035,10 @@ utils-merge@1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713" +uuid@3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.0.0.tgz#6728fc0459c450d796a99c31837569bdf672d728" + uuid@^3.0.0, uuid@^3.0.1, uuid@^3.1.0: version "3.2.1" resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.2.1.tgz#12c528bb9d58d0b9265d9a2f6f0fe8be17ff1f14" @@ -9148,12 +9174,12 @@ webpack-merge@^4.1.0: dependencies: lodash "^4.17.4" -webpack-sources@^1.0.1, webpack-sources@^1.1.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-1.1.0.tgz#a101ebae59d6507354d71d8013950a3a8b7a5a54" +webpack-sources@1.0.1, webpack-sources@^1.0.1, webpack-sources@^1.1.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-1.0.1.tgz#c7356436a4d13123be2e2426a05d1dad9cbe65cf" dependencies: source-list-map "^2.0.0" - source-map "~0.6.1" + source-map "~0.5.3" webpack@^3.10.0: version "3.10.0"