@vtex/diagnostics-nodejs
Version:
Diagnostics library for Node.js applications
37 lines • 1.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Counter = void 0;
exports.NewCounter = NewCounter;
const options_1 = require("./options");
class Counter {
constructor(counter) {
this.counter = counter;
}
add(value, attributes, context) {
this.counter.add(value, this.convertAttributes(attributes), context);
}
increment(attributes, context) {
this.counter.add(1, this.convertAttributes(attributes), context);
}
convertAttributes(attrs) {
if (!attrs)
return undefined;
const result = {};
for (const [key, value] of Object.entries(attrs)) {
if (value !== undefined && value !== null) {
result[key] = value;
}
}
return result;
}
}
exports.Counter = Counter;
function NewCounter(meter, name, opts = []) {
const config = (0, options_1.newConfig)(opts);
const counter = meter.createCounter(name, {
description: config.description,
unit: config.unit,
});
return new Counter(counter);
}
//# sourceMappingURL=counter.js.map