-
Couldn't load subscription status.
- 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
ErrorWebExceptionHandlerwhich adds a log and delegate the error handling to aDefaultErrorWebExceptionHandler - I have a custom context
MyContextmanaged in a ThreadLocal and I want it to be propagated, to do so, I have implemented :- a
CoWebFilterwhich 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 presentI would expect to have MyContext also present in the exception handler...
I found those workarounds though :
- annotate the exception handler class with
@ControllerAdviceand thehandlemethod 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