Skip to content

Commit

Permalink
move esm first logic to hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
juan-fernandez committed Jun 28, 2024
1 parent 0d60e30 commit 37f33e7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
6 changes: 5 additions & 1 deletion packages/datadog-esbuild/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ const hooks = require('../datadog-instrumentations/src/helpers/hooks.js')
const extractPackageAndModulePath = require('../datadog-instrumentations/src/utils/src/extract-package-and-module-path')

for (const hook of Object.values(hooks)) {
hook()
if (typeof hook === 'object') {
hook.fn()
} else {
hook()
}
}

const modulesOfInterest = new Set()
Expand Down
4 changes: 2 additions & 2 deletions packages/datadog-instrumentations/src/helpers/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {
'@opentelemetry/sdk-trace-node': () => require('../otel-sdk-trace'),
'@redis/client': () => require('../redis'),
'@smithy/smithy-client': () => require('../aws-sdk'),
'@vitest/runner': () => require('../vitest'),
'@vitest/runner': { esmFirst: true, fn: () => require('../vitest') },
aerospike: () => require('../aerospike'),
amqp10: () => require('../amqp10'),
amqplib: () => require('../amqplib'),
Expand Down Expand Up @@ -111,7 +111,7 @@ module.exports = {
sharedb: () => require('../sharedb'),
tedious: () => require('../tedious'),
undici: () => require('../undici'),
vitest: () => require('../vitest'),
vitest: { esmFirst: true, fn: () => require('../vitest') },
when: () => require('../when'),
winston: () => require('../winston')
}
11 changes: 6 additions & 5 deletions packages/datadog-instrumentations/src/helpers/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ const disabledInstrumentations = new Set(
DD_TRACE_DISABLED_INSTRUMENTATIONS ? DD_TRACE_DISABLED_INSTRUMENTATIONS.split(',') : []
)

const esmFirstLibraries = new Set(['vitest', '@vitest/runner'])

const loadChannel = channel('dd-trace:instrumentation:load')

// Globals
Expand All @@ -46,15 +44,18 @@ for (const packageName of names) {

const hookOptions = {}

if (esmFirstLibraries.has(packageName)) {
hookOptions.internals = true
let hook = hooks[packageName]

if (typeof hook === 'object') {
hookOptions.internals = hook.esmFirst
hook = hook.fn
}

Hook([packageName], hookOptions, (moduleExports, moduleName, moduleBaseDir, moduleVersion) => {
moduleName = moduleName.replace(pathSepExpr, '/')

// This executes the integration file thus adding its entries to `instrumentations`
hooks[packageName]()
hook()

if (!instrumentations[packageName]) {
return moduleExports
Expand Down

0 comments on commit 37f33e7

Please sign in to comment.