@half0wl/container / wrapWithTracing
Function: wrapWithTracing()
ts
function wrapWithTracing(
instance,
trace,
stopAt): void;Defined in: helpers.ts:50
Wrap all methods on an instance with a tracing function.
Walks the prototype chain from the instance up to stopAt, wrapping every method (functions with a value descriptor) with the trace callback. Getters, setters, and the constructor are skipped. When a method exists on multiple prototypes in the chain, the closest (most derived) version wins.
Span names follow the ClassName.methodName format.
Parameters
| Parameter | Type | Description |
|---|---|---|
instance | object | The object instance whose methods will be wrapped |
trace | TraceFn | The tracing function that wraps each method call |
stopAt | object | The prototype to stop walking at (typically BaseService.prototype) |
Returns
void
Example
ts
wrapWithTracing(instance, (spanName, fn) => {
console.log(`>> ${spanName}`);
const result = fn();
console.log(`<< ${spanName}`);
return result;
}, BaseService.prototype);