Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lazy load dd-trace-api integration #5406

Merged
merged 2 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/datadog-instrumentations/src/dd-trace-api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict'

const { addHook } = require('./helpers/instrument')

// Empty hook just to make the plugin load.
// TODO: Add version range when the module is released on npm.
addHook({ name: 'dd-trace-api' }, api => api)
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 @@ -43,6 +43,7 @@ module.exports = {
couchbase: () => require('../couchbase'),
crypto: () => require('../crypto'),
cypress: () => require('../cypress'),
'dd-trace-api': () => require('../dd-trace-api'),
dns: () => require('../dns'),
elasticsearch: () => require('../elasticsearch'),
express: () => require('../express'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ for (const packageName of names) {
}

function matchVersion (version, ranges) {
return !version || (ranges && ranges.some(range => satisfies(version, range)))
return !version || !ranges || ranges.some(range => satisfies(version, range))
}

function getVersion (moduleBaseDir) {
Expand Down
3 changes: 3 additions & 0 deletions packages/datadog-plugin-dd-trace-api/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ describe('Plugin', () => {

tracer = require('../../dd-trace')

// TODO: Use the real module when it's released.
dc.channel('dd-trace:instrumentation:load').publish({ name: 'dd-trace-api' })

sinon.spy(tracer)
sinon.spy(tracer.appsec)
sinon.spy(tracer.dogstatsd)
Expand Down
3 changes: 0 additions & 3 deletions packages/dd-trace/src/plugin_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ loadChannel.subscribe(({ name }) => {
maybeEnable(plugins[name])
})

// Always enabled
maybeEnable(require('../../datadog-plugin-dd-trace-api/src'))

function maybeEnable (Plugin) {
if (!Plugin || typeof Plugin !== 'function') return
if (!pluginClasses[Plugin.id]) {
Expand Down
Loading