Fix KafkaJS instrumentation of orphaned promise #5270
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Refactors querying the cluster ID in the KafkaJS instrumentation, so that unhandled rejections can't occur if the underlying client is unable to connect to the broker.
Motivation
Bug added in #4808, released under 5.25.0
Similar in effect to the bug which was resolved with #4112
The addition of the logic which added the clusterId to publish and consume spans created orphaned promises in
producer
andconsumer
methods which don't become re-exposed until thesend
orrun
methods are called respectively. This results in unhandled rejections, and by default, exits the process if those secondary methods are not called in time and admin methods fail.Plugin Checklist
Additional Notes
Reproduction:
If the above file is run when no Kafka broker is running/accessible, the expected behavior is for the
connect()
to timeout, throw an error, and be caught and logged at the bottom with a "boom" message.Current behavior will log the expected error from the rejected
connect()
, however, there will also be an unhandled rejection log with a stack trace that originates from the synchronousproducer()
call.I'd like to call out that this file has exhibited the same bug twice in the last year and there doesn't seem to be any test file for the KafkaJS instrumentation.
I'm willing to add tests go along with this PR, but I'd like guidance on test strategy from the DD team.
The PR which added the bug only updated a test suite in
datadog-plugin-kafkajs
, and only covered happy paths. It's unclear to me if any new tests should live indatadog-plugin-kafkajs
ordatadog-instrumentations/test
.cc: @wconti27 @bengl @juan-fernandez