@@ -192,13 +192,28 @@ function _createWrappedRequestMethodFactory(
192192
193193 const scope = getCurrentHub ( ) . getScope ( ) ;
194194
195+ const spanData : Record < string , string > = {
196+ url : requestUrl ,
197+ method : requestOptions . method || 'GET' ,
198+ } ;
199+ if ( requestOptions . hash ) {
200+ // strip leading "#"
201+ spanData [ 'http.fragment' ] = requestOptions . hash . substring ( 1 ) ;
202+ }
203+ if ( requestOptions . search ) {
204+ // strip leading "?"
205+ spanData [ 'http.query' ] = requestOptions . search . substring ( 1 ) ;
206+ }
207+
208+ // TODO potential breaking change... shouldCreateSpanForRequest no longer has access to query + fragment, is that a problem?
195209 if ( scope && tracingOptions && shouldCreateSpan ( requestUrl ) ) {
196210 parentSpan = scope . getSpan ( ) ;
197211
198212 if ( parentSpan ) {
199213 requestSpan = parentSpan . startChild ( {
200- description : `${ requestOptions . method || 'GET' } ${ requestUrl } ` ,
214+ description : `${ spanData . method } ${ spanData . url } ` ,
201215 op : 'http.client' ,
216+ data : spanData ,
202217 } ) ;
203218
204219 if ( shouldAttachTraceData ( requestUrl ) ) {
@@ -253,7 +268,7 @@ function _createWrappedRequestMethodFactory(
253268 // eslint-disable-next-line @typescript-eslint/no-this-alias
254269 const req = this ;
255270 if ( breadcrumbsEnabled ) {
256- addRequestBreadcrumb ( 'response' , requestUrl , req , res ) ;
271+ addRequestBreadcrumb ( 'response' , spanData , req , res ) ;
257272 }
258273 if ( requestSpan ) {
259274 if ( res . statusCode ) {
@@ -268,7 +283,7 @@ function _createWrappedRequestMethodFactory(
268283 const req = this ;
269284
270285 if ( breadcrumbsEnabled ) {
271- addRequestBreadcrumb ( 'error' , requestUrl , req ) ;
286+ addRequestBreadcrumb ( 'error' , spanData , req ) ;
272287 }
273288 if ( requestSpan ) {
274289 requestSpan . setHttpStatus ( 500 ) ;
@@ -283,7 +298,12 @@ function _createWrappedRequestMethodFactory(
283298/**
284299 * Captures Breadcrumb based on provided request/response pair
285300 */
286- function addRequestBreadcrumb ( event : string , url : string , req : http . ClientRequest , res ?: http . IncomingMessage ) : void {
301+ function addRequestBreadcrumb (
302+ event : string ,
303+ spanData : Record < string , string > ,
304+ req : http . ClientRequest ,
305+ res ?: http . IncomingMessage ,
306+ ) : void {
287307 if ( ! getCurrentHub ( ) . getIntegration ( Http ) ) {
288308 return ;
289309 }
@@ -294,7 +314,7 @@ function addRequestBreadcrumb(event: string, url: string, req: http.ClientReques
294314 data : {
295315 method : req . method ,
296316 status_code : res && res . statusCode ,
297- url ,
317+ ... spanData ,
298318 } ,
299319 type : 'http' ,
300320 } ,
0 commit comments