Skip to content

Commit bd3986d

Browse files
committed
remove startChild deprecations in svelte
1 parent f688034 commit bd3986d

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

packages/svelte/src/performance.ts

Lines changed: 16 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,23 +34,24 @@ 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(() => {
54+
if (!initSpan) return;
5955
initSpan.end();
6056
});
6157

@@ -67,21 +63,25 @@ function recordUpdateSpans(componentName: string, initSpan?: Span): void {
6763
beforeUpdate(() => {
6864
// We need to get the active transaction again because the initial one could
6965
// already be finished or there is currently no transaction going on.
70-
const transaction = getActiveTransaction();
71-
if (!transaction) {
66+
const activeSpan = getActiveSpan();
67+
if (!activeSpan) {
7268
return;
7369
}
7470

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

8080
updateSpan = withActiveSpan(parentSpan, () => {
8181
return startInactiveSpan({
8282
op: UI_SVELTE_UPDATE,
8383
name: componentName,
84-
origin: 'auto.ui.svelte',
84+
attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.svelte' },
8585
});
8686
});
8787
});
@@ -94,8 +94,3 @@ function recordUpdateSpans(componentName: string, initSpan?: Span): void {
9494
updateSpan = undefined;
9595
});
9696
}
97-
98-
function getActiveTransaction(): Transaction | undefined {
99-
// eslint-disable-next-line deprecation/deprecation
100-
return getCurrentScope().getTransaction();
101-
}

0 commit comments

Comments
 (0)