Skip to content

Commit

Permalink
fix auto instrumentation of loaded modules without an entrypoint defi…
Browse files Browse the repository at this point in the history
…ned (#587)

* Default to index when package.json doesn't have main

* Remove 'main' from exress-mock package.json

* Add test using the 'other' package and revert express-mock
  • Loading branch information
BrunoBerisso authored and rochdev committed Jun 18, 2019
1 parent 02e7ad0 commit f4f790f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/dd-trace/src/instrumenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ function getModules (instrumentation) {

pkg = require(`${basedir}/package.json`)

if (!id.endsWith(`/node_modules/${instrumentation.name}/${pkg.main}`)) continue
if (!id.endsWith(`/node_modules/${instrumentation.name}/${pkg.main || 'index.js'}`)) continue
}

if (!matchVersion(pkg.version, instrumentation.versions)) continue
Expand Down
20 changes: 17 additions & 3 deletions packages/dd-trace/test/instrumenter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ describe('Instrumenter', () => {
patch: sinon.spy(),
unpatch: sinon.spy()
}
]
],
other: {
name: 'other',
versions: ['1.x'],
patch: sinon.spy()
}
}

shimmer = sinon.spy()
Expand All @@ -54,11 +59,13 @@ describe('Instrumenter', () => {
'./plugins': {
'http': integrations.http,
'express-mock': integrations.express,
'mysql-mock': integrations.mysql
'mysql-mock': integrations.mysql,
'other': integrations.other
},
'../../datadog-plugin-http/src': integrations.http,
'../../datadog-plugin-express-mock/src': integrations.express,
'../../datadog-plugin-mysql-mock/src': integrations.mysql
'../../datadog-plugin-mysql-mock/src': integrations.mysql,
'../../datadog-plugin-other/src': integrations.other
})

instrumenter = new Instrumenter(tracer)
Expand Down Expand Up @@ -181,6 +188,13 @@ describe('Instrumenter', () => {

expect(integrations.express.patch).to.not.have.been.called
})

it('should patch modules without declared entrypoint', () => {
instrumenter.use('other', true)
require('other')

expect(integrations.other.patch).to.have.been.called
})
})

describe('patch', () => {
Expand Down
1 change: 0 additions & 1 deletion packages/dd-trace/test/node_modules/other/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f4f790f

Please sign in to comment.