Code coverage report for core/src/apm/console/metric.ts

Statements: 93.75% (15 / 16)      Branches: 75% (12 / 16)      Functions: 66.67% (2 / 3)      Lines: 93.33% (14 / 15)      Ignored: none     

All files » core/src/apm/console/ » metric.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 52 53 54 551 1 1 1 1                         1                   6 6 18 6 6 6 6         6                                
import {Env, Props} from '../../env';
import {joinFqn, Tags} from '../../util';
import {Enabled, PropEnabled} from '../../configurable';
import {Providers} from '../../providers';
import {APM_ENV, ApmFeatures} from '../constants';
 
 
export type ConsoleMetricOptions = {
  prefix?: string;
  suffix?: string;
  parent?: ConsoleMetric;
  console?: Console;
  tags?: Tags;
  env?: Props;
}
 
 
export class ConsoleMetric implements Enabled {
  readonly tags: Tags;
  protected readonly options: ConsoleMetricOptions;
  readonly name: string;
  readonly fqn: string;
  protected readonly rawName: string;
  protected readonly console: Console;
  protected readonly _enabled: PropEnabled;
 
 
  constructor(name: string, tags: Tags, options: ConsoleMetricOptions, readonly feature: ApmFeatures) {
    this.rawName = name;
    this.name = [options.prefix, name, options.suffix].filter(part => part).join('.');
    this.fqn = joinFqn(this.name, options.parent?.rawName);
    this.console = options.console || console;
    this.options = { ...options };
    this.tags = {
      ...options.tags,
      ...tags,
    };
 
    this._enabled = options.parent?._enabled.extend(this.rawName, 'true') ||
                    new PropEnabled(
                      {
                        name: this.name,
                        global: APM_ENV[feature].envKey,
                      },
                      Providers.useOrProvide(Env, this.options.env)?.getConfig(this.fqn),
                      'true',
                    );
  }
 
 
  enabled(key: string): boolean {
    return this._enabled.enabled(key);
  }
}