@vtex/diagnostics-nodejs
Version:
Diagnostics library for Node.js applications
38 lines • 1.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Histogram = void 0;
exports.NewHistogram = NewHistogram;
const options_1 = require("./options");
class Histogram {
constructor(histogram) {
this.histogram = histogram;
}
record(value, attributes, context) {
this.histogram.record(value, 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.Histogram = Histogram;
function NewHistogram(meter, name, opts = []) {
const config = (0, options_1.newConfig)(opts);
const options = {
description: config.description,
unit: config.unit
};
if (config.buckets && config.buckets.length > 0) {
options.explicitBoundaries = config.buckets;
}
const histogram = meter.createHistogram(name, options);
return new Histogram(histogram);
}
//# sourceMappingURL=histogram.js.map