Skip to content

Commit e9db461

Browse files
authored
ref(svelte): Remove startChild deprecations (#10956)
ref #10900
1 parent 661c466 commit e9db461

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

packages/svelte/src/performance.ts

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { getCurrentScope } from '@sentry/browser';
2-
import type { Span, Transaction } from '@sentry/types';
1+
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, getActiveSpan } from '@sentry/browser';
2+
import type { Span } from '@sentry/types';
33
import { afterUpdate, beforeUpdate, onMount } from 'svelte';
44
import { current_component } from 'svelte/internal';
55

@@ -26,11 +26,6 @@ const defaultTrackComponentOptions: {
2626
export function trackComponent(options?: TrackComponentOptions): void {
2727
const mergedOptions = { ...defaultTrackComponentOptions, ...options };
2828

29-
const transaction = getActiveTransaction();
30-
if (!transaction) {
31-
return;
32-
}
33-
3429
const customComponentName = mergedOptions.componentName;
3530

3631
// current_component.ctor.name is likely to give us the component's name automatically
@@ -39,20 +34,20 @@ export function trackComponent(options?: TrackComponentOptions): void {
3934

4035
let initSpan: Span | undefined = undefined;
4136
if (mergedOptions.trackInit) {
42-
initSpan = recordInitSpan(transaction, componentName);
37+
initSpan = recordInitSpan(componentName);
4338
}
4439

4540
if (mergedOptions.trackUpdates) {
4641
recordUpdateSpans(componentName, initSpan);
4742
}
4843
}
4944

50-
function recordInitSpan(transaction: Transaction, componentName: string): Span {
51-
// eslint-disable-next-line deprecation/deprecation
52-
const initSpan = transaction.startChild({
45+
function recordInitSpan(componentName: string): Span | undefined {
46+
const initSpan = startInactiveSpan({
47+
onlyIfParent: true,
5348
op: UI_SVELTE_INIT,
5449
name: componentName,
55-
origin: 'auto.ui.svelte',
50+
attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.svelte' },
5651
});
5752

5853
onMount(() => {
@@ -67,21 +62,25 @@ function recordUpdateSpans(componentName: string, initSpan?: Span): void {
6762
beforeUpdate(() => {
6863
// We need to get the active transaction again because the initial one could
6964
// already be finished or there is currently no transaction going on.
70-
const transaction = getActiveTransaction();
71-
if (!transaction) {
65+
const activeSpan = getActiveSpan();
66+
if (!activeSpan) {
7267
return;
7368
}
7469

7570
// If we are initializing the component when the update span is started, we start it as child
7671
// of the init span. Else, we start it as a child of the transaction.
7772
const parentSpan =
78-
initSpan && initSpan.isRecording() && getRootSpan(initSpan) === transaction ? initSpan : transaction;
73+
initSpan && initSpan.isRecording() && getRootSpan(initSpan) === getRootSpan(activeSpan)
74+
? initSpan
75+
: getRootSpan(activeSpan);
76+
77+
if (!parentSpan) return;
7978

8079
updateSpan = withActiveSpan(parentSpan, () => {
8180
return startInactiveSpan({
8281
op: UI_SVELTE_UPDATE,
8382
name: componentName,
84-
origin: 'auto.ui.svelte',
83+
attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.svelte' },
8584
});
8685
});
8786
});
@@ -94,8 +93,3 @@ function recordUpdateSpans(componentName: string, initSpan?: Span): void {
9493
updateSpan = undefined;
9594
});
9695
}
97-
98-
function getActiveTransaction(): Transaction | undefined {
99-
// eslint-disable-next-line deprecation/deprecation
100-
return getCurrentScope().getTransaction();
101-
}

0 commit comments

Comments
 (0)