@sentry/node
Version:
Sentry Node SDK using OpenTelemetry for performance instrumentation
94 lines (90 loc) • 2.54 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const attributes = require('@sentry/conventions/attributes');
const metrics = require('@sentry/conventions/metrics');
const core = require('@sentry/core');
const span = require('./span.js');
function toMetricAttributes(attributes) {
if (!attributes) {
return void 0;
}
const result = {};
for (const [key, value] of Object.entries(span.toSentryAttributes(attributes))) {
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
result[key] = value;
}
}
return result;
}
function toSentryUnit(unit) {
if (unit === "ms") {
return "millisecond";
}
if (unit === "1" || unit?.startsWith("{")) {
return "none";
}
return unit;
}
class SentryBullMQCounter {
constructor(name, unit) {
this._name = name;
this._unit = unit;
}
add(value, attributes) {
core.metrics.count(this._name, value, {
unit: this._unit,
attributes: toMetricAttributes(attributes)
});
}
}
class SentryBullMQHistogram {
constructor(name, unit) {
this._name = name;
this._unit = unit;
}
record(value, attributes) {
core.metrics.distribution(this._name, value, {
unit: this._unit,
attributes: toMetricAttributes(attributes)
});
}
}
class SentryBullMQGauge {
constructor(name, unit) {
this._name = name;
this._unit = unit;
}
record(value, attributes) {
core.metrics.gauge(this._name, value, {
unit: this._unit,
attributes: toMetricAttributes(attributes)
});
}
}
class SentryBullMQProcessDuration {
record(value, attributes$1) {
core.metrics.distribution(metrics.MESSAGING_PROCESS_DURATION, value / 1e3, {
unit: "second",
attributes: {
...toMetricAttributes(attributes$1),
[attributes.MESSAGING_SYSTEM]: "bullmq",
[attributes.MESSAGING_OPERATION_NAME]: "process"
}
});
}
}
class SentryBullMQMeter {
createCounter(name, options) {
return new SentryBullMQCounter(span.toMessagingKey(name), toSentryUnit(options?.unit));
}
createHistogram(name, options) {
if (name === "bullmq.job.duration") {
return new SentryBullMQProcessDuration();
}
return new SentryBullMQHistogram(span.toMessagingKey(name), toSentryUnit(options?.unit));
}
createGauge(name, options) {
return new SentryBullMQGauge(span.toMessagingKey(name), toSentryUnit(options?.unit));
}
}
exports.SentryBullMQMeter = SentryBullMQMeter;
//# sourceMappingURL=meter.js.map