This repository has been archived by the owner on Apr 7, 2024. It is now read-only.
forked from dbader/node-datadog-metrics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (44 loc) · 1.5 KB
/
index.js
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
'use strict';
const loggers = require('./lib/loggers');
let sharedLogger = null;
//
// opts may include:
//
// - apiKey: DataDog API key
// - appKey: DataDog APP key
// - host: Default host for all reported metrics
// - prefix: Default key prefix for all metrics
// - defaultTags: Common tags for all metrics
// - flushIntervalSeconds:
//
// You can also use it to override (dependency-inject) the aggregator
// and reporter instance, which is useful for testing:
//
// - aggregator: an Aggregator instance
// - reporter: a Reporter instance
//
function init(opts) {
opts = opts || {};
if (!opts.flushIntervalSeconds && opts.flushIntervalSeconds !== 0) {
opts.flushIntervalSeconds = 15;
}
sharedLogger = new loggers.BufferedMetricsLogger(opts);
}
// This is meant to be curried via bind() so we don't have
// to write wrappers for each metric individually.
function callOnSharedLogger(funcName) {
if (sharedLogger === null) {
init();
}
const args = Array.prototype.slice.call(arguments, 1);
sharedLogger[funcName].apply(sharedLogger, args);
}
module.exports = {
init: init,
flush: callOnSharedLogger.bind(undefined, 'flush'),
gauge: callOnSharedLogger.bind(undefined, 'gauge'),
increment: callOnSharedLogger.bind(undefined, 'increment'),
histogram: callOnSharedLogger.bind(undefined, 'histogram'),
distribution: callOnSharedLogger.bind(undefined, 'distribution'),
BufferedMetricsLogger: loggers.BufferedMetricsLogger
};