@@ -14,7 +14,7 @@ import { LRUMap } from 'lru_map';
1414
1515import  type  {  NodeClient  }  from  '../client' ; 
1616import  type  {  RequestMethod ,  RequestMethodArgs  }  from  './utils/http' ; 
17- import  {  cleanSpanDescription ,  extractUrl ,  isSentryRequest ,  normalizeRequestArgs  }  from  './utils/http' ; 
17+ import  {  cleanSpanDescription ,  extractRawUrl ,   extractUrl ,  isSentryRequest ,  normalizeRequestArgs  }  from  './utils/http' ; 
1818
1919const  NODE_VERSION  =  parseSemver ( process . versions . node ) ; 
2020
@@ -129,6 +129,16 @@ type OriginalRequestMethod = RequestMethod;
129129type  WrappedRequestMethod  =  RequestMethod ; 
130130type  WrappedRequestMethodFactory  =  ( original : OriginalRequestMethod )  =>  WrappedRequestMethod ; 
131131
132+ /** 
133+  * See https://develop.sentry.dev/sdk/data-handling/#structuring-data 
134+  */ 
135+ type  RequestSpanData  =  { 
136+   url : string ; 
137+   method : string ; 
138+   'http.fragment' ?: string ; 
139+   'http.query' ?: string ; 
140+ } ; 
141+ 
132142/** 
133143 * Function which creates a function which creates wrapped versions of internal `request` and `get` calls within `http` 
134144 * and `https` modules. (NB: Not a typo - this is a creator^2!) 
@@ -180,6 +190,8 @@ function _createWrappedRequestMethodFactory(
180190    return  function  wrappedMethod ( this : unknown ,  ...args : RequestMethodArgs ) : http . ClientRequest  { 
181191      const  requestArgs  =  normalizeRequestArgs ( httpModule ,  args ) ; 
182192      const  requestOptions  =  requestArgs [ 0 ] ; 
193+       // eslint-disable-next-line deprecation/deprecation 
194+       const  rawRequestUrl  =  extractRawUrl ( requestOptions ) ; 
183195      const  requestUrl  =  extractUrl ( requestOptions ) ; 
184196
185197      // we don't want to record requests to Sentry as either breadcrumbs or spans, so just use the original method 
@@ -192,16 +204,30 @@ function _createWrappedRequestMethodFactory(
192204
193205      const  scope  =  getCurrentHub ( ) . getScope ( ) ; 
194206
195-       if  ( scope  &&  tracingOptions  &&  shouldCreateSpan ( requestUrl ) )  { 
207+       const  requestSpanData : RequestSpanData  =  { 
208+         url : requestUrl , 
209+         method : requestOptions . method  ||  'GET' , 
210+       } ; 
211+       if  ( requestOptions . hash )  { 
212+         // strip leading "#" 
213+         requestSpanData [ 'http.fragment' ]  =  requestOptions . hash . substring ( 1 ) ; 
214+       } 
215+       if  ( requestOptions . search )  { 
216+         // strip leading "?" 
217+         requestSpanData [ 'http.query' ]  =  requestOptions . search . substring ( 1 ) ; 
218+       } 
219+ 
220+       if  ( scope  &&  tracingOptions  &&  shouldCreateSpan ( rawRequestUrl ) )  { 
196221        parentSpan  =  scope . getSpan ( ) ; 
197222
198223        if  ( parentSpan )  { 
199224          requestSpan  =  parentSpan . startChild ( { 
200-             description : `${ requestOptions . method   ||   'GET' } ${ requestUrl }  , 
225+             description : `${ requestSpanData . method } ${ requestSpanData . url }  , 
201226            op : 'http.client' , 
227+             data : requestSpanData , 
202228          } ) ; 
203229
204-           if  ( shouldAttachTraceData ( requestUrl ) )  { 
230+           if  ( shouldAttachTraceData ( rawRequestUrl ) )  { 
205231            const  sentryTraceHeader  =  requestSpan . toTraceparent ( ) ; 
206232            __DEBUG_BUILD__  && 
207233              logger . log ( 
@@ -253,7 +279,7 @@ function _createWrappedRequestMethodFactory(
253279          // eslint-disable-next-line @typescript-eslint/no-this-alias 
254280          const  req  =  this ; 
255281          if  ( breadcrumbsEnabled )  { 
256-             addRequestBreadcrumb ( 'response' ,  requestUrl ,  req ,  res ) ; 
282+             addRequestBreadcrumb ( 'response' ,  requestSpanData ,  req ,  res ) ; 
257283          } 
258284          if  ( requestSpan )  { 
259285            if  ( res . statusCode )  { 
@@ -268,7 +294,7 @@ function _createWrappedRequestMethodFactory(
268294          const  req  =  this ; 
269295
270296          if  ( breadcrumbsEnabled )  { 
271-             addRequestBreadcrumb ( 'error' ,  requestUrl ,  req ) ; 
297+             addRequestBreadcrumb ( 'error' ,  requestSpanData ,  req ) ; 
272298          } 
273299          if  ( requestSpan )  { 
274300            requestSpan . setHttpStatus ( 500 ) ; 
@@ -283,7 +309,12 @@ function _createWrappedRequestMethodFactory(
283309/** 
284310 * Captures Breadcrumb based on provided request/response pair 
285311 */ 
286- function  addRequestBreadcrumb ( event : string ,  url : string ,  req : http . ClientRequest ,  res ?: http . IncomingMessage ) : void { 
312+ function  addRequestBreadcrumb ( 
313+   event : string , 
314+   requestSpanData : RequestSpanData , 
315+   req : http . ClientRequest , 
316+   res ?: http . IncomingMessage , 
317+ ) : void { 
287318  if  ( ! getCurrentHub ( ) . getIntegration ( Http ) )  { 
288319    return ; 
289320  } 
@@ -294,7 +325,7 @@ function addRequestBreadcrumb(event: string, url: string, req: http.ClientReques
294325      data : { 
295326        method : req . method , 
296327        status_code : res  &&  res . statusCode , 
297-         url , 
328+         ... requestSpanData , 
298329      } , 
299330      type : 'http' , 
300331    } , 
0 commit comments