@sentry/node
Version:
Sentry Node SDK using OpenTelemetry for performance instrumentation
92 lines (89 loc) • 2.46 kB
JavaScript
import { MESSAGING_OPERATION_NAME, MESSAGING_SYSTEM } from '@sentry/conventions/attributes';
import { MESSAGING_PROCESS_DURATION } from '@sentry/conventions/metrics';
import { metrics } from '@sentry/core';
import { toMessagingKey, toSentryAttributes } from './span.js';
function toMetricAttributes(attributes) {
if (!attributes) {
return void 0;
}
const result = {};
for (const [key, value] of Object.entries(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) {
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) {
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) {
metrics.gauge(this._name, value, {
unit: this._unit,
attributes: toMetricAttributes(attributes)
});
}
}
class SentryBullMQProcessDuration {
record(value, attributes) {
metrics.distribution(MESSAGING_PROCESS_DURATION, value / 1e3, {
unit: "second",
attributes: {
...toMetricAttributes(attributes),
[MESSAGING_SYSTEM]: "bullmq",
[MESSAGING_OPERATION_NAME]: "process"
}
});
}
}
class SentryBullMQMeter {
createCounter(name, options) {
return new SentryBullMQCounter(toMessagingKey(name), toSentryUnit(options?.unit));
}
createHistogram(name, options) {
if (name === "bullmq.job.duration") {
return new SentryBullMQProcessDuration();
}
return new SentryBullMQHistogram(toMessagingKey(name), toSentryUnit(options?.unit));
}
createGauge(name, options) {
return new SentryBullMQGauge(toMessagingKey(name), toSentryUnit(options?.unit));
}
}
export { SentryBullMQMeter };
//# sourceMappingURL=meter.js.map