@thomas-adam-leigh/elenjical-electron
v0.3.0
Published
Elenjical error tracking, logs, session replay and native crash reports for Electron apps.
Maintainers
Readme
@elenjical/electron
Error tracking, logs, session replay and native crash reports for Electron apps, reported to Elenjical. One package for every process: the main process, preload scripts, renderers and utility processes.
Install
npm install @elenjical/electron@npm:@thomas-adam-leigh/elenjical-electron@^0.3.0Set up
Main process first, before app.whenReady(). The DSN is public and ships inside the app:
// src/main.ts
import * as Elenjical from "@elenjical/electron/main";
Elenjical.init({
dsn: "https://<key>@<your elenjical host>/<project id>",
enableLogs: true,
});The preload bridge connects renderers to the main process; it works with contextIsolation and the sandbox on:
// src/preload.ts
import "@elenjical/electron/preload";Then every renderer, before the UI mounts. No DSN here: it arrives from the main process over IPC, with the release and environment.
// src/renderer.tsx
import * as Elenjical from "@elenjical/electron/renderer";
Elenjical.init({
enableLogs: true,
integrations: [Elenjical.replayIntegration()],
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1.0,
});With a React renderer, combine the two SDKs: Elenjical.init({ dsn: undefined, ... }, reactInit) with
import { init as reactInit } from "@elenjical/react" (the React package's options need dsn: undefined).
import "@elenjical/electron" resolves to the main side on Node and to the renderer side in a browser bundle.
Report handled errors with Elenjical.captureException(error), write logs with Elenjical.logger.info("..."),
identify people with Elenjical.setUser({ id, email }) in the main process (a renderer's scope is forwarded
there). Replay privacy markers are data-elenjical-mask, -unmask, -block, -unblock and -ignore.
Native crashes of the main process, renderers and GPU process are sent as minidumps and arrive as issues with the
crash reason and a stack walked from the dump. Upload the symbols of your Electron version
(electron-v<version>-<platform>-<arch>-symbols.zip from Electron's release) and of your own native modules with
npx elenjical debug-files upload <dir> so the frames have names.
Utility processes (utilityProcess.fork) start the SDK with init from @elenjical/electron/utility;
@elenjical/electron/native has the event loop block detection; @elenjical/electron/preload-namespaced
exposes hookupIpc(namespace) for a custom IPC namespace.
| Variable (main and utility processes) | Meaning |
| ------------------------------------- | ----------------------------------------------- |
| ELENJICAL_DSN | where to report, when not passed to init |
| ELENJICAL_ENVIRONMENT | development, production, ... |
| ELENJICAL_RELEASE | the version, default <app name>@<app version> |
| ELENJICAL_TRACES_SAMPLE_RATE | tracing sample rate (default 0) |
| ELENJICAL_DEBUG | true logs what the SDK does |
Source maps: upload the main, preload and renderer bundles with the same release (@elenjical/vite-plugin in
each Vite config, or npx elenjical sourcemaps inject and upload per bundle).
See NOTICE for the open-source software this package is built on.
Feature flags
In the main process, read by your user's id:
if (await Elenjical.isFeatureEnabled("new-checkout", user.id)) {
// ...
}getFeatureFlagPayload(key, distinctId) reads a flag's payload and getAllFlags(distinctId) every flag. Each
person's flags are kept for 30 seconds; when they cannot be read, every flag is off. In a renderer, name the DSN to
read them from (its own client has none: its events go through the main process), then read them for the person
setUser names:
Elenjical.init({ flags: { dsn: "<public DSN>" } });
if (Elenjical.isFeatureEnabled("new-checkout")) {
// ...
}Flags load the first time one is read; onFeatureFlags(callback) runs once they have. In both processes, the next
error reports the flags read before it.
