@@ -129,7 +129,7 @@ describe('handleSentry', () => {
129
129
expect ( response ) . toEqual ( mockResponse ) ;
130
130
} ) ;
131
131
132
- it ( ' creates a transaction' , async ( ) => {
132
+ it ( " creates a transaction if there's no active span" , async ( ) => {
133
133
let ref : any = undefined ;
134
134
client . on ( 'finishTransaction' , ( transaction : Transaction ) => {
135
135
ref = transaction ;
@@ -149,6 +149,50 @@ describe('handleSentry', () => {
149
149
expect ( ref . metadata . source ) . toEqual ( 'route' ) ;
150
150
151
151
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
+ ) ;
152
196
} ) ;
153
197
154
198
it ( 'creates a transaction from sentry-trace header' , async ( ) => {
0 commit comments