Skip to content

Commit

Permalink
Adapt to the changes in the context propagation API (#3113)
Browse files Browse the repository at this point in the history
The artifactId has been shortened to `context-propagation`.
The `ContextSnapshot` API has renamed its capture methods.
  • Loading branch information
violetagg committed Jul 8, 2022
1 parent 9de500c commit acdfb31
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions docs/asciidoc/advancedFeatures.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -843,12 +843,12 @@ In case one needs to use one of the remaining APIs that still require a `Context

[[context.propagation]]
=== Micrometer Context-Propagation Support
Since 3.5.0, Reactor-Core embeds basic support for the `io.micrometer:context-propagation-api` SPI.
Since 3.5.0, Reactor-Core embeds basic support for the `io.micrometer:context-propagation` SPI.
This library is intended as a mean to easily adapt between various implementations of the concept of a Context, of which
`ContextView`/`Context` is an example, and between `ThreadLocal` variables as well.

`ReactorContextAccessor` is one implementation of this SPI that is loaded via `ServiceLoader`. No user action is required,
other than depending on reactor-core and `context-propagation-api` (the class is public but shouldn't generally be accessed by user code).
other than depending on reactor-core and `context-propagation` (the class is public but shouldn't generally be accessed by user code).

=== Simple `Context` Examples

Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ asciidoctor = "3.3.2"
bytebuddy = "1.12.10"
jmh = "1.35"
junit = "5.8.2"
#note that context-propagation-api has a different version directly set in libraries
#note that context-propagation has a different version directly set in libraries
micrometer = "1.10.0-SNAPSHOT"
reactiveStreams = "1.0.4"

Expand All @@ -31,7 +31,7 @@ logback = "ch.qos.logback:logback-classic:1.2.11"
micrometer-bom = { module = "io.micrometer:micrometer-bom", version.ref = "micrometer" }
micrometer-commons = { module = "io.micrometer:micrometer-commons" }
micrometer-core = { module = "io.micrometer:micrometer-core" }
micrometer-contextPropagationApi = "io.micrometer:context-propagation-api:1.0.0-SNAPSHOT"
micrometer-contextPropagation = "io.micrometer:context-propagation:1.0.0-SNAPSHOT"
micrometer-observation-test = { module = "io.micrometer:micrometer-observation-test" }
micrometer-tracing-test = "io.micrometer:micrometer-tracing-integration-test:1.0.0-SNAPSHOT"
micrometer-test = { module = "io.micrometer:micrometer-test" }
Expand Down
2 changes: 1 addition & 1 deletion reactor-core-micrometer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dependencies {

implementation platform(libs.micrometer.bom)
api libs.micrometer.core
implementation libs.micrometer.contextPropagationApi
implementation libs.micrometer.contextPropagation

testImplementation platform(libs.junit.bom)
testImplementation "org.junit.jupiter:junit-jupiter-api"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ protected MeterRegistry useRegistry() {
* Finally, the low cardinality {@code type} KeyValue informs whether we're observing a {@code Flux}
* or a {@code Mono}.
* <p>
* Note that the Micrometer {@code context-propagation-api} is used to populate thread locals
* Note that the Micrometer {@code context-propagation} is used to populate thread locals
* around the opening of the observation (upon {@code onSubscribe(Subscription)}).
* <p>
* Observation names are prefixed by the {@link reactor.core.publisher.Flux#name(String)} defined upstream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ final class MicrometerObservationListener<T> implements SignalListener<T> {

@Override
public void doFirst() {
ContextSnapshot contextSnapshot = ContextSnapshot.forContextAndThreadLocalValues(this.originalContext);
ContextSnapshot contextSnapshot = ContextSnapshot.capture(this.originalContext);

try (ContextSnapshot.Scope ignored = contextSnapshot.setThreadLocalValues()) {
this.scope = this.subscribeToTerminalObservation
.start()
.openScope();
//reacquire the scope from ThreadLocal
//tap context hasn't been initialized yet, so addToContext can now use the Scope
ContextSnapshot contextSnapshot2 = ContextSnapshot.forContextAndThreadLocalValues(this.originalContext);
ContextSnapshot contextSnapshot2 = ContextSnapshot.capture(this.originalContext);
this.contextWithScope = contextSnapshot2.updateContext(Context.of(this.originalContext));
}
}
Expand Down
6 changes: 3 additions & 3 deletions reactor-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ dependencies {
compileOnly libs.micrometer.commons
compileOnly libs.micrometer.core

// Optional context-propagation-api
compileOnly libs.micrometer.contextPropagationApi
// Optional context-propagation
compileOnly libs.micrometer.contextPropagation

// Optional BlockHound support
compileOnly libs.blockhound
Expand Down Expand Up @@ -121,7 +121,7 @@ dependencies {
withMicrometerTestImplementation platform(libs.micrometer.bom)
withMicrometerTestImplementation libs.micrometer.commons
withMicrometerTestImplementation libs.micrometer.core
withMicrometerTestImplementation libs.micrometer.contextPropagationApi
withMicrometerTestImplementation libs.micrometer.contextPropagation
withMicrometerTestImplementation sourceSets.test.output

jcstressImplementation(project(":reactor-test")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* A {@code ContextAccessor} to enable reading values from a Reactor
* {@link ContextView} and writing values to {@link Context}.
* <p>
* Please note that this public class implements the {@code libs.micrometer.contextPropagationApi}
* Please note that this public class implements the {@code libs.micrometer.contextPropagation}
* SPI library, which is an optional dependency.
*
* @author Rossen Stoyanchev
Expand Down

0 comments on commit acdfb31

Please sign in to comment.