-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Open
Labels
status: feedback-providedFeedback has been providedFeedback has been providedstatus: waiting-for-triageAn issue we've not yet triaged or decided onAn issue we've not yet triaged or decided ontheme: kotlinAn issue related to Kotlin supportAn issue related to Kotlin support
Description
Hi,
I think it is an issue... but you may qualify this as an enhancement.
in short : a context set in a high level WebFilter is not propagated in the exception handler
I have sample project here : https://github.com/PheelTi/spring-webflux-context
- Weblux / Kotlin / Micrometer context propagation
- a custom
ErrorWebExceptionHandler
which adds a log and delegate the error handling to aDefaultErrorWebExceptionHandler
- I have a custom context
MyContext
managed in a ThreadLocal and I want it to be propagated, to do so, I have implemented :- a
CoWebFilter
which propagates the Kotlin context with a customThreadContextElement
- I used the
ContextRegistry.getInstance().registerThreadLocalAccessor(...)
to register the access toMyContext
- I activated
Hooks.enableAutomaticContextPropagation()
- a
- the value of MyContext is created in a high level business
WebFilter
, and set in its ThreadLocal, and in the Reactor Context, and I print its value in several places :- in the business filter juste after initialisation, and around its cleaning
- in the controller
- in the exception handler.
Here are the results :
[INFO] Context from 'starting request processing' : is present with value 'request 6c8d08dd-6238-48c1-b295-5c134f1c6b7a'
[INFO] Context from 'controller processing' : is present with value 'request 6c8d08dd-6238-48c1-b295-5c134f1c6b7a'
[INFO] Context from 'exception handler' : is not present
[ERROR] 500 Server Error for HTTP GET "/test"
java.lang.RuntimeException: test exception
...
[INFO] Context from 'finishing request processing' : is present with value 'request 6c8d08dd-6238-48c1-b295-5c134f1c6b7a'
[INFO] Context from 'cleaned request processing' : is not present
I would expect to have MyContext
also present in the exception handler...
I found those workarounds though :
- annotate the exception handler class with
@ControllerAdvice
and thehandle
method with@ExceptionHandler(Throwable::class)
- set my context in a higher level place like
HttpHandlerDecoratorFactory
Thanks
Metadata
Metadata
Assignees
Labels
status: feedback-providedFeedback has been providedFeedback has been providedstatus: waiting-for-triageAn issue we've not yet triaged or decided onAn issue we've not yet triaged or decided ontheme: kotlinAn issue related to Kotlin supportAn issue related to Kotlin support