Skip to content
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

Support for asynchronous requests #3982

Open
aesy opened this issue Dec 12, 2024 · 0 comments · May be fixed by #3983
Open

Support for asynchronous requests #3982

aesy opened this issue Dec 12, 2024 · 0 comments · May be fixed by #3983

Comments

@aesy
Copy link

aesy commented Dec 12, 2024

Problem Statement

The Sentry Spring Boot documentation states that there's support for Spring MVC methods to be asynchronous using for example a Callable or StreamingResponseBody by decorating the task executor with a SentryTaskDecorator. While this will propagate the context to the new thread, it will not keep the request transaction open until it's completed, so sometime during the execution of the method, the transaction will finish and subsequent spans will be dropped.

Here's an example:

@GetMapping
public Callable<Void> test() {
  var outerSpan = Sentry.getSpan();

  return () -> {
    var innerSpan = Sentry.getSpan();
    return null;
  };
}
  • outerSpan is always non-null, not noop and not finished, as expected.
  • Without using SentryTaskDecorator, the innerSpan is null, as expected.
  • With a SentryTaskDecorator, the innerSpan is non-null, and not noop, as expected, but it may or may not be finished - this is a race condition! Put a sleep in there and it will always be in a finished state.

The same applies to Futures, StreamingResponseBody, and any other method for async processing. I will give more examples if necessary.

Solution Brainstorm

The underlying issue seems to be that the SentryTracingFilter does not handle async dispatches. This can be fixed by handling DispatcherType.ASYNC and keeping the transaction open until the response is committed. I will provide a pull request for this shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Waiting for: Product Owner
Status: Needs Discussion
Development

Successfully merging a pull request may close this issue.

1 participant