Electron
@zharp/electron sends an Electron app's errors, native crashes, logs and traces from the main process and every window, in one session, with readable stacks from every install.
This SDK is new, and its API may still change before 1.0. Requires Electron 43 or later (the three versions Electron supports).
One package with three entries: @zharp/electron/main in the main process (it runs @zharp/node there), @zharp/electron/renderer in each window (built on @zharp/browser), and @zharp/electron/preload, the bridge between them, which main usually adds by itself.
Install
The quickest way, in the app's folder — electron-vite, Electron Forge (Vite or webpack), electron-builder or plain Electron:
npm init zharp@latest
It signs you in, creates or picks the app in Zharp, installs the SDK, starts it in main and in your windows, and puts the keys where git ignores them. It shows every change before making it.
By hand
npm install @zharp/electron
Initialize
Main
Start it before anything else in main. With ES modules, imports load before any code runs, so put init in a file of its own and import that first:
// src/main/zharp.ts
import { Zharp } from '@zharp/electron/main';
Zharp.init({
key: 'zpk_…',
environment: 'production',
renderer: { tracingOrigins: ['api.example.com'] }, // every window's settings
});
// src/main/index.ts — first line
import './zharp';
import { app, BrowserWindow } from 'electron';// main.js (CommonJS) — first lines
const { Zharp } = require('@zharp/electron/main');
Zharp.init({ key: 'zpk_…' });
const { app, BrowserWindow } = require('electron');The key is safe to ship in the app: it can only send. With electron-vite, keep it in .env as MAIN_VITE_ZHARP_KEY and pass import.meta.env.MAIN_VITE_ZHARP_KEY; it's baked into the build. The service defaults to the app's name, the release to its version, and the environment to production in a packaged app and development otherwise.
Each window
// your renderer entry (src/renderer/src/main.tsx, src/renderer.ts…)
import { Zharp } from '@zharp/electron/renderer';
Zharp.init(); // the key, service, release and session come from mainWindows without a bundler load the script build instead, which starts itself:
<!-- a window without a bundler, before its own scripts --> <script src="../node_modules/@zharp/electron/dist/renderer.min.js"></script>
Windows send through main over IPC. Nothing leaves the page, so a strict Content-Security-Policy (connect-src 'self') needs no Zharp URL; main keeps what can't be sent on disk while the computer is offline; and every window is in the same session as main.
The preload
Main adds its preload to every session by itself — with sandbox and contextIsolation on, as Electron defaults to. Only when main is bundled with its dependencies and node_modules isn't shipped (Electron Forge with Vite or webpack) does your own preload need it:
// src/preload.ts — Electron Forge with Vite or webpack import '@zharp/electron/preload';
Logs
Zharp.log.info('Export finished', { files: 3 }); // trace, debug, info, warn, error, fatal — in main or a windowEach log carries the session, user, device and trace. By default only what you send with Zharp.log goes to Zharp. logs: true sends main's console and output too; renderer: { logs: true } the windows' console.
Logs only
If you only want logs, turn tracing off. Logs, errors, and the user and session they belong to are still sent; no spans are recorded and no trace headers are added to outgoing requests.
// main
Zharp.init({
key: "zpk_…",
tracing: false,
renderer: { tracing: false },
});The logs show on the Logs page under the service name, and on the app's Logs tab with the user and session of each line. The key comes from an app — see Get a key. To add tracing later, remove the option; nothing else changes.
Errors
- Main: uncaught exceptions and unhandled rejections, with the code that ran. Electron still shows its "A JavaScript error occurred in the main process" dialog, as without Zharp, and the app doesn't exit. Failed database queries come with their statement.
- Windows: uncaught errors and unhandled rejections; React render errors with
Zharp.reactErrorHandler()orZharpErrorBoundaryfrom@zharp/browser/react. - Native crashes: main starts Electron's crash reporter, so a crash in any process — main, a window, the GPU process — arrives as a minidump with its native stack, labelled with the release, the device, the session and the user. Frames in Electron itself are read with Electron's symbols and aren't counted as your code, so a crash in your own
.nodemodule is shown where it happened. - A window or helper process gone: when a renderer or the GPU or a utility process crashes, runs out of memory or is killed, main reports it with the reason, the exit code and the window. When the crash has a minidump, that's the crash's one issue, and main's report is a log line naming it (
zharp.minidump_id); without one (killed, out of memory), main's report is the error (RendererProcessGone,GPUProcessGone…). It's written to disk first, so it's sent even if the app goes down with it.
Report one you caught yourself:
try {
await exportPdf(doc);
} catch (error) {
Zharp.captureError(error, { documentId: doc.id }); // handled
}Readable stack traces
Your JavaScript
A packaged app runs from app.asar in a folder that's different on every computer. Zharp reads every install's frames as app:///dist/renderer.js, so errors from all of them are one issue and no one's user folder is sent. With the build's source maps uploaded, frames show your original files and lines, with the code:
// electron.vite.config.ts
import { defineConfig } from 'electron-vite';
import { zharp } from '@zharp/vite-plugin';
export default defineConfig({
main: { plugins: [zharp({ app: 123 })] },
preload: {},
renderer: { plugins: [react(), zharp({ app: 123 })] },
});// vite.renderer.config.ts and vite.main.config.ts (Electron Forge)
import { defineConfig } from 'vite';
import { zharp } from '@zharp/vite-plugin';
export default defineConfig({ plugins: [zharp({ app: 123 })] });With webpack, @zharp/webpack-plugin takes the same options; anything else can use npx @zharp/cli sourcemaps inject and upload after the build. Main's stacks are also read through the.js.map files next to its code, when you ship them.
Electron's native code
Nothing to upload. Electron publishes the symbols of every release, and the first time a crash names an Electron version, Zharp fetches them, so frames in Electron itself read as functions. That first crash can take a few minutes to read; the ones after are read at once.
Your native modules
For .node modules of your own, upload their symbols after the build:
npx @zharp/cli debug-files upload build/Release --app 123
Tracing
Main traces its own requests and database calls, as @zharp/node does. Each window traces its page load, its fetch and XMLHttpRequest calls with their headers (secret ones recorded as [Filtered]), and the clicks that lead to them. Requests to hosts in tracingOrigins carry traceparent and baggage, so your API's spans join the same trace.
const report = await Zharp.startSpan('build report', async () => build(data));
Zharp.setTag('plan', 'pro'); // on everything afterRequest and response bodies
Off by default. Turn it on to see what a request sent and what came back, shown under the request in the trace: main's requests (incoming and outgoing), and in the windows the requests to tracingOrigins; urls changes that.
// main
Zharp.init({
key: 'zpk_…',
captureBodies: 'errors', // main's own requests
renderer: { captureBodies: 'errors' }, // the windows' fetch and XHR
});- Failed requests only (status 400 and above, or no response) by default; every request with the "all" mode.
- Text (JSON, forms, XML, plain text) is kept up to 32 KB, up to 128 KB with the size option.
- Every field name is kept. A file in an upload shows as
[file photo.png · image/png · 240 KB], an inline image as[image/png · 24 KB], a body that isn't text as[binary · application/pdf · 1.2 MB]or[event stream]. File contents are never sent. - Your app reads and sends exactly what it did before.
Values under keys that look secret — password, token, secret, apiKey, authorization, cookie, card, cvv, ssn and similar — are replaced with [Filtered] in the app, before anything is sent. The field stays; only its value is hidden, and under a secret object such as card each value inside is hidden and its keys kept. Anything else, such as names and email addresses, is sent as it is: add those keys to redactKeys.
Whether or not bodies are on, secret-looking values in URL query strings (?token=, key, sig, password …) are recorded as [Filtered].
User context
Zharp.setUser({ id: user.id, email: user.email }); // in main or any window, once someone signs in
Zharp.clearUser(); // on sign-out: a new session for every window- One session for main and every window, and on crash reports. A new one after 30 minutes without activity in any window, and on
clearUser(). - A device ID per installation, kept in the app's user data folder.
- The OS and its version, the architecture, the Electron version, and which process sent it.
Options
In main's Zharp.init. Everything @zharp/node takes works for main too.
| Option | Default | Notes |
|---|---|---|
key | — | Required. |
service | the app's name | service.name |
release | the app's version | Also what native crash reports carry |
environment | production when packaged | deployment.environment.name |
renderer | {} | Every window's settings: tracingOrigins, captureBodies, logs, sampleRate… A window's own Zharp.init({…}) adds to them |
crashReporter | true | false leaves Electron's crash reporter alone, for an app that starts it itself |
preload | true | Add the windows' preload to every session |
logs | false | true sends main's console and output |
tracing | true | false is logs only, in main |
sampleRate | 1 | Share of main's traces kept; errors and logs are always sent |
sessionTimeoutMinutes | 30 | Without activity in any window |
debug | false | Print what the SDK does |
Main sends what the windows hand it at once, and keeps on disk what can't go (up to 200 batches); it's sent at the next start. Quitting waits up to two seconds for what's left. Zharp.flush() sends now. The SDK never throws into your app.
Session replay isn't available in Electron windows yet.
Troubleshooting
Nothing arrives
On the app's setup page (Applications → the app → settings → Setup instructions), the verify step shows the first event as soon as it lands, and Send a test event checks the key on its own. If the test event arrives but your app's don't, the SDK isn't starting or isn't reaching Zharp:
- Is
initcalled, and before the code you expect to see? Without a key, the SDK starts nothing and says so once. - Does the service name match? With an app key everything goes to that app whatever it says; with a workspace key,
servicedecides the app — see Keys. - Data is sent in batches every few seconds. A process that exits straight away should call
flushfirst. - Logs and errors arrive but no traces? Check that tracing isn't turned off — see Logs only.
- A window logs
[Zharp] @zharp/electron/renderer can't reach the main process: main didn't start Zharp, or main is bundled and your preload needsimport '@zharp/electron/preload'. - Native crashes don't arrive: check that nothing else calls
crashReporter.start, or passcrashReporter: falseand give itsubmitURLyourself:https://api.zharp.io/api/v1/minidump?key=zpk_….
401 or 403
Ingest answers 401 when the key is missing, mistyped, revoked or rolled, and 403 when the request comes from an origin or IP address the key doesn't allow. Neither is retried: the SDK warns once and drops what was refused, and it never throws into your code. Copy the key again from the app's settings.
Allowed origins
A browser sends an Origin header, and when the app has Allowed origins, only those may send with its key. An origin is the scheme, host and port, exactly — https://shop.example.com, not shop.example.com or a URL with a path. Add http://localhost:3000 for local development, or leave the list empty.
Ad blockers
Some browser extensions block requests to monitoring services. If it works in a private window with extensions off, that's the cause — your users with the same extension won't be reported either.