@@ -129,7 +129,7 @@ describe('handleSentry', () => {
129129 expect ( response ) . toEqual ( mockResponse ) ;
130130 } ) ;
131131
132- it ( ' creates a transaction' , async ( ) => {
132+ it ( " creates a transaction if there's no active span" , async ( ) => {
133133 let ref : any = undefined ;
134134 client . on ( 'finishTransaction' , ( transaction : Transaction ) => {
135135 ref = transaction ;
@@ -149,6 +149,50 @@ describe('handleSentry', () => {
149149 expect ( ref . metadata . source ) . toEqual ( 'route' ) ;
150150
151151 expect ( ref . endTimestamp ) . toBeDefined ( ) ;
152+ expect ( ref . spanRecorder . spans ) . toHaveLength ( 1 ) ;
153+ } ) ;
154+
155+ it ( 'creates a child span for nested server calls (i.e. if there is an active span)' , async ( ) => {
156+ let ref : any = undefined ;
157+ let txnCount = 0 ;
158+ client . on ( 'finishTransaction' , ( transaction : Transaction ) => {
159+ ref = transaction ;
160+ ++ txnCount ;
161+ } ) ;
162+
163+ try {
164+ await sentryHandle ( {
165+ event : mockEvent ( ) ,
166+ resolve : async _ => {
167+ // simulateing a nested load call:
168+ await sentryHandle ( {
169+ event : mockEvent ( { route : { id : 'api/users/details/[id]' } } ) ,
170+ resolve : resolve ( type , isError ) ,
171+ } ) ;
172+ return mockResponse ;
173+ } ,
174+ } ) ;
175+ } catch ( e ) {
176+ //
177+ }
178+
179+ expect ( txnCount ) . toEqual ( 1 ) ;
180+ expect ( ref ) . toBeDefined ( ) ;
181+
182+ expect ( ref . name ) . toEqual ( 'GET /users/[id]' ) ;
183+ expect ( ref . op ) . toEqual ( 'http.server' ) ;
184+ expect ( ref . status ) . toEqual ( isError ? 'internal_error' : 'ok' ) ;
185+ expect ( ref . metadata . source ) . toEqual ( 'route' ) ;
186+
187+ expect ( ref . endTimestamp ) . toBeDefined ( ) ;
188+
189+ expect ( ref . spanRecorder . spans ) . toHaveLength ( 2 ) ;
190+ expect ( ref . spanRecorder . spans ) . toEqual (
191+ expect . arrayContaining ( [
192+ expect . objectContaining ( { op : 'http.server' , description : 'GET /users/[id]' } ) ,
193+ expect . objectContaining ( { op : 'http.server' , description : 'GET api/users/details/[id]' } ) ,
194+ ] ) ,
195+ ) ;
152196 } ) ;
153197
154198 it ( 'creates a transaction from sentry-trace header' , async ( ) => {
0 commit comments