Skip to content

Commit 6832637

Browse files
feat: Added producer timeslice metrics from otel (#2939)
1 parent f404585 commit 6832637

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

lib/otel/segments/producer.js

+4
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ const {
1111
ATTR_MESSAGING_SYSTEM
1212
} = require('../constants')
1313

14+
const genericRecorder = require('../../metrics/recorders/generic')
15+
1416
module.exports = function createProducerSegment(agent, otelSpan) {
1517
const context = agent.tracer.getContext()
1618
const name = setName(otelSpan)
19+
1720
const segment = agent.tracer.createSegment({
1821
name,
22+
recorder: genericRecorder,
1923
parent: context.segment,
2024
transaction: context.transaction
2125
})

test/versioned/otel-bridge/span.test.js

+31-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ const {
2121
ATTR_HTTP_METHOD,
2222
ATTR_HTTP_REQUEST_METHOD,
2323
ATTR_HTTP_ROUTE,
24+
ATTR_MESSAGING_DESTINATION,
25+
ATTR_MESSAGING_DESTINATION_KIND,
26+
ATTR_MESSAGING_SYSTEM,
2427
ATTR_NET_PEER_NAME,
2528
ATTR_NET_PEER_PORT,
2629
ATTR_RPC_METHOD,
@@ -29,7 +32,8 @@ const {
2932
ATTR_SERVER_ADDRESS,
3033
ATTR_URL_PATH,
3134
ATTR_URL_SCHEME,
32-
DB_SYSTEM_VALUES
35+
DB_SYSTEM_VALUES,
36+
MESSAGING_SYSTEM_KIND_VALUES
3337
} = require('../../../lib/otel/constants.js')
3438

3539
test.beforeEach((ctx) => {
@@ -353,3 +357,29 @@ test('fallback metrics are bridged correctly', (t, end) => {
353357
end()
354358
})
355359
})
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

Comments
 (0)