@zharp/electron 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Zharp
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,63 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # @zharp/electron
2
+
3
+ Zharp Application Monitoring for Electron: errors, native crashes, logs and traces from the main
4
+ process and every window, in one session.
5
+
6
+ ```sh
7
+ npm init zharp@latest # sets it up: electron-vite, Electron Forge, electron-builder, plain Electron
8
+ npm install @zharp/electron
9
+ ```
10
+
11
+ ## Main
12
+
13
+ First thing in main — with ES modules, in a file of its own imported on main's first line:
14
+
15
+ ```ts
16
+ import { Zharp } from '@zharp/electron/main';
17
+
18
+ Zharp.init({
19
+ key: 'zpk_…', // the app's key: it can only send
20
+ renderer: { tracingOrigins: ['api.example.com'] }, // every window's settings
21
+ });
22
+ ```
23
+
24
+ Main runs [`@zharp/node`](https://zharp.io/docs/sdks/node): errors with the code that ran, requests,
25
+ failed queries, logs when asked for. It also:
26
+
27
+ - starts Electron's crash reporter with Zharp's minidump endpoint, so a native crash in any process
28
+ arrives with its stack, read with Electron's own symbols (fetched by Zharp, nothing to upload);
29
+ - reports a window or helper process that went away, written to disk first: as a log line naming
30
+ the crash's minidump when it has one (one crash, one issue), else as the error
31
+ (`RendererProcessGone`, `GPUProcessGone`…);
32
+ - keeps one session, a device ID per installation and the user for main and every window;
33
+ - adds the windows' preload to every session.
34
+
35
+ ## Each window
36
+
37
+ ```ts
38
+ import { Zharp } from '@zharp/electron/renderer';
39
+
40
+ Zharp.init();
41
+ ```
42
+
43
+ Without a bundler: `<script src="../node_modules/@zharp/electron/dist/renderer.min.js"></script>`.
44
+
45
+ Windows send through main over IPC: no outside URL for the page's Content-Security-Policy, one
46
+ queue (on disk while offline), one session.
47
+
48
+ ## The preload
49
+
50
+ Added by main. Only when main is bundled with its dependencies and `node_modules` isn't shipped
51
+ (Electron Forge with Vite or webpack), import it in your own preload:
52
+
53
+ ```ts
54
+ import '@zharp/electron/preload';
55
+ ```
56
+
57
+ ## Stacks
58
+
59
+ Packaged apps run from `app.asar` in a different folder on every computer; stacks are sent as
60
+ `app:///dist/renderer.js`, so every install groups into one issue and no one's user folder is
61
+ sent. Upload source maps with `@zharp/vite-plugin` or `@zharp/webpack-plugin`.
62
+
63
+ Electron 43 and later. Docs: https://zharp.io/docs/sdks/electron
@@ -0,0 +1,129 @@
1
+ import { NodeOptions, Zharp as Zharp$1 } from '@zharp/node';
2
+
3
+ interface User {
4
+ id: string | number;
5
+ email?: string;
6
+ name?: string;
7
+ }
8
+
9
+ /** Sent as `telemetry.sdk.version` and the scope's version. Bumped with package.json. */
10
+ declare const VERSION = "0.1.0";
11
+
12
+ declare const DEFAULT_ENDPOINT = "https://api.zharp.io/api/v1/otlp";
13
+ declare const SEVERITY: {
14
+ readonly trace: 1;
15
+ readonly debug: 5;
16
+ readonly info: 9;
17
+ readonly warn: 13;
18
+ readonly error: 17;
19
+ readonly fatal: 21;
20
+ };
21
+ type Level = keyof typeof SEVERITY;
22
+ type Attributes = Record<string, unknown>;
23
+ type LogFn = (message: unknown, attributes?: Attributes) => void;
24
+ interface ElectronOptions extends Omit<NodeOptions, 'rewritePaths' | 'captureUncaught'> {
25
+ /** The app's key from the Zharp dashboard (`zpk_…`). It can only send, so it's safe to ship in the app. */
26
+ key?: string;
27
+ /** `service.name`. Default: the app's name (`app.getName()`). */
28
+ service?: string;
29
+ /** `service.version`. Default: the app's version (`app.getVersion()`), which is also what its crash reports carry. */
30
+ release?: string;
31
+ /** `deployment.environment.name`. Default: `production` in a packaged app, `development` otherwise. */
32
+ environment?: string;
33
+ /**
34
+ * Native crashes: Electron's crash reporter (Crashpad) sends a minidump of any process that
35
+ * crashes to Zharp. Default **true**. `false` leaves the crash reporter alone, for an app that
36
+ * starts it itself.
37
+ */
38
+ crashReporter?: boolean;
39
+ /** Where minidumps go. Default: Zharp's minidump endpoint next to `endpoint`. */
40
+ minidumpUrl?: string;
41
+ /**
42
+ * Add the windows' preload to every session. Default **true**. When main is bundled and
43
+ * node_modules isn't shipped, import '@zharp/electron/preload' in your own preload instead.
44
+ */
45
+ preload?: boolean;
46
+ /**
47
+ * Settings for every window's SDK (`@zharp/electron/renderer`): `tracingOrigins`,
48
+ * `captureBodies`, `captureConsole`, `sampleRate`… A window's own `Zharp.init({…})` adds to them.
49
+ */
50
+ renderer?: Record<string, unknown>;
51
+ /** Minutes without activity in any window before a new session starts. Default 30. */
52
+ sessionTimeoutMinutes?: number;
53
+ /** Report uncaught exceptions and unhandled rejections in main. Default true. */
54
+ captureUncaught?: boolean;
55
+ }
56
+ /** `https://api.zharp.io/api/v1/otlp` → `https://api.zharp.io/api/v1/minidump`. */
57
+ declare function minidumpUrlFor(endpoint: string, key: string): string;
58
+ declare class ZharpElectron {
59
+ private running;
60
+ private user;
61
+ private readonly tags;
62
+ /** Crash reports already uploaded (earlier runs) or matched to a crash: never matched again. */
63
+ private readonly knownReports;
64
+ /** `Zharp.log.info("Order placed", { orderId })` — and debug, warn, error, fatal, trace. */
65
+ readonly log: Record<Level, LogFn>;
66
+ get isActive(): boolean;
67
+ /** The app's current session (shared by main and every window). */
68
+ get sessionId(): string | undefined;
69
+ /** This installation's ID (`device.id`). */
70
+ get deviceId(): string | undefined;
71
+ init(options?: ElectronOptions): void;
72
+ private start;
73
+ /**
74
+ * Who is using the app: `enduser.id` (and `enduser.email`, `enduser.name`) on everything main
75
+ * and every window send from now on, and on crash reports. Call it after login.
76
+ */
77
+ setUser(user: User | null): void;
78
+ /** Forget the user and start a new session — call it on logout. */
79
+ clearUser(): void;
80
+ /** An attribute on everything main sends from now on. `null` removes it. */
81
+ setTag(key: string, value: string | number | boolean | null | undefined): void;
82
+ /** Report an error you caught in main. Sent as handled, grouped with its other occurrences. */
83
+ captureError(error: unknown, attributes?: Attributes): void;
84
+ /** Run `fn` in a span named `name` (see @zharp/node). */
85
+ startSpan<T>(name: string, fn: (span: any) => T, options?: Parameters<typeof Zharp$1.startSpan>[2]): T;
86
+ /** Send everything waiting now: main's own, and the windows' batches kept on disk. */
87
+ flush(timeoutMs?: number): Promise<void>;
88
+ /** Flush and stop. */
89
+ close(): Promise<void>;
90
+ private startCrashReporter;
91
+ /** The session and user on main's own crash reports (each window's preload labels its own). */
92
+ private crashParameters;
93
+ private currentSession;
94
+ private touch;
95
+ private renew;
96
+ private context;
97
+ /** Every window hears that the session or the user changed. */
98
+ private broadcast;
99
+ private listen;
100
+ /**
101
+ * A process that went away, reported from main, which is still running.
102
+ *
103
+ * When it crashed and the crash reporter is on, Electron's crash reporter uploads its minidump
104
+ * too — the crash with its native stack, as its own issue. The two would be one crash counted
105
+ * twice, so main waits for that upload (Zharp answers it with the crash's ID, which Electron
106
+ * lists in getUploadedReports): once it's there, this is sent as a log line naming the crash
107
+ * (`zharp.minidump_id`) instead of a second error. Without a dump (killed, out of memory, the
108
+ * crash reporter off, the upload failing), it's sent as the error. Either way it's on disk
109
+ * first, so an app that goes down meanwhile sends the error on its next start.
110
+ */
111
+ private processGone;
112
+ /**
113
+ * The ID Zharp gave the next crash report Electron uploads, waiting up to 15 seconds for it. A
114
+ * report is new when it wasn't in the list when Zharp started or claimed by an earlier crash.
115
+ */
116
+ private minidumpUploaded;
117
+ /**
118
+ * Electron shows a dialog for an uncaught exception in main — but only while no one else
119
+ * listens, and @zharp/node does. So once Zharp has reported it, the dialog is shown as Electron
120
+ * would have, unless the app has a listener of its own. An unhandled rejection is reported and
121
+ * left as Electron leaves it (printed), never turned into an exit.
122
+ */
123
+ private keepElectronsDialog;
124
+ /** The windows' preload, added to every session (the default one and any partition). */
125
+ private addPreload;
126
+ }
127
+ declare const Zharp: ZharpElectron;
128
+
129
+ export { DEFAULT_ENDPOINT, type ElectronOptions, VERSION, Zharp, ZharpElectron, type User as ZharpUser, Zharp as default, minidumpUrlFor };
package/dist/main.d.ts ADDED
@@ -0,0 +1,129 @@
1
+ import { NodeOptions, Zharp as Zharp$1 } from '@zharp/node';
2
+
3
+ interface User {
4
+ id: string | number;
5
+ email?: string;
6
+ name?: string;
7
+ }
8
+
9
+ /** Sent as `telemetry.sdk.version` and the scope's version. Bumped with package.json. */
10
+ declare const VERSION = "0.1.0";
11
+
12
+ declare const DEFAULT_ENDPOINT = "https://api.zharp.io/api/v1/otlp";
13
+ declare const SEVERITY: {
14
+ readonly trace: 1;
15
+ readonly debug: 5;
16
+ readonly info: 9;
17
+ readonly warn: 13;
18
+ readonly error: 17;
19
+ readonly fatal: 21;
20
+ };
21
+ type Level = keyof typeof SEVERITY;
22
+ type Attributes = Record<string, unknown>;
23
+ type LogFn = (message: unknown, attributes?: Attributes) => void;
24
+ interface ElectronOptions extends Omit<NodeOptions, 'rewritePaths' | 'captureUncaught'> {
25
+ /** The app's key from the Zharp dashboard (`zpk_…`). It can only send, so it's safe to ship in the app. */
26
+ key?: string;
27
+ /** `service.name`. Default: the app's name (`app.getName()`). */
28
+ service?: string;
29
+ /** `service.version`. Default: the app's version (`app.getVersion()`), which is also what its crash reports carry. */
30
+ release?: string;
31
+ /** `deployment.environment.name`. Default: `production` in a packaged app, `development` otherwise. */
32
+ environment?: string;
33
+ /**
34
+ * Native crashes: Electron's crash reporter (Crashpad) sends a minidump of any process that
35
+ * crashes to Zharp. Default **true**. `false` leaves the crash reporter alone, for an app that
36
+ * starts it itself.
37
+ */
38
+ crashReporter?: boolean;
39
+ /** Where minidumps go. Default: Zharp's minidump endpoint next to `endpoint`. */
40
+ minidumpUrl?: string;
41
+ /**
42
+ * Add the windows' preload to every session. Default **true**. When main is bundled and
43
+ * node_modules isn't shipped, import '@zharp/electron/preload' in your own preload instead.
44
+ */
45
+ preload?: boolean;
46
+ /**
47
+ * Settings for every window's SDK (`@zharp/electron/renderer`): `tracingOrigins`,
48
+ * `captureBodies`, `captureConsole`, `sampleRate`… A window's own `Zharp.init({…})` adds to them.
49
+ */
50
+ renderer?: Record<string, unknown>;
51
+ /** Minutes without activity in any window before a new session starts. Default 30. */
52
+ sessionTimeoutMinutes?: number;
53
+ /** Report uncaught exceptions and unhandled rejections in main. Default true. */
54
+ captureUncaught?: boolean;
55
+ }
56
+ /** `https://api.zharp.io/api/v1/otlp` → `https://api.zharp.io/api/v1/minidump`. */
57
+ declare function minidumpUrlFor(endpoint: string, key: string): string;
58
+ declare class ZharpElectron {
59
+ private running;
60
+ private user;
61
+ private readonly tags;
62
+ /** Crash reports already uploaded (earlier runs) or matched to a crash: never matched again. */
63
+ private readonly knownReports;
64
+ /** `Zharp.log.info("Order placed", { orderId })` — and debug, warn, error, fatal, trace. */
65
+ readonly log: Record<Level, LogFn>;
66
+ get isActive(): boolean;
67
+ /** The app's current session (shared by main and every window). */
68
+ get sessionId(): string | undefined;
69
+ /** This installation's ID (`device.id`). */
70
+ get deviceId(): string | undefined;
71
+ init(options?: ElectronOptions): void;
72
+ private start;
73
+ /**
74
+ * Who is using the app: `enduser.id` (and `enduser.email`, `enduser.name`) on everything main
75
+ * and every window send from now on, and on crash reports. Call it after login.
76
+ */
77
+ setUser(user: User | null): void;
78
+ /** Forget the user and start a new session — call it on logout. */
79
+ clearUser(): void;
80
+ /** An attribute on everything main sends from now on. `null` removes it. */
81
+ setTag(key: string, value: string | number | boolean | null | undefined): void;
82
+ /** Report an error you caught in main. Sent as handled, grouped with its other occurrences. */
83
+ captureError(error: unknown, attributes?: Attributes): void;
84
+ /** Run `fn` in a span named `name` (see @zharp/node). */
85
+ startSpan<T>(name: string, fn: (span: any) => T, options?: Parameters<typeof Zharp$1.startSpan>[2]): T;
86
+ /** Send everything waiting now: main's own, and the windows' batches kept on disk. */
87
+ flush(timeoutMs?: number): Promise<void>;
88
+ /** Flush and stop. */
89
+ close(): Promise<void>;
90
+ private startCrashReporter;
91
+ /** The session and user on main's own crash reports (each window's preload labels its own). */
92
+ private crashParameters;
93
+ private currentSession;
94
+ private touch;
95
+ private renew;
96
+ private context;
97
+ /** Every window hears that the session or the user changed. */
98
+ private broadcast;
99
+ private listen;
100
+ /**
101
+ * A process that went away, reported from main, which is still running.
102
+ *
103
+ * When it crashed and the crash reporter is on, Electron's crash reporter uploads its minidump
104
+ * too — the crash with its native stack, as its own issue. The two would be one crash counted
105
+ * twice, so main waits for that upload (Zharp answers it with the crash's ID, which Electron
106
+ * lists in getUploadedReports): once it's there, this is sent as a log line naming the crash
107
+ * (`zharp.minidump_id`) instead of a second error. Without a dump (killed, out of memory, the
108
+ * crash reporter off, the upload failing), it's sent as the error. Either way it's on disk
109
+ * first, so an app that goes down meanwhile sends the error on its next start.
110
+ */
111
+ private processGone;
112
+ /**
113
+ * The ID Zharp gave the next crash report Electron uploads, waiting up to 15 seconds for it. A
114
+ * report is new when it wasn't in the list when Zharp started or claimed by an earlier crash.
115
+ */
116
+ private minidumpUploaded;
117
+ /**
118
+ * Electron shows a dialog for an uncaught exception in main — but only while no one else
119
+ * listens, and @zharp/node does. So once Zharp has reported it, the dialog is shown as Electron
120
+ * would have, unless the app has a listener of its own. An unhandled rejection is reported and
121
+ * left as Electron leaves it (printed), never turned into an exit.
122
+ */
123
+ private keepElectronsDialog;
124
+ /** The windows' preload, added to every session (the default one and any partition). */
125
+ private addPreload;
126
+ }
127
+ declare const Zharp: ZharpElectron;
128
+
129
+ export { DEFAULT_ENDPOINT, type ElectronOptions, VERSION, Zharp, ZharpElectron, type User as ZharpUser, Zharp as default, minidumpUrlFor };