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
pull/34049/head
Marcin Grzejszczak 2 years ago committed by Moritz Halbritter
parent 4dfc291e15
commit 06aec1a9bf

@ -20,6 +20,10 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import io.micrometer.tracing.SpanCustomizer; 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.EventListener;
import io.micrometer.tracing.otel.bridge.EventPublishingContextWrapper; import io.micrometer.tracing.otel.bridge.EventPublishingContextWrapper;
import io.micrometer.tracing.otel.bridge.OtelBaggageManager; import io.micrometer.tracing.otel.bridge.OtelBaggageManager;
@ -117,12 +121,12 @@ public class OpenTelemetryAutoConfiguration {
} }
@Bean @Bean
SpanProcessor otelSpanProcessor(ObjectProvider<SpanExporter> spanExporters) { SpanProcessor otelSpanProcessor(ObjectProvider<SpanExporter> spanExporters,
return SpanProcessor.composite(spanExporters.orderedStream().map(this::buildBatchSpanProcessor).toList()); ObjectProvider<SpanExportingPredicate> spanExportingPredicates, ObjectProvider<SpanReporter> spanReporters,
} ObjectProvider<SpanFilter> spanFilters) {
return BatchSpanProcessor.builder(new CompositeSpanExporter(spanExporters.orderedStream().toList(),
private SpanProcessor buildBatchSpanProcessor(SpanExporter exporter) { spanExportingPredicates.orderedStream().toList(), spanReporters.orderedStream().toList(),
return BatchSpanProcessor.builder(exporter).build(); spanFilters.orderedStream().toList())).build();
} }
@Bean @Bean

Loading…
Cancel
Save