Skip to content

Commit

Permalink
feat: Update JavaScript SDKs to 7.76.0 (#783)
Browse files Browse the repository at this point in the history
  • Loading branch information
timfish authored Oct 31, 2023
1 parent 6105fb5 commit 060747d
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 104 deletions.
15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,19 @@
"e2e": "cross-env TS_NODE_PROJECT=tsconfig.test.json xvfb-maybe mocha --require ts-node/register/transpile-only --retries 3 ./test/e2e/*.ts"
},
"dependencies": {
"@sentry/browser": "7.74.0",
"@sentry/core": "7.74.0",
"@sentry/node": "7.74.0",
"@sentry/types": "7.74.0",
"@sentry/utils": "7.74.0",
"@sentry/browser": "7.76.0",
"@sentry/core": "7.76.0",
"@sentry/node": "7.76.0",
"@sentry/types": "7.76.0",
"@sentry/utils": "7.76.0",
"deepmerge": "4.3.0",
"lru_map": "^0.3.3",
"tslib": "^2.5.0"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.2.1",
"@rollup/plugin-typescript": "^11.1.4",
"@sentry-internal/eslint-config-sdk": "7.74.0",
"@sentry-internal/typescript": "7.74.0",
"@sentry-internal/eslint-config-sdk": "7.76.0",
"@sentry-internal/typescript": "7.76.0",
"@types/busboy": "^0.2.3",
"@types/chai": "^4.2.10",
"@types/chai-as-promised": "^7.1.5",
Expand Down
24 changes: 23 additions & 1 deletion src/main/anr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ import { app, WebContents } from 'electron';
import { RendererStatus } from '../common';
import { ELECTRON_MAJOR_VERSION } from './electron-normalize';
import { ElectronMainOptions } from './sdk';
import { sessionAnr } from './sessions';

function getRendererName(contents: WebContents): string | undefined {
const options = getCurrentHub().getClient()?.getOptions() as ElectronMainOptions | undefined;
return options?.getRendererName?.(contents);
}

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

const rendererName = getRendererName(contents) || 'renderer';

const event: Event = {
Expand Down Expand Up @@ -67,6 +70,25 @@ function rendererDebugger(contents: WebContents, pausedStack: (frames: StackFram

let rendererWatchdogTimers: Map<WebContents, ReturnType<typeof watchdogTimer>> | undefined;

function createHrTimer(): { getTimeMs: () => number; reset: () => void } {
let lastPoll = process.hrtime();

return {
getTimeMs: (): number => {
const [seconds, nanoSeconds] = process.hrtime(lastPoll);
return Math.floor(seconds * 1e3 + nanoSeconds / 1e6);
},
reset: (): void => {
lastPoll = process.hrtime();
},
};
}

/** Are we currently running in the ANR child process */
export function isAnrChildProcess(): boolean {
return !!process.env.SENTRY_ANR_CHILD_PROCESS;
}

/** Creates a renderer ANR status hook */
export function createRendererAnrStatusHook(): (status: RendererStatus, contents: WebContents) => void {
function log(message: string, ...args: unknown[]): void {
Expand All @@ -90,7 +112,7 @@ export function createRendererAnrStatusHook(): (status: RendererStatus, contents
});
}

watchdog = watchdogTimer(100, message.config.anrThreshold, async () => {
watchdog = watchdogTimer(createHrTimer, 100, message.config.anrThreshold, async () => {
log('Watchdog timeout');
if (pauseAndCapture) {
log('Pausing debugger to capture stack trace');
Expand Down
2 changes: 1 addition & 1 deletion src/main/integrations/net-breadcrumbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
fill,
generateSentryTraceHeader,
logger,
LRUMap,
stringMatchesSomePattern,
} from '@sentry/utils';
import { ClientRequest, ClientRequestConstructorOptions, IncomingMessage, net } from 'electron';
import { LRUMap } from 'lru_map';
import * as urlModule from 'url';

type ShouldTraceFn = (method: string, url: string) => boolean;
Expand Down
3 changes: 2 additions & 1 deletion src/main/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { defaultIntegrations as defaultNodeIntegrations, init as nodeInit, NodeO
import { Integration, Options } from '@sentry/types';
import { app, Session, session, WebContents } from 'electron';

import { isAnrChildProcess } from './anr';
import { getDefaultEnvironment, getDefaultReleaseName } from './context';
import {
AdditionalContext,
Expand Down Expand Up @@ -96,7 +97,7 @@ export function init(userOptions: ElectronMainOptions): void {
const options: ElectronMainOptionsInternal = Object.assign(defaultOptions, userOptions);
const defaults = defaultIntegrations;

if (process.env.SENTRY_ANR_CHILD_PROCESS) {
if (isAnrChildProcess()) {
app.dock?.hide();
options.autoSessionTracking = false;
options.tracesSampleRate = 0;
Expand Down
27 changes: 27 additions & 0 deletions src/main/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { SerializedSession, Session, SessionContext, SessionStatus } from '@sent
import { logger } from '@sentry/utils';
import { app } from 'electron';

import { isAnrChildProcess } from './anr';
import { sentryCachePath } from './fs';
import { Store } from './store';

Expand Down Expand Up @@ -93,6 +94,11 @@ export async function unreportedDuringLastSession(crashDate: Date | undefined):
export async function checkPreviousSession(crashed: boolean): Promise<void> {
const client = getCurrentHub().getClient<NodeClient>();

// We should not check the session storage if we are in an ANR child process
if (isAnrChildProcess()) {
return;
}

const previous = await previousSession;

if (previous && client) {
Expand Down Expand Up @@ -147,6 +153,27 @@ export function sessionCrashed(): void {
hub.captureSession();
}

/** Sets the current session as ANR */
export function sessionAnr(): void {
// stop persisting session
if (persistTimer) {
clearInterval(persistTimer);
}

const hub = getCurrentHub();
const session = hub.getScope()?.getSession();

if (!session) {
return;
}

if (session.status === 'ok') {
logger.log('Setting session as abnormal ANR');
updateSession(session, { status: 'abnormal', abnormal_mechanism: 'anr_foreground' });
hub.captureSession();
}
}

/**
* End the current session on app exit
*/
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ interface ElectronRendererOptions extends BrowserOptions {
export function init<O extends ElectronRendererOptions>(
options: ElectronRendererOptions & O = {} as ElectronRendererOptions & O,
// This parameter name ensures that TypeScript error messages contain a hint for fixing SDK version mismatches
originalInit: (if_you_get_a_typescript_error_ensure_sdks_use_version_v7_74_0: O) => void = browserInit,
originalInit: (if_you_get_a_typescript_error_ensure_sdks_use_version_v7_76_0: O) => void = browserInit,
): void {
ensureProcess('renderer');

Expand Down
18 changes: 18 additions & 0 deletions test/e2e/test-apps/anr/anr-main/session.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"appId": "277345",
"sentryKey": "37f8a2ee37c0409d8970bc7559c7c7e4",
"method": "envelope",
"data": {
"sid": "{{id}}",
"init": true,
"started": 0,
"timestamp": 0,
"status": "abnormal",
"abnormal_mechanism": "anr_foreground",
"errors": 0,
"duration": 0,
"attrs": {
"release": "[email protected]"
}
}
}
1 change: 0 additions & 1 deletion test/e2e/test-apps/anr/anr-main/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const { init, enableMainProcessAnrDetection } = require('@sentry/electron/main')
init({
dsn: '__DSN__',
debug: true,
autoSessionTracking: false,
onFatalError: () => {},
});

Expand Down
18 changes: 18 additions & 0 deletions test/e2e/test-apps/anr/anr-renderer/session.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"appId": "277345",
"sentryKey": "37f8a2ee37c0409d8970bc7559c7c7e4",
"method": "envelope",
"data": {
"sid": "{{id}}",
"init": true,
"started": 0,
"timestamp": 0,
"status": "abnormal",
"abnormal_mechanism": "anr_foreground",
"errors": 0,
"duration": 0,
"attrs": {
"release": "[email protected]"
}
}
}
1 change: 0 additions & 1 deletion test/e2e/test-apps/anr/anr-renderer/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const { init } = require('@sentry/electron/main');
init({
dsn: '__DSN__',
debug: true,
autoSessionTracking: false,
onFatalError: () => {},
});

Expand Down
Loading

0 comments on commit 060747d

Please sign in to comment.