Electron Crash Reporting and Error Tracking
Overview
Enable Error Tracking for your Electron application to surface, triage, and debug errors and crashes in Error Tracking. Errors are deduplicated and grouped into issues to help you prioritize the most impactful problems.
The Electron SDK collects:
- Uncaught errors in the main process.
- Native crashes. The SDK stores a crash report locally and sends it the next time the application launches.
- Errors you report manually with
addError.
The Browser SDK collects errors from renderer processes. See the renderer setup instructions.
Setup
If you have not set up the RUM Electron SDK yet, follow the setup instructions. Error and crash collection is enabled after the SDK is initialized in the main process.
Report handled errors
Use addError to report an error that your code handles:
import { addError } from '@datadog/electron-sdk';
try {
riskyOperation();
} catch (error) {
addError(error, { context: { component: 'sync' } });
}
Native crashes
Electron symbols are resolved automatically. You do not need to upload debug symbols.
Upload source maps
Upload source maps at build time so Error Tracking can display original source code in stack traces.
Stack traces collected in an Electron app contain the app’s install path, which differs on each machine. The SDK rewrites the app path, as returned by app.getAppPath(), to / before sending events. For example, /Users/alice/Applications/MyApp.app/Contents/Resources/app.asar/dist/main/index.js becomes /dist/main/index.js. Other local paths are sent unchanged. URLs of renderers loaded from a custom protocol or http(s):// contain no install path and are not modified.
Prepare your source maps
- Configure your bundler to generate source maps that embed the original code (
sourcesContent). See Upload JavaScript source maps. If you compile the main process with tsc and no bundler, set both sourceMap: true and inlineSources: true. Otherwise, stack traces resolve but show no code snippets. - Use a different
service for the main process and for renderers. Datadog looks up source maps by service, version, and path, and the main process and a renderer can report the same path (for example, /dist/index.js). The main process reports the service passed to the Electron SDK init(). Renderers report the service passed to the Browser SDK init(). - Set a
version in the init() of both SDKs. It is not set by default, and the --release-version of the upload must match it. See Initialization parameters.
Upload with datadog-ci
Use datadog-ci to upload source maps. The --service and --release-version values must match your SDK configuration. The --minified-path-prefix value must be the path at which the uploaded files appear in stack traces. Run datadog-ci from your Git working tree. It sends the repository URL and the commit of the uploaded sources so Error Tracking can link stack frames to your code.
The examples assume an app packaged with its dist/ folder.
Main process built to dist/main/:
datadog-ci sourcemaps upload ./dist/main \
--service my-electron-app-main \
--release-version "$VERSION" \
--minified-path-prefix /dist/main/
Renderer loaded from file:// and built to dist/renderer/:
datadog-ci sourcemaps upload ./dist/renderer \
--service my-electron-app-renderer \
--release-version "$VERSION" \
--minified-path-prefix /dist/renderer/
Renderer loaded from a custom protocol, for example app://app/ serving the files of dist/renderer/. This requires Browser SDK 7.9.0 or later.
datadog-ci sourcemaps upload ./dist/renderer \
--service my-electron-app-renderer \
--release-version "$VERSION" \
--minified-path-prefix app://app/
Renderer loaded from http(s)://, for example a local server serving the files of dist/renderer/ at its root:
datadog-ci sourcemaps upload ./dist/renderer \
--service my-electron-app-renderer \
--release-version "$VERSION" \
--minified-path-prefix /
Limitations
Symbols of native extensions (native Node.js modules and addons) are not supported, so frames from these modules are not symbolicated in native crash reports.
Further Reading
Additional helpful documentation, links, and articles: