---
title: Electron Crash Reporting and Error Tracking
description: >-
  Set up Error Tracking for your Electron applications to get readable stack
  traces for main process and renderer errors.
breadcrumbs: >-
  Docs > RUM & Session Replay > Application Monitoring > Electron Monitoring >
  Electron Crash Reporting and Error Tracking
---

> For the complete documentation index, see [llms.txt](https://docs.datadoghq.com/llms.txt).

# Electron Crash Reporting and Error Tracking

## Overview{% #overview %}

Enable Error Tracking for your Electron application to surface, triage, and debug errors and crashes in [Error Tracking](https://docs.datadoghq.com/real_user_monitoring/error_tracking.md). 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](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/electron/setup.md#set-up-renderer-processes).

## Setup{% #setup %}

If you have not set up the RUM Electron SDK yet, follow the [setup instructions](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/electron/setup.md). Error and crash collection is enabled after the SDK is initialized in the main process.

### Report handled errors{% #report-handled-errors %}

Use `addError` to report an error that your code handles:

```ts
import { addError } from '@datadog/electron-sdk';

try {
  riskyOperation();
} catch (error) {
  addError(error, { context: { component: 'sync' } });
}
```

### Native crashes{% #native-crashes %}

Electron symbols are resolved automatically. You do not need to upload debug symbols.

## Upload source maps{% #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{% #prepare-your-source-maps %}

1. Configure your bundler to generate source maps that embed the original code (`sourcesContent`). See [Upload JavaScript source maps](https://docs.datadoghq.com/real_user_monitoring/guide/upload-javascript-source-maps.md). 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.
1. 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()`.
1. 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](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/electron/advanced_configuration.md#initialization-parameters).

### Upload with `datadog-ci`{% #upload-with-datadog-ci %}

Use [`datadog-ci`](https://github.com/DataDog/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.

{% tab title="Main process" %}
Main process built to `dist/main/`:

```sh
datadog-ci sourcemaps upload ./dist/main \
  --service my-electron-app-main \
  --release-version "$VERSION" \
  --minified-path-prefix /dist/main/
```

{% /tab %}

{% tab title="Renderer (file://)" %}
Renderer loaded from `file://` and built to `dist/renderer/`:

```sh
datadog-ci sourcemaps upload ./dist/renderer \
  --service my-electron-app-renderer \
  --release-version "$VERSION" \
  --minified-path-prefix /dist/renderer/
```

{% /tab %}

{% tab title="Renderer (custom protocol)" %}
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.

```sh
datadog-ci sourcemaps upload ./dist/renderer \
  --service my-electron-app-renderer \
  --release-version "$VERSION" \
  --minified-path-prefix app://app/
```

{% /tab %}

{% tab title="Renderer (http or https)" %}
Renderer loaded from `http(s)://`, for example a local server serving the files of `dist/renderer/` at its root:

```sh
datadog-ci sourcemaps upload ./dist/renderer \
  --service my-electron-app-renderer \
  --release-version "$VERSION" \
  --minified-path-prefix /
```

{% /tab %}

## Limitations{% #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{% #further-reading %}

Additional helpful documentation, links, and articles:

- [Get started with Error Tracking](https://docs.datadoghq.com/real_user_monitoring/error_tracking.md)
- [Visualize Error Tracking data in the Explorer](https://docs.datadoghq.com/real_user_monitoring/error_tracking/explorer.md)
- [Upload JavaScript source maps](https://docs.datadoghq.com/real_user_monitoring/guide/upload-javascript-source-maps.md)
- [datadog-ci](https://github.com/DataDog/datadog-ci)
- [Source code for electron-sdk](https://github.com/DataDog/electron-sdk)
