Skip to content

Commit

Permalink
Fix lazy getters
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperpeulen committed Sep 23, 2023
1 parent 27ded25 commit d44e0bd
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions code/lib/instrumenter/src/instrumenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,19 +302,25 @@ export class Instrumenter {
depth += 1;
return keys.reduce(
(acc, key) => {
const descriptor = getPropertyDescriptor(obj, key);
if (typeof descriptor?.get === 'function') {
Object.defineProperty(acc, key, {
get: () => {
return this.instrument(
(obj as Record<string, any>)[key],
{ ...options, path: path.concat(key) },
depth
);
},
});
return acc;
}

const value = (obj as Record<string, any>)[key];

// Nothing to patch, but might be instrumentable, so we recurse
if (typeof value !== 'function') {
const descriptor = getPropertyDescriptor(obj, key);
if (typeof descriptor?.get === 'function') {
Object.defineProperty(acc, key, {
get: () => {
return this.instrument(value, { ...options, path: path.concat(key) }, depth);
},
});
} else {
acc[key] = this.instrument(value, { ...options, path: path.concat(key) }, depth);
}
acc[key] = this.instrument(value, { ...options, path: path.concat(key) }, depth);
return acc;
}

Expand Down

0 comments on commit d44e0bd

Please sign in to comment.