@@ -74,6 +74,45 @@ describe('wrapSentryHandleRequest', () => {
7474 } ) ;
7575 } ) ;
7676
77+ test ( 'should name an index route after its nearest ancestor path, or `/`' , async ( ) => {
78+ const mockRootSpan = { setAttributes : vi . fn ( ) } ;
79+
80+ ( getActiveSpan as unknown as ReturnType < typeof vi . fn > ) . mockReturnValue ( { } ) ;
81+ ( getRootSpan as unknown as ReturnType < typeof vi . fn > ) . mockReturnValue ( mockRootSpan ) ;
82+
83+ const wrappedHandler = wrapSentryHandleRequest ( vi . fn ( ) . mockResolvedValue ( 'test' ) ) ;
84+
85+ const rootIndexContext = {
86+ staticHandlerContext : { matches : [ { route : { path : '' } } , { route : { index : true } } ] } ,
87+ } as any ;
88+ await wrappedHandler ( new Request ( 'https://nacho.queso/' ) , 200 , new Headers ( ) , rootIndexContext , { } as any ) ;
89+
90+ expect ( mockRootSpan . setAttributes ) . toHaveBeenLastCalledWith ( {
91+ [ HTTP_ROUTE ] : '/' ,
92+ [ SENTRY_SEGMENT_NAME_SOURCE ] : 'route' ,
93+ [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.http.react_router.request_handler' ,
94+ } ) ;
95+
96+ const nestedIndexContext = {
97+ staticHandlerContext : {
98+ matches : [ { route : { path : '' } } , { route : { path : 'dashboard' } } , { route : { index : true } } ] ,
99+ } ,
100+ } as any ;
101+ await wrappedHandler (
102+ new Request ( 'https://nacho.queso/dashboard' ) ,
103+ 200 ,
104+ new Headers ( ) ,
105+ nestedIndexContext ,
106+ { } as any ,
107+ ) ;
108+
109+ expect ( mockRootSpan . setAttributes ) . toHaveBeenLastCalledWith ( {
110+ [ HTTP_ROUTE ] : '/dashboard' ,
111+ [ SENTRY_SEGMENT_NAME_SOURCE ] : 'route' ,
112+ [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.http.react_router.request_handler' ,
113+ } ) ;
114+ } ) ;
115+
77116 test ( 'should not set span attributes when parameterized path does not exist' , async ( ) => {
78117 const mockActiveSpan = { } ;
79118 const mockRootSpan = { setAttributes : vi . fn ( ) } ;
0 commit comments