Skip to content

ref(svelte): Remove startChild deprecations #10956

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 15 additions & 21 deletions packages/svelte/src/performance.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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
Expand All @@ -39,20 +34,20 @@ export function trackComponent(options?: TrackComponentOptions): void {

let initSpan: Span | undefined = undefined;
if (mergedOptions.trackInit) {
initSpan = recordInitSpan(transaction, componentName);
initSpan = recordInitSpan(componentName);
}

if (mergedOptions.trackUpdates) {
recordUpdateSpans(componentName, initSpan);
}
}

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(() => {
Expand All @@ -67,21 +62,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' },
});
});
});
Expand All @@ -94,8 +93,3 @@ function recordUpdateSpans(componentName: string, initSpan?: Span): void {
updateSpan = undefined;
});
}

function getActiveTransaction(): Transaction | undefined {
// eslint-disable-next-line deprecation/deprecation
return getCurrentScope().getTransaction();
}