11import { Component } from '@angular/core' ;
22import type { ActivatedRouteSnapshot , CanActivate , RouterStateSnapshot } from '@angular/router' ;
3+ import { SentrySemanticAttributes } from '@sentry/core' ;
34
45import { TraceClassDecorator , TraceDirective , TraceMethodDecorator , instrumentAngularRouting } from '../src' ;
56import { getParameterizedRouteFromSnapshot } from '../src/tracing' ;
@@ -11,7 +12,13 @@ const defaultStartTransaction = (ctx: any) => {
1112 transaction = {
1213 ...ctx ,
1314 updateName : jest . fn ( name => ( transaction . name = name ) ) ,
14- setMetadata : jest . fn ( ) ,
15+ setAttribute : jest . fn ( ) ,
16+ toJSON : ( ) => ( {
17+ data : {
18+ [ SentrySemanticAttributes . Source ] : 'custom' ,
19+ ...ctx . data ,
20+ } ,
21+ } ) ,
1522 } ;
1623
1724 return transaction ;
@@ -45,7 +52,7 @@ describe('Angular Tracing', () => {
4552 name : '/' ,
4653 op : 'pageload' ,
4754 origin : 'auto.pageload.angular' ,
48- metadata : { source : 'url' } ,
55+ data : { [ SentrySemanticAttributes . Source ] : 'url' } ,
4956 } ) ;
5057 } ) ;
5158 } ) ;
@@ -107,11 +114,15 @@ describe('Angular Tracing', () => {
107114 const customStartTransaction = jest . fn ( ( ctx : any ) => {
108115 transaction = {
109116 ...ctx ,
110- metadata : {
111- ...ctx . metadata ,
112- source : 'custom' ,
113- } ,
117+ toJSON : ( ) => ( {
118+ data : {
119+ ...ctx . data ,
120+ [ SentrySemanticAttributes . Source ] : 'custom' ,
121+ } ,
122+ } ) ,
123+ metadata : ctx . metadata ,
114124 updateName : jest . fn ( name => ( transaction . name = name ) ) ,
125+ setAttribute : jest . fn ( ) ,
115126 } ;
116127
117128 return transaction ;
@@ -135,12 +146,12 @@ describe('Angular Tracing', () => {
135146 name : url ,
136147 op : 'pageload' ,
137148 origin : 'auto.pageload.angular' ,
138- metadata : { source : 'url' } ,
149+ data : { [ SentrySemanticAttributes . Source ] : 'url' } ,
139150 } ) ;
140151
141152 expect ( transaction . updateName ) . toHaveBeenCalledTimes ( 0 ) ;
142153 expect ( transaction . name ) . toEqual ( url ) ;
143- expect ( transaction . metadata . source ) . toBe ( 'custom' ) ;
154+ expect ( transaction . toJSON ( ) . data ) . toEqual ( { [ SentrySemanticAttributes . Source ] : 'custom' } ) ;
144155
145156 env . destroy ( ) ;
146157 } ) ;
@@ -326,10 +337,10 @@ describe('Angular Tracing', () => {
326337 name : url ,
327338 op : 'navigation' ,
328339 origin : 'auto.navigation.angular' ,
329- metadata : { source : 'url' } ,
340+ data : { [ SentrySemanticAttributes . Source ] : 'url' } ,
330341 } ) ;
331342 expect ( transaction . updateName ) . toHaveBeenCalledWith ( result ) ;
332- expect ( transaction . setMetadata ) . toHaveBeenCalledWith ( { source : 'route' } ) ;
343+ expect ( transaction . setAttribute ) . toHaveBeenCalledWith ( SentrySemanticAttributes . Source , 'route' ) ;
333344
334345 env . destroy ( ) ;
335346 } ) ;
0 commit comments