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

Add ContextPropagation runtime util + captureContext operator

Open simonbasle opened this issue 3 years ago • 3 comments

In this PR we introduce a ContextPropagation runtime-detection utility class as well as a contextCapture() operator. If context-propagation isn't on the classpath, this operator is NO-OP.

If context-propagation is on the classpath however, the operator will use it to capture the current context during the subscription phase (at the point a contextWrite would be effected) and store it in the ContextView visible from upstream of the operator.

TODO:

  • [x] Mono version
  • [x] mention in reference guide? whole section?
  • ~marble diagram~

simonbasle avatar Aug 10 '22 08:08 simonbasle

as there is currently no standard marble diagram representation of the Context, we won't provide a marble diagram for now

simonbasle avatar Aug 16 '22 08:08 simonbasle

tentative commit message:

This commit introduces a ContextPropagation runtime-detection utility
class as well as a `contextCapture()` operator.

If context-propagation isn't on the classpath, this operator is NO-OP.

If context-propagation is on the classpath however, the operator will
use it to capture the current context during the subscription phase
(at the point a contextWrite would be effected) and store it in the
ContextView visible from upstream of the operator.

simonbasle avatar Sep 01 '22 14:09 simonbasle

Approved, although I left a few comments - some are minor, for the docs; one I believe to be important for UX, but possible to improve as a follow-up if the logging option is chosen. With additional method, it's probably best to introduce now.

chemicL avatar Sep 09 '22 11:09 chemicL

looks like there was no strong consensus on the contextCapture operator being NO-OP if the lib is not on the classpath. so far all the features in reactor-core that depend on an optional dependency have been exposed that way (eg. Flux#metrics()).

I've fixed the comments on the refguide part.

~Note that this PR is conflicting with #3215, as it adds usage of context-propagation including methods that have seen breaking changes in latest snapshots...~ this is just out-of-sync with M5

simonbasle avatar Oct 05 '22 14:10 simonbasle

I'll need to rebase against current main (which depends on context-propagation M5)

simonbasle avatar Oct 05 '22 14:10 simonbasle