@sentry/node
Version:
Sentry Node SDK using OpenTelemetry for performance instrumentation
52 lines (49 loc) • 1.4 kB
JavaScript
import { getCurrentScope, getActiveSpan, withIsolationScope, withActiveSpan, spanToTraceHeader, extractTraceparentData } from '@sentry/core';
class SentryBullMQContextManager {
active() {
return {
span: getActiveSpan(),
scope: getCurrentScope()
};
}
with(context, fn) {
if (context.span) {
return withIsolationScope(() => {
return withActiveSpan(context.span, fn);
});
}
return withIsolationScope(() => withActiveSpan(null, fn));
}
/**
* Returns a context without a span. BullMQ 6.3.11+ runs the stalled jobs checker in it, so the
* checker does not stay attached to the span that was active when the worker started.
*/
root() {
return {
span: void 0,
scope: getCurrentScope()
};
}
getMetadata(context) {
if (context.span) {
return spanToTraceHeader(context.span);
}
return "";
}
fromMetadata(activeContext, metadata) {
const traceparent = extractTraceparentData(metadata);
if (!traceparent?.traceId || !traceparent?.parentSpanId) {
return activeContext;
}
return {
...activeContext,
producerSpanContext: {
traceId: traceparent.traceId,
spanId: traceparent.parentSpanId,
sampled: traceparent.parentSampled === true
}
};
}
}
export { SentryBullMQContextManager };
//# sourceMappingURL=contextManager.js.map