Skip to content

Commit

Permalink
fix: re-enable bugsnag reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
broofa committed Apr 13, 2021
1 parent 8c18634 commit 7a123ff
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 50 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BUGSNAG_KEY=6a07b66124c696d0f685e1cf28312e41
17 changes: 0 additions & 17 deletions deploy.sh

This file was deleted.

28 changes: 1 addition & 27 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,33 +44,7 @@
</body>
</html>

<!-- <script src="//d2wy8f7a9ursnm.cloudfront.net/v5/bugsnag.min.js"></script> -->
<script>
// TODO: Inject app version as part of deploy
const ENV = window.ENV = {appVersion: '0.0.0'}; // Values injected by deploy script

// if (ENV.bugsnagKey){
// const pageStart = Date.now();
// window.bugsnagClient = bugsnag({
// apiKey: ENV.bugsnagKey,
// appVersion: ENV.appVersion || undefined,
// releaseStage: ENV.releaseStage || 'development',
// notifyReleaseStages: ['production'],
// beforeSend: function(report) {
// report.updateMetaData('page', {
// location: String(location),
// pageTime: Date.now() - pageStart
// });
// }
// });
// } else {
// window.bugsnagClient = {
// notify(err, {severity}) {
// console[severity](err);
// }
// }
// }
</script>
<script src="//d2wy8f7a9ursnm.cloudfront.net/v5/bugsnag.min.js"></script>

<!-- Global site tag (gtag.js) - Google Analytics -->
<!-- <script src="//www.googletagmanager.com/gtag/js?id=UA-6434483-2"></script> -->
Expand Down
5 changes: 2 additions & 3 deletions js/Inspector.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* global ENV */

import React from 'react';
import { tagify } from './util';
import md5 from 'md5';
Expand All @@ -8,6 +6,7 @@ import GraphPane from './GraphPane';
import InfoPane from './InfoPane';
import { selectTag } from './Graph';
import { sharedState } from './App';
import { version as VERSION } from '../package.json';

export function Fix() {
return <span style={{ fontWeight: 'bold', color: 'red' }}>FIX!</span>;
Expand Down Expand Up @@ -119,7 +118,7 @@ export default function Inspector({ className, ...props }) {
{' '}&mdash;{' '}
<ExternalLink id='github' href='//github.com/npmgraph/npmgraph'>GitHub</ExternalLink>
{' '}&mdash;{' '}
v{ENV.appVersion}
v{VERSION}
</footer>
</div>;
}
30 changes: 30 additions & 0 deletions js/bugsnag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* global bugsnag */

import { version as appVersion } from '../package.json';

const config = {
appVersion,
apiKey: process.env.BUGSNAG_KEY,
releaseStage: process.env.NODE_ENV
};

console.log('BugSnag config:', config);

const pageStart = Date.now();

export const client = config.apiKey
? bugsnag({
...config,
notifyReleaseStages: ['production'],
beforeSend: function(report) {
report.updateMetaData('page', {
location: String(location),
pageTime: Date.now() - pageStart
});
}
})
: {
notify(err, { severity }) {
console[severity](err);
}
};
2 changes: 2 additions & 0 deletions js/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import './bugsnag'; // Initialize ASAP!

import React from 'react';
import { render } from 'react-dom';
import App from './App';
Expand Down
4 changes: 2 additions & 2 deletions js/util.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global bugsnagClient */
import { client } from './bugsnag';

export class HttpError extends Error {
constructor(code, message = `HTTP Error ${code}`) {
Expand All @@ -11,7 +11,7 @@ function _report(severity, err) {
// HTTP errors are expected (e.g. if 3rd party service is down)
if (err instanceof HttpError) return;

bugsnagClient?.notify(err, { severity });
client?.notify(err, { severity });
}

export const report = {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"standard-version": "9.1.0"
},
"scripts": {
"start": "parcel index.html --dist-dir docs",
"start": "rm -fr .parcel-cache && parcel index.html --dist-dir docs",
"build": "parcel build index.html --dist-dir docs",
"test": "eslint ."
}
Expand Down

0 comments on commit 7a123ff

Please sign in to comment.