Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { BufferedMetricsLogger } from "datadog-metrics";
import { AkairoClient } from "discord-akairo";
import { countMembers, logger } from "../utils";
const { HIFUMI_DATADOG_API_KEY } = process.env;
const _dd = new BufferedMetricsLogger({
apiKey: HIFUMI_DATADOG_API_KEY || "disabled in development",
host: "hifumi",
prefix: "hifumi.",
// allows us to buffer stats and send them in bulk
flushIntervalSeconds: 15,
});
/**
* Wrapper function that prevents calling metrics in development mode
* @param func
*/
export const withDatadog = (func: (client: BufferedMetricsLogger) => void): void => {
if (HIFUMI_DATADOG_API_KEY) {
func(_dd);
}
};
function buildDataDog(pkg, env) {
const dd = new datadog.BufferedMetricsLogger({
apiKey: env.METRICS_API_KEY,
host: env.METRICS_HOST || require('os').hostname(),
prefix: utils.buildMetricPrefix(env, pkg),
flushIntervalSeconds: env.METRICS_FLUSH_INTERVAL || 15
});
return new DatadogClientToStatsdAdapter(dd);
}
priority: 'low',
alertType: 'info',
tags: []
},
config.event);
debug('creating DatadogReporter with config');
debug(config.apiKey ?
Object.assign({ apiKey: sanitize(config.apiKey) }, config) :
config);
this.config = config;
if (config.apiKey) {
debug('Initializing datadog via HTTPS');
this.metrics = new datadogMetrics.BufferedMetricsLogger({
apiKey: config.apiKey,
prefix: config.prefix,
defaultTags: config.tags,
flushIntervalSeconds: 5
});
this.reportingType = 'api';
} else if (config.host && config.port) {
debug('Initializing datadog via agent');
const options = {
host: config.host,
port: config.port,
prefix: config.prefix,
globalTags: config.tags,
bufferFlushInterval: 1000
};