Skip to content

Commit f226ae6

Browse files
authored
fix(kafka): do identity checks on kafka messages to work around... [backport 2.6] (#8716)
This pull request fixes #8602 by changing `if message` tests in the Kafka contrib to `if message is not None`. This avoids the runtime calling `__len__` on the message object, which is not guaranteed by confluent-kafka to be defined. ## Checklist - [x] Change(s) are motivated and described in the PR description
1 parent 6b9e84e commit f226ae6

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

ddtrace/contrib/kafka/patch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ def traced_poll(func, instance, args, kwargs):
209209
except Exception as e:
210210
err = e
211211
ctx = None
212-
if message and config.kafka.distributed_tracing_enabled and message.headers():
212+
if message is not None and config.kafka.distributed_tracing_enabled and message.headers():
213213
ctx = Propagator.extract(dict(message.headers()))
214-
if message or config.kafka.trace_empty_poll_enabled:
214+
if message is not None or config.kafka.trace_empty_poll_enabled:
215215
with pin.tracer.start_span(
216216
name=schematize_messaging_operation(kafkax.CONSUME, provider="kafka", direction=SpanDirection.PROCESSING),
217217
service=trace_utils.ext_service(pin, config.kafka),
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
kafka: This fix resolves an issue where ``None`` messages from confluent-kafka could cause crashes in the Kafka integration.

0 commit comments

Comments
 (0)