Fix NoSuchElementException from unchecked Optional.get() in Kafka consumer instrumentation#12007
Conversation
…sumer instrumentation extractGroup, extractClusterId, and extractBootstrapServers called Optional.get() without checking isPresent()/using orElse(), which threw NoSuchElementException when the underlying consumer group, metadata, or bootstrap servers were not captured. Introduced in 1.64 and observed in production error telemetry. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
🎯 Code Coverage (details) 🔗 Commit SHA: 6291883 | Docs | Datadog PR Page | Give us feedback! |
Covers the null/empty-Optional cases for extractGroup, extractClusterId, and extractBootstrapServers to prevent regressions of the previously fixed NoSuchElementException. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
There was a problem hiding this comment.
More details
All three Optional.get() calls in KafkaConsumerInstrumentationHelper are correctly replaced: extractGroup and extractBootstrapServers use orElse(null), and extractClusterId replaces the unchecked .get() + dead null-check with an isPresent() guard. 22 adversarial scenarios (null info, all-null fields, partial null, happy path) confirmed the fix eliminates NoSuchElementException without regressing the non-null path.
📊 Validated against 22 scenarios · Open Bits AI session
🤖 Datadog Autotest · Commit e20ee61 · What is Autotest? · Any feedback? Reach out in #autotest
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
|
/merge |
|
View all feedbacks in Devflow UI.
The expected merge time in
Build pipeline has failing jobs for f421774: What to do next?
DetailsSince those jobs are not marked as being allowed to fail, the pipeline will most likely fail. |
|
/merge |
|
View all feedbacks in Devflow UI.
The expected merge time in
|
c66a0b5
into
master
Summary
KafkaConsumerInstrumentationHelper(kafka-clients-3.8) calledOptional.get()on the consumer group, metadata, and bootstrap servers without checkingisPresent()/usingorElse(), throwingNoSuchElementExceptionwhen those values weren't captured (e.g.Optional.geterrors seen in production telemetry, introduced in 1.64).extractGroup,extractClusterId,extractBootstrapServers) to safely handle the empty case instead of throwing.KafkaConsumerInstrumentationHelperTestunit test covering null/empty-Optional cases for all three accessors, to prevent regressions.kafka-clients-0.11module — it never wraps these values inOptional(plain nullable getters with!= nullchecks), so it isn't affected.Reported in https://dd.slack.com/archives/C047YAMGZ7T/p1784318891028629
Test plan
./gradlew :dd-java-agent:instrumentation:kafka:kafka-clients-3.8:compileJavasucceeds./gradlew :dd-java-agent:instrumentation:kafka:kafka-clients-3.8:spotlessApplyclean./gradlew :dd-java-agent:instrumentation:kafka:kafka-clients-3.8:testpasses, including newKafkaConsumerInstrumentationHelperTest🤖 Generated with Claude Code