@@ -167,11 +167,8 @@ export const isIgnored = (
167
167
export const setSpanWithError = ( span : Span , error : Err ) : void => {
168
168
const message = error . message ;
169
169
170
- span . setAttributes ( {
171
- [ AttributeNames . HTTP_ERROR_NAME ] : error . name ,
172
- [ AttributeNames . HTTP_ERROR_MESSAGE ] : message ,
173
- } ) ;
174
-
170
+ span . setAttribute ( AttributeNames . HTTP_ERROR_NAME , error . name ) ;
171
+ span . setAttribute ( AttributeNames . HTTP_ERROR_MESSAGE , message ) ;
175
172
span . setStatus ( { code : SpanStatusCode . ERROR , message } ) ;
176
173
span . recordException ( error ) ;
177
174
} ;
@@ -371,7 +368,7 @@ export const getOutgoingRequestAttributes = (
371
368
[ SEMATTRS_HTTP_METHOD ] : method ,
372
369
[ SEMATTRS_HTTP_TARGET ] : requestOptions . path || '/' ,
373
370
[ SEMATTRS_NET_PEER_NAME ] : hostname ,
374
- [ SEMATTRS_HTTP_HOST ] : requestOptions . headers ? .host ?? `${ hostname } :${ port } ` ,
371
+ [ SEMATTRS_HTTP_HOST ] : headers . host ?? `${ hostname } :${ port } ` ,
375
372
} ;
376
373
377
374
if ( userAgent !== undefined ) {
@@ -399,8 +396,10 @@ export const getOutgoingRequestMetricAttributes = (
399
396
* Returns attributes related to the kind of HTTP protocol used
400
397
* @param {string } [kind] Kind of HTTP protocol used: "1.0", "1.1", "2", "SPDY" or "QUIC".
401
398
*/
402
- export const getAttributesFromHttpKind = ( kind ?: string ) : SpanAttributes => {
403
- const attributes : SpanAttributes = { } ;
399
+ export const setAttributesFromHttpKind = (
400
+ kind : string | undefined ,
401
+ attributes : SpanAttributes
402
+ ) : void => {
404
403
if ( kind ) {
405
404
attributes [ SEMATTRS_HTTP_FLAVOR ] = kind ;
406
405
if ( kind . toUpperCase ( ) !== 'QUIC' ) {
@@ -409,7 +408,6 @@ export const getAttributesFromHttpKind = (kind?: string): SpanAttributes => {
409
408
attributes [ SEMATTRS_NET_TRANSPORT ] = NETTRANSPORTVALUES_IP_UDP ;
410
409
}
411
410
}
412
- return attributes ;
413
411
} ;
414
412
415
413
/**
@@ -436,8 +434,8 @@ export const getOutgoingRequestAttributesOnResponse = (
436
434
) . toUpperCase ( ) ;
437
435
}
438
436
439
- const httpKindAttributes = getAttributesFromHttpKind ( httpVersion ) ;
440
- return Object . assign ( attributes , httpKindAttributes ) ;
437
+ setAttributesFromHttpKind ( httpVersion , attributes ) ;
438
+ return attributes ;
441
439
} ;
442
440
443
441
/**
@@ -509,9 +507,8 @@ export const getIncomingRequestAttributes = (
509
507
attributes [ SEMATTRS_HTTP_USER_AGENT ] = userAgent ;
510
508
}
511
509
setRequestContentLengthAttribute ( request , attributes ) ;
512
-
513
- const httpKindAttributes = getAttributesFromHttpKind ( httpVersion ) ;
514
- return Object . assign ( attributes , httpKindAttributes , options . hookAttributes ) ;
510
+ setAttributesFromHttpKind ( httpVersion , attributes ) ;
511
+ return Object . assign ( attributes , options . hookAttributes ) ;
515
512
} ;
516
513
517
514
/**
@@ -584,24 +581,24 @@ export const getIncomingRequestMetricAttributesOnResponse = (
584
581
} ;
585
582
586
583
export function headerCapture ( type : 'request' | 'response' , headers : string [ ] ) {
587
- const normalizedHeaders = new Map (
588
- headers . map ( header => [
589
- header . toLowerCase ( ) ,
590
- header . toLowerCase ( ) . replace ( / - / g, '_' ) ,
591
- ] )
592
- ) ;
584
+ const normalizedHeaders = new Map < string , string > ( ) ;
585
+ for ( let i = 0 , len = headers . length ; i < len ; i ++ ) {
586
+ const capturedHeader = headers [ i ] . toLowerCase ( ) ;
587
+ normalizedHeaders . set ( capturedHeader , capturedHeader . replace ( / - / g, '_' ) ) ;
588
+ }
593
589
594
590
return (
595
591
span : Span ,
596
592
getHeader : ( key : string ) => undefined | string | string [ ] | number
597
593
) => {
598
- for ( const [ capturedHeader , normalizedHeader ] of normalizedHeaders ) {
594
+ for ( const capturedHeader of normalizedHeaders . keys ( ) ) {
599
595
const value = getHeader ( capturedHeader ) ;
600
596
601
597
if ( value === undefined ) {
602
598
continue ;
603
599
}
604
600
601
+ const normalizedHeader = normalizedHeaders . get ( capturedHeader ) ;
605
602
const key = `http.${ type } .header.${ normalizedHeader } ` ;
606
603
607
604
if ( typeof value === 'string' ) {
0 commit comments