Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/electron-process-tracker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@bugsee/electron': minor
'@bugsee/trackers': minor
'@bugsee/node': minor
---

Electron main now reports per-process CPU and memory and child-process crashes. The `app_metrics` system trace (`{ processes: [{ type, pid, cpu_percent?, working_set_mb?, peak_working_set_mb?, private_mb? }] }`; `cpu_percent` is the share of the whole machine and is omitted on a process's first appearance; polled from `app.getAppMetrics()` when the `app` passed to `launchMain` has it; fields Electron does not supply are omitted) is emitted next to the existing node traces, and a `child_process_gone` system event (`{ type, reason, exitCode?, name? }`) is recorded when a GPU or utility process dies, only while `captureSystemEvents` is on. Both come from a new per-`app` `ElectronProcessTracker` in `@bugsee/trackers/electron`, which also takes over the `app.getGPUInfo` read behind `environment.hardware.gpu`: same `hardware.gpu` output, but a later launch now asks again when the earlier read failed or a different `gpuInfoType` is requested. `@bugsee/node` gains the advanced `wrapSystemEventsSource` launch option, which lets a platform mux extra events into the single `events.system` provider.
1 change: 1 addition & 0 deletions docs/PROGRESS.md

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions packages/bugsee/src/relaunch-options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ function optionKeys(pkg: string, file: string, name: string): string[] {
* - `lifecycleEventsListener` is held on the carrier slot (`setProcessLifecycleEventsListener`), so it
* survives a relaunch without being re-passed;
* - the Electron handles (`app`, `ipcMain`, `crashReporter`, `gpuInfoType`, `bridge`, `post`, `launch`, `onSessionId`,
* `nativeCrash`, `video`) belong to compositions that `relaunchWith` never re-runs (Electron has no
* `relaunch()`), and keeping them would pin Electron objects on `globalThis` for nothing;
* `nativeCrash`, `video`) belong to compositions that `relaunchWith` never re-runs (it re-runs the node
* launch, not `launchMain`), and keeping them would pin Electron objects on `globalThis` for nothing;
* - `appToken` (the Cloudflare and Nuxt adapters accept it inside their options object) is the token itself,
* which `setCarrierLastLaunch` stores separately as `lastLaunch.appToken`; it is never part of the kept options;
* - `onSpanProcessor` and `setupOtelProvider` (Next.js server) wire the Bugsee span processor into an OTel
Expand All @@ -125,7 +125,12 @@ function optionKeys(pkg: string, file: string, name: string): string[] {
* - `systemTraceProducers` (node/bun/deno) holds STATEFUL producer instances: a producer's `start()` is a
* no-op while it is already started, so an instance still running on another client would silently no-op
* on the new one, and its trackers stay bound to the scheduler/onError of the launch that built them. A
* relaunch therefore builds the runtime's fresh default set.
* relaunch therefore builds the runtime's fresh default set;
* - `wrapSystemEventsSource` (node, set by `@bugsee/electron`'s `launchMain`) is a platform composition seam whose
* wrapper is bound to the launch's tracker and reporter. A node/umbrella `relaunch()` in an Electron main re-runs
* the NODE launch, so like `systemTraceProducers` it is not re-applied: the relaunched client has the plain node
* producers and events source (no `app_metrics`/`child_process_gone`), while the kept `hardwareExtras` keeps
* serving `hardware.gpu`.
*/
const RESET_OPTIONS: readonly string[] = [
'app',
Expand Down Expand Up @@ -213,6 +218,7 @@ const RESET_OPTIONS: readonly string[] = [
'traceResponse',
'unhandledRejections',
'video',
'wrapSystemEventsSource',
];

// Builds a TypeScript program per platform interface: far slower on a shared CI runner than locally.
Expand Down
10 changes: 10 additions & 0 deletions packages/electron/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ If you pass `app` to `launchMain`, the SDK reports `app.getVersion()` as your ap

Electron does not expose a build number, so set `appBuild` (or `BUGSEE_APP_BUILD`) if you want one; in CI the commit hash is picked up automatically.

## Process telemetry

If you pass `app` to `launchMain`, the main process also reports what Electron can say about the app's processes, next to the usual Node traces (`process_memory_*`, `cpu_*`, `event_loop_*`):

- The `app_metrics` system trace, polled from `app.getAppMetrics()` once a second while system traces are captured: `{ processes: [{ type, pid, cpu_percent, working_set_mb, peak_working_set_mb, private_mb }] }`. `type` is Electron's process type (`Browser`, `Tab`, `GPU`, `Utility`, ...). `cpu_percent` is the share of the whole machine (0-100, rounded to 2 decimals), measured since the previous call. A field Electron does not supply is left out, never sent as zero, there is no sample for the first interval, and a process's first appearance (a new renderer, a restarted GPU or utility process) carries no `cpu_percent` because Chromium has no CPU window for it yet.
- A `child_process_gone` system event (`{ type, reason, exitCode, name }`) when a GPU or utility process exits, including a normal exit (`reason: 'clean-exit'`), so filter on `reason` if you only want crashes. It is recorded only while `captureSystemEvents` is on, and the `child-process-gone` listener is removed again by `client.stop()`.
- `environment.hardware.gpu` from `app.getGPUInfo(gpuInfoType)` (`'basic'` by default). A usable result is kept; a failed read, or a different `gpuInfoType` on a later launch, asks again.

A `relaunch()` from `@bugsee/node` or `@bugsee/bugsee` is not Electron-aware: after it `hardware.gpu` is still served, but `app_metrics` and `child_process_gone` stop until `launchMain` runs again.

## Links

- Repository: https://github.com/bugsee/bugsee-javascript/tree/main/packages/electron
Expand Down
4 changes: 3 additions & 1 deletion packages/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@
},
"dependencies": {
"@bugsee/browser": "workspace:*",
"@bugsee/capture": "workspace:*",
"@bugsee/core": "workspace:*",
"@bugsee/node": "workspace:*",
"@bugsee/protocol": "workspace:*"
"@bugsee/protocol": "workspace:*",
"@bugsee/trackers": "workspace:*"
},
"devDependencies": {
"@bugsee/util": "workspace:*",
Expand Down
Loading