import {CounterMetricPayload, GaugeMetricPayload, HistogramMetricPayload, MetricType} from "../types/MetricPayload.ts"; import GenericObject from "../types/GenericObject.ts"; class MetricsProcessor { private metricUrl : string private portal : string private isMetricEnabled : boolean constructor(metricUrl: string, portal: string) { this.metricUrl = metricUrl; this.portal = portal; this.isMetricEnabled = true } _sendMetricToMetricServer(payload: { metricType: MetricType; metadata: any; metricName: string; subflow?: any; value?: number | string flow?: string Metadata?:GenericObject }) { if(!this.isMetricEnabled) { return; } fetch(this.metricUrl, { method: 'POST', body: JSON.stringify({group: `universal-call-sdk-${this.portal}`,...payload}) }) } pushCounterMetric({metricName, flow, metaData}: CounterMetricPayload ) { this._sendMetricToMetricServer({ flow: flow, metadata: metaData, metricType: MetricType.COUNTER, metricName, }) } pushHistogramMetric({metricName, value, flow, metaData}: HistogramMetricPayload) { this._sendMetricToMetricServer({ flow: flow, metadata: metaData, metricType: MetricType.HISTOGRAM, metricName, value }) } pushGaugeMetric({metricName, value, flow, metaData}: GaugeMetricPayload) { this._sendMetricToMetricServer({ flow: flow, metadata: metaData, metricType: MetricType.GAUGE, metricName, value, }) } } export default MetricsProcessor;