Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
juan-fernandez committed Jun 18, 2024
1 parent 4b03ee1 commit 689d9aa
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 5 deletions.
10 changes: 10 additions & 0 deletions ci/init.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
/* eslint-disable no-console */
const tracer = require('../packages/dd-trace')
const { isTrue } = require('../packages/dd-trace/src/util')
const { isMainThread, parentPort } = require('node:worker_threads')

const isJestWorker = !!process.env.JEST_WORKER_ID
const isCucumberWorker = !!process.env.CUCUMBER_WORKER_ID
const isMochaWorker = !!process.env.MOCHA_WORKER_ID
// eslint-disable-next-line
// https://github.com/vitest-dev/vitest/blob/f969fb0f9f0247a7daa2afee8f70de25ea5e123f/packages/vitest/src/node/pool.ts#L110-L111
const isVitestWorker = !isMainThread && process.env.VITEST === 'true' && process.env.TEST === 'true'

const options = {
startupLogs: false,
Expand Down Expand Up @@ -51,6 +55,12 @@ if (isMochaWorker) {
}
}

if (isVitestWorker) {
// if (parentPort?.postMessage) {
// parentPort.postMessage({ type: 'ci:vitest:worker:ready' })
// }
}

if (shouldInit) {
tracer.init(options)
tracer.use('fs', false)
Expand Down
5 changes: 3 additions & 2 deletions ext/exporters.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ declare const exporters: {
DATADOG: 'datadog',
AGENT_PROXY: 'agent_proxy',
JEST_WORKER: 'jest_worker',
CUCUMBER_WORKER: 'cucumber_worker'
MOCHA_WORKER: 'mocha_worker'
CUCUMBER_WORKER: 'cucumber_worker',
MOCHA_WORKER: 'mocha_worker',
VITEST_WORKER: 'vitest_worker'
}

export = exporters
3 changes: 2 additions & 1 deletion ext/exporters.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ module.exports = {
AGENT_PROXY: 'agent_proxy',
JEST_WORKER: 'jest_worker',
CUCUMBER_WORKER: 'cucumber_worker',
MOCHA_WORKER: 'mocha_worker'
MOCHA_WORKER: 'mocha_worker',
VITEST_WORKER: 'vitest_worker'
}
5 changes: 3 additions & 2 deletions packages/datadog-instrumentations/src/helpers/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ function Hook (modules, onrequire) {
const parts = [moduleBaseDir, moduleName].filter(v => v)
const filename = path.join(...parts)

if (this._patched[filename]) return moduleExports
// this does not seem to work with IITM: the same file seems to import different stuff
// if (this._patched[filename]) return moduleExports

this._patched[filename] = true

Expand All @@ -30,7 +31,7 @@ function Hook (modules, onrequire) {
this._ritmHook = ritm(modules, {}, safeHook)
this._iitmHook = iitm(modules, {}, (moduleExports, moduleName, moduleBaseDir) => {
// TODO: Move this logic to import-in-the-middle and only do it for CommonJS
// modules and not ESM. In the meantime, all the modules we instrument are
// modules and not ESM. In the meantime, all thpe modules we instrument are
// CommonJS modules for which the default export is always moved to
// `default` anyway.
if (moduleExports && moduleExports.default) {
Expand Down
1 change: 1 addition & 0 deletions packages/datadog-instrumentations/src/helpers/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ module.exports = {
vitest: () => require('../vitest'),
'@vitest': () => require('../vitest'),
'@vitest/runner': () => require('../vitest'),
tinypool: () => require('../vitest'),
workerpool: () => require('../mocha'),
moleculer: () => require('../moleculer'),
mongodb: () => require('../mongodb'),
Expand Down
1 change: 1 addition & 0 deletions packages/dd-trace/src/exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = name => {
case exporters.JEST_WORKER:
case exporters.CUCUMBER_WORKER:
case exporters.MOCHA_WORKER:
case exporters.VITEST_WORKER:
return require('./ci-visibility/exporters/test-worker')
default:
return inAWSLambda && !usingLambdaExtension ? require('./exporters/log') : require('./exporters/agent')
Expand Down
3 changes: 3 additions & 0 deletions packages/dd-trace/src/iitm.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const dc = require('dc-polyfill')
if (semver.satisfies(process.versions.node, '>=14.13.1')) {
const moduleLoadStartChannel = dc.channel('dd-trace:moduleLoadStart')
addHook((name, namespace) => {
// if (name.includes('/vitest/') || name.includes('@vitest')) {
// debugger
// }
if (moduleLoadStartChannel.hasSubscribers) {
moduleLoadStartChannel.publish({
filename: name,
Expand Down
1 change: 1 addition & 0 deletions packages/dd-trace/src/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ module.exports = {
get vitest () { return require('../../../datadog-plugin-vitest/src') },
get '@vitest' () { return require('../../../datadog-plugin-vitest/src') },
get '@vitest/runner' () { return require('../../../datadog-plugin-vitest/src') },
get tinypool () { return require('../../../datadog-plugin-vitest/src') },
get workerpool () { return require('../../../datadog-plugin-mocha/src') },
get moleculer () { return require('../../../datadog-plugin-moleculer/src') },
get mongodb () { return require('../../../datadog-plugin-mongodb-core/src') },
Expand Down

0 comments on commit 689d9aa

Please sign in to comment.