Skip to content
Open
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
10 changes: 6 additions & 4 deletions ddtrace/_trace/trace_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,8 @@ def _on_aiokafka_send_start(
span._set_attribute(SPAN_KIND, SpanKind.PRODUCER)
span._set_attribute(TOMBSTONE, str(send_value is None))
span.set_tag(MESSAGE_KEY, send_key.decode("utf-8") if send_key else None)
span._set_attribute(PARTITION, partition or -1)
if partition is not None:
span._set_attribute(PARTITION, partition)
span._set_attribute(_SPAN_MEASURED_KEY, 1)

if config.aiokafka.distributed_tracing_enabled:
Expand Down Expand Up @@ -1396,16 +1397,17 @@ def _on_aiokafka_getone_message(

if message is not None:
message_key = message.key.decode("utf-8") if message.key else None
message_offset = message.offset or -1
topic = str(message.topic)
span._set_attribute(TOPIC, topic)
span._set_attribute(TOMBSTONE, str(message.value is None))

if isinstance(message_key, str):
span.set_tag(MESSAGE_KEY, message_key)

span._set_attribute(PARTITION, message.partition or -1)
span._set_attribute(MESSAGE_OFFSET, message_offset)
if message.partition is not None:
span._set_attribute(PARTITION, message.partition)
if message.offset is not None:
span._set_attribute(MESSAGE_OFFSET, message.offset)

if err is not None:
span.set_exc_info(type(err), err, err.__traceback__)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
fixes:
- |
aiokafka: Fixes ``kafka.partition`` and ``kafka.message_offset`` span tags
being incorrectly set to ``-1``. Consumer spans no longer misreport ``0``
(e.g. single-partition topics or the first message in a partition) due to
falsy evaluation. Producer spans and any span where the value is genuinely
unknown now omit these tags entirely rather than emitting a misleading ``-1``.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"_dd.top_level": 1.0,
"_dd.tracer_kr": 1.0,
"_sampling_priority_v1": 1.0,
"kafka.message_offset": -1.0,
"kafka.partition": -1.0,
"kafka.message_offset": 0.0,
"kafka.partition": 0.0,
"process_id": 510.0
},
"duration": 5840561,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"_dd.top_level": 1.0,
"_dd.tracer_kr": 1.0,
"_sampling_priority_v1": 1.0,
"kafka.partition": -1.0,
"process_id": 510.0
},
"duration": 104618323,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
"_dd.top_level": 1.0,
"_dd.tracer_kr": 1.0,
"_sampling_priority_v1": 1.0,
"kafka.message_offset": -1.0,
"kafka.partition": -1.0,
"kafka.message_offset": 0.0,
"kafka.partition": 0.0,
"process_id": 510.0
},
"duration": 2732458,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"_dd.top_level": 1.0,
"_dd.tracer_kr": 1.0,
"_sampling_priority_v1": 1.0,
"kafka.message_offset": -1.0,
"kafka.partition": -1.0,
"kafka.message_offset": 0.0,
"kafka.partition": 0.0,
"process_id": 510.0
},
"duration": 4094210,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"_dd.top_level": 1.0,
"_dd.tracer_kr": 1.0,
"_sampling_priority_v1": 1.0,
"kafka.message_offset": -1.0,
"kafka.partition": -1.0,
"kafka.message_offset": 0.0,
"kafka.partition": 0.0,
"process_id": 510.0
},
"duration": 3528046,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"_dd.top_level": 1.0,
"_dd.tracer_kr": 1.0,
"_sampling_priority_v1": 1.0,
"kafka.message_offset": -1.0,
"kafka.partition": -1.0,
"kafka.message_offset": 0.0,
"kafka.partition": 0.0,
"process_id": 510.0
},
"duration": 2561725,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@
"_dd.top_level": 1.0,
"_dd.tracer_kr": 1.0,
"_sampling_priority_v1": 1.0,
"kafka.message_offset": -1.0,
"kafka.partition": -1.0,
"kafka.message_offset": 0.0,
"kafka.partition": 0.0,
"process_id": 510.0
},
"duration": 1800834,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"_dd.top_level": 1.0,
"_dd.tracer_kr": 1.0,
"_sampling_priority_v1": 1.0,
"kafka.message_offset": -1.0,
"kafka.partition": -1.0,
"kafka.message_offset": 0.0,
"kafka.partition": 0.0,
"process_id": 510.0
},
"duration": 2675113,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
"_dd.top_level": 1.0,
"_dd.tracer_kr": 1.0,
"_sampling_priority_v1": 1.0,
"kafka.message_offset": -1.0,
"kafka.partition": -1.0,
"kafka.message_offset": 0.0,
"kafka.partition": 0.0,
"process_id": 648.0
},
"duration": 499024,
Expand Down
Loading