Skip to content

fix(vue): prevent after hook from starting new span #4438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions packages/vue/src/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,25 @@ export const createTracingMixins = (options: TracingOptions): Mixins => {

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

// On the first handler call (before), it'll be undefined, as `$once` will add it in the future.
// However, on the second call (after), it'll be already in place.
const span = this.$_sentrySpans[operation];

if (span) {
span.finish();
finishRootSpan(this, timestampInSeconds(), options.timeout);
} else {
// Start a new span if current hook is a 'before' hook.
// Otherwise, retrieve the current span and finish it.
if (internalHook == internalHooks[0]) {
const activeTransaction = this.$root?.$_sentryRootSpan || getActiveTransaction();
if (activeTransaction) {
this.$_sentrySpans[operation] = activeTransaction.startChild({
description: `Vue <${name}>`,
op: `${VUE_OP}.${operation}`,
});
}
} else {
// The span should already be added via the first handler call (in the 'before' hook)
const span = this.$_sentrySpans[operation];
// The before hook did not start the tracking span, so the span was not added.
// This is probably because it happened before there is an active transaction
if (!span) return;

span.finish();
finishRootSpan(this, timestampInSeconds(), options.timeout);
}
};
}
Expand Down