From b611ab2c00d65cdefda0a6bda4b46f4bc235a8be Mon Sep 17 00:00:00 2001 From: Bryan English Date: Fri, 22 Nov 2024 22:33:24 -0500 Subject: [PATCH 1/4] make it not crash on 12.0.0 --- .github/workflows/project.yml | 2 +- init.js | 6 ++++-- integration-tests/init.spec.js | 30 +++++++++++++++++++++++++++--- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/.github/workflows/project.yml b/.github/workflows/project.yml index 38c43297947..28c934cd442 100644 --- a/.github/workflows/project.yml +++ b/.github/workflows/project.yml @@ -34,7 +34,7 @@ jobs: integration-guardrails: strategy: matrix: - version: [12, 14, 16] + version: [12.0.0, 12, 14, 16] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/init.js b/init.js index 8b183fc17ab..d9286b0307f 100644 --- a/init.js +++ b/init.js @@ -2,7 +2,9 @@ /* eslint-disable no-var */ -var NODE_MAJOR = require('./version').NODE_MAJOR +var nodeVersion = require('./version') +var NODE_MAJOR = nodeVersion.NODE_MAJOR +var NODE_MINOR = nodeVersion.NODE_MINOR // We use several things that are not supported by older versions of Node: // - AsyncLocalStorage @@ -11,7 +13,7 @@ var NODE_MAJOR = require('./version').NODE_MAJOR // - Mocha (for testing) // and probably others. // TODO: Remove all these dependencies so that we can report telemetry. -if (NODE_MAJOR >= 12) { +if ((NODE_MAJOR === 12 && NODE_MINOR >= 17) || NODE_MAJOR > 12) { var path = require('path') var Module = require('module') var semver = require('semver') diff --git a/integration-tests/init.spec.js b/integration-tests/init.spec.js index 571179276e1..54cb5c18409 100644 --- a/integration-tests/init.spec.js +++ b/integration-tests/init.spec.js @@ -20,6 +20,7 @@ const telemetryGood = ['complete', 'injection_forced:false'] const { engines } = require('../package.json') const supportedRange = engines.node const currentVersionIsSupported = semver.satisfies(process.versions.node, supportedRange) +const currentVersionCanLog = semver.satisfies(process.versions.node, '>=12.17.0') // These are on by default in release tests, so we'll turn them off for // more fine-grained control of these variables in these tests. @@ -83,7 +84,30 @@ function testRuntimeVersionChecks (arg, filename) { } } - if (!currentVersionIsSupported) { + if (!currentVersionCanLog) { + context('when node version is too low for AsyncLocalStorage', () => { + useEnv({ NODE_OPTIONS }) + + it('should initialize the tracer, if no DD_INJECTION_ENABLED', () => + doTest('false\n')) + context('with DD_INJECTION_ENABLED', () => { + useEnv({ DD_INJECTION_ENABLED }) + + context('without debug', () => { + it('should not initialize the tracer', () => doTest('false\n')) + it('should not, if DD_INJECT_FORCE', () => doTestForced('false\n')) + }) + context('with debug', () => { + useEnv({ DD_TRACE_DEBUG }) + + it('should not initialize the tracer', () => + doTest('false\n')) + it('should initialize the tracer, if DD_INJECT_FORCE', () => + doTestForced('false\n')) + }) + }) + }) + } else if (!currentVersionIsSupported) { context('when node version is less than engines field', () => { useEnv({ NODE_OPTIONS }) @@ -165,8 +189,8 @@ describe('init.js', () => { testRuntimeVersionChecks('require', 'init.js') }) -// ESM is not supportable prior to Node.js 12 -if (semver.satisfies(process.versions.node, '>=12')) { +// ESM is not supportable prior to Node.js 12.17.0 +if (semver.satisfies(process.versions.node, '>=12.17.0')) { describe('initialize.mjs', () => { useSandbox() stubTracerIfNeeded() From 0f64306b9e163b126ffd8f1ecaa925cb144ba493 Mon Sep 17 00:00:00 2001 From: Bryan English Date: Fri, 22 Nov 2024 23:32:47 -0500 Subject: [PATCH 2/4] wider ranged test matrix for init.spec.js --- .github/workflows/project.yml | 4 ++-- integration-tests/init.spec.js | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/project.yml b/.github/workflows/project.yml index 28c934cd442..f91d6374eec 100644 --- a/.github/workflows/project.yml +++ b/.github/workflows/project.yml @@ -18,7 +18,7 @@ jobs: # setting fail-fast to false in an attempt to prevent this from happening fail-fast: false matrix: - version: [18, 20, latest] + version: [18.0.0, 18.1.0, 18, 20.0.0, 20, 22.0.0, 22, latest] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -34,7 +34,7 @@ jobs: integration-guardrails: strategy: matrix: - version: [12.0.0, 12, 14, 16] + version: [12.0.0, 12, 14.0.0, 14, 16.0.0, 16] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/integration-tests/init.spec.js b/integration-tests/init.spec.js index 54cb5c18409..5b5f2935b28 100644 --- a/integration-tests/init.spec.js +++ b/integration-tests/init.spec.js @@ -189,8 +189,13 @@ describe('init.js', () => { testRuntimeVersionChecks('require', 'init.js') }) -// ESM is not supportable prior to Node.js 12.17.0 -if (semver.satisfies(process.versions.node, '>=12.17.0')) { +// ESM is not supportable prior to Node.js 12.17.0, 14.13.1 on the 14.x line, +// or on 18.0.0 in particular. +if ( + semver.satisfies(process.versions.node, '>=12.17.0') && + semver.satisfies(process.versions.node, '>=14.13.1') && + !semver.satisfies(process.versions.node, '18.0.0') +) { describe('initialize.mjs', () => { useSandbox() stubTracerIfNeeded() @@ -199,7 +204,7 @@ if (semver.satisfies(process.versions.node, '>=12.17.0')) { testInjectionScenarios('loader', 'initialize.mjs', true) testRuntimeVersionChecks('loader', 'initialize.mjs') }) - if (Number(process.versions.node.split('.')[0]) >= 18) { + if (semver.satisfies(process.versions.node, '>=20.6.0')) { context('as --import', () => { testInjectionScenarios('import', 'initialize.mjs', true) testRuntimeVersionChecks('loader', 'initialize.mjs') From 9a09e6cf9437e2bc58e6e80633ec2aeeef2190d1 Mon Sep 17 00:00:00 2001 From: Bryan English Date: Fri, 22 Nov 2024 23:50:50 -0500 Subject: [PATCH 3/4] make 18.0.0 not crash, even though ESM can't be supported in it --- initialize.mjs | 9 +++++++-- integration-tests/init.spec.js | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/initialize.mjs b/initialize.mjs index 777f45cc046..104e253d22d 100644 --- a/initialize.mjs +++ b/initialize.mjs @@ -31,11 +31,16 @@ ${result.source}` return result } +const [NODE_MAJOR, NODE_MINOR] = process.versions.node.split('.').map(x => +x) + +const brokenLoaders = NODE_MAJOR === 18 && NODE_MINOR === 0 + export async function load (...args) { - return insertInit(await origLoad(...args)) + const loadHook = brokenLoaders ? args[args.length - 1] : origLoad + return insertInit(await loadHook(...args)) } -export const resolve = origResolve +export const resolve = brokenLoaders ? undefined : origResolve export const getFormat = origGetFormat diff --git a/integration-tests/init.spec.js b/integration-tests/init.spec.js index 5b5f2935b28..3c37004f607 100644 --- a/integration-tests/init.spec.js +++ b/integration-tests/init.spec.js @@ -193,15 +193,15 @@ describe('init.js', () => { // or on 18.0.0 in particular. if ( semver.satisfies(process.versions.node, '>=12.17.0') && - semver.satisfies(process.versions.node, '>=14.13.1') && - !semver.satisfies(process.versions.node, '18.0.0') + semver.satisfies(process.versions.node, '>=14.13.1') ) { describe('initialize.mjs', () => { useSandbox() stubTracerIfNeeded() context('as --loader', () => { - testInjectionScenarios('loader', 'initialize.mjs', true) + testInjectionScenarios('loader', 'initialize.mjs', + process.versions.node !== '18.0.0') testRuntimeVersionChecks('loader', 'initialize.mjs') }) if (semver.satisfies(process.versions.node, '>=20.6.0')) { From c3fc38027535c84f3a06c926d76ffbc7e6a569aa Mon Sep 17 00:00:00 2001 From: Bryan English Date: Fri, 22 Nov 2024 23:59:34 -0500 Subject: [PATCH 4/4] isolate old/weird node version tests to the init test --- .github/workflows/project.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/project.yml b/.github/workflows/project.yml index f91d6374eec..92a97c56457 100644 --- a/.github/workflows/project.yml +++ b/.github/workflows/project.yml @@ -18,7 +18,7 @@ jobs: # setting fail-fast to false in an attempt to prevent this from happening fail-fast: false matrix: - version: [18.0.0, 18.1.0, 18, 20.0.0, 20, 22.0.0, 22, latest] + version: [18, 20, 22, latest] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -34,7 +34,7 @@ jobs: integration-guardrails: strategy: matrix: - version: [12.0.0, 12, 14.0.0, 14, 16.0.0, 16] + version: [12.0.0, 12, 14.0.0, 14, 16.0.0, 16, 18.0.0, 18.1.0, 20.0.0, 22.0.0] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4