Skip to content

Commit

Permalink
Refactor newSentryTransaction to use improved API
Browse files Browse the repository at this point in the history
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
  • Loading branch information
MrSerth committed May 27, 2024
1 parent e20ee45 commit 3e73c65
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions app/assets/javascripts/editor/editor.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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;

console.error(JSON.stringify(error));
Sentry.captureException(JSON.stringify(error), {mechanism: {handled: false}});
}
});
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}});
}
});
});
},
Expand Down

0 comments on commit 3e73c65

Please sign in to comment.