Skip to content
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

Document io.micrometer:context-propagation #385

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/main/docs/guide/contextPropagation.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Since Micronaut Framework version 4, https://projectreactor.io[Project Reactor] integration no longer captures the state automatically. Micronaut Framework users need to extend the propagation context manually.

Before version 4, Micronaut Framework required the instrumentation of every reactive operator to capture the current state to propagate it. It added an unwanted overhead and forced us to maintain complicated Reactor operators' instrumentation.

Since 3.5.0, Reactor-Core embeds support for the `io.micrometer:context-propagation` SPI. This allows to achieve the same thread-local propagation by including the https://micrometer.io/docs/contextPropagation[Micrometer Context Propagation] dependency.

The framework automatically adds the `PropagatedContext` to Project Reactor's context for interceptors and the HTTP filters. You can access it via the utility class link:https://docs.micronaut.io/latest/api/io/micronaut/core/async/propagation/ReactorPropagation.html[ReactorPropagation].

NOTE: link:https://docs.micronaut.io/latest/api/io/micronaut/core/async/propagation/ReactorPropagation.html[ReactorPropagation] is an experimental class and might change in the future.

It is possible to use https://micrometer.io/docs/contextPropagation[Micrometer Context Propagation], which Reactor supports for propagation and restoring the thread-local context.

To enable it, include the dependency:

dependency:context-propagation[groupId="io.micrometer",scope="compile"]

After that, all the thread-local propagated elements can restore their thread-local value.

NOTE: The thread-local values are read-only. To modify them, the `PropagatedContext` instance needs to be changed and put into the Reactor's context.

If you have Micrometer Context Propagation on the classpath but don't want to use it, apply the following configuration:

.Disable Micrometer Context Propagation in Reactor
[configuration]
----
reactor:
enable-automatic-context-propagation: false
----
1 change: 1 addition & 0 deletions src/main/docs/guide/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ releaseHistory: Release History
breaks: Breaking Changes
quickStart:
title: Quick Start
contextPropagation: Reactor context propagation
repository: Repository

Loading