Skip to content

Commit

Permalink
fix: check parent exists during instrumentation: (#525)
Browse files Browse the repository at this point in the history
Co-authored-by: Mike Goldsmth <[email protected]>
  • Loading branch information
Asgaroth and MikeGoldsmith authored Jan 6, 2022
1 parent e426fce commit cdd32ad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/instrumentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function getPackageVersion(request, options) {
}

const instrumentLoad = (exports.instrumentLoad = (mod, loadRequest, parent, opts = {}) => {
if (parent.id.includes(`node_modules/${pkg.name}`) || !enabledInstrumentations.has(loadRequest)) {
if (!parent || parent.id.includes(`node_modules/${pkg.name}`) || !enabledInstrumentations.has(loadRequest)) {
// no magic here
return mod;
}
Expand Down
8 changes: 8 additions & 0 deletions lib/instrumentation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,11 @@ test("we keep track of the active instrumentations in a sorted array", () => {
// activeInstrumentations now includes child_process
expect(instrumentation.activeInstrumentations()).toEqual(["child_process", "express"]);
});

test("don't instrument module if parent is null", () => {
instrumentation.clearInstrumentationForTesting();
let fakeExpress = createFakeExpress();
let m = instrumentation.instrumentLoad(fakeExpress, "express", null);
expect(m).toBe(fakeExpress);
expect(m.__wrapped).toBeUndefined();
});

0 comments on commit cdd32ad

Please sign in to comment.