Skip to content

Commit

Permalink
feat(suite-deskop): electron/sentry integration
Browse files Browse the repository at this point in the history
  • Loading branch information
marekrjpolak committed Feb 23, 2022
1 parent 5f79bdb commit 28b8d04
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
10 changes: 9 additions & 1 deletion packages/suite-desktop/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const { build } = require('esbuild');
const pkg = require('../package.json');
const { suiteVersion } = require('../../suite/package.json');

const { NODE_ENV, USE_MOCKS } = process.env;
const { NODE_ENV, USE_MOCKS, IS_CODESIGN_BUILD } = process.env;
const PROJECT = 'desktop';

const electronSource = path.join(__dirname, '..', 'src-electron');
const isDev = NODE_ENV !== 'production';
Expand All @@ -15,6 +16,11 @@ const useMocks = USE_MOCKS === 'true' || (isDev && USE_MOCKS !== 'false');
// Get git revision
const gitRevision = childProcess.execSync('git rev-parse HEAD').toString().trim();

// Assemble release for Sentry
const sentryRelease = `${suiteVersion}.${PROJECT}${
IS_CODESIGN_BUILD === 'true' ? '.codesign' : ''
}.${gitRevision}`;

// Get all modules (used as entry points)
const modulePath = path.join(electronSource, 'modules');
const modules = glob.sync(`${modulePath}/**/*.ts`).map(m => `modules${m.replace(modulePath, '')}`);
Expand Down Expand Up @@ -64,6 +70,8 @@ build({
'process.env.PROTOCOLS': JSON.stringify(pkg.build.protocols.schemes),
'process.env.PKGNAME': JSON.stringify(pkg.name),
'process.env.VERSION': JSON.stringify(suiteVersion),
'process.env.SENTRY_RELEASE': JSON.stringify(sentryRelease),
'process.env.SUITE_TYPE': JSON.stringify(PROJECT),
},
inject: [path.join(__dirname, 'build-inject.js')],
plugins: useMocks ? [mockPlugin] : [],
Expand Down
14 changes: 13 additions & 1 deletion packages/suite-desktop/src-electron/app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import path from 'path';
import url from 'url';
import { app, BrowserWindow, ipcMain } from 'electron';
import { app, BrowserWindow, ipcMain, session } from 'electron';
import { init as initSentry, ElectronOptions, IPCMode } from '@sentry/electron';

import { SENTRY_CONFIG } from '@suite-config';
import { isDev } from '@suite-utils/build';
import { PROTOCOL } from './libs/constants';
import * as store from './libs/store';
Expand Down Expand Up @@ -140,3 +142,13 @@ ipcMain.on('app/restart', () => {
app.relaunch();
app.exit();
});

if (!isDev) {
const sentryConfig: ElectronOptions = {
...SENTRY_CONFIG,
ipcMode: IPCMode.Classic,
getSessions: () => [session.defaultSession],
};

initSentry(sentryConfig);
}
2 changes: 2 additions & 0 deletions packages/suite-desktop/src-electron/modules/request-filter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* Request Filter feature (blocks non-allowed requests)
*/
import { captureMessage, Severity } from '@sentry/electron';
import { allowedDomains } from '../config';
import { Module } from './index';

Expand Down Expand Up @@ -31,6 +32,7 @@ const init: Module = ({ interceptor }) => {
'request-filter',
`${details.url} was blocked because ${hostname} is not in the exception list`,
);
captureMessage(`request-filter: ${hostname}`, Severity.Warning);
return { cancel: true };
});
};
Expand Down

0 comments on commit 28b8d04

Please sign in to comment.