This repository has been archived by the owner on Jul 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added a shim to externalize all 3rd party libraries the Node.js…
… agent instruments
- Loading branch information
Showing
6 changed files
with
64 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright 2024 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict' | ||
const instrumentedLibraries = require('newrelic/lib/instrumentations')() || {} | ||
const libNames = Object.keys(instrumentedLibraries) | ||
module.exports = function loadExternals(config) { | ||
if (config.target.includes('node')) { | ||
config.externals.push(...libNames) | ||
} | ||
|
||
return config | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
"THIRD_PARTY_NOTICES.md", | ||
"index.js", | ||
"nr-hooks.js", | ||
"load-externals.js", | ||
"lib/" | ||
], | ||
"repository": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2024 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict' | ||
|
||
const tap = require('tap') | ||
const loadExternals = require('../../load-externals') | ||
|
||
tap.test('should load libs to webpack externals', async (t) => { | ||
const config = { | ||
target: 'node-20.x', | ||
externals: ['next'] | ||
} | ||
loadExternals(config) | ||
t.ok(config.externals.length > 1, 'should add all libraries agent supports to the externals list') | ||
}) | ||
|
||
tap.test('should not add externals when target is not node', async (t) => { | ||
const config = { | ||
target: 'web', | ||
externals: ['next'] | ||
} | ||
loadExternals(config) | ||
t.ok(config.externals.length === 1, 'should not agent libraries when target is not node') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters