All files / types/metrics Histogram.ts

20% Statements 3/15
0% Branches 0/10
0% Functions 0/3
20% Lines 3/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 401x   1x   1x                                                                      
import { Constants } from '../Constants';
import { Namespace } from '../Namespace';
import { Metric } from './Metric';
 
export class Histogram extends Metric {
  protected defaultBuckets: number[] = Constants.DefaultHistogramBuckets;
  private buckets: number[] = [];
 
  constructor(
    namespace: Namespace,
    name: string,
    description?: string,
    unit?: string,
    buckets: number[] = [],
    attributes: Record<string, string> = {},
  ) {
    super(namespace, name, description, unit, attributes);
    this.buckets = buckets;
  }
 
  record(value: number, buckets: number[] = [], attributes: Record<string, string> = {}): void {
    const resolvedBuckets = this.resolveBuckets(buckets);
    const combinedAttributes = this.combineAttributes(attributes);
 
    this.getNamespace().getMetricClient().recordTimer(this.getFullName(), value, resolvedBuckets, combinedAttributes);
  }
 
  protected resolveBuckets(buckets: number[]): number[] {
    Iif (buckets && buckets.length) {
      return buckets;
    }
 
    Iif (this.buckets && this.buckets.length) {
      return this.buckets;
    }
 
    return this.defaultBuckets;
  }
}