Skip to content

Commit 3e73c65

Browse files
committed
Refactor newSentryTransaction to use improved API
This change is based on a suggestion by Sentry staff. It requires SDK version > 8.4.0 getsentry/sentry-javascript#12116 (comment) getsentry/sentry-javascript#12138
1 parent e20ee45 commit 3e73c65

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

app/assets/javascripts/editor/editor.js.erb

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -205,23 +205,19 @@ var CodeOceanEditor = {
205205
newSentryTransaction: function (initiator, callback) {
206206
// based on Sentry recommendation.
207207
// See https://github.com/getsentry/sentry-javascript/issues/12116
208-
return Sentry.continueTrace({ sentryTrace: '', baggage: '' }, () => {
209-
// inside of this we have a new trace!
210-
return Sentry.withActiveSpan(null, () => {
211-
// inside of this there is no parent span, no matter what!
212-
const cause = initiator.data('cause') || initiator.prop('id');
213-
return Sentry.startSpan({name: cause, op: "transaction", forceTransaction: true}, async () => {
214-
// Execute the desired custom code
215-
try {
216-
return await callback();
217-
} catch (error) {
218-
// WebSocket errors are handled in `showWebsocketError` already.
219-
if (error.target instanceof WebSocket) return;
220-
221-
console.error(JSON.stringify(error));
222-
Sentry.captureException(JSON.stringify(error), {mechanism: {handled: false}});
223-
}
224-
});
208+
return Sentry.startNewTrace(() => {
209+
const cause = initiator.data('cause') || initiator.prop('id');
210+
return Sentry.startSpan({name: cause, op: "transaction"}, async () => {
211+
// Execute the desired custom code
212+
try {
213+
return await callback();
214+
} catch (error) {
215+
// WebSocket errors are handled in `showWebsocketError` already.
216+
if (error.target instanceof WebSocket) return;
217+
218+
console.error(JSON.stringify(error));
219+
Sentry.captureException(JSON.stringify(error), {mechanism: {handled: false}});
220+
}
225221
});
226222
});
227223
},

0 commit comments

Comments
 (0)