diff --git a/opentracing-jdbc/opentracing-jdbc/src/main/java/org/zalando/opentracing/jdbc/span/ServiceLoaderSpanDecorator.java b/opentracing-jdbc/opentracing-jdbc/src/main/java/org/zalando/opentracing/jdbc/span/ServiceLoaderSpanDecorator.java index 03bc405d..c394f1b6 100644 --- a/opentracing-jdbc/opentracing-jdbc/src/main/java/org/zalando/opentracing/jdbc/span/ServiceLoaderSpanDecorator.java +++ b/opentracing-jdbc/opentracing-jdbc/src/main/java/org/zalando/opentracing/jdbc/span/ServiceLoaderSpanDecorator.java @@ -2,9 +2,12 @@ import org.apiguardian.api.API; +import java.util.List; import java.util.ServiceLoader; import static java.util.ServiceLoader.load; +import static java.util.stream.Collectors.toList; +import static java.util.stream.StreamSupport.stream; import static org.apiguardian.api.API.Status.EXPERIMENTAL; import static org.zalando.opentracing.jdbc.span.SpanDecorator.composite; @@ -15,7 +18,11 @@ public final class ServiceLoaderSpanDecorator extends ForwardingSpanDecorator { public ServiceLoaderSpanDecorator() { - super(composite(load(SpanDecorator.class))); + super(composite(loadDecorators())); + } + + private static synchronized List loadDecorators() { + return stream(load(SpanDecorator.class).spliterator(), false).collect(toList()); } } diff --git a/opentracing-servlet-extension/opentracing-servlet-extension/src/main/java/org/zalando/opentracing/servlet/extension/ServiceLoaderSpanDecorator.java b/opentracing-servlet-extension/opentracing-servlet-extension/src/main/java/org/zalando/opentracing/servlet/extension/ServiceLoaderSpanDecorator.java index af8ccd84..18981c93 100644 --- a/opentracing-servlet-extension/opentracing-servlet-extension/src/main/java/org/zalando/opentracing/servlet/extension/ServiceLoaderSpanDecorator.java +++ b/opentracing-servlet-extension/opentracing-servlet-extension/src/main/java/org/zalando/opentracing/servlet/extension/ServiceLoaderSpanDecorator.java @@ -3,9 +3,12 @@ import io.opentracing.contrib.web.servlet.filter.ServletFilterSpanDecorator; import org.apiguardian.api.API; +import java.util.List; import java.util.ServiceLoader; import static java.util.ServiceLoader.load; +import static java.util.stream.Collectors.toList; +import static java.util.stream.StreamSupport.stream; import static org.apiguardian.api.API.Status.EXPERIMENTAL; /** @@ -15,7 +18,11 @@ public final class ServiceLoaderSpanDecorator extends ForwardingSpanDecorator { public ServiceLoaderSpanDecorator() { - super(CompositeSpanDecorator.composite(load(ServletFilterSpanDecorator.class))); + super(CompositeSpanDecorator.composite(loadDecorators())); + } + + private static synchronized List loadDecorators() { + return stream(load(ServletFilterSpanDecorator.class).spliterator(), false).collect(toList()); } } diff --git a/opentracing-spring-extension/opentracing-spring-web-extension/src/main/java/org/zalando/opentracing/spring/web/extension/ServiceLoaderSpanDecorator.java b/opentracing-spring-extension/opentracing-spring-web-extension/src/main/java/org/zalando/opentracing/spring/web/extension/ServiceLoaderSpanDecorator.java index f95974d3..65a4b798 100644 --- a/opentracing-spring-extension/opentracing-spring-web-extension/src/main/java/org/zalando/opentracing/spring/web/extension/ServiceLoaderSpanDecorator.java +++ b/opentracing-spring-extension/opentracing-spring-web-extension/src/main/java/org/zalando/opentracing/spring/web/extension/ServiceLoaderSpanDecorator.java @@ -3,9 +3,12 @@ import io.opentracing.contrib.spring.web.interceptor.HandlerInterceptorSpanDecorator; import org.apiguardian.api.API; +import java.util.List; import java.util.ServiceLoader; import static java.util.ServiceLoader.load; +import static java.util.stream.Collectors.toList; +import static java.util.stream.StreamSupport.stream; import static org.apiguardian.api.API.Status.EXPERIMENTAL; import static org.zalando.opentracing.spring.web.extension.CompositeSpanDecorator.composite; @@ -17,6 +20,11 @@ public final class ServiceLoaderSpanDecorator extends ForwardingSpanDecorator { public ServiceLoaderSpanDecorator() { - super(composite(load(HandlerInterceptorSpanDecorator.class))); + super(composite(loadDecorators())); } + + private static synchronized List loadDecorators() { + return stream(load(HandlerInterceptorSpanDecorator.class).spliterator(), false).collect(toList()); + } + } diff --git a/opentracing-spring-extension/opentracing-spring-webflux-extension/src/main/java/org/zalando/opentracing/spring/webflux/extension/ServiceLoaderSpanDecorator.java b/opentracing-spring-extension/opentracing-spring-webflux-extension/src/main/java/org/zalando/opentracing/spring/webflux/extension/ServiceLoaderSpanDecorator.java index 94772895..084aafb6 100644 --- a/opentracing-spring-extension/opentracing-spring-webflux-extension/src/main/java/org/zalando/opentracing/spring/webflux/extension/ServiceLoaderSpanDecorator.java +++ b/opentracing-spring-extension/opentracing-spring-webflux-extension/src/main/java/org/zalando/opentracing/spring/webflux/extension/ServiceLoaderSpanDecorator.java @@ -3,9 +3,12 @@ import io.opentracing.contrib.spring.web.webfilter.WebFluxSpanDecorator; import org.apiguardian.api.API; +import java.util.List; import java.util.ServiceLoader; import static java.util.ServiceLoader.load; +import static java.util.stream.Collectors.toList; +import static java.util.stream.StreamSupport.stream; import static org.apiguardian.api.API.Status.EXPERIMENTAL; import static org.zalando.opentracing.spring.webflux.extension.CompositeSpanDecorator.composite; @@ -17,6 +20,11 @@ public final class ServiceLoaderSpanDecorator extends ForwardingSpanDecorator { public ServiceLoaderSpanDecorator() { - super(composite(load(WebFluxSpanDecorator.class))); + super(composite(loadDecorators())); } + + private static synchronized List loadDecorators() { + return stream(load(WebFluxSpanDecorator.class).spliterator(), false).collect(toList()); + } + }