From a99d86068a38367ed556b0af96aa2520553252e0 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Mon, 27 May 2024 10:36:24 +0200 Subject: [PATCH] Refactor `newSentryTransaction` to use improved API This change is based on a suggestion by Sentry staff. It requires SDK version > 8.4.0 https://github.com/getsentry/sentry-javascript/issues/12116#issuecomment-2132812315 https://github.com/getsentry/sentry-javascript/pull/12138 --- app/assets/javascripts/editor/editor.js.erb | 28 +++++++++------------ 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/app/assets/javascripts/editor/editor.js.erb b/app/assets/javascripts/editor/editor.js.erb index 703844c3..cc91fa96 100644 --- a/app/assets/javascripts/editor/editor.js.erb +++ b/app/assets/javascripts/editor/editor.js.erb @@ -205,23 +205,19 @@ var CodeOceanEditor = { newSentryTransaction: function (initiator, callback) { // based on Sentry recommendation. // See https://github.com/getsentry/sentry-javascript/issues/12116 - return Sentry.continueTrace({ sentryTrace: '', baggage: '' }, () => { - // inside of this we have a new trace! - return Sentry.withActiveSpan(null, () => { - // inside of this there is no parent span, no matter what! - const cause = initiator.data('cause') || initiator.prop('id'); - return Sentry.startSpan({name: cause, op: "transaction", forceTransaction: true}, async () => { - // Execute the desired custom code - try { - return await callback(); - } catch (error) { - // WebSocket errors are handled in `showWebsocketError` already. - if (error.target instanceof WebSocket) return; + return Sentry.startNewTrace(() => { + const cause = initiator.data('cause') || initiator.prop('id'); + return Sentry.startSpan({name: cause, op: "transaction"}, async () => { + // Execute the desired custom code + try { + return await callback(); + } catch (error) { + // WebSocket errors are handled in `showWebsocketError` already. + if (error.target instanceof WebSocket) return; - console.error(JSON.stringify(error)); - Sentry.captureException(JSON.stringify(error), {mechanism: {handled: false}}); - } - }); + console.error(JSON.stringify(error)); + Sentry.captureException(JSON.stringify(error), {mechanism: {handled: false}}); + } }); }); },