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);
}
}
|