From 69526e2f9591b46c9be204bb8d968f4d975a9484 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 17 Nov 2025 16:25:01 -0500 Subject: [PATCH 01/10] feat: Add support for Sentry Metrics --- CHANGELOG.md | 135 +++++++++--------- src/common/ipc.ts | 7 +- src/main/ipc.ts | 53 +++++-- src/preload/index.ts | 3 +- src/renderer/ipc.ts | 11 +- src/renderer/metric.ts | 122 ++++++++++++++++ test/e2e/test-apps/other/metrics/package.json | 9 ++ .../test-apps/other/metrics/src/index.html | 24 ++++ test/e2e/test-apps/other/metrics/src/main.js | 36 +++++ test/e2e/test-apps/other/metrics/test.ts | 58 ++++++++ 10 files changed, 369 insertions(+), 89 deletions(-) create mode 100644 src/renderer/metric.ts create mode 100644 test/e2e/test-apps/other/metrics/package.json create mode 100644 test/e2e/test-apps/other/metrics/src/index.html create mode 100644 test/e2e/test-apps/other/metrics/src/main.js create mode 100644 test/e2e/test-apps/other/metrics/test.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index a210f8c7..0c02f99d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,11 +4,14 @@ ## 7.3.0 -- feat: Update JavaScript SDKs from [v10.17.0](https://github.com/getsentry/sentry-javascript/releases/tag/10.17.0) to [v10.22.0](https://github.com/getsentry/sentry-javascript/releases/tag/10.22.0) +- feat: Update JavaScript SDKs from [v10.17.0](https://github.com/getsentry/sentry-javascript/releases/tag/10.17.0) to + [v10.25.0](https://github.com/getsentry/sentry-javascript/releases/tag/10.25.0) +- feat: Add support for [Sentry Metrics](https://docs.sentry.io/product/metrics/) (#1260) ## 7.2.0 -- feat: Update JavaScript SDKs from [v10.11.0](https://github.com/getsentry/sentry-javascript/releases/tag/10.11.0) to [v10.17.0](https://github.com/getsentry/sentry-javascript/releases/tag/10.17.0) +- feat: Update JavaScript SDKs from [v10.11.0](https://github.com/getsentry/sentry-javascript/releases/tag/10.11.0) to + [v10.17.0](https://github.com/getsentry/sentry-javascript/releases/tag/10.17.0) - feat: Log os and device attributes (#1246) ## 7.1.1 @@ -19,163 +22,151 @@ ## 7.1.0 -- feat: Update JavaScript SDKs from [v10.7.0](https://github.com/getsentry/sentry-javascript/releases/tag/10.7.0) to [v10.11.0](https://github.com/getsentry/sentry-javascript/releases/tag/10.11.0) (#1236) +- feat: Update JavaScript SDKs from [v10.7.0](https://github.com/getsentry/sentry-javascript/releases/tag/10.7.0) to + [v10.11.0](https://github.com/getsentry/sentry-javascript/releases/tag/10.11.0) (#1236) - feat: Optional Namespaced IPC (#1234) - fix: Export `ErrorEvent` type (#1229) - fix: Only capture logs if `enableLogs` is true (#1235) ## 7.0.0 -This release updates the underlying Sentry JavaScript SDKs to v10 which includes -some breaking changes. Check out the the [migration guide](./MIGRATION.md) for -more details. +This release updates the underlying Sentry JavaScript SDKs to v10 which includes some breaking changes. Check out the +the [migration guide](./MIGRATION.md) for more details. - feat: Update JavaScript SDKs to v10.8.0 (#1205) ## 6.11.0 -- feat: Update JavaScript SDKs from [v9.45.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.45.0) to [v9.46.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.46.0) +- feat: Update JavaScript SDKs from [v9.45.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.45.0) to + [v9.46.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.46.0) - fix: Ensure native directory ends up in package (#1216) ## 6.10.0 -- feat: Update JavaScript SDKs from [v9.43.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.43.0) to [v9.45.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.45.0) +- feat: Update JavaScript SDKs from [v9.43.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.43.0) to + [v9.45.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.45.0) - fix: Don't use `deepmerge` to merge events to remove circular ref. issues (#1210) - fix: Support `node16` for TypeScript `moduleResolution` (#1203) ## 6.9.0 -- feat: Update JavaScript SDKs from - [v9.26.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.26.0) - to +- feat: Update JavaScript SDKs from [v9.26.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.26.0) to [v9.43.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.43.0) - feat: Add `eventLoopBlockIntegration` (#1188) - feat: Move renderer event loop block detection to an integration (#1196) ## 6.8.0 -- feat: Update JavaScript SDKs from [v9.25.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.25.0) to [v9.26.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.26.0) +- feat: Update JavaScript SDKs from [v9.25.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.25.0) to + [v9.26.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.26.0) - fix: Don't capture stack traces from destroyed renderers (#1165) ## 6.7.0 -- feat: Update JavaScript SDKs from [v9.18.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.18.0) to [v9.25.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.25.0) +- feat: Update JavaScript SDKs from [v9.18.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.18.0) to + [v9.25.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.25.0) - feat: Add structured logging support (#1159) ## 6.6.0 -- feat: Update JavaScript SDKs from [v9.11.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.11.0) to [v9.18.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.18.0) +- feat: Update JavaScript SDKs from [v9.11.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.11.0) to + [v9.18.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.18.0) ## 6.5.0 -- feat: Update JavaScript SDKs from [v9.10.1](https://github.com/getsentry/sentry-javascript/releases/tag/9.10.1) to [v9.11.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.11.0) +- feat: Update JavaScript SDKs from [v9.10.1](https://github.com/getsentry/sentry-javascript/releases/tag/9.10.1) to + [v9.11.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.11.0) - fix: GPU context should use id rather than device_id (#1126) - feat: Optionally capture manufacturer and model device context (#1125) ## 6.4.0 -- feat: Update JavaScript SDKs from [v9.8.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.8.0) to [v9.10.1](https://github.com/getsentry/sentry-javascript/releases/tag/9.10.1) +- feat: Update JavaScript SDKs from [v9.8.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.8.0) to + [v9.10.1](https://github.com/getsentry/sentry-javascript/releases/tag/9.10.1) - fix: Missing Dynamic Sampling Context in envelope header for renderer tracing (#1117) - feat: Use `frame.collectJavaScriptCallStack()` for renderer ANR in Electron >= v34 (#1105) ## 6.3.0 -- feat: Update JavaScript SDKs from [v9.6.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.6.0) to [v9.8.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.8.0) +- feat: Update JavaScript SDKs from [v9.6.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.6.0) to + [v9.8.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.8.0) - fix: Electron app.getPath('crashDumps') API can throw (#1106) ## 6.2.0 -- feat: Update JavaScript SDKs from [v9.1.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.1.0) to [v9.6.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.6.0) +- feat: Update JavaScript SDKs from [v9.1.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.1.0) to + [v9.6.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.6.0) - feat: Use new `registerPreloadScript` API in Electron >= v35 (#1098) - feat: Add `gpuContextIntegration` (#1097) -- feat: Parse crashpad metadata from minidumps and include in electron context - (#1095) +- feat: Parse crashpad metadata from minidumps and include in electron context (#1095) ## 6.1.0 -- feat: Update JavaScript SDKs from [v9.0.1](https://github.com/getsentry/sentry-javascript/releases/tag/9.0.1) to [v9.1.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.1.0) (#1080) +- feat: Update JavaScript SDKs from [v9.0.1](https://github.com/getsentry/sentry-javascript/releases/tag/9.0.1) to + [v9.1.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.1.0) (#1080) - feat: Support `@sentry/profiling-node` (#1084) - fix: Renderer ANR detection (#1083) ## 6.0.0 -This release updates the underlying Sentry JavaScript SDKs to v9 which includes -some breaking changes. Check out the the [migration guide](./MIGRATION.md) for -more details. +This release updates the underlying Sentry JavaScript SDKs to v9 which includes some breaking changes. Check out the the +[migration guide](./MIGRATION.md) for more details. - feat: Update JavaScript SDKs to v9.0.0 (#1072) ### Supported Electron Versions -The Sentry Node SDK now requires Node >= 18.0.0 which means the Sentry Electron -SDK now supports Electron >= 23.0.0. +The Sentry Node SDK now requires Node >= 18.0.0 which means the Sentry Electron SDK now supports Electron >= 23.0.0. ### The `autoSessionTracking` option has been removed -Whereas in v5, session tracking was disabled by setting `autoSessionTracking` to -`false`, in v6 session tracking can be disabled by removing the `MainProcessSession` integration +Whereas in v5, session tracking was disabled by setting `autoSessionTracking` to `false`, in v6 session tracking can be +disabled by removing the `MainProcessSession` integration ```javascript -import * as Sentry from "@sentry/electron/main"; +import * as Sentry from '@sentry/electron/main'; Sentry.init({ - dsn: "__DSN__", + dsn: '__DSN__', // autoSessionTracking: false, - integrations: (defaults) => defaults.filter((i) => i.name !== "MainProcessSession"), + integrations: (defaults) => defaults.filter((i) => i.name !== 'MainProcessSession'), }); ``` ## 5.11.0 -- feat: Update from - [v8.48.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.48.0) - to - [v8.51.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.51.0) - (#1066) -- fix: Returing `null` in `beforeSend` for native crashes should not impact - release health (#1066) +- feat: Update from [v8.48.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.48.0) to + [v8.51.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.51.0) (#1066) +- fix: Returing `null` in `beforeSend` for native crashes should not impact release health (#1066) - feat: Set log level for `net` breadcrumbs based on status code (#1070) - test: Test more child process types (#1063) ## 5.10.0 -- fix: Deprecate renderer init options which should only be used in main process - (#1044) -- feat: Update from - [v8.46.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.46.0) - to - [v8.48.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.48.0) - of JavaScript SDKs (#1046) +- fix: Deprecate renderer init options which should only be used in main process (#1044) +- feat: Update from [v8.46.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.46.0) to + [v8.48.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.48.0) of JavaScript SDKs (#1046) - feat: Determine Electron process from minidump metadata (#1049) - fix: Guard against invalid queue entries (#1053) ## 5.9.0 -- feat: Update from - [v8.42.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.42.0) - to - [v8.46.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.46.0) - of JavaScript SDKs +- feat: Update from [v8.42.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.42.0) to + [v8.46.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.46.0) of JavaScript SDKs - fix: Disable ANR when screen locked (#1036) - fix: Disable ANR when debugger is in use ## 5.8.0 -- feat: Update from - [v8.35.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.35.0) - to - [v8.42.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.42.0) - of JavaScript SDKs +- feat: Update from [v8.35.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.35.0) to + [v8.42.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.42.0) of JavaScript SDKs - fix: Sync global scope to main process (#1024) - fix: contextLinesIntegration should come before path normalization (#1008) ## 5.7.0 -- feat: Update from - [v8.33.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.33.0) - to - [v8.35.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.35.0) - of JavaScript SDKs +- feat: Update from [v8.33.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.33.0) to + [v8.35.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.35.0) of JavaScript SDKs ## 5.6.0 @@ -291,7 +282,7 @@ For the full list of changes, see the [migration guide](./MIGRATION.md). - feat: Renderer process ANR detection with stack traces (#770) - Update from [v7.73.0](https://github.com/getsentry/sentry-javascript/releases/tag/7.73.0) to - [v7.74.0](https://github.com/getsentry/sentry-javascript/releases/tag/7.74.0) of JavaScript SDKs + [v7.74.0](https://github.com/getsentry/sentry-javascript/releases/tag/7.74.0) of JavaScript SDKs - fix: Hide ANR child process from dock (#777) - test: Electron v28 main process ESM (#773) @@ -320,21 +311,22 @@ fix: Don't send minidumps that are too small to be valid (#748) [v7.68.0](https://github.com/getsentry/sentry-javascript/releases/tag/7.68.0) of JavaScript SDKs (#738) - **feat: Mark errors caught by the SDK as unhandled** -As per the changes in the JavaScript SDKs [for -v7.67.0](https://github.com/getsentry/sentry-javascript/blob/develop/CHANGELOG.md#7670), this release fixes inconsistent -behaviour of when our SDKs classify captured errors as unhandled. Previously, some of our instrumentations correctly set -unhandled, while others set handled. +As per the changes in the JavaScript SDKs +[for v7.67.0](https://github.com/getsentry/sentry-javascript/blob/develop/CHANGELOG.md#7670), this release fixes +inconsistent behaviour of when our SDKs classify captured errors as unhandled. Previously, some of our instrumentations +correctly set unhandled, while others set handled. -Going forward, all errors caught automatically from our SDKs will be marked as unhandled. -If you manually capture errors (e.g. by calling `Sentry.captureException`), your errors will continue to be reported as handled. +Going forward, all errors caught automatically from our SDKs will be marked as unhandled. If you manually capture errors +(e.g. by calling `Sentry.captureException`), your errors will continue to be reported as handled. -This change might lead to a decrease in reported crash-free sessions and consequently in your release health score. -If you have concerns about this, feel free to open an issue. +This change might lead to a decrease in reported crash-free sessions and consequently in your release health score. If +you have concerns about this, feel free to open an issue. ## 4.10.0 - feat: Optionally send sessions when they're created (#715) -- feat: Update from [v7.61.0](https://github.com/getsentry/sentry-javascript/releases/tag/7.61.0) to [v7.63.0](https://github.com/getsentry/sentry-javascript/releases/tag/7.63.0) of JavaScript SDKs (#719) +- feat: Update from [v7.61.0](https://github.com/getsentry/sentry-javascript/releases/tag/7.61.0) to + [v7.63.0](https://github.com/getsentry/sentry-javascript/releases/tag/7.63.0) of JavaScript SDKs (#719) ## 4.9.0 @@ -342,7 +334,8 @@ If you have concerns about this, feel free to open an issue. - feat: Tracing without performance (#710) - feat: Deprecate `tracingOrigins` for `tracePropagationTargets` (#703) - feat: Use `protocol.handle` on Electron >= v25 (#704) -- test: Update from [v7.58.0](https://github.com/getsentry/sentry-javascript/releases/tag/7.58.0) to [v7.61.0](https://github.com/getsentry/sentry-javascript/releases/tag/7.61.0) of JavaScript SDKs (#709) +- test: Update from [v7.58.0](https://github.com/getsentry/sentry-javascript/releases/tag/7.58.0) to + [v7.61.0](https://github.com/getsentry/sentry-javascript/releases/tag/7.61.0) of JavaScript SDKs (#709) ## 4.8.0 diff --git a/src/common/ipc.ts b/src/common/ipc.ts index 8ee01433..42f9a228 100644 --- a/src/common/ipc.ts +++ b/src/common/ipc.ts @@ -1,4 +1,4 @@ -import { SerializedLog } from '@sentry/core'; +import { SerializedLog, SerializedMetric } from '@sentry/core'; /** Ways to communicate between the renderer and main process */ export enum IPCMode { @@ -25,7 +25,9 @@ export type Channel = /** IPC to pass renderer status updates */ | 'status' /** IPC to pass structured log messages */ - | 'structured-log'; + | 'structured-log' + /** IPC to pass metric data */ + | 'metric'; export interface IpcUtils { createUrl: (channel: Channel) => string; @@ -85,6 +87,7 @@ export interface IPCInterface { sendEnvelope: (evn: Uint8Array | string) => void; sendStatus: (state: RendererStatus) => void; sendStructuredLog: (log: SerializedLog) => void; + sendMetric: (metric: SerializedMetric) => void; } export const RENDERER_ID_HEADER = 'sentry-electron-renderer-id'; diff --git a/src/main/ipc.ts b/src/main/ipc.ts index 803bcd49..5a3eec5c 100644 --- a/src/main/ipc.ts +++ b/src/main/ipc.ts @@ -1,5 +1,6 @@ import { _INTERNAL_captureSerializedLog, + _INTERNAL_captureSerializedMetric, Attachment, Client, debug, @@ -8,6 +9,7 @@ import { parseEnvelope, ScopeData, SerializedLog, + SerializedMetric, } from '@sentry/core'; import { captureEvent, getClient, getCurrentScope } from '@sentry/node'; import { app, ipcMain, protocol, WebContents, webContents } from 'electron'; @@ -161,50 +163,68 @@ function handleScope(options: ElectronMainOptionsInternal, jsonScope: string): v } } -function handleLogFromRenderer( +function handleAttributes( client: Client, options: ElectronMainOptionsInternal, - log: SerializedLog, contents: WebContents | undefined, -): void { + maybeAttributes?: (typeof SerializedLog)['attributes'], +): (typeof SerializedLog)['attributes'] { const process = contents ? options?.getRendererName?.(contents) || 'renderer' : 'renderer'; - log.attributes = log.attributes || {}; + const attributes: Record = maybeAttributes || {}; if (options.release) { - log.attributes['sentry.release'] = { value: options.release, type: 'string' }; + attributes['sentry.release'] = { value: options.release, type: 'string' }; } if (options.environment) { - log.attributes['sentry.environment'] = { value: options.environment, type: 'string' }; + attributes['sentry.environment'] = { value: options.environment, type: 'string' }; } - log.attributes['sentry.sdk.name'] = { value: 'sentry.javascript.electron', type: 'string' }; - log.attributes['sentry.sdk.version'] = { value: SDK_VERSION, type: 'string' }; + attributes['sentry.sdk.name'] = { value: 'sentry.javascript.electron', type: 'string' }; + attributes['sentry.sdk.version'] = { value: SDK_VERSION, type: 'string' }; - log.attributes['electron.process'] = { value: process, type: 'string' }; + attributes['electron.process'] = { value: process, type: 'string' }; const osDeviceAttributes = getOsDeviceLogAttributes(client); if (osDeviceAttributes['os.name']) { - log.attributes['os.name'] = { value: osDeviceAttributes['os.name'], type: 'string' }; + attributes['os.name'] = { value: osDeviceAttributes['os.name'], type: 'string' }; } if (osDeviceAttributes['os.version']) { - log.attributes['os.version'] = { value: osDeviceAttributes['os.version'], type: 'string' }; + attributes['os.version'] = { value: osDeviceAttributes['os.version'], type: 'string' }; } if (osDeviceAttributes['device.brand']) { - log.attributes['device.brand'] = { value: osDeviceAttributes['device.brand'], type: 'string' }; + attributes['device.brand'] = { value: osDeviceAttributes['device.brand'], type: 'string' }; } if (osDeviceAttributes['device.model']) { - log.attributes['device.model'] = { value: osDeviceAttributes['device.model'], type: 'string' }; + attributes['device.model'] = { value: osDeviceAttributes['device.model'], type: 'string' }; } if (osDeviceAttributes['device.family']) { - log.attributes['device.family'] = { value: osDeviceAttributes['device.family'], type: 'string' }; + attributes['device.family'] = { value: osDeviceAttributes['device.family'], type: 'string' }; } +} +function handleLogFromRenderer( + client: Client, + options: ElectronMainOptionsInternal, + log: SerializedLog, + contents: WebContents | undefined, +): void { + log.attributes = handleAttributes(client, options, contents, log.attributes); _INTERNAL_captureSerializedLog(client, log); } +function handleMetricFromRenderer( + client: Client, + options: ElectronMainOptionsInternal, + metric: SerializedMetric, + contents: WebContents | undefined, +): void { + metric.attributes = handleAttributes(client, options, contents, metric.attributes); + _INTERNAL_captureSerializedMetric(client, metric); +} + /** Enables Electron protocol handling */ function configureProtocol(client: Client, ipcUtil: IpcUtils, options: ElectronMainOptionsInternal): void { if (app.isReady()) { @@ -247,6 +267,8 @@ function configureProtocol(client: Client, ipcUtil: IpcUtils, options: ElectronM handleEnvelope(client, options, data, getWebContents()); } else if (ipcUtil.urlMatches(request.url, 'structured-log') && data) { handleLogFromRenderer(client, options, JSON.parse(data.toString()), getWebContents()); + } else if (ipcUtil.urlMatches(request.url, 'metric') && data) { + handleMetricFromRenderer(client, options, JSON.parse(data.toString()), getWebContents()); } else if (rendererStatusChanged && ipcUtil.urlMatches(request.url, 'status') && data) { const contents = getWebContents(); if (contents) { @@ -289,6 +311,9 @@ function configureClassic(client: Client, ipcUtil: IpcUtils, options: ElectronMa ipcMain.on(ipcUtil.createKey('structured-log'), ({ sender }, log: SerializedLog) => handleLogFromRenderer(client, options, log, sender), ); + ipcMain.on(ipcUtil.createKey('metric'), ({ sender }, metric: SerializedMetric) => + handleMetricFromRenderer(client, options, metric, sender), + ); const rendererStatusChanged = createRendererEventLoopBlockStatusHandler(client); if (rendererStatusChanged) { diff --git a/src/preload/index.ts b/src/preload/index.ts index e6f4297b..cf06a87d 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -2,7 +2,7 @@ * This preload script may be used with sandbox mode enabled which means regular require is not available. */ -import { SerializedLog } from '@sentry/core'; +import { SerializedLog, SerializedMetric } from '@sentry/core'; import { contextBridge, ipcRenderer } from 'electron'; import { ipcChannelUtils, RendererStatus } from '../common/ipc.js'; @@ -28,6 +28,7 @@ export function hookupIpc(namespace: string = 'sentry-ipc'): void { sendEnvelope: (envelope: Uint8Array | string) => ipcRenderer.send(ipcUtil.createKey('envelope'), envelope), sendStatus: (status: RendererStatus) => ipcRenderer.send(ipcUtil.createKey('status'), status), sendStructuredLog: (log: SerializedLog) => ipcRenderer.send(ipcUtil.createKey('structured-log'), log), + sendMetric: (metric: SerializedMetric) => ipcRenderer.send(ipcUtil.createKey('metric'), metric), }; // eslint-disable-next-line no-restricted-globals diff --git a/src/renderer/ipc.ts b/src/renderer/ipc.ts index 6fb81bd5..0b2c6ed1 100644 --- a/src/renderer/ipc.ts +++ b/src/renderer/ipc.ts @@ -1,6 +1,6 @@ /* eslint-disable no-restricted-globals */ /* eslint-disable no-console */ -import { Client, debug, getClient, SerializedLog, uuid4 } from '@sentry/core'; +import { Client, debug, getClient, SerializedLog, SerializedMetric, uuid4 } from '@sentry/core'; import { ipcChannelUtils, IPCInterface, RENDERER_ID_HEADER, RendererStatus } from '../common/ipc.js'; import { ElectronRendererOptionsInternal } from './sdk.js'; @@ -56,6 +56,15 @@ function getImplementation(ipcKey: string): IPCInterface { // ignore }); }, + sendMetric: (metric: SerializedMetric) => { + fetch(ipcUtil.createUrl('metric'), { + method: 'POST', + body: JSON.stringify(metric), + headers, + }).catch(() => { + // ignore + }); + }, }; } } diff --git a/src/renderer/metric.ts b/src/renderer/metric.ts new file mode 100644 index 00000000..a58ce427 --- /dev/null +++ b/src/renderer/metric.ts @@ -0,0 +1,122 @@ +import { + _INTERNAL_captureMetric, + getClient, + getCurrentScope, + MetricOptions, + MetricType, + SerializedMetric, +} from '@sentry/core'; +import { getIPC } from './ipc.js'; + +function captureMetric(type: MetricType, name: string, value: number, options?: MetricOptions): void { + const client = getClient(); + _INTERNAL_captureMetric( + { type, name, value, unit: options?.unit, attributes: options?.attributes }, + { + scope: options?.scope ?? getCurrentScope(), + captureSerializedMetric: (_: unknown, metric: SerializedMetric) => getIPC(client).sendMetric(metric), + }, + ); +} + +/** + * @summary Increment a counter metric. Requires the `_experiments.enableMetrics` option to be enabled. + * + * @param name - The name of the counter metric. + * @param value - The value to increment by (defaults to 1). + * @param options - Options for capturing the metric. + * + * @example + * + * ``` + * Sentry.metrics.count('api.requests', 1, { + * attributes: { + * endpoint: '/api/users', + * method: 'GET', + * status: 200 + * } + * }); + * ``` + * + * @example With custom value + * + * ``` + * Sentry.metrics.count('items.processed', 5, { + * attributes: { + * processor: 'batch-processor', + * queue: 'high-priority' + * } + * }); + * ``` + */ +export function count(name: string, value: number = 1, options?: MetricOptions): void { + captureMetric('counter', name, value, options); +} + +/** + * @summary Set a gauge metric to a specific value. Requires the `_experiments.enableMetrics` option to be enabled. + * + * @param name - The name of the gauge metric. + * @param value - The current value of the gauge. + * @param options - Options for capturing the metric. + * + * @example + * + * ``` + * Sentry.metrics.gauge('memory.usage', 1024, { + * unit: 'megabyte', + * attributes: { + * process: 'web-server', + * region: 'us-east-1' + * } + * }); + * ``` + * + * @example Without unit + * + * ``` + * Sentry.metrics.gauge('active.connections', 42, { + * attributes: { + * server: 'api-1', + * protocol: 'websocket' + * } + * }); + * ``` + */ +export function gauge(name: string, value: number, options?: MetricOptions): void { + captureMetric('gauge', name, value, options); +} + +/** + * @summary Record a value in a distribution metric. Requires the `_experiments.enableMetrics` option to be enabled. + * + * @param name - The name of the distribution metric. + * @param value - The value to record in the distribution. + * @param options - Options for capturing the metric. + * + * @example + * + * ``` + * Sentry.metrics.distribution('task.duration', 500, { + * unit: 'millisecond', + * attributes: { + * task: 'data-processing', + * priority: 'high' + * } + * }); + * ``` + * + * @example Without unit + * + * ``` + * Sentry.metrics.distribution('batch.size', 100, { + * attributes: { + * processor: 'batch-1', + * type: 'async' + * } + * }); + * ``` + */ +export function distribution(name: string, value: number, options?: MetricOptions): void { + captureMetric('distribution', name, value, options); +} diff --git a/test/e2e/test-apps/other/metrics/package.json b/test/e2e/test-apps/other/metrics/package.json new file mode 100644 index 00000000..3a61b233 --- /dev/null +++ b/test/e2e/test-apps/other/metrics/package.json @@ -0,0 +1,9 @@ +{ + "name": "javascript-logs", + "description": "JavaScript Structural Logging", + "version": "1.0.0", + "main": "src/main.js", + "dependencies": { + "@sentry/electron": "7.2.0" + } +} diff --git a/test/e2e/test-apps/other/metrics/src/index.html b/test/e2e/test-apps/other/metrics/src/index.html new file mode 100644 index 00000000..938c2147 --- /dev/null +++ b/test/e2e/test-apps/other/metrics/src/index.html @@ -0,0 +1,24 @@ + + + + + + + + + diff --git a/test/e2e/test-apps/other/metrics/src/main.js b/test/e2e/test-apps/other/metrics/src/main.js new file mode 100644 index 00000000..436b7fae --- /dev/null +++ b/test/e2e/test-apps/other/metrics/src/main.js @@ -0,0 +1,36 @@ +const path = require('path'); + +const { app, BrowserWindow } = require('electron'); +const { init, metrics } = require('@sentry/electron/main'); + +init({ + dsn: '__DSN__', + debug: true, + enableLogs: true, + onFatalError: () => {}, +}); + +app.on('ready', () => { + const mainWindow = new BrowserWindow({ + show: false, + webPreferences: { + nodeIntegration: true, + contextIsolation: false, + }, + }); + + mainWindow.loadFile(path.join(__dirname, 'index.html')); + + setTimeout(() => { + metrics.count('User profile updated', 1, { + attributes: { + userId: 'user_123', + updatedFields: ['email', 'preferences'], + }, + }); + }, 500); +}); + +setTimeout(() => { + app.quit(); +}, 4000); diff --git a/test/e2e/test-apps/other/metrics/test.ts b/test/e2e/test-apps/other/metrics/test.ts new file mode 100644 index 00000000..9970b510 --- /dev/null +++ b/test/e2e/test-apps/other/metrics/test.ts @@ -0,0 +1,58 @@ +import { expect } from 'vitest'; +import { SDK_VERSION } from '../../../../../src/main/version'; +import { electronTestRunner, UUID_MATCHER } from '../../..'; + +electronTestRunner(__dirname, async (ctx) => { + await ctx + .expect({ + envelope: [ + { sdk: { name: 'sentry.javascript.electron', version: SDK_VERSION } }, + [ + [ + { + type: 'trace_metric', + item_count: expect.any(Number), + content_type: 'application/vnd.sentry.items.trace-metric+json', + }, + { + items: expect.arrayContaining([ + { + timestamp: expect.any(Number), + level: 'info', + name: 'User profile updated', + type: 'count', + value: 1, + trace_id: UUID_MATCHER, + attributes: { + 'sentry.release': { value: 'javascript-logs@1.0.0', type: 'string' }, + 'sentry.environment': { value: 'development', type: 'string' }, + 'sentry.sdk.name': { value: 'sentry.javascript.electron', type: 'string' }, + 'sentry.sdk.version': { value: SDK_VERSION, type: 'string' }, + userId: { value: 'user_123', type: 'string' }, + updatedFields: { value: '["email","preferences"]', type: 'string' }, + }, + }, + { + timestamp: expect.any(Number), + trace_id: UUID_MATCHER, + name: 'User clicked submit button', + type: 'count', + value: 1, + attributes: { + buttonId: { value: 'submit-form', type: 'string' }, + formId: { value: 'user-profile', type: 'string' }, + timestamp: { value: expect.any(Number), type: 'integer' }, + 'sentry.release': { value: 'javascript-logs@1.0.0', type: 'string' }, + 'sentry.environment': { value: 'development', type: 'string' }, + 'sentry.sdk.name': { value: 'sentry.javascript.electron', type: 'string' }, + 'sentry.sdk.version': { value: SDK_VERSION, type: 'string' }, + }, + }, + ]), + }, + ], + ], + ], + }) + .run(); +}); From 2b7ddc449176dd10c85ded36584c0ff3541b358d Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 17 Nov 2025 16:36:04 -0500 Subject: [PATCH 02/10] thanks sentry --- src/main/ipc.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/ipc.ts b/src/main/ipc.ts index 5a3eec5c..d302562d 100644 --- a/src/main/ipc.ts +++ b/src/main/ipc.ts @@ -203,6 +203,8 @@ function handleAttributes( if (osDeviceAttributes['device.family']) { attributes['device.family'] = { value: osDeviceAttributes['device.family'], type: 'string' }; } + + return attributes; } function handleLogFromRenderer( From 2e8677eaffce31b4143413076ab9bb722adf949f Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Thu, 27 Nov 2025 14:58:13 -0500 Subject: [PATCH 03/10] fix export in renderer --- src/renderer/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/renderer/index.ts b/src/renderer/index.ts index 3f163790..778e623a 100644 --- a/src/renderer/index.ts +++ b/src/renderer/index.ts @@ -1,6 +1,7 @@ import * as logger from './log.js'; +import * as metrics from './metric.js'; -export { logger }; +export { logger, metrics }; export type { Breadcrumb, @@ -84,7 +85,6 @@ export { lastEventId, launchDarklyIntegration, linkedErrorsIntegration, - metrics, moduleMetadataIntegration, onLoad, openFeatureIntegration, From d2ab5904f04bbb7f94f93e6a254515c52f321951 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Thu, 27 Nov 2025 15:07:13 -0500 Subject: [PATCH 04/10] make tests better --- .../test-apps/other/metrics/src/index.html | 15 +++++++ test/e2e/test-apps/other/metrics/src/main.js | 1 - test/e2e/test-apps/other/metrics/test.ts | 40 +++++++++++++++++-- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/test/e2e/test-apps/other/metrics/src/index.html b/test/e2e/test-apps/other/metrics/src/index.html index 938c2147..e06ef51f 100644 --- a/test/e2e/test-apps/other/metrics/src/index.html +++ b/test/e2e/test-apps/other/metrics/src/index.html @@ -18,6 +18,21 @@ formId: 'user-profile', }, }); + + metrics.gauge('Active users online', 42, { + attributes: { + region: 'us-east', + tier: 'premium', + }, + }); + + metrics.distribution('Page load time', 1250, { + unit: 'millisecond', + attributes: { + page: 'dashboard', + cached: 'false', + }, + }); }, 500); diff --git a/test/e2e/test-apps/other/metrics/src/main.js b/test/e2e/test-apps/other/metrics/src/main.js index 436b7fae..a298d60d 100644 --- a/test/e2e/test-apps/other/metrics/src/main.js +++ b/test/e2e/test-apps/other/metrics/src/main.js @@ -6,7 +6,6 @@ const { init, metrics } = require('@sentry/electron/main'); init({ dsn: '__DSN__', debug: true, - enableLogs: true, onFatalError: () => {}, }); diff --git a/test/e2e/test-apps/other/metrics/test.ts b/test/e2e/test-apps/other/metrics/test.ts index 9970b510..b4dc91ca 100644 --- a/test/e2e/test-apps/other/metrics/test.ts +++ b/test/e2e/test-apps/other/metrics/test.ts @@ -18,9 +18,8 @@ electronTestRunner(__dirname, async (ctx) => { items: expect.arrayContaining([ { timestamp: expect.any(Number), - level: 'info', name: 'User profile updated', - type: 'count', + type: 'counter', value: 1, trace_id: UUID_MATCHER, attributes: { @@ -36,18 +35,51 @@ electronTestRunner(__dirname, async (ctx) => { timestamp: expect.any(Number), trace_id: UUID_MATCHER, name: 'User clicked submit button', - type: 'count', + type: 'counter', value: 1, attributes: { buttonId: { value: 'submit-form', type: 'string' }, formId: { value: 'user-profile', type: 'string' }, - timestamp: { value: expect.any(Number), type: 'integer' }, 'sentry.release': { value: 'javascript-logs@1.0.0', type: 'string' }, 'sentry.environment': { value: 'development', type: 'string' }, 'sentry.sdk.name': { value: 'sentry.javascript.electron', type: 'string' }, 'sentry.sdk.version': { value: SDK_VERSION, type: 'string' }, + 'electron.process': { value: 'renderer', type: 'string' }, }, }, + { + timestamp: expect.any(Number), + trace_id: UUID_MATCHER, + name: 'Active users online', + type: 'gauge', + value: 42, + attributes: expect.objectContaining({ + region: { value: 'us-east', type: 'string' }, + tier: { value: 'premium', type: 'string' }, + 'sentry.release': { value: 'javascript-logs@1.0.0', type: 'string' }, + 'sentry.environment': { value: 'development', type: 'string' }, + 'sentry.sdk.name': { value: 'sentry.javascript.electron', type: 'string' }, + 'sentry.sdk.version': { value: SDK_VERSION, type: 'string' }, + 'electron.process': { value: 'renderer', type: 'string' }, + }), + }, + { + timestamp: expect.any(Number), + trace_id: UUID_MATCHER, + name: 'Page load time', + type: 'distribution', + value: 1250, + unit: 'millisecond', + attributes: expect.objectContaining({ + page: { value: 'dashboard', type: 'string' }, + cached: { value: 'false', type: 'string' }, + 'sentry.release': { value: 'javascript-logs@1.0.0', type: 'string' }, + 'sentry.environment': { value: 'development', type: 'string' }, + 'sentry.sdk.name': { value: 'sentry.javascript.electron', type: 'string' }, + 'sentry.sdk.version': { value: SDK_VERSION, type: 'string' }, + 'electron.process': { value: 'renderer', type: 'string' }, + }), + }, ]), }, ], From 36366b8bbd3c448720c784d739b7561074f3fee2 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Thu, 27 Nov 2025 15:08:37 -0500 Subject: [PATCH 05/10] revert changelog formatting --- CHANGELOG.md | 137 +++++++++++++++++++++++++++------------------------ 1 file changed, 72 insertions(+), 65 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c02f99d..2a891007 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,14 +4,11 @@ ## 7.3.0 -- feat: Update JavaScript SDKs from [v10.17.0](https://github.com/getsentry/sentry-javascript/releases/tag/10.17.0) to - [v10.25.0](https://github.com/getsentry/sentry-javascript/releases/tag/10.25.0) -- feat: Add support for [Sentry Metrics](https://docs.sentry.io/product/metrics/) (#1260) +- feat: Update JavaScript SDKs from [v10.17.0](https://github.com/getsentry/sentry-javascript/releases/tag/10.17.0) to [v10.26.0](https://github.com/getsentry/sentry-javascript/releases/tag/10.26.0) ## 7.2.0 -- feat: Update JavaScript SDKs from [v10.11.0](https://github.com/getsentry/sentry-javascript/releases/tag/10.11.0) to - [v10.17.0](https://github.com/getsentry/sentry-javascript/releases/tag/10.17.0) +- feat: Update JavaScript SDKs from [v10.11.0](https://github.com/getsentry/sentry-javascript/releases/tag/10.11.0) to [v10.17.0](https://github.com/getsentry/sentry-javascript/releases/tag/10.17.0) - feat: Log os and device attributes (#1246) ## 7.1.1 @@ -22,151 +19,163 @@ ## 7.1.0 -- feat: Update JavaScript SDKs from [v10.7.0](https://github.com/getsentry/sentry-javascript/releases/tag/10.7.0) to - [v10.11.0](https://github.com/getsentry/sentry-javascript/releases/tag/10.11.0) (#1236) +- feat: Update JavaScript SDKs from [v10.7.0](https://github.com/getsentry/sentry-javascript/releases/tag/10.7.0) to [v10.11.0](https://github.com/getsentry/sentry-javascript/releases/tag/10.11.0) (#1236) - feat: Optional Namespaced IPC (#1234) - fix: Export `ErrorEvent` type (#1229) - fix: Only capture logs if `enableLogs` is true (#1235) ## 7.0.0 -This release updates the underlying Sentry JavaScript SDKs to v10 which includes some breaking changes. Check out the -the [migration guide](./MIGRATION.md) for more details. +This release updates the underlying Sentry JavaScript SDKs to v10 which includes +some breaking changes. Check out the the [migration guide](./MIGRATION.md) for +more details. - feat: Update JavaScript SDKs to v10.8.0 (#1205) ## 6.11.0 -- feat: Update JavaScript SDKs from [v9.45.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.45.0) to - [v9.46.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.46.0) +- feat: Update JavaScript SDKs from [v9.45.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.45.0) to [v9.46.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.46.0) - fix: Ensure native directory ends up in package (#1216) ## 6.10.0 -- feat: Update JavaScript SDKs from [v9.43.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.43.0) to - [v9.45.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.45.0) +- feat: Update JavaScript SDKs from [v9.43.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.43.0) to [v9.45.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.45.0) - fix: Don't use `deepmerge` to merge events to remove circular ref. issues (#1210) - fix: Support `node16` for TypeScript `moduleResolution` (#1203) ## 6.9.0 -- feat: Update JavaScript SDKs from [v9.26.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.26.0) to +- feat: Update JavaScript SDKs from + [v9.26.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.26.0) + to [v9.43.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.43.0) - feat: Add `eventLoopBlockIntegration` (#1188) - feat: Move renderer event loop block detection to an integration (#1196) ## 6.8.0 -- feat: Update JavaScript SDKs from [v9.25.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.25.0) to - [v9.26.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.26.0) +- feat: Update JavaScript SDKs from [v9.25.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.25.0) to [v9.26.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.26.0) - fix: Don't capture stack traces from destroyed renderers (#1165) ## 6.7.0 -- feat: Update JavaScript SDKs from [v9.18.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.18.0) to - [v9.25.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.25.0) +- feat: Update JavaScript SDKs from [v9.18.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.18.0) to [v9.25.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.25.0) - feat: Add structured logging support (#1159) ## 6.6.0 -- feat: Update JavaScript SDKs from [v9.11.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.11.0) to - [v9.18.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.18.0) +- feat: Update JavaScript SDKs from [v9.11.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.11.0) to [v9.18.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.18.0) ## 6.5.0 -- feat: Update JavaScript SDKs from [v9.10.1](https://github.com/getsentry/sentry-javascript/releases/tag/9.10.1) to - [v9.11.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.11.0) +- feat: Update JavaScript SDKs from [v9.10.1](https://github.com/getsentry/sentry-javascript/releases/tag/9.10.1) to [v9.11.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.11.0) - fix: GPU context should use id rather than device_id (#1126) - feat: Optionally capture manufacturer and model device context (#1125) ## 6.4.0 -- feat: Update JavaScript SDKs from [v9.8.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.8.0) to - [v9.10.1](https://github.com/getsentry/sentry-javascript/releases/tag/9.10.1) +- feat: Update JavaScript SDKs from [v9.8.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.8.0) to [v9.10.1](https://github.com/getsentry/sentry-javascript/releases/tag/9.10.1) - fix: Missing Dynamic Sampling Context in envelope header for renderer tracing (#1117) - feat: Use `frame.collectJavaScriptCallStack()` for renderer ANR in Electron >= v34 (#1105) ## 6.3.0 -- feat: Update JavaScript SDKs from [v9.6.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.6.0) to - [v9.8.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.8.0) +- feat: Update JavaScript SDKs from [v9.6.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.6.0) to [v9.8.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.8.0) - fix: Electron app.getPath('crashDumps') API can throw (#1106) ## 6.2.0 -- feat: Update JavaScript SDKs from [v9.1.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.1.0) to - [v9.6.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.6.0) +- feat: Update JavaScript SDKs from [v9.1.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.1.0) to [v9.6.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.6.0) - feat: Use new `registerPreloadScript` API in Electron >= v35 (#1098) - feat: Add `gpuContextIntegration` (#1097) -- feat: Parse crashpad metadata from minidumps and include in electron context (#1095) +- feat: Parse crashpad metadata from minidumps and include in electron context + (#1095) ## 6.1.0 -- feat: Update JavaScript SDKs from [v9.0.1](https://github.com/getsentry/sentry-javascript/releases/tag/9.0.1) to - [v9.1.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.1.0) (#1080) +- feat: Update JavaScript SDKs from [v9.0.1](https://github.com/getsentry/sentry-javascript/releases/tag/9.0.1) to [v9.1.0](https://github.com/getsentry/sentry-javascript/releases/tag/9.1.0) (#1080) - feat: Support `@sentry/profiling-node` (#1084) - fix: Renderer ANR detection (#1083) ## 6.0.0 -This release updates the underlying Sentry JavaScript SDKs to v9 which includes some breaking changes. Check out the the -[migration guide](./MIGRATION.md) for more details. +This release updates the underlying Sentry JavaScript SDKs to v9 which includes +some breaking changes. Check out the the [migration guide](./MIGRATION.md) for +more details. - feat: Update JavaScript SDKs to v9.0.0 (#1072) ### Supported Electron Versions -The Sentry Node SDK now requires Node >= 18.0.0 which means the Sentry Electron SDK now supports Electron >= 23.0.0. +The Sentry Node SDK now requires Node >= 18.0.0 which means the Sentry Electron +SDK now supports Electron >= 23.0.0. ### The `autoSessionTracking` option has been removed -Whereas in v5, session tracking was disabled by setting `autoSessionTracking` to `false`, in v6 session tracking can be -disabled by removing the `MainProcessSession` integration +Whereas in v5, session tracking was disabled by setting `autoSessionTracking` to +`false`, in v6 session tracking can be disabled by removing the `MainProcessSession` integration ```javascript -import * as Sentry from '@sentry/electron/main'; +import * as Sentry from "@sentry/electron/main"; Sentry.init({ - dsn: '__DSN__', + dsn: "__DSN__", // autoSessionTracking: false, - integrations: (defaults) => defaults.filter((i) => i.name !== 'MainProcessSession'), + integrations: (defaults) => defaults.filter((i) => i.name !== "MainProcessSession"), }); ``` ## 5.11.0 -- feat: Update from [v8.48.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.48.0) to - [v8.51.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.51.0) (#1066) -- fix: Returing `null` in `beforeSend` for native crashes should not impact release health (#1066) +- feat: Update from + [v8.48.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.48.0) + to + [v8.51.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.51.0) + (#1066) +- fix: Returing `null` in `beforeSend` for native crashes should not impact + release health (#1066) - feat: Set log level for `net` breadcrumbs based on status code (#1070) - test: Test more child process types (#1063) ## 5.10.0 -- fix: Deprecate renderer init options which should only be used in main process (#1044) -- feat: Update from [v8.46.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.46.0) to - [v8.48.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.48.0) of JavaScript SDKs (#1046) +- fix: Deprecate renderer init options which should only be used in main process + (#1044) +- feat: Update from + [v8.46.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.46.0) + to + [v8.48.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.48.0) + of JavaScript SDKs (#1046) - feat: Determine Electron process from minidump metadata (#1049) - fix: Guard against invalid queue entries (#1053) ## 5.9.0 -- feat: Update from [v8.42.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.42.0) to - [v8.46.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.46.0) of JavaScript SDKs +- feat: Update from + [v8.42.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.42.0) + to + [v8.46.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.46.0) + of JavaScript SDKs - fix: Disable ANR when screen locked (#1036) - fix: Disable ANR when debugger is in use ## 5.8.0 -- feat: Update from [v8.35.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.35.0) to - [v8.42.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.42.0) of JavaScript SDKs +- feat: Update from + [v8.35.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.35.0) + to + [v8.42.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.42.0) + of JavaScript SDKs - fix: Sync global scope to main process (#1024) - fix: contextLinesIntegration should come before path normalization (#1008) ## 5.7.0 -- feat: Update from [v8.33.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.33.0) to - [v8.35.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.35.0) of JavaScript SDKs +- feat: Update from + [v8.33.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.33.0) + to + [v8.35.0](https://github.com/getsentry/sentry-javascript/releases/tag/8.35.0) + of JavaScript SDKs ## 5.6.0 @@ -282,7 +291,7 @@ For the full list of changes, see the [migration guide](./MIGRATION.md). - feat: Renderer process ANR detection with stack traces (#770) - Update from [v7.73.0](https://github.com/getsentry/sentry-javascript/releases/tag/7.73.0) to - [v7.74.0](https://github.com/getsentry/sentry-javascript/releases/tag/7.74.0) of JavaScript SDKs + [v7.74.0](https://github.com/getsentry/sentry-javascript/releases/tag/7.74.0) of JavaScript SDKs - fix: Hide ANR child process from dock (#777) - test: Electron v28 main process ESM (#773) @@ -311,22 +320,21 @@ fix: Don't send minidumps that are too small to be valid (#748) [v7.68.0](https://github.com/getsentry/sentry-javascript/releases/tag/7.68.0) of JavaScript SDKs (#738) - **feat: Mark errors caught by the SDK as unhandled** -As per the changes in the JavaScript SDKs -[for v7.67.0](https://github.com/getsentry/sentry-javascript/blob/develop/CHANGELOG.md#7670), this release fixes -inconsistent behaviour of when our SDKs classify captured errors as unhandled. Previously, some of our instrumentations -correctly set unhandled, while others set handled. +As per the changes in the JavaScript SDKs [for +v7.67.0](https://github.com/getsentry/sentry-javascript/blob/develop/CHANGELOG.md#7670), this release fixes inconsistent +behaviour of when our SDKs classify captured errors as unhandled. Previously, some of our instrumentations correctly set +unhandled, while others set handled. -Going forward, all errors caught automatically from our SDKs will be marked as unhandled. If you manually capture errors -(e.g. by calling `Sentry.captureException`), your errors will continue to be reported as handled. +Going forward, all errors caught automatically from our SDKs will be marked as unhandled. +If you manually capture errors (e.g. by calling `Sentry.captureException`), your errors will continue to be reported as handled. -This change might lead to a decrease in reported crash-free sessions and consequently in your release health score. If -you have concerns about this, feel free to open an issue. +This change might lead to a decrease in reported crash-free sessions and consequently in your release health score. +If you have concerns about this, feel free to open an issue. ## 4.10.0 - feat: Optionally send sessions when they're created (#715) -- feat: Update from [v7.61.0](https://github.com/getsentry/sentry-javascript/releases/tag/7.61.0) to - [v7.63.0](https://github.com/getsentry/sentry-javascript/releases/tag/7.63.0) of JavaScript SDKs (#719) +- feat: Update from [v7.61.0](https://github.com/getsentry/sentry-javascript/releases/tag/7.61.0) to [v7.63.0](https://github.com/getsentry/sentry-javascript/releases/tag/7.63.0) of JavaScript SDKs (#719) ## 4.9.0 @@ -334,8 +342,7 @@ you have concerns about this, feel free to open an issue. - feat: Tracing without performance (#710) - feat: Deprecate `tracingOrigins` for `tracePropagationTargets` (#703) - feat: Use `protocol.handle` on Electron >= v25 (#704) -- test: Update from [v7.58.0](https://github.com/getsentry/sentry-javascript/releases/tag/7.58.0) to - [v7.61.0](https://github.com/getsentry/sentry-javascript/releases/tag/7.61.0) of JavaScript SDKs (#709) +- test: Update from [v7.58.0](https://github.com/getsentry/sentry-javascript/releases/tag/7.58.0) to [v7.61.0](https://github.com/getsentry/sentry-javascript/releases/tag/7.61.0) of JavaScript SDKs (#709) ## 4.8.0 @@ -889,4 +896,4 @@ See the readme for full usage instructions, as well as the - Support for JavaScript errors and native crashes (Electron `CrashReporter`) - Record breadcrumbs and context information across renderers and the main process - Device and event information is included in every event -- Buffer crash reports and events as long as the device is offline +- Buffer crash reports and events as long as the device is offline \ No newline at end of file From c47aff932f41fc8f7ab78a984451bf3a59357e71 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Thu, 27 Nov 2025 15:11:47 -0500 Subject: [PATCH 06/10] changelog again --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a891007..8273f8c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -896,4 +896,4 @@ See the readme for full usage instructions, as well as the - Support for JavaScript errors and native crashes (Electron `CrashReporter`) - Record breadcrumbs and context information across renderers and the main process - Device and event information is included in every event -- Buffer crash reports and events as long as the device is offline \ No newline at end of file +- Buffer crash reports and events as long as the device is offline From 52e1691b9dc61d43a869e2b650ffdfc20d2b7a64 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Thu, 27 Nov 2025 15:22:11 -0500 Subject: [PATCH 07/10] better name --- test/e2e/test-apps/other/metrics/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/e2e/test-apps/other/metrics/package.json b/test/e2e/test-apps/other/metrics/package.json index 3a61b233..d698feee 100644 --- a/test/e2e/test-apps/other/metrics/package.json +++ b/test/e2e/test-apps/other/metrics/package.json @@ -1,6 +1,6 @@ { - "name": "javascript-logs", - "description": "JavaScript Structural Logging", + "name": "electron-metrics", + "description": "Electron Metrics", "version": "1.0.0", "main": "src/main.js", "dependencies": { From cf242a6bad1f03213918587be0204b4a13d620eb Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Thu, 27 Nov 2025 15:29:35 -0500 Subject: [PATCH 08/10] fix types --- src/main/ipc.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/ipc.ts b/src/main/ipc.ts index d302562d..a43dd81a 100644 --- a/src/main/ipc.ts +++ b/src/main/ipc.ts @@ -1,4 +1,6 @@ import { + type SerializedLog, + type SerializedMetric, _INTERNAL_captureSerializedLog, _INTERNAL_captureSerializedMetric, Attachment, @@ -8,8 +10,6 @@ import { Event, parseEnvelope, ScopeData, - SerializedLog, - SerializedMetric, } from '@sentry/core'; import { captureEvent, getClient, getCurrentScope } from '@sentry/node'; import { app, ipcMain, protocol, WebContents, webContents } from 'electron'; @@ -167,11 +167,11 @@ function handleAttributes( client: Client, options: ElectronMainOptionsInternal, contents: WebContents | undefined, - maybeAttributes?: (typeof SerializedLog)['attributes'], -): (typeof SerializedLog)['attributes'] { + maybeAttributes?: SerializedLog['attributes'], +): SerializedLog['attributes'] { const process = contents ? options?.getRendererName?.(contents) || 'renderer' : 'renderer'; - const attributes: Record = maybeAttributes || {}; + const attributes: SerializedLog['attributes'] = maybeAttributes || {}; if (options.release) { attributes['sentry.release'] = { value: options.release, type: 'string' }; From f8dadae6e64d007c5509678d229235d938ffba19 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Thu, 27 Nov 2025 15:31:22 -0500 Subject: [PATCH 09/10] fix tests --- test/e2e/test-apps/other/metrics/test.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/e2e/test-apps/other/metrics/test.ts b/test/e2e/test-apps/other/metrics/test.ts index b4dc91ca..0f8e0fb4 100644 --- a/test/e2e/test-apps/other/metrics/test.ts +++ b/test/e2e/test-apps/other/metrics/test.ts @@ -22,14 +22,14 @@ electronTestRunner(__dirname, async (ctx) => { type: 'counter', value: 1, trace_id: UUID_MATCHER, - attributes: { - 'sentry.release': { value: 'javascript-logs@1.0.0', type: 'string' }, + attributes: expect.objectContaining({ + 'sentry.release': { value: 'electron-metrics@1.0.0', type: 'string' }, 'sentry.environment': { value: 'development', type: 'string' }, 'sentry.sdk.name': { value: 'sentry.javascript.electron', type: 'string' }, 'sentry.sdk.version': { value: SDK_VERSION, type: 'string' }, userId: { value: 'user_123', type: 'string' }, updatedFields: { value: '["email","preferences"]', type: 'string' }, - }, + }), }, { timestamp: expect.any(Number), @@ -37,15 +37,15 @@ electronTestRunner(__dirname, async (ctx) => { name: 'User clicked submit button', type: 'counter', value: 1, - attributes: { + attributes: expect.objectContaining({ buttonId: { value: 'submit-form', type: 'string' }, formId: { value: 'user-profile', type: 'string' }, - 'sentry.release': { value: 'javascript-logs@1.0.0', type: 'string' }, + 'sentry.release': { value: 'electron-metrics@1.0.0', type: 'string' }, 'sentry.environment': { value: 'development', type: 'string' }, 'sentry.sdk.name': { value: 'sentry.javascript.electron', type: 'string' }, 'sentry.sdk.version': { value: SDK_VERSION, type: 'string' }, 'electron.process': { value: 'renderer', type: 'string' }, - }, + }), }, { timestamp: expect.any(Number), @@ -56,7 +56,7 @@ electronTestRunner(__dirname, async (ctx) => { attributes: expect.objectContaining({ region: { value: 'us-east', type: 'string' }, tier: { value: 'premium', type: 'string' }, - 'sentry.release': { value: 'javascript-logs@1.0.0', type: 'string' }, + 'sentry.release': { value: 'electron-metrics@1.0.0', type: 'string' }, 'sentry.environment': { value: 'development', type: 'string' }, 'sentry.sdk.name': { value: 'sentry.javascript.electron', type: 'string' }, 'sentry.sdk.version': { value: SDK_VERSION, type: 'string' }, @@ -73,7 +73,7 @@ electronTestRunner(__dirname, async (ctx) => { attributes: expect.objectContaining({ page: { value: 'dashboard', type: 'string' }, cached: { value: 'false', type: 'string' }, - 'sentry.release': { value: 'javascript-logs@1.0.0', type: 'string' }, + 'sentry.release': { value: 'electron-metrics@1.0.0', type: 'string' }, 'sentry.environment': { value: 'development', type: 'string' }, 'sentry.sdk.name': { value: 'sentry.javascript.electron', type: 'string' }, 'sentry.sdk.version': { value: SDK_VERSION, type: 'string' }, From 799d972517e9024d272999c4a170b4e8e219047f Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Thu, 27 Nov 2025 15:42:30 -0500 Subject: [PATCH 10/10] remove --- .../test-apps/other/metrics/src/index.html | 15 --------- test/e2e/test-apps/other/metrics/test.ts | 33 ------------------- 2 files changed, 48 deletions(-) diff --git a/test/e2e/test-apps/other/metrics/src/index.html b/test/e2e/test-apps/other/metrics/src/index.html index e06ef51f..938c2147 100644 --- a/test/e2e/test-apps/other/metrics/src/index.html +++ b/test/e2e/test-apps/other/metrics/src/index.html @@ -18,21 +18,6 @@ formId: 'user-profile', }, }); - - metrics.gauge('Active users online', 42, { - attributes: { - region: 'us-east', - tier: 'premium', - }, - }); - - metrics.distribution('Page load time', 1250, { - unit: 'millisecond', - attributes: { - page: 'dashboard', - cached: 'false', - }, - }); }, 500); diff --git a/test/e2e/test-apps/other/metrics/test.ts b/test/e2e/test-apps/other/metrics/test.ts index 0f8e0fb4..6ff8ef3b 100644 --- a/test/e2e/test-apps/other/metrics/test.ts +++ b/test/e2e/test-apps/other/metrics/test.ts @@ -47,39 +47,6 @@ electronTestRunner(__dirname, async (ctx) => { 'electron.process': { value: 'renderer', type: 'string' }, }), }, - { - timestamp: expect.any(Number), - trace_id: UUID_MATCHER, - name: 'Active users online', - type: 'gauge', - value: 42, - attributes: expect.objectContaining({ - region: { value: 'us-east', type: 'string' }, - tier: { value: 'premium', type: 'string' }, - 'sentry.release': { value: 'electron-metrics@1.0.0', type: 'string' }, - 'sentry.environment': { value: 'development', type: 'string' }, - 'sentry.sdk.name': { value: 'sentry.javascript.electron', type: 'string' }, - 'sentry.sdk.version': { value: SDK_VERSION, type: 'string' }, - 'electron.process': { value: 'renderer', type: 'string' }, - }), - }, - { - timestamp: expect.any(Number), - trace_id: UUID_MATCHER, - name: 'Page load time', - type: 'distribution', - value: 1250, - unit: 'millisecond', - attributes: expect.objectContaining({ - page: { value: 'dashboard', type: 'string' }, - cached: { value: 'false', type: 'string' }, - 'sentry.release': { value: 'electron-metrics@1.0.0', type: 'string' }, - 'sentry.environment': { value: 'development', type: 'string' }, - 'sentry.sdk.name': { value: 'sentry.javascript.electron', type: 'string' }, - 'sentry.sdk.version': { value: SDK_VERSION, type: 'string' }, - 'electron.process': { value: 'renderer', type: 'string' }, - }), - }, ]), }, ],