Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added producer timeslice metrics from otel #2939

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/otel/segments/producer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@
ATTR_MESSAGING_SYSTEM
} = require('../constants')

const genericRecorder = require('../../metrics/recorders/generic')

module.exports = function createProducerSegment(agent, otelSpan) {
const context = agent.tracer.getContext()
const name = setName(otelSpan)

Check warning on line 19 in lib/otel/segments/producer.js

View check run for this annotation

Codecov / codecov/patch

lib/otel/segments/producer.js#L19

Added line #L19 was not covered by tests
const segment = agent.tracer.createSegment({
name,
recorder: genericRecorder,

Check warning on line 22 in lib/otel/segments/producer.js

View check run for this annotation

Codecov / codecov/patch

lib/otel/segments/producer.js#L22

Added line #L22 was not covered by tests
parent: context.segment,
transaction: context.transaction
})
Expand Down
32 changes: 31 additions & 1 deletion test/versioned/otel-bridge/span.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const {
ATTR_HTTP_METHOD,
ATTR_HTTP_REQUEST_METHOD,
ATTR_HTTP_ROUTE,
ATTR_MESSAGING_DESTINATION,
ATTR_MESSAGING_DESTINATION_KIND,
ATTR_MESSAGING_SYSTEM,
ATTR_NET_PEER_NAME,
ATTR_NET_PEER_PORT,
ATTR_RPC_METHOD,
Expand All @@ -29,7 +32,8 @@ const {
ATTR_SERVER_ADDRESS,
ATTR_URL_PATH,
ATTR_URL_SCHEME,
DB_SYSTEM_VALUES
DB_SYSTEM_VALUES,
MESSAGING_SYSTEM_KIND_VALUES
} = require('../../../lib/otel/constants.js')

test.beforeEach((ctx) => {
Expand Down Expand Up @@ -353,3 +357,29 @@ test('fallback metrics are bridged correctly', (t, end) => {
end()
})
})

test('Otel producer span test', (t, end) => {
const { agent, tracer } = t.nr
const attributes = {
[ATTR_MESSAGING_SYSTEM]: 'messaging-lib',
[ATTR_MESSAGING_DESTINATION_KIND]: MESSAGING_SYSTEM_KIND_VALUES.QUEUE,
[ATTR_MESSAGING_DESTINATION]: 'test-queue'
}
helper.runInTransaction(agent, (tx) => {
tx.name = 'prod-test'
tracer.startActiveSpan('prod-test', { kind: otel.SpanKind.PRODUCER, attributes }, (span) => {
const segment = agent.tracer.getSegment()
assert.equal(segment.name, 'MessageBroker/messaging-lib/queue/Produce/Named/test-queue')
span.end()
const duration = hrTimeToMilliseconds(span.duration)
assert.equal(duration, segment.getDurationInMillis())
tx.end()
const metrics = tx.metrics.scoped[tx.name]
assert.equal(metrics['MessageBroker/messaging-lib/queue/Produce/Named/test-queue'].callCount, 1)
const unscopedMetrics = tx.metrics.unscoped
assert.equal(unscopedMetrics['MessageBroker/messaging-lib/queue/Produce/Named/test-queue'].callCount, 1)
jsumners-nr marked this conversation as resolved.
Show resolved Hide resolved

end()
})
})
})
Loading