import { BufferedMetricsLogger } from "datadog-metrics" ; import SFPLogger , { Logger , LoggerLevel } from "../../logger/SFPLogger" ; import { NativeMetricSender } from "../NativeMetricSender" ; export class DataDogMetricsSender extends NativeMetricSender { constructor ( logger ) { super ( logger ) ; } private nativeDataDogMetricsLogger : BufferedMetricsLogger ; public initialize ( apiHost , apiKey ) { try { this . nativeDataDogMetricsLogger = new BufferedMetricsLogger ( { apiHost : apiHost , apiKey : apiKey , prefix : "sfpowerscripts." , flushIntervalSeconds : 0 , } ) ; } catch ( error ) { SFPLogger . log ( "Unable to intialize native datadog logger" + error , LoggerLevel . TRACE , this . logger ) ; } } public sendGaugeMetric ( metric , value , tags ) { try { let transformedTags = this . transformTagsToStringArray ( tags ) ; this . nativeDataDogMetricsLogger . gauge ( metric , value , transformedTags ) ; this . nativeDataDogMetricsLogger . flush ( ) ; } catch ( error ) { SFPLogger . log ( `Unable to transmit metrics for metric ${ metric } due to` + error , LoggerLevel . TRACE , this . logger ) ; } } public sendCountMetric ( metric , tags ) { try { let transformedTags = this . transformTagsToStringArray ( tags ) ; this . nativeDataDogMetricsLogger . increment ( metric , 1 , transformedTags ) ; this . nativeDataDogMetricsLogger . flush ( ) ; } catch ( error ) { SFPLogger . log ( `Unable to transmit metrics for metric ${ metric } due to` + error , LoggerLevel . TRACE , this . logger ) ; } } }