Skip to content

Commit 733f75a

Browse files
docs(js): Update Electron quick start guide (#15298)
<!-- Use this checklist to make sure your PR is ready for merge. You may delete any sections you don't need. --> ## DESCRIBE YOUR PR This PR focuses on transforming the existing Electron guide into a Quick Start guide. **Notes:** - I've removed the information about the Wizard. After testing it, I found that it created a file where I can add my project/org data, but it didn't set up the SDK (like the Next.js wizard, for example). This could be frustrating for users. Please let me know what you think and if I've missed something! - I added a new section, verify > I tested the code snippets locally, and they worked in my setup, but please have a good look at them **Next steps:** You will notice that I haven't changed much for Steps number 3,4,5, and 7. The content in these sections seems to advanced for a quick start guide. I plan to create a **follow-up ticket to move this content** to other pages within the Electron docs (of course, we will link to them from the quick start guide). I noticed that @timfish handles a lot of the Electron SDK work, and you seem like the person to involve when changing the docs. Is that correct? If so, I will @ you in the follow-up ticket so we can align on the changes. Thanks!! Closes #15269 ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [x] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/)
1 parent c5fd8dd commit 733f75a

File tree

1 file changed

+149
-63
lines changed
  • docs/platforms/javascript/guides/electron

1 file changed

+149
-63
lines changed

docs/platforms/javascript/guides/electron/index.mdx

Lines changed: 149 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
11
---
22
title: Electron
3-
description: "Electron is a framework for building desktop applications using JavaScript, HTML, and CSS. Learn how to set it up with Sentry."
3+
description: "Learn how to manually set up Sentry in your Electron app and capture your first errors."
44
sdk: sentry.javascript.electron
55
categories:
66
- javascript
77
- desktop
88
---
99

10-
`@sentry/electron` is the official Sentry SDK for Electron applications. It can capture JavaScript exceptions in the `main` and `renderer` processes, as well as collect native crash reports (Minidumps).
10+
<PlatformContent includePath="getting-started-prerequisites" />
1111

12-
## Features
12+
## Step 1: Install
1313

14-
In addition to capturing errors, you can monitor interactions between multiple services or applications by [enabling tracing](/concepts/key-terms/tracing/). You can also get to the root of an error or performance issue faster, by watching a video-like reproduction of a user session with [session replay](/product/explore/session-replay/web/getting-started/).
14+
Choose the features you want to configure, and this guide will show you how:
1515

16-
Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.
16+
<OnboardingOptionButtons
17+
options={[
18+
"error-monitoring",
19+
"performance",
20+
"session-replay",
21+
"user-feedback",
22+
"logs",
23+
]}
24+
/>
1725

18-
## Install
26+
<PlatformContent includePath="getting-started-features-expandable" />
1927

20-
<OnboardingOptionButtons options={["error-monitoring", "performance", "session-replay", "user-feedback", "logs"]} />
28+
### Install the Sentry SDK
29+
30+
Run the command for your preferred package manager to add the Sentry SDK to your application:
2131

2232
```bash {tabTitle:npm}
2333
npm install @sentry/electron --save
@@ -31,21 +41,29 @@ yarn add @sentry/electron
3141
pnpm add @sentry/electron
3242
```
3343

34-
## Configure
44+
## Step 2: Configure
45+
46+
You should initialize the SDK in both the `main` process and every `renderer` process you spawn.
3547

36-
You should `init` the SDK in the `main` process and every `renderer` process you spawn.
48+
### Configure the Main Process
3749

38-
In the Electron `main` process:
50+
Initialize the SDK in your Electron `main` process as early as possible:
3951

4052
```javascript
4153
import * as Sentry from "@sentry/electron/main";
4254

4355
Sentry.init({
4456
dsn: "___PUBLIC_DSN___",
57+
// ___PRODUCT_OPTION_START___ logs
58+
// Enable logs to be sent to Sentry
59+
_experiments: { enableLogs: true },
60+
// ___PRODUCT_OPTION_END___ logs
4561
});
4662
```
4763

48-
In the Electron `renderer` process:
64+
### Configure the Renderer Process
65+
66+
Initialize the SDK in your Electron renderer processes:
4967

5068
```javascript
5169
import * as Sentry from "@sentry/electron/renderer";
@@ -86,36 +104,28 @@ Sentry.init({
86104
replaysSessionSampleRate: 0.1,
87105
replaysOnErrorSampleRate: 1.0,
88106
// ___PRODUCT_OPTION_END___ session-replay
107+
// ___PRODUCT_OPTION_START___ logs
108+
109+
// Enable logs to be sent to Sentry
110+
_experiments: { enableLogs: true },
111+
// ___PRODUCT_OPTION_END___ logs
89112
});
90113
```
91114

92-
Once configured, all unhandled exceptions and native crashes are automatically captured by Sentry.
115+
<Alert>
116+
If your app uses a preload script and `contextIsolation: true`, Sentry can't automatically capture errors that occur in the preload context. To include those, initialize Sentry in your preload script as well:
93117

94-
**Important:** Note your DSN. The DSN (Data Source Name) tells the SDK where to send events. If you forget it, view _Settings -> Projects -> Client Keys (DSN)_ in the Sentry web UI.
95-
96-
## Wizard
97-
98-
Our Sentry Wizard can help with the setup process. Make sure you have installed the `@sentry/wizard` npm package globally, then run:
118+
```javascript
119+
import * as Sentry from "@sentry/electron/renderer";
99120

100-
```shell
101-
npx @sentry/wizard@latest -i electron
121+
Sentry.init(); // don't forget to add your configuration options
102122
```
103123

104-
This will guide you through the installation and configuration process and suggest useful tools for development. If you instead prefer to setup manually, keep reading.
105-
106-
## Configuring the Client
107-
108-
Start by configuring the SDK as described above. This will enable the [Electron CrashReporter](https://electronjs.org/docs/api/crash-reporter) for native app crashes and capture any uncaught JavaScript exceptions using the JavaScript SDKs under the hood. Be sure to call this function as early as possible in the `main` process and all `renderer` processes to also catch errors during startup.
109-
110-
If you are using preload scripts, have `contextIsolation` enabled and want to
111-
capture errors from the isolated preload context, you should call the renderer `init`
112-
early in that context too.
113-
114-
### App `userData` Directory
124+
</Alert>
115125

126+
<Expandable title="Did you change the userData directory?" level="warning">
116127
If you change the `userData` directory used by your app, ensure this change is made before you configure the SDK as this path is used to cache scope and events between application restarts.
117128

118-
119129
```javascript
120130
import { app } from "electron";
121131
import * as Sentry from "@sentry/electron/main";
@@ -124,10 +134,11 @@ app.setPath("userData", "~/.config/my-app");
124134
Sentry.init({ dsn: "___PUBLIC_DSN___" });
125135
```
126136

127-
## Framework-Specific SDKs
137+
</Expandable>
138+
139+
### Using Framework-Specific SDKs
128140

129-
If you're using a framework-specific Sentry SDK in the Electron renderers, you
130-
can pass that `init` function as the second parameter and the two SDKs functionalities will be combined:
141+
If you're using a framework in your renderers, you can combine the Electron SDK with the framework SDK:
131142

132143
```javascript
133144
import { init } from "@sentry/electron/renderer";
@@ -136,19 +147,19 @@ import { init as reactInit } from "@sentry/react";
136147
init(
137148
{
138149
dsn: "___PUBLIC_DSN___",
139-
integrations: [ /* integrations */ ],
150+
integrations: [
151+
/* integrations */
152+
],
140153
/* Other Electron and React SDK config */
141154
},
142155
reactInit
143156
);
144157
```
145158

146-
## Offline Support
159+
## Step 3: Offline Support
147160

148161
The default transport automatically handles offline events caching from both the
149-
main and renderer processes. Following, are a number of options that allow you
150-
to customize queueing behavior:
151-
162+
main and renderer processes. Here are several options that allow you to customize queueing behavior:
152163

153164
```javascript
154165
import * as Sentry from "@sentry/electron/main";
@@ -194,12 +205,11 @@ Sentry.init({
194205
});
195206
```
196207

197-
## Inter-Process Communication
198-
199-
To give the most detailed context for all events including native crashes, the SDK merges context, scope and breadcrumbs from all processes in the Electron `main` process.
208+
## Step 4: Inter-Process Communication (Optional)
200209

201-
By default, the SDK attempts to establish communication from `renderer` to `main` via Electron IPC API's and if that fails, falls back to using a custom HTTP protocol. You can change this default via the `ipcMode` option which can be one of `Classic`, `Protocol` or `Both`.
210+
To provide the most detailed context for all events, including native crashes, the SDK merges context, scope, and breadcrumbs from all processes into the Electron `main` process.
202211

212+
By default, the SDK attempts to establish communication from `renderer` to `main` via Electron IPC APIs, and if that fails, falls back to using a custom HTTP protocol. You can change this default via the `ipcMode` option, which can be one of `Classic`, `Protocol`, or `Both`.
203213

204214
```javascript
205215
const { init, IPCMode } = require("@sentry/electron/main");
@@ -231,19 +241,19 @@ Sentry.init({
231241
**In renderer processes:**
232242

233243
```javascript
234-
import * as Sentry from '@sentry/electron/renderer';
244+
import * as Sentry from "@sentry/electron/renderer";
235245

236246
Sentry.init({
237-
ipcNamespace: 'some-app',
247+
ipcNamespace: "some-app",
238248
});
239249
```
240250

241251
**In preload scripts:**
242252

243253
```javascript
244-
import { hookupIpc } from '@sentry/electron/preload-namespaced';
254+
import { hookupIpc } from "@sentry/electron/preload-namespaced";
245255

246-
hookupIpc('some-app');
256+
hookupIpc("some-app");
247257
```
248258

249259
When set, the IPC channels used by Sentry will be prefixed with the specified namespace (e.g., `some-app`), helping to avoid conflicts with other IPC channels in your application. Make sure to use the same namespace value across all processes for proper communication.
@@ -254,7 +264,6 @@ For more configuration options, see the <PlatformLink to="/configuration/options
254264

255265
The SDK attempts to inject a preload script via [`session.setPreloads(preloads)`](https://www.electronjs.org/docs/latest/api/session#sessetpreloadspreloads) and by default only does this for the `defaultSession`. If you are using other sessions, you can pass custom sessions via the `getSessions` option in the `main` process:
256266

257-
258267
```javascript
259268
import { session } from "electron";
260269
import * as Sentry from "@sentry/electron/main";
@@ -278,39 +287,39 @@ If you would like to manually bundle and configure the preload script, you shoul
278287
import "@sentry/electron/preload";
279288
```
280289

281-
This script exposes IPC to the isolated renderer via Electrons `contextBridge` API.
290+
This script exposes IPC to the isolated renderer via Electron's `contextBridge` API.
282291

283292
Check out the [example apps](https://github.com/getsentry/sentry-electron/tree/master/examples) for how to do this.
284293

285-
## Debug Information
294+
## Step 5: Debug Information (Optional)
286295

287296
To get symbolicated stack traces for native crashes, you should enable fetching
288297
debug symbols from the Electron symbol server. Go to **Project Settings > Debug
289298
Files** and add Electron to the list of built-in repositories.
290299

291-
If your app uses a custom Electron fork, contains modules with native extensions
300+
If your app uses a custom Electron fork, contains modules with native extensions,
292301
or spawns subprocesses, you should upload those symbols manually using the
293302
Sentry CLI. For more information, see [_Native Usage_](/platforms/javascript/guides/electron/#native).
294303

295304
<Alert level="warning" title="Known Issue">
296305

297-
It is currently not possible to send events from native code (such as a C++ extension). However, crashes will still be reported to Sentry if they happen in a process where the SDK has been configured. Also, crash reports from sub processes will not be reported automatically on all platforms. This feature will be added in a future SDK update.
306+
It is currently not possible to send events from native code (such as a C++ extension). However, crashes will still be reported to Sentry if they happen in a process where the SDK has been configured. Additionally, crash reports from sub-processes will not be reported automatically on all platforms. This feature will be added in a future SDK update.
298307

299308
</Alert>
300309

301-
## Dealing with Minified Source Code
310+
## Step 6: Add Readable Stack Traces With Source Maps (Optional)
302311

303-
The Electron SDK supports [Source Maps](https://web.dev/articles/source-maps). If you upload source maps in addition to your minified files that data becomes available in Sentry. For more information see [_Source Maps_](/platforms/javascript/guides/electron/#source-maps).
312+
<PlatformContent includePath="getting-started-sourcemaps-short-version" />
304313

305-
## Native
314+
## Step 7: Native (Optional)
306315

307-
Sentry can process Minidumps created when any of the Electron processes crash. To do so, the SDK needs to upload those files once the application restarts (or immediately for renderer crashes). All event meta data including user information and breadcrumbs are included in these uploads.
316+
Sentry can process Minidumps created when any of the Electron processes crash. To do so, the SDK needs to upload those files once the application restarts (or immediately for renderer crashes). All event metadata, including user information and breadcrumbs, is included in these uploads.
308317

309318
Due to [restrictions of macOS app sandboxing](https://electronjs.org/docs/tutorial/mac-app-store-submission-guide#limitations-of-mas-build), native crashes cannot be collected in Mac App Store builds. In this case, native crash handling will be disabled.
310319

311320
<Alert level="warning" title="A Word on Data Privacy">
312321

313-
Minidumps are memory dumps of the process at the moment it crashes. As such, they might contain sensitive information on the target system, such as environment variables, local path names or maybe even in-memory representations of input fields including passwords. **Sentry does not store these memory dumps**. Once processed, they are removed immediately and all sensitive information is stripped from the resulting issues.
322+
Minidumps are memory dumps of the process at the moment it crashes. As such, they might contain sensitive information on the target system, such as environment variables, local path names, or maybe even in-memory representations of input fields including passwords. **Sentry does not store these memory dumps**. Once processed, they are removed immediately, and all sensitive information is stripped from the resulting issues.
314323

315324
</Alert>
316325

@@ -329,17 +338,17 @@ If your application contains custom native extensions or you wish to symbolicate
329338
crashes from a spawned child process, upload their debug information manually
330339
during your build or release process. See [_Debug Information Files_](/platforms/javascript/guides/electron/data-management/debug-files/) for a detailed description of how to
331340
set up Sentry for native development. Additionally, see [_Uploading Debug
332-
Information_](/cli/dif/) for the upload process.
341+
Information_](/cli/dif/) for details on the upload process.
333342

334343
### Child Processes
335344

336-
The SDK relies on the [Electron crashReporter](https://electronjs.org/docs/api/crash-reporter) to capture crash dumps. To receive crash reports for child processes, you need to make sure the crash reporter is activated by either the SDK or manually (see [below](/platforms/javascript/guides/electron/#manual-crash-reporting)).
345+
The SDK relies on the [Electron crashReporter](https://electronjs.org/docs/api/crash-reporter) to capture crash dumps. To receive crash reports for child processes, ensure the crash reporter is activated by either the SDK or manually (see [below](/platforms/javascript/guides/electron/#manual-crash-reporting)).
337346

338347
Once the crash reporter is active, the SDK will automatically capture native
339348
crashes for the following processes:
340349

341350
| | `event.process` tag | macOS | Windows | Linux |
342-
|-----------------------------|---------------------|-------|---------|----------------|
351+
| --------------------------- | ------------------- | ----- | ------- | -------------- |
343352
| Electron `main` process | `browser` ||||
344353
| Electron `renderer` process | `renderer` ||||
345354
| Electron `utilityProcess` | `utility` ||| ✓ <sup>1</sup> |
@@ -350,7 +359,7 @@ crashes for the following processes:
350359

351360
### Manual Crash Reporting
352361

353-
You can also capture native crashes by starting the [Electron CrashReporter](https://electronjs.org/docs/api/crash-reporter) manually. Sentry is able to provide symbolicated stack traces and show system information, but no Electron-specific metadata, breadcrumbs or context information will be present. This is useful in cases where you cannot use the full Electron SDK:
362+
You can also capture native crashes by starting the [Electron CrashReporter](https://electronjs.org/docs/api/crash-reporter) manually. Sentry can provide symbolicated stack traces and show system information, but no Electron-specific metadata, breadcrumbs, or context information will be present. This is useful in cases where you cannot use the full Electron SDK:
354363

355364
```javascript
356365
const { crashReporter } = require("electron");
@@ -362,6 +371,83 @@ crashReporter.start({
362371
});
363372
```
364373

365-
## Source Maps
374+
## Step 8: Verify Your Setup
375+
376+
Let's test your setup and confirm that Sentry is working correctly.
377+
378+
### Issues
379+
380+
**Main process error**
381+
382+
Add an event listener that throws an error in your main process:
383+
384+
```javascript
385+
import { app } from "electron";
386+
import * as Sentry from "@sentry/electron/main";
387+
388+
app.on("ready", () => {
389+
throw new Error("Sentry test error in main process");
390+
});
391+
```
392+
393+
**Renderer process error**
394+
395+
Add a test button in one of your HTML pages:
396+
397+
```html {filename: index.html}
398+
<button id="testError">Break the world</button>
399+
400+
<script src="renderer.js"></script>
401+
```
402+
403+
Then, in your renderer, add the following:
404+
405+
```javascript
406+
document.getElementById("testError").addEventListener("click", () => {
407+
throw new Error("Sentry test error in renderer process");
408+
});
409+
```
410+
411+
<OnboardingOption optionId="performance" hideForThisOption>
412+
Start your app and trigger two errors that Sentry will capture: one from the
413+
main process and one from the renderer.
414+
</OnboardingOption>
415+
416+
<OnboardingOption optionId="performance">
417+
### Tracing
418+
To test tracing in your renderer, start a trace to measure the time it takes to execute your code:
419+
420+
```javascript
421+
document.getElementById("testError").addEventListener("click", () => {
422+
Sentry.startSpan({ op: "test", name: "Renderer test span" }, () => {
423+
throw new Error("Sentry test error in renderer process");
424+
});
425+
});
426+
```
427+
428+
Start your app and trigger two errors that Sentry will capture: one from the main process and one from the renderer. It will also start a trace with the defined name.
429+
430+
</OnboardingOption>
431+
432+
### View Captured Data in Sentry
433+
434+
Now, head over to your project on [Sentry.io](https://sentry.io/) to view the collected data (it takes a couple of moments for the data to appear).
435+
436+
<PlatformContent includePath="getting-started-verify-locate-data" />
437+
438+
## Next Steps
439+
440+
At this point, you should have integrated Sentry into your Electron application and should already be sending data to your Sentry project.
441+
442+
Now's a good time to customize your setup and look into more advanced topics. Our next recommended steps for you are:
443+
444+
- Continue to <PlatformLink to="/configuration">customize your configuration</PlatformLink>
445+
- Learn how to <PlatformLink to="/usage">manually capture errors</PlatformLink>
446+
- Get familiar with [Sentry's product features](/product/) like tracing, insights, and alerts
447+
448+
<Expandable permalink={false} title="Are you having problems setting up the SDK?">
449+
450+
- Find various topics in <PlatformLink to="/troubleshooting">Troubleshooting</PlatformLink>
451+
- [Get support](https://sentry.zendesk.com/hc/en-us/)
366452

367-
To find out why Sentry needs your source maps and how to provide them visit: [Source Maps](/platforms/javascript/sourcemaps/)
453+
</Expandable>

0 commit comments

Comments
 (0)