File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -168,6 +168,21 @@ export function normalizeRequestArgs(
168168 requestOptions = urlToOptions ( requestArgs [ 0 ] ) ;
169169 } else {
170170 requestOptions = requestArgs [ 0 ] ;
171+
172+ try {
173+ const parsed = new URL (
174+ requestOptions . path || '' ,
175+ `${ requestOptions . protocol || 'http:' } //${ requestOptions . hostname } ` ,
176+ ) ;
177+ requestOptions = {
178+ pathname : parsed . pathname ,
179+ search : parsed . search ,
180+ hash : parsed . hash ,
181+ ...requestOptions ,
182+ } ;
183+ } catch ( e ) {
184+ // ignore
185+ }
171186 }
172187
173188 // 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', () => {
298298 expect ( spans [ 1 ] . data [ 'http.fragment' ] ) . toEqual ( 'learn-more' ) ;
299299 } ) ;
300300
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+
301320 it . each ( [
302321 [ 'user:pwd' , '[Filtered]:[Filtered]@' ] ,
303322 [ 'user:' , '[Filtered]:@' ] ,
You can’t perform that action at this time.
0 commit comments