Skip to content

Commit 83adcc4

Browse files
authored
chore: Added subscriber packages to load-externals (#3868)
1 parent 92c70a8 commit 83adcc4

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

load-externals.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,21 @@
66
'use strict'
77
const instrumentedLibraries = require('./lib/instrumentations')() || {}
88
const libNames = Object.keys(instrumentedLibraries)
9+
const subscriptions = require('./lib/subscriber-configs')
10+
const subscribers = Object.keys(subscriptions)
11+
const packages = [...libNames, ...subscribers]
12+
13+
/**
14+
* This is to be used with bundlers. It will add all of our instrumented 3rd party modules
15+
* into the `externals` array.
16+
*
17+
* **Note** Only tested with `webpack`, [see](https://webpack.js.org/configuration/externals/)
18+
*
19+
* @param {object} config bundler config
20+
*/
921
module.exports = function loadExternals(config) {
1022
if (config.target.includes('node')) {
11-
config.externals.push(...libNames)
23+
config.externals.push(...packages)
1224
}
1325

1426
return config

test/unit/load-externals.test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,20 @@ const loadExternals = require('../../load-externals')
1313
test('should load libs to webpack externals', async () => {
1414
const config = {
1515
target: 'node-20.x',
16-
externals: ['next']
16+
externals: ['test-pkg']
1717
}
1818
loadExternals(config)
19+
// This number is arbitrary but accounts for legacy instrumentation + subscriber instrumentation
1920
assert.ok(
20-
config.externals.length > 1,
21-
'should add all libraries agent supports to the externals list'
21+
config.externals.length > 40,
22+
`should add all libraries agent supports to the externals list, got ${config.externals.length}`
2223
)
2324
})
2425

2526
test('should not add externals when target is not node', async () => {
2627
const config = {
2728
target: 'web',
28-
externals: ['next']
29+
externals: ['test-pkg']
2930
}
3031
loadExternals(config)
3132
assert.ok(config.externals.length === 1, 'should not agent libraries when target is not node')

0 commit comments

Comments
 (0)