Skip to content

Commit 28e89dd

Browse files
committed
fix(sentry): use local identity functions when startNewTrace is not available
1 parent 26e51e8 commit 28e89dd

3 files changed

Lines changed: 15 additions & 9 deletions

File tree

packages/server/src/middleware/sentry.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { _compasSentryExport, uuid } from "@compas/stdlib";
22

3+
const cbIdentity = (cb) => {
4+
return cb();
5+
};
6+
37
/**
48
* Sentry support;
59
* - Starts a new root span for each incoming request.
@@ -32,8 +36,10 @@ export function sentry() {
3236
}
3337

3438
const _sentry = _compasSentryExport;
39+
// Sentry v7 / v8 compat
40+
const startNewTrace = _sentry.startNewTrace ?? cbIdentity;
3541

36-
return _sentry.startNewTrace(() => {
42+
return startNewTrace(() => {
3743
return _sentry.startSpanManual(
3844
{
3945
// @ts-expect-error compat

packages/stdlib/src/sentry.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,4 @@ export let _compasSentryEnableQuerySpans = false;
4747
export function compasWithSentry(instance, { sendQueriesAsSpans } = {}) {
4848
_compasSentryExport = instance;
4949
_compasSentryEnableQuerySpans = sendQueriesAsSpans ?? false;
50-
51-
if (typeof instance?.startNewTrace !== "function") {
52-
// v7 / v8 compat
53-
instance.startNewTrace = (cb) => {
54-
return cb();
55-
};
56-
}
5750
}

packages/store/src/queue-worker.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import { validateStoreJob } from "./generated/store/validators.js";
1515
import { queries } from "./generated.js";
1616
import { query } from "./query.js";
1717

18+
const cbIdentity = (cb) => {
19+
return cb();
20+
};
21+
1822
/**
1923
* @typedef {(
2024
* event: import("@compas/stdlib").InsightEvent,
@@ -520,7 +524,10 @@ async function queueWorkerExecuteJob(logger, sql, options, job) {
520524

521525
if (_compasSentryExport) {
522526
const _sentry = _compasSentryExport;
523-
await _sentry.startNewTrace(() => {
527+
// Sentry v7 / v8 compat
528+
const startNewTrace = _sentry.startNewTrace ?? cbIdentity;
529+
530+
await startNewTrace(() => {
524531
return _sentry.startSpan(
525532
{
526533
// @ts-expect-error compat

0 commit comments

Comments
 (0)