@@ -21,6 +21,9 @@ const {
21
21
ATTR_HTTP_METHOD ,
22
22
ATTR_HTTP_REQUEST_METHOD ,
23
23
ATTR_HTTP_ROUTE ,
24
+ ATTR_MESSAGING_DESTINATION ,
25
+ ATTR_MESSAGING_DESTINATION_KIND ,
26
+ ATTR_MESSAGING_SYSTEM ,
24
27
ATTR_NET_PEER_NAME ,
25
28
ATTR_NET_PEER_PORT ,
26
29
ATTR_RPC_METHOD ,
@@ -29,7 +32,8 @@ const {
29
32
ATTR_SERVER_ADDRESS ,
30
33
ATTR_URL_PATH ,
31
34
ATTR_URL_SCHEME ,
32
- DB_SYSTEM_VALUES
35
+ DB_SYSTEM_VALUES ,
36
+ MESSAGING_SYSTEM_KIND_VALUES
33
37
} = require ( '../../../lib/otel/constants.js' )
34
38
35
39
test . beforeEach ( ( ctx ) => {
@@ -353,3 +357,29 @@ test('fallback metrics are bridged correctly', (t, end) => {
353
357
end ( )
354
358
} )
355
359
} )
360
+
361
+ test ( 'Otel producer span test' , ( t , end ) => {
362
+ const { agent, tracer } = t . nr
363
+ const attributes = {
364
+ [ ATTR_MESSAGING_SYSTEM ] : 'messaging-lib' ,
365
+ [ ATTR_MESSAGING_DESTINATION_KIND ] : MESSAGING_SYSTEM_KIND_VALUES . QUEUE ,
366
+ [ ATTR_MESSAGING_DESTINATION ] : 'test-queue'
367
+ }
368
+ helper . runInTransaction ( agent , ( tx ) => {
369
+ tx . name = 'prod-test'
370
+ tracer . startActiveSpan ( 'prod-test' , { kind : otel . SpanKind . PRODUCER , attributes } , ( span ) => {
371
+ const segment = agent . tracer . getSegment ( )
372
+ assert . equal ( segment . name , 'MessageBroker/messaging-lib/queue/Produce/Named/test-queue' )
373
+ span . end ( )
374
+ const duration = hrTimeToMilliseconds ( span . duration )
375
+ assert . equal ( duration , segment . getDurationInMillis ( ) )
376
+ tx . end ( )
377
+ const metrics = tx . metrics . scoped [ tx . name ]
378
+ assert . equal ( metrics [ 'MessageBroker/messaging-lib/queue/Produce/Named/test-queue' ] . callCount , 1 )
379
+ const unscopedMetrics = tx . metrics . unscoped
380
+ assert . equal ( unscopedMetrics [ 'MessageBroker/messaging-lib/queue/Produce/Named/test-queue' ] . callCount , 1 )
381
+
382
+ end ( )
383
+ } )
384
+ } )
385
+ } )
0 commit comments