Skip to content

Commit 41ba98a

Browse files
timfishAbhiPrasad
andauthored
fix(node): Disable LocalVariables integration on Node < v18 (#7748)
Co-authored-by: Abhijeet Prasad <[email protected]>
1 parent 1d7f18f commit 41ba98a

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

packages/node-integration-tests/suites/public-api/LocalVariables/test.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import type { Event } from '@sentry/node';
2-
import { parseSemver } from '@sentry/utils';
32
import * as childProcess from 'child_process';
43
import * as path from 'path';
54

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

8-
const testIf = (condition: boolean, t: jest.It) => (condition ? t : t.skip);
9-
10-
describe('LocalVariables integration', () => {
7+
conditionalTest({ min: 18 })('LocalVariables integration', () => {
118
test('Should not include local variables by default', done => {
129
expect.assertions(2);
1310

@@ -57,7 +54,7 @@ describe('LocalVariables integration', () => {
5754
});
5855
});
5956

60-
testIf(nodeMajor > 10, test)('Should include local variables with ESM', done => {
57+
test('Should include local variables with ESM', done => {
6158
expect.assertions(4);
6259

6360
const testScriptPath = path.resolve(__dirname, 'local-variables-caught.mjs');

packages/node/src/integrations/localvariables.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import type { Event, EventProcessor, Exception, Hub, Integration, StackFrame, StackParser } from '@sentry/types';
2+
import { logger } from '@sentry/utils';
23
import type { Debugger, InspectorNotification, Runtime, Session } from 'inspector';
34
import { LRUMap } from 'lru_map';
45

6+
import { NODE_VERSION } from '../nodeVersion';
57
import type { NodeClientOptions } from '../types';
68

79
type Variables = Record<string, unknown>;
@@ -282,6 +284,15 @@ export class LocalVariables implements Integration {
282284
clientOptions: NodeClientOptions | undefined,
283285
): void {
284286
if (this._session && clientOptions?.includeLocalVariables) {
287+
// Only setup this integration if the Node version is >= v18
288+
// https://github.com/getsentry/sentry-javascript/issues/7697
289+
const unsupportedNodeVersion = (NODE_VERSION.major || 0) < 18;
290+
291+
if (unsupportedNodeVersion) {
292+
logger.log('The `LocalVariables` integration is only supported on Node >= v18.');
293+
return;
294+
}
295+
285296
this._session.configureAndConnect(
286297
(ev, complete) =>
287298
this._handlePaused(clientOptions.stackParser, ev as InspectorNotification<PausedExceptionEvent>, complete),

packages/node/test/integrations/localvariables.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ import type { LRUMap } from 'lru_map';
55
import { defaultStackParser } from '../../src';
66
import type { DebugSession, FrameVariables } from '../../src/integrations/localvariables';
77
import { createCallbackList, LocalVariables } from '../../src/integrations/localvariables';
8+
import { NODE_VERSION } from '../../src/nodeVersion';
89
import { getDefaultNodeClientOptions } from '../../test/helper/node-client-options';
910

11+
const describeIf = (condition: boolean) => (condition ? describe : describe.skip);
12+
1013
interface ThrowOn {
1114
configureAndConnect?: boolean;
1215
getLocalVariables?: boolean;
@@ -145,7 +148,7 @@ const exceptionEvent100Frames = {
145148
},
146149
};
147150

148-
describe('LocalVariables', () => {
151+
describeIf(NODE_VERSION >= 18)('LocalVariables', () => {
149152
it('Adds local variables to stack frames', async () => {
150153
expect.assertions(7);
151154

0 commit comments

Comments
 (0)