-
-
Notifications
You must be signed in to change notification settings - Fork 435
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
Finish WebFlux transaction before popping scope #2724
Changes from all commits
8324fd8
bbb1440
504a195
d832b5b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
package io.sentry.spring.jakarta.webflux; | ||
|
||
import io.sentry.IHub; | ||
import io.sentry.NoOpHub; | ||
import io.sentry.ITransaction; | ||
import io.sentry.Sentry; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.springframework.web.server.ServerWebExchange; | ||
import org.springframework.web.server.WebFilterChain; | ||
import reactor.core.publisher.Mono; | ||
|
@@ -21,17 +22,26 @@ public SentryWebFilterWithThreadLocalAccessor(final @NotNull IHub hub) { | |
public Mono<Void> filter( | ||
final @NotNull ServerWebExchange serverWebExchange, | ||
final @NotNull WebFilterChain webFilterChain) { | ||
final @NotNull TransactionContainer transactionContainer = new TransactionContainer(); | ||
return ReactorUtils.withSentryNewMainHubClone( | ||
webFilterChain | ||
.filter(serverWebExchange) | ||
.doFinally( | ||
__ -> { | ||
doFinally(Sentry.getCurrentHub()); | ||
Sentry.setCurrentHub(NoOpHub.getInstance()); | ||
}) | ||
__ -> | ||
doFinally( | ||
serverWebExchange, | ||
Sentry.getCurrentHub(), | ||
transactionContainer.transaction)) | ||
.doOnError(e -> doOnError(transactionContainer.transaction, e)) | ||
.doFirst( | ||
() -> { | ||
doFirst(serverWebExchange, Sentry.getCurrentHub()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comment about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
transactionContainer.transaction = | ||
maybeStartTransaction(Sentry.getCurrentHub(), serverWebExchange.getRequest()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comment about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
})); | ||
} | ||
|
||
private static class TransactionContainer { | ||
private volatile @Nullable ITransaction transaction; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does
Sentry.getCurrentHub()
work correctly in this filter method?ReactorUtils.withSentryNewMainHubClone
does not set the current hub, so shouldn't we get the hub from the context?Or is this somehow handled by reactor behind the scenes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ThreadLocal
is set viaThreadLocalAccessor
and propagated via reactor context.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just tested again with debugger, works as expected (i.e. uses the correct hub).