Code coverage report for node/src/apm/statsd/timer.ts

Statements: 33.33% (3 / 9)      Branches: 0% (0 / 3)      Functions: 0% (0 / 5)      Lines: 33.33% (3 / 9)      Ignored: none     

All files » node/src/apm/statsd/ » timer.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 521 1                                                         1                                          
import {Tags, TimerWrapper, TimerWrapperFactory} from '@btilford/ts-base-core';
import {StatsDMetric, StatsDOptions} from './metric';
 
 
class StatsDTimerWrapper<T> extends StatsDMetric implements TimerWrapper<T> {
  wrap(func: (...args: unknown[]) => T): (...args: unknown[]) => T {
    return this.statsd.timer(
      func,
      this.name,
      this.options.sampleRate,
      { ...this.tags },
    );
 
  }
}
 
 
class AsyncStatsDTimerWrapper<T> extends StatsDMetric implements TimerWrapper<Promise<T>> {
  wrap(func: (...args: unknown[]) => Promise<T>): (...args: unknown[]) => Promise<T> {
    return this.statsd.asyncTimer(
      func,
      this.name,
      this.options.sampleRate,
      { ...this.tags },
    );
 
  }
}
 
 
export class StatsDTimerFactory extends TimerWrapperFactory {
  protected readonly options: StatsDOptions;
 
 
  constructor(options: StatsDOptions = {}) {
    super();
    this.options = { ...options };
  }
 
 
  timer<T>(name: string, tags: Tags = {}): TimerWrapper<T> {
    return new StatsDTimerWrapper<T>(name, this.options, tags);
  }
 
 
  asyncTimer<T>(name: string, tags: Tags = {}): TimerWrapper<Promise<T>> {
    return new AsyncStatsDTimerWrapper<T>(name, this.options, tags);
  }
 
 
}