From 71f12e26407e8cde33b2202042b8ebd5b1f3b3f2 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Wed, 28 Jul 2021 11:20:19 +0200 Subject: [PATCH] Add temporary guard to TraceFunctionAroundWrapper for cases which are not properly supported by it --- .../messaging/TraceFunctionAroundWrapper.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/spring-cloud-sleuth-instrumentation/src/main/java/org/springframework/cloud/sleuth/instrument/messaging/TraceFunctionAroundWrapper.java b/spring-cloud-sleuth-instrumentation/src/main/java/org/springframework/cloud/sleuth/instrument/messaging/TraceFunctionAroundWrapper.java index aca731b49..b31cc3ad7 100644 --- a/spring-cloud-sleuth-instrumentation/src/main/java/org/springframework/cloud/sleuth/instrument/messaging/TraceFunctionAroundWrapper.java +++ b/spring-cloud-sleuth-instrumentation/src/main/java/org/springframework/cloud/sleuth/instrument/messaging/TraceFunctionAroundWrapper.java @@ -26,6 +26,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.cloud.context.scope.refresh.RefreshScopeRefreshedEvent; import org.springframework.cloud.function.context.catalog.FunctionAroundWrapper; +import org.springframework.cloud.function.context.catalog.FunctionTypeUtils; import org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; @@ -84,6 +85,22 @@ public class TraceFunctionAroundWrapper extends FunctionAroundWrapper @Override protected Object doApply(Message message, SimpleFunctionRegistry.FunctionInvocationWrapper targetFunction) { + + /* + * This code is temporary to disable conditions for which this interceptor is not ready. + * For example, + * - it does not handle properly input or output of type Publisher + * - it wraps output in Message when function returns a Collection which it should not do. + * + */ + if ( (!FunctionTypeUtils.isCollectionOfMessage(targetFunction.getOutputType()) && !targetFunction.isOutputTypePublisher()) + || (targetFunction.isSupplier() && !targetFunction.isOutputTypePublisher()) + ) { + return targetFunction.apply(message); // no instrumentation + } + + + MessageAndSpans invocationMessage = null; Span span; if (message == null && targetFunction.isSupplier()) { // Supplier