Skip to content

Commit

Permalink
[DSM] Add messaging.destination tag to spans so they show up in queue…
Browse files Browse the repository at this point in the history
… pages
  • Loading branch information
ericfirth committed Feb 10, 2025
1 parent adbba87 commit dc52d7d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
5 changes: 4 additions & 1 deletion packages/datadog-plugin-kafkajs/src/consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const ConsumerPlugin = require('../../dd-trace/src/plugins/consumer')
const afterStartCh = dc.channel('dd-trace:kafkajs:consumer:afterStart')
const beforeFinishCh = dc.channel('dd-trace:kafkajs:consumer:beforeFinish')

const MESSAGING_DESTINATION_KEY = 'messaging.destination'

class KafkajsConsumerPlugin extends ConsumerPlugin {
static get id () { return 'kafkajs' }
static get operation () { return 'consume' }
Expand Down Expand Up @@ -72,7 +74,8 @@ class KafkajsConsumerPlugin extends ConsumerPlugin {
component: 'kafkajs',
'kafka.topic': topic,
'kafka.message.offset': message.offset,
'kafka.cluster_id': clusterId
'kafka.cluster_id': clusterId,
[MESSAGING_DESTINATION_KEY]: topic
},
metrics: {
'kafka.partition': partition
Expand Down
4 changes: 3 additions & 1 deletion packages/datadog-plugin-kafkajs/src/producer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { DsmPathwayCodec } = require('../../dd-trace/src/datastreams/pathway')
const { getMessageSize } = require('../../dd-trace/src/datastreams/processor')

const BOOTSTRAP_SERVERS_KEY = 'messaging.kafka.bootstrap.servers'
const MESSAGING_DESTINATION_KEY = 'messaging.destination'

class KafkajsProducerPlugin extends ProducerPlugin {
static get id () { return 'kafkajs' }
Expand Down Expand Up @@ -72,7 +73,8 @@ class KafkajsProducerPlugin extends ProducerPlugin {
meta: {
component: 'kafkajs',
'kafka.topic': topic,
'kafka.cluster_id': clusterId
'kafka.cluster_id': clusterId,
[MESSAGING_DESTINATION_KEY]: topic
},
metrics: {
'kafka.batch_size': messages.length
Expand Down
7 changes: 5 additions & 2 deletions packages/datadog-plugin-kafkajs/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ describe('Plugin', () => {
const meta = {
'span.kind': 'producer',
component: 'kafkajs',
'pathway.hash': expectedProducerHash.readBigUInt64BE(0).toString()
'pathway.hash': expectedProducerHash.readBigUInt64BE(0).toString(),
'messaging.destination': 'test-topic',
'messaging.kafka.bootstrap.servers': '127.0.0.1:9092'
}
if (clusterIdAvailable) meta['kafka.cluster_id'] = testKafkaClusterId

Expand Down Expand Up @@ -182,7 +184,8 @@ describe('Plugin', () => {
meta: {
'span.kind': 'consumer',
component: 'kafkajs',
'pathway.hash': expectedConsumerHash.readBigUInt64BE(0).toString()
'pathway.hash': expectedConsumerHash.readBigUInt64BE(0).toString(),
'messaging.destination': 'test-topic'
},
resource: testTopic,
error: 0,
Expand Down

0 comments on commit dc52d7d

Please sign in to comment.