-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improving Observability in Asynchronous Processing (CompletableFuture
, Mono
)
#3528
Comments
I think this makes sense, but does not look that easy to fix.
So, as long as listener returns control over here, an observation is closed. |
@artembilan thanks for considering this as a one of reasonable request! It means that Therefore, i believe a new // MessagingMessageListenerAdapater.java
if (result instanceof CompletableFuture<?> completable) {
...
completable.whenComplete((r, t) -> {
// newObservation maybe?
observation.observer(() -> {
if (t == null) {
asyncSuccess(r, replyTopic, source, messageReturnType);
acknowledge(acknowledgment);
}
else {
asyncFailure(request, acknowledgment, consumer, t, source);
}
}
... This way can't measure processed time metrics accurately. To sum up, i think we have two options.
@KafkaListener(...)
static class TopicListener {
@KafkaHandler
public Mono<Void> listenAgain(String message) {
Observation ob = new AsyncAwareObservation();
return Mono.fromCallable(() -> {
ob.observer(() -> {
try {
// Developer's logic.
...
}
catch (Exception e) {
ob.error(e);
}
});
...
});
}
} What do you think? |
Well, async it or not, it is still a unit of work. I don't think though that we need to instrument an async executor, but having a variable for the |
@chickenchickenlove We will take a crack at this on our end and share the feedback. |
Thanks for giving me deep information! 🙇♂️ Also, thanks for keeping me updated on what's going on! |
…ssing (CompletableFuture, Mono) Fixes: spring-projects#3528 spring-projects#3528 - Improve spring-kafka observability for failures in async consumer tasks when listener methods return CompletableFuture<?> or Mono<?> and throw errors during async execution - Refactoring code in KafkaMessageListenerContainer and MessagingMessageListenerAdapter around observability - Adding tests to verify - Add @nullable annotations to relevant methods for better null safety
…ssing Fixes: spring-projects#3528 spring-projects#3528 - Improve spring-kafka observability for failures in async consumer tasks when listener methods return CompletableFuture<?> or Mono<?> and throw errors during async execution - Refactoring code in KafkaMessageListenerContainer and MessagingMessageListenerAdapter around observability - Adding tests to verify - Add @nullable annotations to relevant methods for better null safety
Fixes: #3528 #3528 - Improve spring-kafka observability for failures in async consumer tasks when listener methods return CompletableFuture<?> or Mono<?> and throw errors during async execution - Refactoring code in KafkaMessageListenerContainer and MessagingMessageListenerAdapter around observability - Adding tests to verify - Add @nullable annotations to relevant methods for better null safety * Addressing PR review
Expected Behavior
When the consumer endpoint method returns
CompletableFuture<?>
orMono<?>
as a result, and both theCompletableFuture<?>
and theMono<?>
are fail to complete due to an error thrown in the async loop,spring-kafka
should report metrics indicating that there have been failures in async consumer tasks.For example,
Current Behavior
When the consumer endpoint method returns
CompletableFuture<?>
orMono<?>
as result, theMessagingMessageListenerAdapater
adds a callback to both theCompletableFuture<?>
and theMono<?>
.However, currently,
KafkaMessageListenerContainer
does not consider whetherCompletableFuture
andMono
fail to complete.If both
CompletableFuture
andMono
instances are success to be created,KafkaMessageListenerContainer
will not report error metric even if bothCompletableFuture
andMono
fail to complete.Context
I discovered this issue while solving another problem(GH-3276), and I checked to see if it was actually the case.
As expected, there was an issue.
To reproduce it, you can use method below.
it describes that
CompletableFuture<?>
successes to be created.CompletableFuture<?>
fails to complete.To reviewer
If you consider this to be a reasonable request,
may I take on this task and try to solve it?
The text was updated successfully, but these errors were encountered: