File tree 2 files changed +29
-0
lines changed 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -168,6 +168,16 @@ export function normalizeRequestArgs(
168
168
requestOptions = urlToOptions ( requestArgs [ 0 ] ) ;
169
169
} else {
170
170
requestOptions = requestArgs [ 0 ] ;
171
+
172
+ if ( ! requestOptions . pathname || ! requestOptions . search ) {
173
+ const parsed = new URL (
174
+ requestOptions . path || '' ,
175
+ `${ requestOptions . protocol || 'http:' } //${ requestOptions . hostname } ` ,
176
+ ) ;
177
+ requestOptions . pathname = parsed . pathname ;
178
+ requestOptions . search = parsed . search ;
179
+ requestOptions . hash = parsed . hash ;
180
+ }
171
181
}
172
182
173
183
// if the options were given separately from the URL, fold them in
Original file line number Diff line number Diff line change @@ -298,6 +298,25 @@ describe('tracing', () => {
298
298
expect ( spans [ 1 ] . data [ 'http.fragment' ] ) . toEqual ( 'learn-more' ) ;
299
299
} ) ;
300
300
301
+ it ( 'fills in span data from http.RequestOptions object' , ( ) => {
302
+ nock ( 'http://dogs.are.great' ) . get ( '/spaniel?tail=wag&cute=true#learn-more' ) . reply ( 200 ) ;
303
+
304
+ const transaction = createTransactionOnScope ( ) ;
305
+ const spans = ( transaction as unknown as Span ) . spanRecorder ?. spans as Span [ ] ;
306
+
307
+ http . request ( { method : 'GET' , host : 'dogs.are.great' , path : '/spaniel?tail=wag&cute=true#learn-more' } ) ;
308
+
309
+ expect ( spans . length ) . toEqual ( 2 ) ;
310
+
311
+ // our span is at index 1 because the transaction itself is at index 0
312
+ expect ( spans [ 1 ] . description ) . toEqual ( 'GET http://dogs.are.great/spaniel' ) ;
313
+ expect ( spans [ 1 ] . op ) . toEqual ( 'http.client' ) ;
314
+ expect ( spans [ 1 ] . data [ 'http.method' ] ) . toEqual ( 'GET' ) ;
315
+ expect ( spans [ 1 ] . data . url ) . toEqual ( 'http://dogs.are.great/spaniel' ) ;
316
+ expect ( spans [ 1 ] . data [ 'http.query' ] ) . toEqual ( 'tail=wag&cute=true' ) ;
317
+ expect ( spans [ 1 ] . data [ 'http.fragment' ] ) . toEqual ( 'learn-more' ) ;
318
+ } ) ;
319
+
301
320
it . each ( [
302
321
[ 'user:pwd' , '[Filtered]:[Filtered]@' ] ,
303
322
[ 'user:' , '[Filtered]:@' ] ,
You can’t perform that action at this time.
0 commit comments