Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit 69dddde

Browse files
Peter Martonmayurkale22
authored andcommitted
feat(nodejs-base): do not hook require when not necessary (#585)
1 parent 1f57125 commit 69dddde

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

packages/opencensus-nodejs-base/src/trace/instrumentation/plugin-loader.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,18 @@ export class PluginLoader {
126126
*/
127127
loadPlugins(pluginList: PluginNames) {
128128
if (this.hookState === HookState.UNINITIALIZED) {
129-
hook(Object.keys(pluginList), (exports, name, basedir) => {
129+
const modulesToHook = Object.keys(pluginList);
130+
131+
// Do not hook require when no module is provided. In this case it is
132+
// not necessary. With skipping this step we lower our footprint in
133+
// customer applications and require-in-the-middle won't show up in CPU
134+
// frames.
135+
if (modulesToHook.length === 0) {
136+
this.hookState = HookState.DISABLED;
137+
return;
138+
}
139+
140+
hook(modulesToHook, (exports, name, basedir) => {
130141
if (this.hookState !== HookState.ENABLED) {
131142
return exports;
132143
}

0 commit comments

Comments
 (0)