Skip to content

Commit 4d44ea3

Browse files
committed
Remove code targeting unsupported Node.js versions
1 parent 54c8666 commit 4d44ea3

File tree

37 files changed

+186
-483
lines changed

37 files changed

+186
-483
lines changed

benchmark/sirun/plugin-graphql/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict'
22

3-
const semver = require('semver')
4-
53
// TODO: benchmark the tracer as well but for now it's just too slow
64
if (Number(process.env.WITH_TRACER)) {
75
const tracer = require('../../..').init()
@@ -16,9 +14,7 @@ if (Number(process.env.WITH_TRACER)) {
1614
}
1715

1816
if (Number(process.env.WITH_ASYNC_HOOKS)) {
19-
const hook = semver.satisfies(process.versions.node, '>=14.5')
20-
? { init () {} }
21-
: { init () {}, before () {}, after () {}, destroy () {} }
17+
const hook = { init () {} }
2218

2319
require('async_hooks').createHook(hook).enable()
2420
}

integration-tests/init.spec.js

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -168,27 +168,20 @@ describe('init.js', () => {
168168
testRuntimeVersionChecks('require', 'init.js')
169169
})
170170

171-
// ESM is not supportable prior to Node.js 12.17.0, 14.13.1 on the 14.x line,
172-
// or on 18.0.0 in particular.
173-
if (
174-
semver.satisfies(process.versions.node, '>=12.17.0') &&
175-
semver.satisfies(process.versions.node, '>=14.13.1')
176-
) {
177-
describe('initialize.mjs', () => {
178-
setShouldKill(false)
179-
useSandbox()
180-
stubTracerIfNeeded()
181-
182-
context('as --loader', () => {
183-
testInjectionScenarios('loader', 'initialize.mjs',
184-
process.versions.node !== '18.0.0')
171+
describe('initialize.mjs', () => {
172+
setShouldKill(false)
173+
useSandbox()
174+
stubTracerIfNeeded()
175+
176+
context('as --loader', () => {
177+
testInjectionScenarios('loader', 'initialize.mjs',
178+
process.versions.node !== '18.0.0')
179+
testRuntimeVersionChecks('loader', 'initialize.mjs')
180+
})
181+
if (semver.satisfies(process.versions.node, '>=20.6.0')) {
182+
context('as --import', () => {
183+
testInjectionScenarios('import', 'initialize.mjs', true)
185184
testRuntimeVersionChecks('loader', 'initialize.mjs')
186185
})
187-
if (semver.satisfies(process.versions.node, '>=20.6.0')) {
188-
context('as --import', () => {
189-
testInjectionScenarios('import', 'initialize.mjs', true)
190-
testRuntimeVersionChecks('loader', 'initialize.mjs')
191-
})
192-
}
193-
})
194-
}
186+
}
187+
})

integration-tests/opentelemetry.spec.js

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const { FakeAgent, createSandbox } = require('./helpers')
44
const { fork } = require('child_process')
55
const { join } = require('path')
66
const { assert } = require('chai')
7-
const { satisfies } = require('semver')
87
const axios = require('axios')
98

109
function check (agent, proc, timeout, onMessage = () => { }, isMetrics) {
@@ -61,13 +60,11 @@ describe('opentelemetry', () => {
6160
'@opentelemetry/instrumentation',
6261
'@opentelemetry/instrumentation-http',
6362
'@opentelemetry/instrumentation-express@0.47.1',
64-
'express@4' // TODO: Remove pinning once our tests support Express v5
65-
]
66-
if (satisfies(process.version.slice(1), '>=14')) {
67-
dependencies.push('@opentelemetry/sdk-node')
63+
'express@4', // TODO: Remove pinning once our tests support Express v5
64+
'@opentelemetry/sdk-node',
6865
// Needed because sdk-node doesn't start a tracer without an exporter
69-
dependencies.push('@opentelemetry/exporter-jaeger')
70-
}
66+
'@opentelemetry/exporter-jaeger'
67+
]
7168
sandbox = await createSandbox(dependencies)
7269
cwd = sandbox.folder
7370
agent = await new FakeAgent().start()
@@ -453,26 +450,24 @@ describe('opentelemetry', () => {
453450
})
454451
})
455452

456-
if (satisfies(process.version.slice(1), '>=14')) {
457-
it('should auto-instrument @opentelemetry/sdk-node', async () => {
458-
proc = fork(join(cwd, 'opentelemetry/env-var.js'), {
459-
cwd,
460-
env: {
461-
DD_TRACE_AGENT_PORT: agent.port
462-
}
463-
})
464-
return check(agent, proc, timeout, ({ payload }) => {
465-
// Should have a single trace with a single span
466-
assert.strictEqual(payload.length, 1)
467-
const [trace] = payload
468-
assert.strictEqual(trace.length, 1)
469-
const [span] = trace
470-
471-
// Should be the expected otel span
472-
assert.strictEqual(span.name, 'otel-sub')
473-
})
453+
it('should auto-instrument @opentelemetry/sdk-node', async () => {
454+
proc = fork(join(cwd, 'opentelemetry/env-var.js'), {
455+
cwd,
456+
env: {
457+
DD_TRACE_AGENT_PORT: agent.port
458+
}
474459
})
475-
}
460+
return check(agent, proc, timeout, ({ payload }) => {
461+
// Should have a single trace with a single span
462+
assert.strictEqual(payload.length, 1)
463+
const [trace] = payload
464+
assert.strictEqual(trace.length, 1)
465+
const [span] = trace
466+
467+
// Should be the expected otel span
468+
assert.strictEqual(span.name, 'otel-sub')
469+
})
470+
})
476471
})
477472

478473
function isChildOf (childSpan, parentSpan) {

packages/datadog-instrumentations/src/grpc/client.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ const types = require('./types')
44
const { addHook, channel } = require('../helpers/instrument')
55
const shimmer = require('../../../datadog-shimmer')
66

7-
const nodeMajor = parseInt(process.versions.node.split('.')[0])
8-
97
const patched = new WeakSet()
108
const instances = new WeakMap()
119

@@ -245,16 +243,6 @@ function patch (hasPeer = false) {
245243
}
246244
}
247245

248-
if (nodeMajor <= 14) {
249-
addHook({ name: 'grpc', versions: ['>=1.24.3'] }, patch(true))
250-
251-
addHook({ name: 'grpc', versions: ['>=1.24.3'], file: 'src/client.js' }, client => {
252-
shimmer.wrap(client, 'makeClientConstructor', createWrapMakeClientConstructor(true))
253-
254-
return client
255-
})
256-
}
257-
258246
addHook({ name: '@grpc/grpc-js', versions: ['>=1.0.3 <1.1.4'] }, patch(false))
259247

260248
addHook({ name: '@grpc/grpc-js', versions: ['>=1.0.3 <1.1.4'], file: 'build/src/make-client.js' }, client => {

packages/datadog-instrumentations/src/grpc/server.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ const types = require('./types')
44
const { channel, addHook } = require('../helpers/instrument')
55
const shimmer = require('../../../datadog-shimmer')
66

7-
const nodeMajor = parseInt(process.versions.node.split('.')[0])
8-
97
const startChannel = channel('apm:grpc:server:request:start')
108
const asyncStartChannel = channel('apm:grpc:server:request:asyncStart')
119
const errorChannel = channel('apm:grpc:server:request:error')
@@ -152,14 +150,6 @@ function isEmitter (obj) {
152150
return typeof obj.emit === 'function' && typeof obj.once === 'function'
153151
}
154152

155-
if (nodeMajor <= 14) {
156-
addHook({ name: 'grpc', versions: ['>=1.24.3'], file: 'src/server.js' }, server => {
157-
shimmer.wrap(server.Server.prototype, 'register', wrapRegister)
158-
159-
return server
160-
})
161-
}
162-
163153
addHook({ name: '@grpc/grpc-js', versions: ['>=1.0.3'], file: 'build/src/server.js' }, server => {
164154
shimmer.wrap(server.Server.prototype, 'register', wrapRegister)
165155

packages/datadog-instrumentations/src/helpers/hooks.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ module.exports = {
103103
nyc: () => require('../nyc'),
104104
oracledb: () => require('../oracledb'),
105105
openai: { esmFirst: true, fn: () => require('../openai') },
106-
paperplane: () => require('../paperplane'),
107106
passport: () => require('../passport'),
108107
'passport-http': () => require('../passport-http'),
109108
'passport-local': () => require('../passport-local'),
Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict'
22

33
const dc = require('dc-polyfill')
4-
const satisfies = require('semifies')
54
const instrumentations = require('./instrumentations')
65
const { AsyncResource } = require('async_hooks')
76

@@ -34,43 +33,4 @@ exports.addHook = function addHook ({ name, versions, file, filePattern }, hook)
3433
}
3534
}
3635

37-
// AsyncResource.bind exists and binds `this` properly only from 17.8.0 and up.
38-
// https://nodejs.org/api/async_context.html#asyncresourcebindfn-thisarg
39-
if (satisfies(process.versions.node, '>=17.8.0')) {
40-
exports.AsyncResource = AsyncResource
41-
} else {
42-
exports.AsyncResource = class extends AsyncResource {
43-
static bind (fn, type, thisArg) {
44-
type = type || fn.name
45-
return (new exports.AsyncResource(type || 'bound-anonymous-fn')).bind(fn, thisArg)
46-
}
47-
48-
bind (fn, thisArg) {
49-
let bound
50-
if (thisArg === undefined) {
51-
const resource = this
52-
bound = function (...args) {
53-
args.unshift(fn, this)
54-
return Reflect.apply(resource.runInAsyncScope, resource, args)
55-
}
56-
} else {
57-
bound = this.runInAsyncScope.bind(this, fn, thisArg)
58-
}
59-
Object.defineProperties(bound, {
60-
length: {
61-
configurable: true,
62-
enumerable: false,
63-
value: fn.length,
64-
writable: false
65-
},
66-
asyncResource: {
67-
configurable: true,
68-
enumerable: true,
69-
value: this,
70-
writable: true
71-
}
72-
})
73-
return bound
74-
}
75-
}
76-
}
36+
exports.AsyncResource = AsyncResource

packages/datadog-instrumentations/src/paperplane.js

Lines changed: 0 additions & 77 deletions
This file was deleted.

packages/datadog-instrumentations/test/child_process.spec.js

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
const { promisify } = require('util')
44
const agent = require('../../dd-trace/test/plugins/agent')
55
const dc = require('dc-polyfill')
6-
const { NODE_MAJOR } = require('../../../version')
76

87
describe('child process', () => {
98
const modules = ['child_process', 'node:child_process']
@@ -494,32 +493,28 @@ describe('child process', () => {
494493
}
495494
})
496495

497-
if (methodName !== 'execFileSync' || NODE_MAJOR > 16) {
498-
// when a process return an invalid code, in node <=16, in execFileSync with shell:true
499-
// an exception is not thrown
500-
it('should execute error callback with `exit 1` command with shell: true', () => {
501-
let childError
502-
try {
503-
childProcess[methodName]('node -e "process.exit(1)"', { shell: true })
504-
} catch (error) {
505-
childError = error
506-
} finally {
507-
const expectedContext = {
508-
command: 'node -e "process.exit(1)"',
509-
file: 'node -e "process.exit(1)"',
510-
shell: true
511-
}
512-
expect(start).to.have.been.calledOnceWith({
513-
...expectedContext,
514-
abortController: sinon.match.instanceOf(AbortController)
515-
})
516-
expect(finish).to.have.been.calledOnceWith({
517-
...expectedContext,
518-
error: childError
519-
})
496+
it('should execute error callback with `exit 1` command with shell: true', () => {
497+
let childError
498+
try {
499+
childProcess[methodName]('node -e "process.exit(1)"', { shell: true })
500+
} catch (error) {
501+
childError = error
502+
} finally {
503+
const expectedContext = {
504+
command: 'node -e "process.exit(1)"',
505+
file: 'node -e "process.exit(1)"',
506+
shell: true
520507
}
521-
})
522-
}
508+
expect(start).to.have.been.calledOnceWith({
509+
...expectedContext,
510+
abortController: sinon.match.instanceOf(AbortController)
511+
})
512+
expect(finish).to.have.been.calledOnceWith({
513+
...expectedContext,
514+
error: childError
515+
})
516+
}
517+
})
523518
}
524519
})
525520
})

0 commit comments

Comments
 (0)