Skip to content

Commit a386f5d

Browse files
committed
fix(svelte): Make component tracking compatible with Svelte 5
1 parent f4227b8 commit a386f5d

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

packages/svelte/src/performance.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { getCurrentScope } from '@sentry/browser';
22
import type { Span, Transaction } from '@sentry/types';
33
import { afterUpdate, beforeUpdate, onMount } from 'svelte';
4-
import { current_component } from 'svelte/internal';
54

65
import { getRootSpan } from '@sentry/core';
76
import { DEFAULT_COMPONENT_NAME, UI_SVELTE_INIT, UI_SVELTE_UPDATE } from './constants';
@@ -35,7 +34,7 @@ export function trackComponent(options?: TrackComponentOptions): void {
3534

3635
// current_component.ctor.name is likely to give us the component's name automatically
3736
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
38-
const componentName = `<${customComponentName || current_component.constructor.name || DEFAULT_COMPONENT_NAME}>`;
37+
const componentName = `<${customComponentName || DEFAULT_COMPONENT_NAME}>`;
3938

4039
let initSpan: Span | undefined = undefined;
4140
if (mergedOptions.trackInit) {
@@ -56,6 +55,7 @@ function recordInitSpan(transaction: Transaction, componentName: string): Span {
5655
});
5756

5857
onMount(() => {
58+
console.log('END SPAN', componentName);
5959
initSpan.end();
6060
});
6161

packages/svelte/src/preprocessors.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export const FIRST_PASS_COMPONENT_TRACKING_PREPROC_ID = 'FIRST_PASS_COMPONENT_TR
2121
export function componentTrackingPreprocessor(options?: ComponentTrackingInitOptions): PreprocessorGroup {
2222
const mergedOptions = { ...defaultComponentTrackingOptions, ...options };
2323

24+
console.log('mergedOptions', mergedOptions);
25+
2426
const visitedFiles = new Set<string>();
2527
const visitedFilesMarkup = new Set<string>();
2628

packages/svelte/src/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,10 @@ export type ComponentTrackingInitOptions = {
6060
} & SpanOptions;
6161

6262
export type TrackComponentOptions = {
63+
/**
64+
* The name of the component to be used in the recorded spans.
65+
*
66+
* @default to <Svelte Component> if not specified
67+
*/
6368
componentName?: string;
6469
} & SpanOptions;

0 commit comments

Comments
 (0)