Skip to content

Commit 2984b59

Browse files
fix(kafka): do identity checks on kafka messages to work around... [backport 2.7] (#8712)
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 - [x] Testing strategy is described if automated tests are not included in the PR - [x] Risks are described (performance impact, potential for breakage, maintainability) - [x] Change is maintainable (easy to change, telemetry, documentation) - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed or label `changelog/no-changelog` is set - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)) - [x] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) - [x] If this PR changes the public interface, I've notified `@DataDog/apm-tees`. - [x] If change touches code that signs or publishes builds or packages, or handles credentials of any kind, I've requested a review from `@DataDog/security-design-and-guidance`. ## Reviewer Checklist - [x] Title is accurate - [x] All changes are related to the pull request's stated goal - [x] Description motivates each change - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - [x] Testing strategy adequately addresses listed risks - [x] Change is maintainable (easy to change, telemetry, documentation) - [x] Release note makes sense to a user of the library - [x] Author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - [x] Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) Co-authored-by: Tahir H. Butt <[email protected]>
1 parent c927d02 commit 2984b59

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)