@@ -16,7 +16,8 @@ const {
16
16
} = require ( '@opentelemetry/api' ) ;
17
17
const { Resource } = require ( '@opentelemetry/resources' ) ;
18
18
const {
19
- SemanticResourceAttributes
19
+ SemanticResourceAttributes,
20
+ SemanticAttributes
20
21
} = require ( '@opentelemetry/semantic-conventions' ) ;
21
22
22
23
const {
@@ -363,7 +364,11 @@ class OTelReporter {
363
364
userContext . scenario ?. name || `artillery-${ engine } -scenario` ,
364
365
{
365
366
startTime : Date . now ( ) ,
366
- kind : SpanKind . CLIENT
367
+ kind : SpanKind . CLIENT ,
368
+ attributes : {
369
+ 'vu.uuid' : userContext . vars . $uuid ,
370
+ [ SemanticAttributes . PEER_SERVICE ] : this . config . serviceName
371
+ }
367
372
}
368
373
) ;
369
374
@@ -397,11 +402,28 @@ class OTelReporter {
397
402
this . traceConfig . useRequestNames && req . name
398
403
? req . name
399
404
: req . method . toLowerCase ( ) ;
405
+
406
+ const url = new URL ( req . url ) ;
407
+ let parsedUrl ;
408
+ if ( url . username || url . password ) {
409
+ parsedUrl = url . origin + url . pathname + url . search + url . hash ;
410
+ }
400
411
const span = this . httpTracer . startSpan ( spanName , {
401
412
startTime,
402
413
kind : SpanKind . CLIENT ,
403
- attributes : { 'vu.uuid' : userContext . $uuid }
414
+ attributes : {
415
+ 'vu.uuid' : userContext . vars . $uuid ,
416
+ [ SemanticAttributes . HTTP_URL ] : parsedUrl || url . href ,
417
+
418
+ // We set the port if it is specified, if not we set to a default port based on the protocol
419
+ [ SemanticAttributes . HTTP_SCHEME ] :
420
+ url . port || ( url . protocol === 'http' ? 80 : 443 ) ,
421
+ [ SemanticAttributes . HTTP_METHOD ] : req . method ,
422
+ [ SemanticAttributes . NET_HOST_NAME ] : url . hostname ,
423
+ ...( this . traceConfig . attributes || { } )
424
+ }
404
425
} ) ;
426
+
405
427
userContext . vars [ '__otlpHTTPRequestSpan' ] = span ;
406
428
407
429
events . on ( 'error' , ( err ) => {
@@ -449,7 +471,8 @@ class OTelReporter {
449
471
this . httpTracer
450
472
. startSpan ( name , {
451
473
kind : SpanKind . CLIENT ,
452
- startTime : res . timings [ value . start ]
474
+ startTime : res . timings [ value . start ] ,
475
+ attributes : { 'vu.uuid' : userContext . vars . $uuid }
453
476
} )
454
477
. end ( res . timings [ value . end ] ) ;
455
478
}
@@ -459,23 +482,22 @@ class OTelReporter {
459
482
}
460
483
461
484
try {
462
- const url = new URL ( req . url ) ;
463
485
span . setAttributes ( {
464
- 'url.full' : url . href ,
465
- 'url.path' : url . pathname ,
466
- 'server.address' : url . hostname ,
467
- // We set the port if it is specified, if not we set to a default port based on the protocol
468
- 'server.port' : url . port || ( url . protocol === 'http' ? 80 : 443 ) ,
469
- 'http.request.method' : req . method ,
470
- 'http.response.status_code' : res . statusCode
486
+ [ SemanticAttributes . HTTP_STATUS_CODE ] : res . statusCode ,
487
+ [ SemanticAttributes . HTTP_REQUEST_CONTENT_LENGTH ] :
488
+ res . request . options . headers [ 'content-length' ] ,
489
+ [ SemanticAttributes . HTTP_FLAVOR ] : res . httpVersion ,
490
+ [ SemanticAttributes . HTTP_USER_AGENT ] :
491
+ res . request . options . headers [ 'user-agent' ]
471
492
} ) ;
472
493
473
494
if ( res . statusCode >= 400 ) {
474
- span . setStatus ( { code : SpanStatusCode . ERROR } ) ;
475
- }
476
- if ( this . traceConfig ?. attributes ) {
477
- span . setAttributes ( this . traceConfig . attributes ) ;
495
+ span . setStatus ( {
496
+ code : SpanStatusCode . ERROR ,
497
+ message : res . statusMessage
498
+ } ) ;
478
499
}
500
+
479
501
span . end ( endTime || Date . now ( ) ) ;
480
502
} catch ( err ) {
481
503
// We don't do anything, if error occurs at this point it will be due to us already ending the span in beforeRequest hook in case of an error.
0 commit comments