From 06aec1a9bf1411a5de7910b452d725611fe5f2a8 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Fri, 27 Jan 2023 16:29:01 +0100 Subject: [PATCH] Adds CompositeSpanExporter Micrometer Tracing comes with 3 generic interfaces, SpanExportingPredicate, SpanReporter and SpanFilter, thanks to which you can decide whether you want to export a span, how you want to report it and how to mutate it regardless of which tracer library you are using. Without this change usage of these 3 interfaces is not possible for OpenTelemetry. With this change we're putting all SpanExporters to the CompositeSpanExporter and apply the exporters only after predicates, filtering and reporting took place. See gh-34002 --- .../tracing/OpenTelemetryAutoConfiguration.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/OpenTelemetryAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/OpenTelemetryAutoConfiguration.java index 2c5a8b85c8..8ed9a8d4fd 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/OpenTelemetryAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/OpenTelemetryAutoConfiguration.java @@ -20,6 +20,10 @@ import java.util.Collections; import java.util.List; import io.micrometer.tracing.SpanCustomizer; +import io.micrometer.tracing.exporter.SpanExportingPredicate; +import io.micrometer.tracing.exporter.SpanFilter; +import io.micrometer.tracing.exporter.SpanReporter; +import io.micrometer.tracing.otel.bridge.CompositeSpanExporter; import io.micrometer.tracing.otel.bridge.EventListener; import io.micrometer.tracing.otel.bridge.EventPublishingContextWrapper; import io.micrometer.tracing.otel.bridge.OtelBaggageManager; @@ -117,12 +121,12 @@ public class OpenTelemetryAutoConfiguration { } @Bean - SpanProcessor otelSpanProcessor(ObjectProvider spanExporters) { - return SpanProcessor.composite(spanExporters.orderedStream().map(this::buildBatchSpanProcessor).toList()); - } - - private SpanProcessor buildBatchSpanProcessor(SpanExporter exporter) { - return BatchSpanProcessor.builder(exporter).build(); + SpanProcessor otelSpanProcessor(ObjectProvider spanExporters, + ObjectProvider spanExportingPredicates, ObjectProvider spanReporters, + ObjectProvider spanFilters) { + return BatchSpanProcessor.builder(new CompositeSpanExporter(spanExporters.orderedStream().toList(), + spanExportingPredicates.orderedStream().toList(), spanReporters.orderedStream().toList(), + spanFilters.orderedStream().toList())).build(); } @Bean