Skip to content

Commit f7b78c2

Browse files
committed
Implement "reportError"
1 parent 258a2f2 commit f7b78c2

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
},
4848
"homepage": "http://platformio.org",
4949
"dependencies": {
50+
"@sentry/node": "^4.2.3",
5051
"cross-spawn": "^6.0.3",
5152
"fs-plus": "^3.0.1",
5253
"ini": "^1.3.5",

src/misc.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { getCacheDir , getEnvBinDir, getEnvDir, getHomeDir } from './core';
1010

1111
import fs from 'fs-plus';
1212
import path from 'path';
13+
import os from 'os';
1314
import qs from 'querystringify';
1415
import request from 'request';
1516
import spawn from 'cross-spawn';
@@ -208,3 +209,24 @@ export function disposeSubscriptions(subscriptions) {
208209
subscriptions.pop().dispose();
209210
}
210211
}
212+
213+
export function reportError(err, tags) {
214+
// Hook for Webpack: include dependencies for Sentry
215+
require("@sentry/core");
216+
require("@sentry/hub");
217+
require("@sentry/minimal");
218+
require("@sentry/types");
219+
require("@sentry/utils");
220+
// End hook for Webpack
221+
const Sentry = require("@sentry/node");
222+
Sentry.init({
223+
dsn: 'https://2c83f4457e234ddf9b3476d079fb8334@sentry.io/1309781',
224+
release: PACKAGE_VERSION,
225+
serverName: `${os.type()}, ${os.release()}, ${os.arch()}`,
226+
defaultIntegrations: false
227+
});
228+
Sentry.withScope(scope => {
229+
Object.entries(tags || {}).forEach(([key, value]) => scope.setTag(key, value));
230+
Sentry.captureException(err);
231+
});
232+
}

webpack.config.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88

99
const fs = require('fs');
1010
const path = require('path');
11+
const webpack = require('webpack');
1112

12-
const externals = Object.keys(JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8')).dependencies);
13-
externals.push('path');
14-
externals.push('zlib');
13+
const packageConfig = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8'));
1514

1615
module.exports = {
1716
mode: 'production',
@@ -24,7 +23,7 @@ module.exports = {
2423
umdNamedDefine: true
2524
},
2625
target: 'node',
27-
externals: externals,
26+
externals: Object.keys(packageConfig.dependencies).filter(key => !key.includes('sentry')),
2827
module: {
2928
rules: [
3029
{
@@ -34,6 +33,11 @@ module.exports = {
3433
}
3534
]
3635
},
36+
plugins: [
37+
new webpack.DefinePlugin({
38+
PACKAGE_VERSION: JSON.stringify(packageConfig.version)
39+
}),
40+
],
3741
resolve: {
3842
modules: [path.resolve('./node_modules'), path.resolve('./src')],
3943
extensions: ['.json', '.js']

0 commit comments

Comments
 (0)