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' ;
3
3
import { afterUpdate , beforeUpdate , onMount } from 'svelte' ;
4
4
import { current_component } from 'svelte/internal' ;
5
5
@@ -26,11 +26,6 @@ const defaultTrackComponentOptions: {
26
26
export function trackComponent ( options ?: TrackComponentOptions ) : void {
27
27
const mergedOptions = { ...defaultTrackComponentOptions , ...options } ;
28
28
29
- const transaction = getActiveTransaction ( ) ;
30
- if ( ! transaction ) {
31
- return ;
32
- }
33
-
34
29
const customComponentName = mergedOptions . componentName ;
35
30
36
31
// current_component.ctor.name is likely to give us the component's name automatically
@@ -39,20 +34,20 @@ export function trackComponent(options?: TrackComponentOptions): void {
39
34
40
35
let initSpan : Span | undefined = undefined ;
41
36
if ( mergedOptions . trackInit ) {
42
- initSpan = recordInitSpan ( transaction , componentName ) ;
37
+ initSpan = recordInitSpan ( componentName ) ;
43
38
}
44
39
45
40
if ( mergedOptions . trackUpdates ) {
46
41
recordUpdateSpans ( componentName , initSpan ) ;
47
42
}
48
43
}
49
44
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 ,
53
48
op : UI_SVELTE_INIT ,
54
49
name : componentName ,
55
- origin : 'auto.ui.svelte' ,
50
+ attributes : { [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.ui.svelte' } ,
56
51
} ) ;
57
52
58
53
onMount ( ( ) => {
@@ -67,21 +62,25 @@ function recordUpdateSpans(componentName: string, initSpan?: Span): void {
67
62
beforeUpdate ( ( ) => {
68
63
// We need to get the active transaction again because the initial one could
69
64
// 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 ) {
72
67
return ;
73
68
}
74
69
75
70
// If we are initializing the component when the update span is started, we start it as child
76
71
// of the init span. Else, we start it as a child of the transaction.
77
72
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 ;
79
78
80
79
updateSpan = withActiveSpan ( parentSpan , ( ) => {
81
80
return startInactiveSpan ( {
82
81
op : UI_SVELTE_UPDATE ,
83
82
name : componentName ,
84
- origin : 'auto.ui.svelte' ,
83
+ attributes : { [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.ui.svelte' } ,
85
84
} ) ;
86
85
} ) ;
87
86
} ) ;
@@ -94,8 +93,3 @@ function recordUpdateSpans(componentName: string, initSpan?: Span): void {
94
93
updateSpan = undefined ;
95
94
} ) ;
96
95
}
97
-
98
- function getActiveTransaction ( ) : Transaction | undefined {
99
- // eslint-disable-next-line deprecation/deprecation
100
- return getCurrentScope ( ) . getTransaction ( ) ;
101
- }
0 commit comments