Skip to content

Commit 8ed0151

Browse files
committed
rename to component spans
1 parent 7911f65 commit 8ed0151

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

packages/vue/src/tracing.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ type Mixins = Parameters<Vue['mixin']>[0];
1212

1313
interface VueSentry extends ViewModel {
1414
readonly $root: VueSentry;
15-
$_sentrySpans?: {
15+
$_sentryComponentSpans?: {
1616
[key: string]: Span | undefined;
1717
};
18-
$_sentryRootSpan?: Span;
19-
$_sentryRootSpanTimer?: ReturnType<typeof setTimeout>;
18+
$_sentryRootComponentSpan?: Span;
19+
$_sentryRootComponentSpanTimer?: ReturnType<typeof setTimeout>;
2020
}
2121

2222
// Mappings from operation to corresponding lifecycle hook.
@@ -31,16 +31,16 @@ const HOOKS: { [key in Operation]: Hook[] } = {
3131
update: ['beforeUpdate', 'updated'],
3232
};
3333

34-
/** Finish top-level span and activity with a debounce configured using `timeout` option */
35-
function finishRootSpan(vm: VueSentry, timestamp: number, timeout: number): void {
36-
if (vm.$_sentryRootSpanTimer) {
37-
clearTimeout(vm.$_sentryRootSpanTimer);
34+
/** Finish top-level component span and activity with a debounce configured using `timeout` option */
35+
function finishRootComponentSpan(vm: VueSentry, timestamp: number, timeout: number): void {
36+
if (vm.$_sentryRootComponentSpanTimer) {
37+
clearTimeout(vm.$_sentryRootComponentSpanTimer);
3838
}
3939

40-
vm.$_sentryRootSpanTimer = setTimeout(() => {
41-
if (vm.$root?.$_sentryRootSpan) {
42-
vm.$root.$_sentryRootSpan.end(timestamp);
43-
vm.$root.$_sentryRootSpan = undefined;
40+
vm.$_sentryRootComponentSpanTimer = setTimeout(() => {
41+
if (vm.$root?.$_sentryRootComponentSpan) {
42+
vm.$root.$_sentryRootComponentSpan.end(timestamp);
43+
vm.$root.$_sentryRootComponentSpan = undefined;
4444
}
4545
}, timeout);
4646
}
@@ -77,12 +77,12 @@ export const createTracingMixins = (options: Partial<TracingOptions> = {}): Mixi
7777

7878
for (const internalHook of internalHooks) {
7979
mixins[internalHook] = function (this: VueSentry) {
80-
const isRoot = this.$root === this;
80+
const isRootComponent = this.$root === this;
8181

82-
// 1. Root span creation
83-
if (isRoot) {
84-
this.$_sentryRootSpan =
85-
this.$_sentryRootSpan ||
82+
// 1. Root Component span creation
83+
if (isRootComponent) {
84+
this.$_sentryRootComponentSpan =
85+
this.$_sentryRootComponentSpan ||
8686
startInactiveSpan({
8787
name: 'Application Render',
8888
op: `${VUE_OP}.render`,
@@ -97,7 +97,7 @@ export const createTracingMixins = (options: Partial<TracingOptions> = {}): Mixi
9797
const componentName = formatComponentName(this, false);
9898

9999
const shouldTrack =
100-
isRoot || // We always want to track the root component
100+
isRootComponent || // We always want to track the root component
101101
(Array.isArray(options.trackComponents)
102102
? findTrackComponent(options.trackComponents, componentName)
103103
: options.trackComponents);
@@ -106,11 +106,11 @@ export const createTracingMixins = (options: Partial<TracingOptions> = {}): Mixi
106106
return;
107107
}
108108

109-
this.$_sentrySpans = this.$_sentrySpans || {};
109+
this.$_sentryComponentSpans = this.$_sentryComponentSpans || {};
110110

111111
// 3. Span lifecycle management based on the hook type
112112
const isBeforeHook = internalHook === internalHooks[0];
113-
const activeSpan = this.$root?.$_sentryRootSpan || getActiveSpan();
113+
const activeSpan = this.$root?.$_sentryRootComponentSpan || getActiveSpan();
114114

115115
if (isBeforeHook) {
116116
// Starting a new span in the "before" hook
@@ -119,12 +119,12 @@ export const createTracingMixins = (options: Partial<TracingOptions> = {}): Mixi
119119
// We're actually not sure if it will ever be the case that cleanup hooks were not called.
120120
// However, we had users report that spans didn't get finished, so we finished the span before
121121
// starting a new one, just to be sure.
122-
const oldSpan = this.$_sentrySpans[operation];
122+
const oldSpan = this.$_sentryComponentSpans[operation];
123123
if (oldSpan) {
124124
oldSpan.end();
125125
}
126126

127-
this.$_sentrySpans[operation] = startInactiveSpan({
127+
this.$_sentryComponentSpans[operation] = startInactiveSpan({
128128
name: `Vue ${componentName}`,
129129
op: `${VUE_OP}.${operation}`,
130130
attributes: {
@@ -136,14 +136,14 @@ export const createTracingMixins = (options: Partial<TracingOptions> = {}): Mixi
136136
}
137137
} else {
138138
// The span should already be added via the first handler call (in the 'before' hook)
139-
const span = this.$_sentrySpans[operation];
139+
const span = this.$_sentryComponentSpans[operation];
140140
// The before hook did not start the tracking span, so the span was not added.
141141
// This is probably because it happened before there is an active transaction
142142
if (!span) return; // Skip if no span was created in the "before" hook
143143
span.end();
144144

145-
// For any "after" hook, also schedule the root span to finish
146-
finishRootSpan(this, timestampInSeconds(), options.timeout || 2000);
145+
// For any "after" hook, also schedule the root component span to finish
146+
finishRootComponentSpan(this, timestampInSeconds(), options.timeout || 2000);
147147
}
148148
};
149149
}

packages/vue/test/tracing/tracingMixin.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ describe('Vue Tracing Mixins', () => {
4646
mockRootInstance = {
4747
$root: null,
4848
componentName: 'RootComponent',
49-
$_sentrySpans: {},
49+
$_sentryComponentSpans: {},
5050
};
5151
mockRootInstance.$root = mockRootInstance; // Self-reference for root
5252

5353
mockVueInstance = {
5454
$root: mockRootInstance,
5555
componentName: 'TestComponent',
56-
$_sentrySpans: {},
56+
$_sentryComponentSpans: {},
5757
};
5858

5959
(getActiveSpan as any).mockReturnValue({ id: 'parent-span' });
@@ -131,7 +131,7 @@ describe('Vue Tracing Mixins', () => {
131131
// todo/fixme: This root component span is only finished if trackComponents is true --> it should probably be always finished
132132
const mixins = createTracingMixins({ trackComponents: true, timeout: 1000 });
133133
const rootMockSpan = mockSpanFactory();
134-
mockRootInstance.$_sentryRootSpan = rootMockSpan;
134+
mockRootInstance.$_sentryRootComponentSpan = rootMockSpan;
135135

136136
// Create and finish a component span
137137
mixins.beforeMount.call(mockVueInstance);
@@ -160,10 +160,10 @@ describe('Vue Tracing Mixins', () => {
160160
op: 'ui.vue.mount',
161161
}),
162162
);
163-
expect(mockVueInstance.$_sentrySpans.mount).toBeDefined();
163+
expect(mockVueInstance.$_sentryComponentSpans.mount).toBeDefined();
164164

165165
// 2. Get the span for verification
166-
const componentSpan = mockVueInstance.$_sentrySpans.mount;
166+
const componentSpan = mockVueInstance.$_sentryComponentSpans.mount;
167167

168168
// 3. End span in "after" hook
169169
mixins.mounted.call(mockVueInstance);
@@ -175,14 +175,14 @@ describe('Vue Tracing Mixins', () => {
175175

176176
// Create an existing span first
177177
const oldSpan = mockSpanFactory();
178-
mockVueInstance.$_sentrySpans.mount = oldSpan;
178+
mockVueInstance.$_sentryComponentSpans.mount = oldSpan;
179179

180180
// Create a new span for the same operation
181181
mixins.beforeMount.call(mockVueInstance);
182182

183183
// Verify old span was ended and new span was created
184184
expect(oldSpan.end).toHaveBeenCalled();
185-
expect(mockVueInstance.$_sentrySpans.mount).not.toBe(oldSpan);
185+
expect(mockVueInstance.$_sentryComponentSpans.mount).not.toBe(oldSpan);
186186
});
187187

188188
it('should gracefully handle when "after" hook is called without "before" hook', () => {
@@ -197,7 +197,7 @@ describe('Vue Tracing Mixins', () => {
197197

198198
// Remove active spans
199199
(getActiveSpan as any).mockReturnValue(null);
200-
mockRootInstance.$_sentryRootSpan = null;
200+
mockRootInstance.$_sentryRootComponentSpan = null;
201201

202202
// Try to create a span
203203
mixins.beforeMount.call(mockVueInstance);

0 commit comments

Comments
 (0)