reactor-core icon indicating copy to clipboard operation
reactor-core copied to clipboard

Context Propagation next steps

Open chemicL opened this issue 2 years ago • 0 comments

This issue is meant to coordinate tasks required for context-propagation library integration and propagation of ThreadLocal values in Reactor to be in a desired state.

More details to come.

  • [x] context-propagation: Improve ThreadLocalAccessor contract to allow entering an empty scope and reverting previously stacked values
    • https://github.com/micrometer-metrics/context-propagation/pull/102
    • https://github.com/micrometer-metrics/context-propagation/pull/103
  • [x] context-propagation: Allow Reactor's use case - restoring ThreadLocal values by removing existing values when Context object doesn't have a mapping for a key -> replacing the custom implementation within reactor-core
    • https://github.com/micrometer-metrics/context-propagation/pull/105
    • https://github.com/reactor/reactor-core/pull/3489
  • [x] reactor-core: Allow configuring automatic context capture in block()
    • https://github.com/reactor/reactor-core/pull/3420
  • [x] reactor-core + reactor-netty: Allow distinguishing Flux and Mono that is guaranteed to have ThreadLocal values present in case of automatic context propagation from custom implementations that can switch threads (reactor-netty case when execution continues after event on the event loop); allow custom implementations to use a propagating Subscriber.
    • #3478
  • [x] reactor-core: Remove the queue wrapper hook from automatic context propagation - it can be a source of ThreadLocal leaks, while it does not provide value in the current design. [depends on the above to be sure source signals have ThreadLocal values restored]
    • https://github.com/reactor/reactor-core/pull/3498
  • [ ] reactor-core: In 3.7 remove automatic ThreadLocal restoration in handle/tap operators and provide means to wrap a user-provided function to have ThreadLocals present. Currently there is no opt-out from the TL restoration in these operators when the context-propagation library is on the classpath; this might be undesired when users want to explicitly have TLs present in only particular places that they control.
    • Consider using properties to drive this feature: in 3.6 have the property of handle/tap restoration set to true, while in 3.7 have it as false
  • [x] spring-boot: config knob for automatic context propagation
    • https://github.com/spring-projects/spring-boot/issues/34201
  • [x] Documentation update
    • https://github.com/reactor/reactor-core/pull/3617
  • [ ] reactor-core: Research means to optimise the amount of ThreadLocal accesses (e.g. distinguish custom Mono that is not async and not restore ThreadLocals by a wrapping Subscriber)

chemicL avatar May 22 '23 14:05 chemicL