Skip to content

feat: Update JavaScript SDKs to v10 #1205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@
"e2e": "xvfb-maybe vitest run --root=./test/e2e --silent=false --disable-console-intercept"
},
"dependencies": {
"@sentry/browser": "9.45.0",
"@sentry/core": "9.45.0",
"@sentry/node": "9.45.0"
"@sentry/browser": "10.5.0",
"@sentry/core": "10.5.0",
"@sentry/node": "10.5.0"
},
"peerDependencies": {
"@sentry/node-native": "9.45.0"
"@sentry/node-native": "10.5.0"
},
"peerDependenciesMeta": {
"@sentry/node-native": {
Expand All @@ -109,9 +109,9 @@
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-typescript": "^11.1.6",
"@sentry/node-native": "9.45.0",
"@sentry-internal/eslint-config-sdk": "9.45.0",
"@sentry-internal/typescript": "9.45.0",
"@sentry/node-native": "10.5.0",
"@sentry-internal/eslint-config-sdk": "10.5.0",
"@sentry-internal/typescript": "10.5.0",
"@types/busboy": "^1.5.4",
"@types/form-data": "^2.5.0",
"@types/koa": "^2.0.52",
Expand Down
4 changes: 3 additions & 1 deletion scripts/check-exports.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ const ignoredNode = [
'initWithoutDefaultIntegrations',
// We can't call these from Electron
'vercelAIIntegration',
'anrIntegration',
'disableAnrDetectionForCallback'
];

const ignoredUtility = [...ignoredNode, 'anrIntegration'];
const ignoredUtility = [...ignoredNode];

const missingRenderer = browserExports.filter((key) => !rendererExports.includes(key) && !ignoredBrowser.includes(key));
const missingMain = nodeExports.filter((key) => !mainExports.includes(key) && !ignoredNode.includes(key));
Expand Down
3 changes: 2 additions & 1 deletion src/main/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { SDK_VERSION } from './version.js';
export const SDK_NAME = 'sentry.javascript.electron';

/** Gets SDK info */
export function getSdkInfo(): SdkInfo {
export function getSdkInfo(sendDefaultPii: boolean): SdkInfo {
return {
name: SDK_NAME,
packages: [
Expand All @@ -17,6 +17,7 @@ export function getSdkInfo(): SdkInfo {
},
],
version: SDK_VERSION,
settings: { infer_ip: sendDefaultPii ? 'auto' : 'never' },
};
}

Expand Down
7 changes: 3 additions & 4 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ export {
cron,
dataloaderIntegration,
dedupeIntegration,
disableAnrDetectionForCallback,
endSession,
eventFiltersIntegration,
expressErrorHandler,
expressIntegration,
extraErrorDataIntegration,
fastifyIntegration,
featureFlagsIntegration,
firebaseIntegration,
flush,
fsIntegration,
functionToStringIntegration,
Expand Down Expand Up @@ -135,6 +135,7 @@ export {
statsigIntegration,
supabaseIntegration,
suppressTracing,
systemErrorIntegration,
tediousIntegration,
trpcMiddleware,
unleashIntegration,
Expand Down Expand Up @@ -165,9 +166,7 @@ export { rendererProfileFromIpc } from './integrations/renderer-profiling.js';
export { normalizePathsIntegration } from './integrations/normalize-paths.js';
export { electronContextIntegration } from './integrations/electron-context.js';
export { gpuContextIntegration } from './integrations/gpu-context.js';
// eslint-disable-next-line deprecation/deprecation
export { anrIntegration } from './integrations/anr.js';
export { rendererAnrIntegration } from './integrations/renderer-anr.js';
export { rendererEventLoopBlockIntegration } from './integrations/renderer-anr.js';

export { makeElectronTransport } from './transports/electron-net.js';
export { makeElectronOfflineTransport } from './transports/electron-offline-net.js';
Expand Down
49 changes: 0 additions & 49 deletions src/main/integrations/anr.ts

This file was deleted.

4 changes: 3 additions & 1 deletion src/main/integrations/electron-minidump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ export const electronMinidumpIntegration = defineIntegration(() => {
let updateEpoch = 0;

async function getNativeUploaderEvent(client: NodeClient, scope: ScopeData): Promise<Event> {
const { sendDefaultPii = false } = client.getOptions();

const event = mergeEvents(await getEventDefaults(client), {
sdk: getSdkInfo(),
sdk: getSdkInfo(sendDefaultPii),
event_id: uuid4(),
level: 'fatal',
platform: 'native',
Expand Down
29 changes: 14 additions & 15 deletions src/main/integrations/renderer-anr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { sessionAnr } from '../sessions.js';
import { captureRendererStackFrames } from '../stack-parse.js';

function log(message: string, ...args: unknown[]): void {
debug.log(`[Renderer ANR] ${message}`, ...args);
debug.log(`[Renderer Event Loop Block] ${message}`, ...args);
}

interface ScriptParsedEventDataType {
Expand Down Expand Up @@ -132,7 +132,7 @@ function createHrTimer(): { getTimeMs: () => number; reset: () => void } {
};
}

const INTEGRATION_NAME = 'RendererAnr';
const INTEGRATION_NAME = 'RendererEventLoopBlock';

type Options = {
/**
Expand All @@ -148,23 +148,23 @@ type Options = {

type RendererStatusHandler = (status: RendererStatus, contents: WebContents) => void;

type RendererAnrIntegration = Integration & {
createRendererAnrStatusHandler: () => RendererStatusHandler;
type RendererEventLoopBlockIntegration = Integration & {
createRendererEventLoopBlockStatusHandler: () => RendererStatusHandler;
};

/**
* An integration that captures App Not Responding events from renderer processes
*/
export const rendererAnrIntegration: (options?: Options) => RendererAnrIntegration = defineIntegration(
(options: Options = {}) => {
export const rendererEventLoopBlockIntegration: (options?: Options) => RendererEventLoopBlockIntegration =
defineIntegration((options: Options = {}) => {
const rendererWatchdogTimers = new Map<WebContents, ReturnType<typeof watchdogTimer>>();
let clientOptions: ElectronMainOptionsInternal | undefined;

function getRendererName(contents: WebContents): string | undefined {
return clientOptions?.getRendererName?.(contents);
}

function sendRendererAnrEvent(contents: WebContents, blockedMs: number, frames?: StackFrame[]): void {
function sendRendererEventLoopBlockEvent(contents: WebContents, blockedMs: number, frames?: StackFrame[]): void {
sessionAnr();

const rendererName = getRendererName(contents) || 'renderer';
Expand Down Expand Up @@ -211,7 +211,7 @@ export const rendererAnrIntegration: (options?: Options) => RendererAnrIntegrati
}
}
},
createRendererAnrStatusHandler: (): RendererStatusHandler => {
createRendererEventLoopBlockStatusHandler: (): RendererStatusHandler => {
return (message: RendererStatus, contents: WebContents): void => {
let watchdog = rendererWatchdogTimers.get(contents);

Expand All @@ -237,7 +237,7 @@ export const rendererAnrIntegration: (options?: Options) => RendererAnrIntegrati

pauseAndCapture = stackCaptureImpl(contents, (frames) => {
log('Event captured with stack frames');
sendRendererAnrEvent(contents, message.config.anrThreshold, frames);
sendRendererEventLoopBlockEvent(contents, message.config.anrThreshold, frames);
});
}

Expand All @@ -247,7 +247,7 @@ export const rendererAnrIntegration: (options?: Options) => RendererAnrIntegrati
pauseAndCapture();
} else {
log('Capturing event');
sendRendererAnrEvent(contents, message.config.anrThreshold);
sendRendererEventLoopBlockEvent(contents, message.config.anrThreshold);
}
});

Expand Down Expand Up @@ -279,13 +279,12 @@ export const rendererAnrIntegration: (options?: Options) => RendererAnrIntegrati
};
},
};
},
) as (options?: Options) => RendererAnrIntegration;
}) as (options?: Options) => RendererEventLoopBlockIntegration;

/**
* Creates a hook which notifies the integration when the state of renderers change
*/
export function createRendererAnrStatusHandler(client: Client): RendererStatusHandler | undefined {
const integration = client.getIntegrationByName(INTEGRATION_NAME) as RendererAnrIntegration | undefined;
return integration?.createRendererAnrStatusHandler();
export function createRendererEventLoopBlockStatusHandler(client: Client): RendererStatusHandler | undefined {
const integration = client.getIntegrationByName(INTEGRATION_NAME) as RendererEventLoopBlockIntegration | undefined;
return integration?.createRendererEventLoopBlockStatusHandler();
}
9 changes: 1 addition & 8 deletions src/main/integrations/sentry-minidump/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,7 @@ export const sentryMinidumpIntegration = defineIntegration((options: Options = {
await minidumpLoader?.(deleteAll, async (minidumpResult, attachment) => {
minidumpFound = true;

let minidumpProcess = minidumpResult.crashpadAnnotations?.process_type;

// For backwards compatibility, we need to map 'gpu-process' to 'GPU'
// TODO (v7): Remove this
if (minidumpProcess === 'gpu-process') {
minidumpProcess = 'GPU';
}
const minidumpProcess = minidumpResult.crashpadAnnotations?.process_type?.replace('-process', '');

const event = await getEvent(minidumpProcess);

Expand Down Expand Up @@ -191,7 +185,6 @@ export const sentryMinidumpIntegration = defineIntegration((options: Options = {
'event.environment': 'native',
'event.process': minidumpProcess || details.type,
'exit.reason': details.reason,
event_type: 'native',
},
}));
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { app, ipcMain, protocol, WebContents, webContents } from 'electron';
import { eventFromEnvelope } from '../common/envelope.js';
import { IPCChannel, IPCMode, PROTOCOL_SCHEME, RendererStatus } from '../common/ipc.js';
import { registerProtocol } from './electron-normalize.js';
import { createRendererAnrStatusHandler } from './integrations/renderer-anr.js';
import { createRendererEventLoopBlockStatusHandler } from './integrations/renderer-anr.js';
import { rendererProfileFromIpc } from './integrations/renderer-profiling.js';
import { mergeEvents } from './merge.js';
import { normalizeReplayEnvelope } from './normalize.js';
Expand Down Expand Up @@ -198,7 +198,7 @@ function configureProtocol(client: Client, options: ElectronMainOptionsInternal)
},
});

const rendererStatusChanged = createRendererAnrStatusHandler(client);
const rendererStatusChanged = createRendererEventLoopBlockStatusHandler(client);

app
.whenReady()
Expand Down Expand Up @@ -264,7 +264,7 @@ function configureClassic(client: Client, options: ElectronMainOptionsInternal):
);
ipcMain.on(IPCChannel.STRUCTURED_LOG, (_, log: SerializedLog) => handleLogFromRenderer(client, options, log));

const rendererStatusChanged = createRendererAnrStatusHandler(client);
const rendererStatusChanged = createRendererEventLoopBlockStatusHandler(client);
if (rendererStatusChanged) {
ipcMain.on(IPCChannel.STATUS, ({ sender }, status: RendererStatus) => rendererStatusChanged(status, sender));
}
Expand Down
8 changes: 3 additions & 5 deletions src/main/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
addAutoIpAddressToSession,
addAutoIpAddressToUser,
debug,
getIntegrationsToSetup,
Integration,
Expand Down Expand Up @@ -36,7 +35,7 @@ import { electronNetIntegration } from './integrations/net-breadcrumbs.js';
import { normalizePathsIntegration } from './integrations/normalize-paths.js';
import { onUncaughtExceptionIntegration } from './integrations/onuncaughtexception.js';
import { preloadInjectionIntegration } from './integrations/preload-injection.js';
import { rendererAnrIntegration } from './integrations/renderer-anr.js';
import { rendererEventLoopBlockIntegration } from './integrations/renderer-anr.js';
import { rendererProfilingIntegration } from './integrations/renderer-profiling.js';
import { screenshotsIntegration } from './integrations/screenshots.js';
import { sentryMinidumpIntegration } from './integrations/sentry-minidump/index.js';
Expand All @@ -59,7 +58,7 @@ export function getDefaultIntegrations(options: ElectronMainOptions): Integratio
additionalContextIntegration(),
screenshotsIntegration(),
gpuContextIntegration(),
rendererAnrIntegration(),
rendererEventLoopBlockIntegration(),

// Main process sessions
mainProcessSessionIntegration(),
Expand Down Expand Up @@ -153,7 +152,7 @@ export function init(userOptions: ElectronMainOptions): void {
}

const optionsWithDefaults = {
_metadata: { sdk: getSdkInfo() },
_metadata: { sdk: getSdkInfo(!!userOptions.sendDefaultPii) },
ipcMode: IPCMode.Both,
release: getDefaultReleaseName(),
environment: getDefaultEnvironment(),
Expand Down Expand Up @@ -186,7 +185,6 @@ export function init(userOptions: ElectronMainOptions): void {
const client = new NodeClient(options);

if (options.sendDefaultPii === true) {
client.on('postprocessEvent', addAutoIpAddressToUser);
client.on('beforeSendSession', addAutoIpAddressToSession);
}

Expand Down
12 changes: 6 additions & 6 deletions src/renderer/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function captureLog(
}

/**
* @summary Capture a log with the `trace` level. Requires `_experiments.enableLogs` to be enabled in the Electron main process.
* @summary Capture a log with the `trace` level. Requires `enableLogs` to be enabled in the Electron main process.
*
* @param message - The message to log.
* @param attributes - Arbitrary structured data that stores information about the log - e.g., { userId: 100, route: '/dashboard' }.
Expand Down Expand Up @@ -53,7 +53,7 @@ export function trace(message: ParameterizedString, attributes?: Log['attributes
}

/**
* @summary Capture a log with the `debug` level. Requires `_experiments.enableLogs` to be enabled in the Electron main process.
* @summary Capture a log with the `debug` level. Requires `enableLogs` to be enabled in the Electron main process.
*
* @param message - The message to log.
* @param attributes - Arbitrary structured data that stores information about the log - e.g., { component: 'Header', state: 'loading' }.
Expand Down Expand Up @@ -83,7 +83,7 @@ export function debug(message: ParameterizedString, attributes?: Log['attributes
}

/**
* @summary Capture a log with the `info` level. Requires `_experiments.enableLogs` to be enabled in the Electron main process.
* @summary Capture a log with the `info` level. Requires `enableLogs` to be enabled in the Electron main process.
*
* @param message - The message to log.
* @param attributes - Arbitrary structured data that stores information about the log - e.g., { feature: 'checkout', status: 'completed' }.
Expand Down Expand Up @@ -113,7 +113,7 @@ export function info(message: ParameterizedString, attributes?: Log['attributes'
}

/**
* @summary Capture a log with the `warn` level. Requires `_experiments.enableLogs` to be enabled in the Electron main process.
* @summary Capture a log with the `warn` level. Requires `enableLogs` to be enabled in the Electron main process.
*
* @param message - The message to log.
* @param attributes - Arbitrary structured data that stores information about the log - e.g., { browser: 'Chrome', version: '91.0' }.
Expand Down Expand Up @@ -144,7 +144,7 @@ export function warn(message: ParameterizedString, attributes?: Log['attributes'
}

/**
* @summary Capture a log with the `error` level. Requires `_experiments.enableLogs` to be enabled in the Electron main process.
* @summary Capture a log with the `error` level. Requires `enableLogs` to be enabled in the Electron main process.
*
* @param message - The message to log.
* @param attributes - Arbitrary structured data that stores information about the log - e.g., { error: 'NetworkError', url: '/api/data' }.
Expand Down Expand Up @@ -176,7 +176,7 @@ export function error(message: ParameterizedString, attributes?: Log['attributes
}

/**
* @summary Capture a log with the `fatal` level. Requires `_experiments.enableLogs` to be enabled in the Electron main process.
* @summary Capture a log with the `fatal` level. Requires `enableLogs` to be enabled in the Electron main process.
*
* @param message - The message to log.
* @param attributes - Arbitrary structured data that stores information about the log - e.g., { appState: 'corrupted', sessionId: 'abc-123' }.
Expand Down
Loading