Skip to content

Commit a51552c

Browse files
committed
fix(instrumentation-kafkajs): check for definedness, not truthiness on partition IDs
a message with a partition ID of `0` should now have the proper attribute set
1 parent c6606a1 commit a51552c

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

plugins/node/instrumentation-kafkajs/src/instrumentation.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ export class KafkaJsInstrumentation extends InstrumentationBase<KafkaJsInstrumen
516516
[ATTR_MESSAGING_SYSTEM]: MESSAGING_SYSTEM_VALUE_KAFKA,
517517
[ATTR_MESSAGING_OPERATION_NAME]: 'send',
518518
[ATTR_MESSAGING_DESTINATION_NAME]: topicMessage.topic,
519-
...(message.partition
519+
...(message.partition !== undefined
520520
? {
521521
[ATTR_MESSAGING_DESTINATION_PARTITION_ID]: String(
522522
message.partition
@@ -557,7 +557,7 @@ export class KafkaJsInstrumentation extends InstrumentationBase<KafkaJsInstrumen
557557
[ATTR_MESSAGING_SYSTEM]: MESSAGING_SYSTEM_VALUE_KAFKA,
558558
[ATTR_MESSAGING_OPERATION_NAME]: 'send',
559559
[ATTR_MESSAGING_DESTINATION_NAME]: record.topic,
560-
...(m.partition
560+
...(m.partition !== undefined
561561
? {
562562
[ATTR_MESSAGING_DESTINATION_PARTITION_ID]: String(
563563
m.partition
@@ -681,9 +681,10 @@ export class KafkaJsInstrumentation extends InstrumentationBase<KafkaJsInstrumen
681681
: undefined,
682682
[ATTR_MESSAGING_KAFKA_MESSAGE_TOMBSTONE]:
683683
message.key && message.value === null ? true : undefined,
684-
[ATTR_MESSAGING_DESTINATION_PARTITION_ID]: message.partition
685-
? String(message.partition)
686-
: undefined,
684+
[ATTR_MESSAGING_DESTINATION_PARTITION_ID]:
685+
message.partition !== undefined
686+
? String(message.partition)
687+
: undefined,
687688
[ATTR_MESSAGING_OPERATION_NAME]: 'send',
688689
[ATTR_MESSAGING_OPERATION_TYPE]: MESSAGING_OPERATION_TYPE_VALUE_SEND,
689690
},

plugins/node/instrumentation-kafkajs/test/kafkajs.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,11 @@ describe('instrumentation-kafkajs', () => {
323323
topic: 'topic-name-1',
324324
messages: [
325325
{
326+
partition: 0,
326327
value: 'message1',
327328
},
328329
{
330+
partition: 0,
329331
value: 'message2',
330332
},
331333
],
@@ -352,6 +354,7 @@ describe('instrumentation-kafkajs', () => {
352354
attributes: {
353355
[ATTR_MESSAGING_SYSTEM]: MESSAGING_SYSTEM_VALUE_KAFKA,
354356
[ATTR_MESSAGING_DESTINATION_NAME]: 'topic-name-1',
357+
[ATTR_MESSAGING_DESTINATION_PARTITION_ID]: '0',
355358
[ATTR_MESSAGING_OPERATION_NAME]: 'send',
356359
},
357360
},
@@ -400,6 +403,7 @@ describe('instrumentation-kafkajs', () => {
400403
topic: 'topic-name-2',
401404
messages: [
402405
{
406+
partition: 1,
403407
value: 'message2-1',
404408
},
405409
],
@@ -435,6 +439,7 @@ describe('instrumentation-kafkajs', () => {
435439
attributes: {
436440
[ATTR_MESSAGING_SYSTEM]: MESSAGING_SYSTEM_VALUE_KAFKA,
437441
[ATTR_MESSAGING_DESTINATION_NAME]: 'topic-name-2',
442+
[ATTR_MESSAGING_DESTINATION_PARTITION_ID]: '1',
438443
[ATTR_MESSAGING_OPERATION_NAME]: 'send',
439444
},
440445
},

0 commit comments

Comments
 (0)