@@ -13,6 +13,7 @@ const { hrTimeToMilliseconds } = require('@opentelemetry/core')
13
13
const helper = require ( '../../lib/agent_helper' )
14
14
const { otelSynthesis } = require ( '../../../lib/symbols' )
15
15
16
+ const { DESTINATIONS } = require ( '../../../lib/transaction' )
16
17
const {
17
18
ATTR_DB_NAME ,
18
19
ATTR_DB_STATEMENT ,
@@ -26,6 +27,7 @@ const {
26
27
ATTR_HTTP_URL ,
27
28
ATTR_MESSAGING_DESTINATION ,
28
29
ATTR_MESSAGING_DESTINATION_KIND ,
30
+ ATTR_MESSAGING_DESTINATION_NAME ,
29
31
ATTR_MESSAGING_MESSAGE_CONVERSATION_ID ,
30
32
ATTR_MESSAGING_OPERATION ,
31
33
ATTR_MESSAGING_RABBITMQ_DESTINATION_ROUTING_KEY ,
@@ -414,12 +416,15 @@ test('Otel producer span test', (t, end) => {
414
416
415
417
test ( 'messaging consumer metrics are bridged correctly' , ( t , end ) => {
416
418
const { agent, tracer } = t . nr
419
+ const expectedHost = agent . config . getHostnameSafe ( 'localhost' )
417
420
const attributes = {
418
421
[ ATTR_MESSAGING_SYSTEM ] : 'kafka' ,
419
422
[ ATTR_MESSAGING_OPERATION ] : 'getMessage' ,
420
423
[ ATTR_SERVER_ADDRESS ] : '127.0.0.1' ,
424
+ [ ATTR_SERVER_PORT ] : '1234' ,
421
425
[ ATTR_MESSAGING_DESTINATION ] : 'work-queue' ,
422
- [ ATTR_MESSAGING_DESTINATION_KIND ] : 'queue'
426
+ [ ATTR_MESSAGING_DESTINATION_KIND ] : 'queue' ,
427
+ [ ATTR_MESSAGING_RABBITMQ_DESTINATION_ROUTING_KEY ] : 'test-key'
423
428
}
424
429
425
430
tracer . startActiveSpan ( 'consumer-test' , { kind : otel . SpanKind . CONSUMER , attributes } , ( span ) => {
@@ -444,6 +449,44 @@ test('messaging consumer metrics are bridged correctly', (t, end) => {
444
449
assert . equal ( unscopedMetrics [ expectedMetric ] . callCount , 1 , `${ expectedMetric } .callCount` )
445
450
}
446
451
452
+ // Verify that required reconciled attributes are present:
453
+ let attrs = tx . baseSegment . getAttributes ( )
454
+ assert . equal ( attrs . host , expectedHost )
455
+ assert . equal ( attrs . port , '1234' )
456
+ attrs = tx . trace . attributes . get ( DESTINATIONS . TRANS_COMMON )
457
+ assert . equal ( attrs [ 'message.queueName' ] , 'work-queue' )
458
+ assert . equal ( attrs [ 'message.routingKey' ] , 'test-key' )
459
+
460
+ end ( )
461
+ } )
462
+ } )
463
+
464
+ test ( 'messaging consumer skips high security attributes' , ( t , end ) => {
465
+ const { agent, tracer } = t . nr
466
+ const expectedHost = agent . config . getHostnameSafe ( 'localhost' )
467
+ const attributes = {
468
+ [ ATTR_MESSAGING_SYSTEM ] : 'kafka' ,
469
+ [ ATTR_MESSAGING_OPERATION ] : 'getMessage' ,
470
+ [ ATTR_SERVER_ADDRESS ] : '127.0.0.1' ,
471
+ [ ATTR_SERVER_PORT ] : '1234' ,
472
+ [ ATTR_MESSAGING_DESTINATION_KIND ] : 'queue' ,
473
+ [ ATTR_MESSAGING_DESTINATION_NAME ] : 'test-queue' ,
474
+ [ ATTR_MESSAGING_RABBITMQ_DESTINATION_ROUTING_KEY ] : 'test-key'
475
+ }
476
+ agent . config . high_security = true
477
+
478
+ tracer . startActiveSpan ( 'consumer-test' , { kind : otel . SpanKind . CONSUMER , attributes } , ( span ) => {
479
+ const tx = agent . getTransaction ( )
480
+ span . end ( )
481
+
482
+ // Verify that required reconciled attributes are present:
483
+ let attrs = tx . baseSegment . getAttributes ( )
484
+ assert . equal ( attrs . host , expectedHost )
485
+ assert . equal ( attrs . port , '1234' )
486
+ attrs = tx . trace . attributes . get ( DESTINATIONS . TRANS_COMMON )
487
+ assert . equal ( attrs [ 'message.queueName' ] , undefined )
488
+ assert . equal ( attrs [ 'message.routingKey' ] , undefined )
489
+
447
490
end ( )
448
491
} )
449
492
} )
0 commit comments