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 authored and matejkriz committed Feb 24, 2022
1 parent f2be761 commit 90e95bd
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
5 changes: 5 additions & 0 deletions packages/suite-build/configs/base.webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ import { getPathForProject } from '../utils/path';
import { suiteVersion } from '../../suite/package.json';

const gitRevision = getRevision();

/**
* Assemble release name for Sentry
* Same definition is in packages/suite-desktop/scripts/build.js
*/
const sentryRelease = `${suiteVersion}.${project}${
isCodesignBuild ? '.codesign' : ''
}.${gitRevision}`;
Expand Down
14 changes: 13 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,15 @@ const useMocks = USE_MOCKS === 'true' || (isDev && USE_MOCKS !== 'false');
// Get git revision
const gitRevision = childProcess.execSync('git rev-parse HEAD').toString().trim();

/**
* Assemble release name for Sentry
* Same definition is in packages/suite-build/configs/base.webpack.config.ts,
* but reusing is not straightforward because this is JS script run by Node during build.
*/
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 @@ -69,6 +79,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 90e95bd

Please sign in to comment.