Skip to content

Commit 7382836

Browse files
committed
feat(stdlib,store,server): Sentry v7 & v8 compat
1 parent d8da5d8 commit 7382836

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

packages/server/src/middleware/sentry.js

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

33
/**
44
* Sentry support;
@@ -36,6 +36,12 @@ export function sentry() {
3636
return _sentry.startNewTrace(() => {
3737
return _sentry.startSpanManual(
3838
{
39+
// @ts-expect-error compat
40+
//
41+
// v7 / v8 compat to force a new trace
42+
traceId: uuid().replace(/-/g, ""),
43+
spanId: uuid().replace(/-/g, "").slice(16),
44+
3945
op: "http.server",
4046
name: "http",
4147
attributes: {

packages/stdlib/src/sentry.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,11 @@ 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+
}
5057
}

packages/store/src/queue-worker.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
isNil,
88
newEvent,
99
newLogger,
10+
uuid,
1011
} from "@compas/stdlib";
1112
import cron from "cron-parser";
1213
import { jobWhere } from "./generated/database/job.js";
@@ -522,6 +523,12 @@ async function queueWorkerExecuteJob(logger, sql, options, job) {
522523
await _sentry.startNewTrace(() => {
523524
return _sentry.startSpan(
524525
{
526+
// @ts-expect-error compat
527+
//
528+
// v7 / v8 compat to force a new trace
529+
traceId: uuid().replace(/-/g, ""),
530+
spanId: uuid().replace(/-/g, "").slice(16),
531+
525532
op: "queue.task",
526533
name: job.name,
527534
forceTransaction: true,

0 commit comments

Comments
 (0)