Skip to content

Commit 093de9f

Browse files
committed
fix(vue): prevent after hook from starting new span
1 parent eaf2e81 commit 093de9f

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

packages/vue/src/tracing.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,21 +95,23 @@ export const createTracingMixins = (options: TracingOptions): Mixins => {
9595

9696
this.$_sentrySpans = this.$_sentrySpans || {};
9797

98-
// On the first handler call (before), it'll be undefined, as `$once` will add it in the future.
99-
// However, on the second call (after), it'll be already in place.
100-
const span = this.$_sentrySpans[operation];
101-
102-
if (span) {
103-
span.finish();
104-
finishRootSpan(this, timestampInSeconds(), options.timeout);
105-
} else {
98+
// Start a new span if current hook is a 'before' hook.
99+
// Otherwise, retrieve the current span and finish it.
100+
if (internalHook == internalHooks[0]) {
106101
const activeTransaction = this.$root?.$_sentryRootSpan || getActiveTransaction();
107102
if (activeTransaction) {
108103
this.$_sentrySpans[operation] = activeTransaction.startChild({
109104
description: `Vue <${name}>`,
110105
op: `${VUE_OP}.${operation}`,
111106
});
112107
}
108+
} else {
109+
// The span should already be added via the first handler call (in the 'before' hook)
110+
const span = this.$_sentrySpans[operation];
111+
if (!span) return; // If not, then the before hook did not start the tracking span, probably because it happened even before there is an active transaction
112+
113+
span.finish();
114+
finishRootSpan(this, timestampInSeconds(), options.timeout);
113115
}
114116
};
115117
}

0 commit comments

Comments
 (0)