Skip to content

@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 ​

ParameterTypeDescription
instanceobjectThe object instance whose methods will be wrapped
traceTraceFnThe tracing function that wraps each method call
stopAtobjectThe 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);