Skip to content
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

fix(node): Disable LocalVariables integration on Node < v18 #7748

Merged
merged 7 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import type { Event } from '@sentry/node';
import { parseSemver } from '@sentry/utils';
import * as childProcess from 'child_process';
import * as path from 'path';

const nodeMajor = parseSemver(process.version.slice(1)).major || 1;
import { conditionalTest } from '../../../utils';

const testIf = (condition: boolean, t: jest.It) => (condition ? t : t.skip);

describe('LocalVariables integration', () => {
conditionalTest({ min: 18 })('LocalVariables integration', () => {
test('Should not include local variables by default', done => {
expect.assertions(2);

Expand Down Expand Up @@ -57,7 +54,7 @@ describe('LocalVariables integration', () => {
});
});

testIf(nodeMajor > 10, test)('Should include local variables with ESM', done => {
test('Should include local variables with ESM', done => {
expect.assertions(4);

const testScriptPath = path.resolve(__dirname, 'local-variables-caught.mjs');
Expand Down
11 changes: 11 additions & 0 deletions packages/node/src/integrations/localvariables.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { Event, EventProcessor, Exception, Hub, Integration, StackFrame, StackParser } from '@sentry/types';
import { logger } from '@sentry/utils';
import type { Debugger, InspectorNotification, Runtime, Session } from 'inspector';
import { LRUMap } from 'lru_map';

import { NODE_VERSION } from '../nodeVersion';
import type { NodeClientOptions } from '../types';

type Variables = Record<string, unknown>;
Expand Down Expand Up @@ -282,6 +284,15 @@ export class LocalVariables implements Integration {
clientOptions: NodeClientOptions | undefined,
): void {
if (this._session && clientOptions?.includeLocalVariables) {
// Only setup this integration if the Node version is >= v18
// https://github.com/getsentry/sentry-javascript/issues/7697
const unsupportedNodeVersion = (NODE_VERSION.major || 0) < 18;

if (unsupportedNodeVersion) {
logger.log('The `LocalVariables` integration is only supported on Node >= v18.');
return;
}

this._session.configureAndConnect(
(ev, complete) =>
this._handlePaused(clientOptions.stackParser, ev as InspectorNotification<PausedExceptionEvent>, complete),
Expand Down
5 changes: 4 additions & 1 deletion packages/node/test/integrations/localvariables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import type { LRUMap } from 'lru_map';
import { defaultStackParser } from '../../src';
import type { DebugSession, FrameVariables } from '../../src/integrations/localvariables';
import { createCallbackList, LocalVariables } from '../../src/integrations/localvariables';
import { NODE_VERSION } from '../../src/nodeVersion';
import { getDefaultNodeClientOptions } from '../../test/helper/node-client-options';

const describeIf = (condition: boolean) => (condition ? describe : describe.skip);

interface ThrowOn {
configureAndConnect?: boolean;
getLocalVariables?: boolean;
Expand Down Expand Up @@ -145,7 +148,7 @@ const exceptionEvent100Frames = {
},
};

describe('LocalVariables', () => {
describeIf(NODE_VERSION >= 18)('LocalVariables', () => {
it('Adds local variables to stack frames', async () => {
expect.assertions(7);

Expand Down