You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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/)
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."
4
4
sdk: sentry.javascript.electron
5
5
categories:
6
6
- javascript
7
7
- desktop
8
8
---
9
9
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).
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:
15
15
16
-
Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.
Run the command for your preferred package manager to add the Sentry SDK to your application:
21
31
22
32
```bash {tabTitle:npm}
23
33
npm install @sentry/electron --save
@@ -31,21 +41,29 @@ yarn add @sentry/electron
31
41
pnpm add @sentry/electron
32
42
```
33
43
34
-
## Configure
44
+
## Step 2: Configure
45
+
46
+
You should initialize the SDK in both the `main` process and every `renderer` process you spawn.
35
47
36
-
You should `init`the SDK in the `main` process and every `renderer` process you spawn.
48
+
### Configure the Main Process
37
49
38
-
In the Electron `main` process:
50
+
Initialize the SDK in your Electron `main` process as early as possible:
39
51
40
52
```javascript
41
53
import*asSentryfrom"@sentry/electron/main";
42
54
43
55
Sentry.init({
44
56
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
45
61
});
46
62
```
47
63
48
-
In the Electron `renderer` process:
64
+
### Configure the Renderer Process
65
+
66
+
Initialize the SDK in your Electron renderer processes:
49
67
50
68
```javascript
51
69
import*asSentryfrom"@sentry/electron/renderer";
@@ -86,36 +104,28 @@ Sentry.init({
86
104
replaysSessionSampleRate:0.1,
87
105
replaysOnErrorSampleRate:1.0,
88
106
// ___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
89
112
});
90
113
```
91
114
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:
93
117
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*asSentryfrom"@sentry/electron/renderer";
99
120
100
-
```shell
101
-
npx @sentry/wizard@latest -i electron
121
+
Sentry.init(); // don't forget to add your configuration options
102
122
```
103
123
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>
115
125
126
+
<Expandabletitle="Did you change the userData directory?"level="warning">
116
127
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.
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:
131
142
132
143
```javascript
133
144
import { init } from"@sentry/electron/renderer";
@@ -136,19 +147,19 @@ import { init as reactInit } from "@sentry/react";
136
147
init(
137
148
{
138
149
dsn:"___PUBLIC_DSN___",
139
-
integrations: [ /* integrations */ ],
150
+
integrations: [
151
+
/* integrations */
152
+
],
140
153
/* Other Electron and React SDK config */
141
154
},
142
155
reactInit
143
156
);
144
157
```
145
158
146
-
## Offline Support
159
+
## Step 3: Offline Support
147
160
148
161
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:
152
163
153
164
```javascript
154
165
import*asSentryfrom"@sentry/electron/main";
@@ -194,12 +205,11 @@ Sentry.init({
194
205
});
195
206
```
196
207
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)
200
209
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.
202
211
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`.
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
254
264
255
265
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:
256
266
257
-
258
267
```javascript
259
268
import { session } from"electron";
260
269
import*asSentryfrom"@sentry/electron/main";
@@ -278,39 +287,39 @@ If you would like to manually bundle and configure the preload script, you shoul
278
287
import"@sentry/electron/preload";
279
288
```
280
289
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.
282
291
283
292
Check out the [example apps](https://github.com/getsentry/sentry-electron/tree/master/examples) for how to do this.
284
293
285
-
## Debug Information
294
+
## Step 5: Debug Information (Optional)
286
295
287
296
To get symbolicated stack traces for native crashes, you should enable fetching
288
297
debug symbols from the Electron symbol server. Go to **Project Settings > Debug
289
298
Files** and add Electron to the list of built-in repositories.
290
299
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,
292
301
or spawns subprocesses, you should upload those symbols manually using the
293
302
Sentry CLI. For more information, see [_Native Usage_](/platforms/javascript/guides/electron/#native).
294
303
295
304
<Alertlevel="warning"title="Known Issue">
296
305
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 subprocesses 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.
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).
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.
308
317
309
318
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.
310
319
311
320
<Alertlevel="warning"title="A Word on Data Privacy">
312
321
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.
314
323
315
324
</Alert>
316
325
@@ -329,17 +338,17 @@ If your application contains custom native extensions or you wish to symbolicate
329
338
crashes from a spawned child process, upload their debug information manually
330
339
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
331
340
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.
333
342
334
343
### Child Processes
335
344
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)).
337
346
338
347
Once the crash reporter is active, the SDK will automatically capture native
| Electron `renderer` process |`renderer`| ✓ | ✓ | ✓ |
345
354
| Electron `utilityProcess`|`utility`| ✓ | ✓ | ✓ <sup>1</sup> |
@@ -350,7 +359,7 @@ crashes for the following processes:
350
359
351
360
### Manual Crash Reporting
352
361
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:
354
363
355
364
```javascript
356
365
const { crashReporter } =require("electron");
@@ -362,6 +371,83 @@ crashReporter.start({
362
371
});
363
372
```
364
373
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*asSentryfrom"@sentry/electron/main";
387
+
388
+
app.on("ready", () => {
389
+
thrownewError("Sentry test error in main process");
Sentry.startSpan({ op:"test", name:"Renderer test span" }, () => {
423
+
thrownewError("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).
0 commit comments