diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7454180f2..41d9927a4 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2e6e5897b..41dfb8790 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle b/settings.gradle index 5e4b949ec..354482582 100644 --- a/settings.gradle +++ b/settings.gradle @@ -18,7 +18,6 @@ include 'tracing-zipkin' include 'tests:kotlin-tests' enableFeaturePreview 'TYPESAFE_PROJECT_ACCESSORS' -enableFeaturePreview 'VERSION_CATALOGS' dependencyResolutionManagement { repositories { diff --git a/tests/kotlin-tests/src/test/kotlin/reactor/ReactorContextPropagationSpec.kt b/tests/kotlin-tests/src/test/kotlin/reactor/ReactorContextPropagationSpec.kt index e40558cd1..fab47f485 100644 --- a/tests/kotlin-tests/src/test/kotlin/reactor/ReactorContextPropagationSpec.kt +++ b/tests/kotlin-tests/src/test/kotlin/reactor/ReactorContextPropagationSpec.kt @@ -5,7 +5,12 @@ import io.micronaut.context.annotation.Requires import io.micronaut.core.annotation.Introspected import io.micronaut.http.HttpRequest import io.micronaut.http.MutableHttpResponse -import io.micronaut.http.annotation.* +import io.micronaut.http.annotation.Body +import io.micronaut.http.annotation.Controller +import io.micronaut.http.annotation.Filter +import io.micronaut.http.annotation.Filter.MATCH_ALL_PATTERN +import io.micronaut.http.annotation.Get +import io.micronaut.http.annotation.Post import io.micronaut.http.client.HttpClient import io.micronaut.http.filter.HttpServerFilter import io.micronaut.http.filter.ServerFilterChain @@ -27,12 +32,13 @@ import reactor.core.publisher.Mono import reactor.util.context.Context import reactor.util.function.Tuple2 import reactor.util.function.Tuples -import java.util.* +import java.util.UUID class ReactorContextPropagationSpec { @Test fun testKotlinPropagation() { + val embeddedServer = ApplicationContext.run(EmbeddedServer::class.java, mapOf("reactortestpropagation.enabled" to "true", "micronaut.http.client.read-timeout" to "30s") ) @@ -41,7 +47,8 @@ class ReactorContextPropagationSpec { val result: MutableList> = Flux.range(1, 100) .flatMap { val tracingId = UUID.randomUUID().toString() - val get = HttpRequest.POST("http://localhost:${embeddedServer.port}/trigger", NameRequestBody("sss-" + tracingId)).header("X-TrackingId", tracingId) + val get = HttpRequest.POST("http://localhost:${embeddedServer.port}/trigger", NameRequestBody("sss-" + tracingId)) + .header("X-TrackingId", tracingId) Mono.from(client.retrieve(get, String::class.java)) .map { Tuples.of(it as String, tracingId) } } @@ -54,8 +61,6 @@ class ReactorContextPropagationSpec { embeddedServer.stop() } - - } @Requires(property = "reactortestpropagation.enabled") @@ -74,7 +79,6 @@ class TestController(private val someService: SomeService) { val reactorContextView = currentCoroutineContext()[ReactorContext.Key]!!.context return reactorContextView.get("reactorTrackingId") as String } - } @Introspected @@ -97,11 +101,10 @@ class SomeService { suspendTrackingId } } - } @Requires(property = "reactortestpropagation.enabled") -@Filter(Filter.MATCH_ALL_PATTERN) +@Filter(MATCH_ALL_PATTERN) class ReactorHttpServerFilter : HttpServerFilter { override fun doFilter(request: HttpRequest<*>, chain: ServerFilterChain): Publisher> { @@ -115,7 +118,7 @@ class ReactorHttpServerFilter : HttpServerFilter { } @Requires(property = "reactortestpropagation.enabled") -@Filter(Filter.MATCH_ALL_PATTERN) +@Filter(MATCH_ALL_PATTERN) class SuspendHttpServerFilter : CoroutineHttpServerFilter { override suspend fun filter(request: HttpRequest<*>, chain: ServerFilterChain): MutableHttpResponse<*> { @@ -138,11 +141,10 @@ interface CoroutineHttpServerFilter : HttpServerFilter { filter(request, chain) } } - } suspend fun ServerFilterChain.next(request: HttpRequest<*>): MutableHttpResponse<*> { - return this.proceed(request).asFlow().single() + return proceed(request).asFlow().single() } @Introspected diff --git a/tracing-core/src/main/java/io/micronaut/tracing/instrument/http/OpenTracingClientFilter.java b/tracing-core/src/main/java/io/micronaut/tracing/instrument/http/OpenTracingClientFilter.java index 778239da6..0e7ff160a 100644 --- a/tracing-core/src/main/java/io/micronaut/tracing/instrument/http/OpenTracingClientFilter.java +++ b/tracing-core/src/main/java/io/micronaut/tracing/instrument/http/OpenTracingClientFilter.java @@ -114,7 +114,6 @@ public void doOnError(@NonNull Throwable error, @NonNull Span span) { } setErrorTags(span, error); } - }); } } diff --git a/tracing-core/src/main/java/io/micronaut/tracing/instrument/http/OpenTracingServerFilter.java b/tracing-core/src/main/java/io/micronaut/tracing/instrument/http/OpenTracingServerFilter.java index ea6906585..c828f2c70 100644 --- a/tracing-core/src/main/java/io/micronaut/tracing/instrument/http/OpenTracingServerFilter.java +++ b/tracing-core/src/main/java/io/micronaut/tracing/instrument/http/OpenTracingServerFilter.java @@ -119,7 +119,6 @@ public boolean isContinued() { public boolean isFinishOnError() { return false; } - }); } diff --git a/tracing-core/src/main/java/io/micronaut/tracing/instrument/util/TracingCorePublisher.java b/tracing-core/src/main/java/io/micronaut/tracing/instrument/util/TracingCorePublisher.java index 78ee84d40..7fa1dbcba 100644 --- a/tracing-core/src/main/java/io/micronaut/tracing/instrument/util/TracingCorePublisher.java +++ b/tracing-core/src/main/java/io/micronaut/tracing/instrument/util/TracingCorePublisher.java @@ -31,7 +31,7 @@ * @author Denis Stepanov */ @SuppressWarnings("PublisherImplementation") -public class TracingCorePublisher extends TracingPublisher implements CorePublisher { +public class TracingCorePublisher extends TracingPublisher implements CorePublisher { /** * Creates a new tracing publisher for the given arguments. @@ -40,7 +40,9 @@ public class TracingCorePublisher extends TracingPublisher implements Cor * @param tracer the tracer * @param operationName the operation name that should be started */ - public TracingCorePublisher(CorePublisher publisher, Tracer tracer, String operationName) { + public TracingCorePublisher(CorePublisher publisher, + Tracer tracer, + String operationName) { super(publisher, tracer, operationName); } @@ -52,7 +54,10 @@ public TracingCorePublisher(CorePublisher publisher, Tracer tracer, String op * @param operationName the operation name that should be started * @param tracingObserver the tracing observer */ - public TracingCorePublisher(CorePublisher publisher, Tracer tracer, String operationName, TracingObserver tracingObserver) { + public TracingCorePublisher(CorePublisher publisher, + Tracer tracer, + String operationName, + TracingObserver tracingObserver) { super(publisher, tracer, operationName, tracingObserver); } @@ -63,7 +68,8 @@ public TracingCorePublisher(CorePublisher publisher, Tracer tracer, String op * @param publisher the target publisher * @param tracer the tracer */ - public TracingCorePublisher(CorePublisher publisher, Tracer tracer) { + public TracingCorePublisher(CorePublisher publisher, + Tracer tracer) { super(publisher, tracer); } @@ -75,7 +81,9 @@ public TracingCorePublisher(CorePublisher publisher, Tracer tracer) { * @param tracer the tracer * @param tracingObserver the tracing observer */ - public TracingCorePublisher(CorePublisher publisher, Tracer tracer, TracingObserver tracingObserver) { + public TracingCorePublisher(CorePublisher publisher, + Tracer tracer, + TracingObserver tracingObserver) { super(publisher, tracer, tracingObserver); } @@ -86,7 +94,9 @@ public TracingCorePublisher(CorePublisher publisher, Tracer tracer, TracingOb * @param tracer the tracer * @param spanBuilder the span builder that represents the span that will be */ - public TracingCorePublisher(CorePublisher publisher, Tracer tracer, SpanBuilder spanBuilder) { + public TracingCorePublisher(CorePublisher publisher, + Tracer tracer, + SpanBuilder spanBuilder) { super(publisher, tracer, spanBuilder); } @@ -98,7 +108,10 @@ public TracingCorePublisher(CorePublisher publisher, Tracer tracer, SpanBuild * @param spanBuilder the span builder that represents the span that will be * @param tracingObserver the tracing observer */ - public TracingCorePublisher(CorePublisher publisher, Tracer tracer, SpanBuilder spanBuilder, TracingObserver tracingObserver) { + public TracingCorePublisher(CorePublisher publisher, + Tracer tracer, + SpanBuilder spanBuilder, + TracingObserver tracingObserver) { super(publisher, tracer, spanBuilder, tracingObserver); } @@ -111,7 +124,10 @@ public TracingCorePublisher(CorePublisher publisher, Tracer tracer, SpanBuild * be created when the publisher is subscribed to * @param isSingle true if the publisher emits a single item */ - public TracingCorePublisher(CorePublisher publisher, Tracer tracer, SpanBuilder spanBuilder, boolean isSingle) { + public TracingCorePublisher(CorePublisher publisher, + Tracer tracer, + SpanBuilder spanBuilder, + boolean isSingle) { super(publisher, tracer, spanBuilder, isSingle); } @@ -125,7 +141,11 @@ public TracingCorePublisher(CorePublisher publisher, Tracer tracer, SpanBuild * @param isSingle true if the publisher emits a single item * @param tracingObserver the tracing observer */ - public TracingCorePublisher(CorePublisher publisher, Tracer tracer, SpanBuilder spanBuilder, boolean isSingle, TracingObserver tracingObserver) { + public TracingCorePublisher(CorePublisher publisher, + Tracer tracer, + SpanBuilder spanBuilder, + boolean isSingle, + TracingObserver tracingObserver) { super(publisher, tracer, spanBuilder, isSingle, tracingObserver); } @@ -135,7 +155,10 @@ public void subscribe(CoreSubscriber subscriber) { } @Override - protected void doSubscribe(Subscriber actual, ScopeManager scopeManager, Span span, boolean finishOnClose) { + protected void doSubscribe(Subscriber actual, + ScopeManager scopeManager, + Span span, + boolean finishOnClose) { CoreSubscriber coreActual = (CoreSubscriber) actual; publisher.subscribe(new TracingCoreSubscriber(scopeManager, span, actual, finishOnClose, coreActual.currentContext())); } @@ -144,7 +167,11 @@ private final class TracingCoreSubscriber extends TracingSubscriber implements C private final Context context; - public TracingCoreSubscriber(ScopeManager scopeManager, Span span, Subscriber actual, boolean finishOnClose, Context context) { + public TracingCoreSubscriber(ScopeManager scopeManager, + Span span, + Subscriber actual, + boolean finishOnClose, + Context context) { super(scopeManager, span, actual, finishOnClose); this.context = context; } @@ -154,5 +181,4 @@ public Context currentContext() { return context; } } - } diff --git a/tracing-core/src/main/java/io/micronaut/tracing/instrument/util/TracingObserver.java b/tracing-core/src/main/java/io/micronaut/tracing/instrument/util/TracingObserver.java index c88f147b8..966ee295e 100644 --- a/tracing-core/src/main/java/io/micronaut/tracing/instrument/util/TracingObserver.java +++ b/tracing-core/src/main/java/io/micronaut/tracing/instrument/util/TracingObserver.java @@ -32,28 +32,31 @@ public interface TracingObserver { TracingObserver NO_OP = new TracingObserver() { }; /** - * Designed for subclasses to override if the current active span is to be continued by this publisher. False by default. - * This only has effects if no spanBuilder was defined. + * Designed for subclasses to override if the current active span is to be + * continued by this publisher. False by default. This only has effects if + * no spanBuilder was defined. * * @return true, if the current span should be continued by this publisher - * @since 2.0.3 + * @since 4.0.2 */ default boolean isContinued() { return false; } /** - * Designed for subclasses to override if the span needs to be finished upon error. True by default. + * Designed for subclasses to override if the span needs to be finished + * upon error. True by default. * * @return true, if the active span needs to be finished on error - * @since 2.0.3 + * @since 4.0.2 */ default boolean isFinishOnError() { return true; } /** - * Designed for subclasses to override and implement custom behaviour when an item is emitted. + * Designed for subclasses to override and implement custom behaviour when + * an item is emitted. * * @param object The object * @param span The span @@ -72,8 +75,8 @@ default void doOnSubscribe(@NonNull Span span) { } /** - * Designed for subclasses to override and implement custom on finish behaviour. Fired - * prior to calling {@link Span#finish()}. + * Designed for subclasses to override and implement custom on finish + * behaviour. Fired prior to calling {@link Span#finish()}. * * @param span The span */ @@ -91,5 +94,4 @@ default void doOnFinish(@NonNull Span span) { default void doOnError(@NonNull Throwable throwable, @NonNull Span span) { // no-op } - } diff --git a/tracing-core/src/main/java/io/micronaut/tracing/instrument/util/TracingPublisher.java b/tracing-core/src/main/java/io/micronaut/tracing/instrument/util/TracingPublisher.java index 020c197b6..13b14c929 100644 --- a/tracing-core/src/main/java/io/micronaut/tracing/instrument/util/TracingPublisher.java +++ b/tracing-core/src/main/java/io/micronaut/tracing/instrument/util/TracingPublisher.java @@ -52,9 +52,9 @@ public class TracingPublisher implements Publishers.MicronautPublisher { /** * Creates a new tracing publisher for the given arguments. * - * @param publisher the target publisher - * @param tracer the tracer - * @param operationName the operation name that should be started + * @param publisher the target publisher + * @param tracer the tracer + * @param operationName the operation name that should be started */ public TracingPublisher(Publisher publisher, Tracer tracer, @@ -81,8 +81,8 @@ public TracingPublisher(Publisher publisher, * Creates a new tracing publisher for the given arguments. This constructor * will just add tracing of the existing span if it is present. * - * @param publisher the target publisher - * @param tracer the tracer + * @param publisher the target publisher + * @param tracer the tracer */ public TracingPublisher(Publisher publisher, Tracer tracer) { this(publisher, tracer, (SpanBuilder) null, TracingObserver.NO_OP); @@ -105,9 +105,9 @@ public TracingPublisher(Publisher publisher, /** * Creates a new tracing publisher for the given arguments. * - * @param publisher the target publisher - * @param tracer the tracer - * @param spanBuilder the span builder that represents the span that will be + * @param publisher the target publisher + * @param tracer the tracer + * @param spanBuilder the span builder that represents the span that will be */ public TracingPublisher(Publisher publisher, Tracer tracer, @@ -133,11 +133,11 @@ public TracingPublisher(Publisher publisher, /** * Creates a new tracing publisher for the given arguments. * - * @param publisher the target publisher - * @param tracer the tracer - * @param spanBuilder the span builder that represents the span that will - * be created when the publisher is subscribed to - * @param isSingle true if the publisher emits a single item + * @param publisher the target publisher + * @param tracer the tracer + * @param spanBuilder the span builder that represents the span that will + * be created when the publisher is subscribed to + * @param isSingle true if the publisher emits a single item */ public TracingPublisher(Publisher publisher, Tracer tracer, diff --git a/tracing-core/src/main/java/io/micronaut/tracing/instrument/util/TracingPublisherUtils.java b/tracing-core/src/main/java/io/micronaut/tracing/instrument/util/TracingPublisherUtils.java index 787dd461f..403d3c538 100644 --- a/tracing-core/src/main/java/io/micronaut/tracing/instrument/util/TracingPublisherUtils.java +++ b/tracing-core/src/main/java/io/micronaut/tracing/instrument/util/TracingPublisherUtils.java @@ -17,6 +17,7 @@ import io.micronaut.core.annotation.NonNull; import io.opentracing.Tracer; +import io.opentracing.Tracer.SpanBuilder; import org.reactivestreams.Publisher; import reactor.core.CorePublisher; @@ -33,7 +34,7 @@ public final class TracingPublisherUtils { * @param publisher the target publisher * @param tracer the tracer * @param tracingObserver the tracing observer - * @param The publisher's type + * @param the publisher's type * @return new instance */ public static TracingPublisher createTracingPublisher(Publisher publisher, @@ -54,12 +55,12 @@ public static TracingPublisher createTracingPublisher(Publisher publis * @param spanBuilder the span builder that represents the span that will * be created when the publisher is subscribed to * @param tracingObserver the tracing observer - * @param The publisher's type + * @param the publisher's type * @return new instance */ public static TracingPublisher createTracingPublisher(Publisher publisher, Tracer tracer, - Tracer.SpanBuilder spanBuilder, + SpanBuilder spanBuilder, @NonNull TracingObserver tracingObserver) { if (publisher instanceof CorePublisher) { @@ -77,12 +78,12 @@ public static TracingPublisher createTracingPublisher(Publisher publis * be created when the publisher is subscribed to * @param isSingle true if the publisher emits a single item * @param tracingObserver the tracing observer - * @param The publisher's type + * @param the publisher's type * @return new instance */ public static TracingPublisher createTracingPublisher(Publisher publisher, Tracer tracer, - Tracer.SpanBuilder spanBuilder, + SpanBuilder spanBuilder, boolean isSingle, @NonNull TracingObserver tracingObserver) { @@ -91,5 +92,4 @@ public static TracingPublisher createTracingPublisher(Publisher publis } return new TracingPublisher<>(publisher, tracer, spanBuilder, isSingle, tracingObserver); } - }