From 5e12b9882191688a9fc92e231791203e670456b6 Mon Sep 17 00:00:00 2001 From: s1gr1d Date: Thu, 7 Mar 2024 09:39:39 +0100 Subject: [PATCH 1/2] remove startChild deprecations in svelte --- packages/svelte/src/performance.ts | 37 +++++++++++++----------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/packages/svelte/src/performance.ts b/packages/svelte/src/performance.ts index 302f346e32b9..237bb28c6d1d 100644 --- a/packages/svelte/src/performance.ts +++ b/packages/svelte/src/performance.ts @@ -1,5 +1,5 @@ -import { getCurrentScope } from '@sentry/browser'; -import type { Span, Transaction } from '@sentry/types'; +import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, getActiveSpan } from '@sentry/browser'; +import type { Span } from '@sentry/types'; import { afterUpdate, beforeUpdate, onMount } from 'svelte'; import { current_component } from 'svelte/internal'; @@ -26,11 +26,6 @@ const defaultTrackComponentOptions: { export function trackComponent(options?: TrackComponentOptions): void { const mergedOptions = { ...defaultTrackComponentOptions, ...options }; - const transaction = getActiveTransaction(); - if (!transaction) { - return; - } - const customComponentName = mergedOptions.componentName; // current_component.ctor.name is likely to give us the component's name automatically @@ -39,7 +34,7 @@ export function trackComponent(options?: TrackComponentOptions): void { let initSpan: Span | undefined = undefined; if (mergedOptions.trackInit) { - initSpan = recordInitSpan(transaction, componentName); + initSpan = recordInitSpan(componentName); } if (mergedOptions.trackUpdates) { @@ -47,15 +42,16 @@ export function trackComponent(options?: TrackComponentOptions): void { } } -function recordInitSpan(transaction: Transaction, componentName: string): Span { - // eslint-disable-next-line deprecation/deprecation - const initSpan = transaction.startChild({ +function recordInitSpan(componentName: string): Span | undefined { + const initSpan = startInactiveSpan({ + onlyIfParent: true, op: UI_SVELTE_INIT, name: componentName, - origin: 'auto.ui.svelte', + attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.svelte' }, }); onMount(() => { + if (!initSpan) return; initSpan.end(); }); @@ -67,21 +63,25 @@ function recordUpdateSpans(componentName: string, initSpan?: Span): void { beforeUpdate(() => { // We need to get the active transaction again because the initial one could // already be finished or there is currently no transaction going on. - const transaction = getActiveTransaction(); - if (!transaction) { + const activeSpan = getActiveSpan(); + if (!activeSpan) { return; } // If we are initializing the component when the update span is started, we start it as child // of the init span. Else, we start it as a child of the transaction. const parentSpan = - initSpan && initSpan.isRecording() && getRootSpan(initSpan) === transaction ? initSpan : transaction; + initSpan && initSpan.isRecording() && getRootSpan(initSpan) === getRootSpan(activeSpan) + ? initSpan + : getRootSpan(activeSpan); + + if (!parentSpan) return; updateSpan = withActiveSpan(parentSpan, () => { return startInactiveSpan({ op: UI_SVELTE_UPDATE, name: componentName, - origin: 'auto.ui.svelte', + attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.svelte' }, }); }); }); @@ -94,8 +94,3 @@ function recordUpdateSpans(componentName: string, initSpan?: Span): void { updateSpan = undefined; }); } - -function getActiveTransaction(): Transaction | undefined { - // eslint-disable-next-line deprecation/deprecation - return getCurrentScope().getTransaction(); -} From 0845afa4187e6d814ace0b3e4fd9958ec3a395de Mon Sep 17 00:00:00 2001 From: s1gr1d Date: Thu, 7 Mar 2024 10:26:51 +0100 Subject: [PATCH 2/2] delete if --- packages/svelte/src/performance.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/svelte/src/performance.ts b/packages/svelte/src/performance.ts index 237bb28c6d1d..df3862f3258a 100644 --- a/packages/svelte/src/performance.ts +++ b/packages/svelte/src/performance.ts @@ -51,7 +51,6 @@ function recordInitSpan(componentName: string): Span | undefined { }); onMount(() => { - if (!initSpan) return; initSpan.end(); });