Skip to content
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

fix(vue): Finish spans in component tracking before starting new ones for same operation #5918

Merged
merged 1 commit into from Oct 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/vue/src/tracing.ts
Expand Up @@ -13,7 +13,7 @@ type Mixins = Parameters<Vue['mixin']>[0];
interface VueSentry extends ViewModel {
readonly $root: VueSentry;
$_sentrySpans?: {
[key: string]: Span;
[key: string]: Span | undefined;
};
$_sentryRootSpan?: Span;
$_sentryRootSpanTimer?: ReturnType<typeof setTimeout>;
Expand Down Expand Up @@ -98,6 +98,14 @@ export const createTracingMixins = (options: TracingOptions): Mixins => {
if (internalHook == internalHooks[0]) {
const activeTransaction = this.$root?.$_sentryRootSpan || getActiveTransaction();
if (activeTransaction) {
// Cancel old span for this hook operation in case it didn't get cleaned up. We're not actually sure if it
// will ever be the case that cleanup hooks re not called, but we had users report that spans didn't get
// finished so we finish the span before starting a new one, just to be sure.
const oldSpan = this.$_sentrySpans[operation];
if (oldSpan && !oldSpan.endTimestamp) {
oldSpan.finish();
}

this.$_sentrySpans[operation] = activeTransaction.startChild({
description: `Vue <${name}>`,
op: `${VUE_OP}.${operation}`,
Expand Down