electron-sentry-modtest
v1.1.3
Published
JavaScript and native crash reporting from Electron to Sentry
Readme
JavaScript and native crash reporting from Electron to Sentry
Breadcrumbs and JavaScript instrumentation for native crashes too!
Simply call ElectronSentry.start() as early as possible in the main AND renderer processes.
- Starts the Electron native
crashReporterin both processes and points it at the new Sentry.io minidump endpoint - Starts
raven-jsin therendererprocess- Breadcrumbs and exceptions are passed to the main process. This means we can still report both if the renderer terminates due to a native crash.
- Exception URLs are normalised to the app base so Sentry can group them correctly
NOTE: This normalisation only works with
asarpackaged apps!
- Starts
raven-nodein themainprocess- Hooks most
app,BrowserWindow,webContents,screenandpowerMonitorevents and records breadcrumbs - Breadcrumbs from all processes are combined
- If a render crashes due to a native exception, the native crash
idis sent along with breadcrumbs so the two can be linked. Currently two errors are reported in Sentry and linking the two is manual.
- Hooks most
TODO
- Offline support
- Spectron tests
- Better multiple renderer support?
- Means to identify identify renderers
- Keep breadcrumbs from different renderer separate
Import it like this:
const { ElectronSentry } = require('electron-sentry');
// or
import { ElectronSentry } from 'electron-sentry';If you don't supply any options, the sentry node in the root of your package.json is used. This can be your non-public DSN string or an options object (options and defaults at bottom).
ElectronSentry.start();
// or
ElectronSentry.start('https://xxxxxxx:[email protected]/xxxxx');
// or
ElectronSentry.start({
dsn: 'https://xxxxxxx:[email protected]/xxxxx',
native: false,
// ...
});There are some helpers available which check for, save and delete an empty file in userData to signify if reporting should be enabled or disabled. You can call these from either process but changes to the reporting state will not take effect until the app is restarted. This keeps things simple as the native reporter cannot be stopped once its started on Windows.
if (ElectronSentry.isEnabled()) {
ElectronSentry.start();
}
// Disable error reporting, I don't like to help devs...
ElectronSentry.setEnabled(false);Config & Defaults
import { app } from 'electron';
const defaults = {
// Sentry non-public DSN
// We need the non-public one for raven-node
dsn: string = undefined,
// productName || appName from package.json
// https://electronjs.org/docs/api/app#appgetname
appName: string = app.getName(),
// Defaults to the same as appName
companyName: string: app.getName(),
// Start the native crash reporter
native: boolean = true,
// Used by Sentry to identify this release
// It's common to use git hashes but for Electron the
// app version makes more sense
release: string = app.getVersion(),
// Environment string passed to Sentry
// process.defaultApp is undefined when the app is packaged
environment: string = process.defaultApp == undefined
? 'production'
: 'development'
// Extra tags passed through the crash reporters
// Only first level properties make it through the native crash reporter
tags: any = undefined
};Example configuration in package.json
{
"name": "example-app",
"displayName": "Example App",
"version": "1.0.0",
"sentry": {
"dsn": "https://xxxxxxxxxxxxxxxxxxxxxxx:[email protected]/xxxxxx",
"native": false
...
},
"dependencies": {
"sentry-electron": "^1.0.0"
}
}