Skip to content

Commit

Permalink
feat: implement sentry error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
stdavis authored and steveoh committed Apr 14, 2022
1 parent ab04757 commit f726b2e
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 21 deletions.
2 changes: 2 additions & 0 deletions forge.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ const config = {
[
'@electron-forge/plugin-webpack',
{
devContentSecurityPolicy:
"default-src 'self' 'unsafe-inline' data:; script-src 'self' 'unsafe-eval' 'unsafe-inline' data:; connect-src 'self' 'unsafe-inline' *.ingest.sentry.io data:;",
mainConfig: './webpack.main.config.js',
renderer: {
config: './webpack.renderer.config.js',
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"dependencies": {
"@headlessui/react": "^1.5.0",
"@heroicons/react": "^1.0.5",
"@sentry/electron": "^3.0.0",
"@sentry/electron": "^3.0.2",
"assert": "^2.0.0",
"clsx": "^1.1.1",
"crypto-browserify": "^3.12.0",
Expand Down
14 changes: 8 additions & 6 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require('./services/sentry');
const { app, BrowserWindow, dialog, ipcMain, shell } = require('electron');
const windowStateKeeper = require('electron-window-state');
const path = require('path');
Expand All @@ -7,11 +8,6 @@ require('./services/csv');
require('./services/geocode');
const { enforceMacOSAppLocation, is } = require('electron-util');
const { trackException } = require('./services/analytics');
const Sentry = require('@sentry/electron/main');

Sentry.init({
dsn: 'https://02bfd36076c647c9a9a2f66a9c7465c4@o1150892.ingest.sentry.io/6225803',
});

require('update-electron-app')({
updateInterval: '1 hour',
Expand Down Expand Up @@ -105,7 +101,13 @@ app.on('activate', () => {

app.on('web-contents-created', (_, contents) => {
const isSafeForExternalOpen = (urlString) => {
const safeHosts = ['github.com', 'api.mapserv.utah.gov', 'developer.mapserv.utah.gov', 'agrc-status.netlify.app'];
const safeHosts = [
'github.com',
'api.mapserv.utah.gov',
'developer.mapserv.utah.gov',
'agrc-status.netlify.app',
'o1150892.ingest.sentry.io',
];
try {
const url = new URL(urlString);
if (url.protocol === 'mailto:') {
Expand Down
7 changes: 1 addition & 6 deletions src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ import Routes from './pages/Routes.jsx';
import './styles/tailwind.css';
import { ErrorBoundary } from 'react-error-boundary';
import ErrorPage from './pages/Error.jsx';

const Sentry = require('@sentry/electron/renderer');

Sentry.init({
dsn: 'https://02bfd36076c647c9a9a2f66a9c7465c4@o1150892.ingest.sentry.io/6225803',
});
require('./services/sentry');

(async () => {
render(
Expand Down
2 changes: 2 additions & 0 deletions src/pages/Error.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Chrome } from '../components/PageElements';
import * as Sentry from '@sentry/electron/renderer';

export default function Error({ error, children }) {
window.ugrc.trackException(error.toString());
Sentry.captureException(error);

return (
<article>
Expand Down
10 changes: 10 additions & 0 deletions src/services/sentry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
let Sentry;
if (global.process) {
Sentry = require('@sentry/electron/main');
} else {
Sentry = require('@sentry/electron/renderer');
}

Sentry.init({
dsn: 'https://02bfd36076c647c9a9a2f66a9c7465c4@o1150892.ingest.sentry.io/6225803',
});
8 changes: 7 additions & 1 deletion webpack.renderer.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
const rules = require('./webpack.rules');
const webpack = require('webpack');

rules.push({
test: /\.css$/,
use: [{ loader: 'style-loader' }, { loader: 'css-loader' }, { loader: 'postcss-loader' }],
});

module.exports = {
// Put your normal webpack config below here
module: {
rules,
},
plugins: [
// ignore sentry main code since it requires node apis
new webpack.IgnorePlugin({
resourceRegExp: /@sentry\/electron\/main/,
}),
],
};

0 comments on commit f726b2e

Please sign in to comment.