Skip to content

Commit 516eba5

Browse files
authored
fix(vue): Finish spans in component tracking before starting new ones for same operation (#5918)
1 parent 21dbf55 commit 516eba5

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

packages/vue/src/tracing.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type Mixins = Parameters<Vue['mixin']>[0];
1313
interface VueSentry extends ViewModel {
1414
readonly $root: VueSentry;
1515
$_sentrySpans?: {
16-
[key: string]: Span;
16+
[key: string]: Span | undefined;
1717
};
1818
$_sentryRootSpan?: Span;
1919
$_sentryRootSpanTimer?: ReturnType<typeof setTimeout>;
@@ -98,6 +98,14 @@ export const createTracingMixins = (options: TracingOptions): Mixins => {
9898
if (internalHook == internalHooks[0]) {
9999
const activeTransaction = this.$root?.$_sentryRootSpan || getActiveTransaction();
100100
if (activeTransaction) {
101+
// Cancel old span for this hook operation in case it didn't get cleaned up. We're not actually sure if it
102+
// will ever be the case that cleanup hooks re not called, but we had users report that spans didn't get
103+
// finished so we finish the span before starting a new one, just to be sure.
104+
const oldSpan = this.$_sentrySpans[operation];
105+
if (oldSpan && !oldSpan.endTimestamp) {
106+
oldSpan.finish();
107+
}
108+
101109
this.$_sentrySpans[operation] = activeTransaction.startChild({
102110
description: `Vue <${name}>`,
103111
op: `${VUE_OP}.${operation}`,

0 commit comments

Comments
 (0)