From 053186929e502f44ea74ebf9929ee3f033422718 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Fri, 9 Feb 2024 15:10:13 +0100 Subject: [PATCH 01/21] add ComponentLoader to support more auto configuration scenarios, e.g. spring boot --- ...ntelemetry-sdk-extension-autoconfigure.txt | 13 ++- .../spi/ConfigurablePropagatorProvider.java | 3 +- .../spi/ConfigurableProvider.java | 17 ++++ .../ConfigurableMetricReaderProvider.java | 4 +- ...ConfigurableLogRecordExporterProvider.java | 4 +- .../ConfigurableMetricExporterProvider.java | 4 +- .../traces/ConfigurableSamplerProvider.java | 4 +- .../ConfigurableSpanExporterProvider.java | 4 +- ...AutoConfiguredOpenTelemetrySdkBuilder.java | 80 ++++++++++------- .../sdk/autoconfigure/ComponentLoader.java | 48 +++++++++++ .../LogRecordExporterConfiguration.java | 1 - .../MeterProviderConfiguration.java | 34 +++++--- .../MetricExporterConfiguration.java | 2 - .../PropagatorConfiguration.java | 1 - .../SpanExporterConfiguration.java | 1 - .../TracerProviderConfiguration.java | 30 +++---- .../sdk/autoconfigure/internal/SpiHelper.java | 86 ++++++++++++------- .../autoconfigure/internal/SpiHelperTest.java | 57 ++++++------ .../ConfigurableSpanExporterTest.java | 12 ++- .../fileconfig/LogRecordExporterFactory.java | 1 - .../fileconfig/MetricExporterFactory.java | 1 - .../fileconfig/MetricReaderFactory.java | 1 - .../incubator/fileconfig/SamplerFactory.java | 1 - .../fileconfig/SpanExporterFactory.java | 1 - .../fileconfig/TextMapPropagatorFactory.java | 1 - .../LogRecordExporterFactoryTest.java | 4 +- .../fileconfig/MetricExporterFactoryTest.java | 4 +- .../fileconfig/MetricReaderFactoryTest.java | 4 +- .../fileconfig/SpanExporterFactoryTest.java | 8 +- 29 files changed, 270 insertions(+), 161 deletions(-) create mode 100644 sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/ConfigurableProvider.java create mode 100644 sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/ComponentLoader.java diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt index df26146497b..8b1c020cd13 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt @@ -1,2 +1,13 @@ Comparing source compatibility of against -No changes. \ No newline at end of file +*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder setComponentLoader(io.opentelemetry.sdk.autoconfigure.ComponentLoader) ++++* NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.autoconfigure.ComponentLoader (not serializable) + +++ CLASS FILE FORMAT VERSION: 52.0 <- n.a. + +++ NEW SUPERCLASS: java.lang.Object + +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) java.lang.Iterable load(java.lang.Class) + GENERIC TEMPLATES: +++ T:java.lang.Object + +++* NEW METHOD: PUBLIC(+) java.util.Map loadConfigurableProviders(java.lang.Class) + GENERIC TEMPLATES: +++ T:io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider + +++* NEW METHOD: PUBLIC(+) java.util.List loadOrdered(java.lang.Class) + GENERIC TEMPLATES: +++ T:io.opentelemetry.sdk.autoconfigure.spi.Ordered diff --git a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/ConfigurablePropagatorProvider.java b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/ConfigurablePropagatorProvider.java index b5f693ed1f8..a2bfd57dcad 100644 --- a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/ConfigurablePropagatorProvider.java +++ b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/ConfigurablePropagatorProvider.java @@ -15,7 +15,7 @@ * #getPropagator(ConfigProperties)} will be enabled and available as part of {@link * OpenTelemetry#getPropagators()}. */ -public interface ConfigurablePropagatorProvider { +public interface ConfigurablePropagatorProvider extends ConfigurableProvider { /** * Returns a {@link TextMapPropagator} that can be registered to OpenTelemetry by providing the * property value specified by {@link #getName()}. @@ -27,5 +27,6 @@ public interface ConfigurablePropagatorProvider { * property to enable it. If the name is the same as any other defined propagator name, it is * undefined which will be used. */ + @Override String getName(); } diff --git a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/ConfigurableProvider.java b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/ConfigurableProvider.java new file mode 100644 index 00000000000..f41910c4768 --- /dev/null +++ b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/ConfigurableProvider.java @@ -0,0 +1,17 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.autoconfigure.spi; + +/** + * A named configurable provider. + * + *

It can be used to generically determine if a provider should be replaced by another provider + * with the same name. + */ +public interface ConfigurableProvider { + /** Returns the name of this provider. */ + String getName(); +} diff --git a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ConfigurableMetricReaderProvider.java b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ConfigurableMetricReaderProvider.java index 1a9feb4acb8..6e8febd7237 100644 --- a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ConfigurableMetricReaderProvider.java +++ b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ConfigurableMetricReaderProvider.java @@ -6,6 +6,7 @@ package io.opentelemetry.sdk.autoconfigure.spi.internal; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider; import io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider; import io.opentelemetry.sdk.metrics.export.MetricExporter; import io.opentelemetry.sdk.metrics.export.MetricReader; @@ -24,7 +25,7 @@ *

This class is internal and is hence not for public use. Its APIs are unstable and can change * at any time. */ -public interface ConfigurableMetricReaderProvider { +public interface ConfigurableMetricReaderProvider extends ConfigurableProvider { /** * Returns a {@link MetricReader} that can be registered to OpenTelemetry by providing the @@ -40,5 +41,6 @@ public interface ConfigurableMetricReaderProvider { * name, the resulting behavior is undefined and it is explicitly unspecified which reader / * exporter will actually be used. */ + @Override String getName(); } diff --git a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/logs/ConfigurableLogRecordExporterProvider.java b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/logs/ConfigurableLogRecordExporterProvider.java index d4e3d2bc949..300b0c15aa8 100644 --- a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/logs/ConfigurableLogRecordExporterProvider.java +++ b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/logs/ConfigurableLogRecordExporterProvider.java @@ -6,6 +6,7 @@ package io.opentelemetry.sdk.autoconfigure.spi.logs; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider; import io.opentelemetry.sdk.logs.export.LogRecordExporter; /** @@ -16,7 +17,7 @@ * * @since 1.19.0 */ -public interface ConfigurableLogRecordExporterProvider { +public interface ConfigurableLogRecordExporterProvider extends ConfigurableProvider { /** * Returns a {@link LogRecordExporter} that can be registered to OpenTelemetry by providing the @@ -30,5 +31,6 @@ public interface ConfigurableLogRecordExporterProvider { * the name does conflict with another exporter name, the resulting behavior is undefined and it * is explicitly unspecified which exporter will actually be used. */ + @Override String getName(); } diff --git a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/metrics/ConfigurableMetricExporterProvider.java b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/metrics/ConfigurableMetricExporterProvider.java index 465366c4e29..0d66a502fc2 100644 --- a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/metrics/ConfigurableMetricExporterProvider.java +++ b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/metrics/ConfigurableMetricExporterProvider.java @@ -6,6 +6,7 @@ package io.opentelemetry.sdk.autoconfigure.spi.metrics; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider; import io.opentelemetry.sdk.autoconfigure.spi.internal.ConfigurableMetricReaderProvider; import io.opentelemetry.sdk.metrics.export.MetricExporter; import io.opentelemetry.sdk.metrics.export.MetricReader; @@ -22,7 +23,7 @@ * * @since 1.15.0 */ -public interface ConfigurableMetricExporterProvider { +public interface ConfigurableMetricExporterProvider extends ConfigurableProvider { /** * Returns a {@link MetricExporter} that can be registered to OpenTelemetry by providing the @@ -38,5 +39,6 @@ public interface ConfigurableMetricExporterProvider { * name, the resulting behavior is undefined and it is explicitly unspecified which exporter / * reader will actually be used. */ + @Override String getName(); } diff --git a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/traces/ConfigurableSamplerProvider.java b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/traces/ConfigurableSamplerProvider.java index b97d9eb4a43..5c20473bad0 100644 --- a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/traces/ConfigurableSamplerProvider.java +++ b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/traces/ConfigurableSamplerProvider.java @@ -6,6 +6,7 @@ package io.opentelemetry.sdk.autoconfigure.spi.traces; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider; import io.opentelemetry.sdk.trace.samplers.Sampler; /** @@ -14,7 +15,7 @@ * returned by {@link #getName()}, the sampler returned by {@link #createSampler(ConfigProperties)} * will be enabled and added to the SDK. */ -public interface ConfigurableSamplerProvider { +public interface ConfigurableSamplerProvider extends ConfigurableProvider { /** * Returns a {@link Sampler} that can be registered to OpenTelemetry by providing the property @@ -28,5 +29,6 @@ public interface ConfigurableSamplerProvider { * the name does conflict with another exporter name, the resulting behavior is undefined and it * is explicitly unspecified which exporter will actually be used. */ + @Override String getName(); } diff --git a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/traces/ConfigurableSpanExporterProvider.java b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/traces/ConfigurableSpanExporterProvider.java index 94ac4cedafb..576785776a5 100644 --- a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/traces/ConfigurableSpanExporterProvider.java +++ b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/traces/ConfigurableSpanExporterProvider.java @@ -6,6 +6,7 @@ package io.opentelemetry.sdk.autoconfigure.spi.traces; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider; import io.opentelemetry.sdk.trace.export.SpanExporter; /** @@ -14,7 +15,7 @@ * is returned by {@link #getName()}, the exporter returned by {@link * #createExporter(ConfigProperties)} will be enabled and added to the SDK. */ -public interface ConfigurableSpanExporterProvider { +public interface ConfigurableSpanExporterProvider extends ConfigurableProvider { /** * Returns a {@link SpanExporter} that can be registered to OpenTelemetry by providing the @@ -28,5 +29,6 @@ public interface ConfigurableSpanExporterProvider { * the name does conflict with another exporter name, the resulting behavior is undefined and it * is explicitly unspecified which exporter will actually be used. */ + @Override String getName(); } diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java index 8e332c2a2b7..0230acf37e4 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java @@ -368,6 +368,12 @@ public AutoConfiguredOpenTelemetrySdkBuilder setServiceClassLoader( return this; } + public AutoConfiguredOpenTelemetrySdkBuilder setComponentLoader(ComponentLoader componentLoader) { + requireNonNull(componentLoader, "componentLoader"); + this.spiHelper = SpiHelper.create(componentLoader); + return this; + } + /** * Returns a new {@link AutoConfiguredOpenTelemetrySdk} holding components auto-configured using * the settings of this {@link AutoConfiguredOpenTelemetrySdkBuilder}. @@ -403,41 +409,53 @@ public AutoConfiguredOpenTelemetrySdk build() { boolean sdkEnabled = !config.getBoolean("otel.sdk.disabled", false); if (sdkEnabled) { - SdkMeterProviderBuilder meterProviderBuilder = SdkMeterProvider.builder(); - meterProviderBuilder.setResource(resource); - MeterProviderConfiguration.configureMeterProvider( - meterProviderBuilder, config, spiHelper, metricExporterCustomizer, closeables); - meterProviderBuilder = meterProviderCustomizer.apply(meterProviderBuilder, config); - SdkMeterProvider meterProvider = meterProviderBuilder.build(); + SdkMeterProvider meterProvider = + spiHelper.loadOptional(SdkMeterProvider.class).orElse(null); + if (meterProvider == null) { + SdkMeterProviderBuilder meterProviderBuilder = SdkMeterProvider.builder(); + meterProviderBuilder.setResource(resource); + MeterProviderConfiguration.configureMeterProvider( + meterProviderBuilder, config, spiHelper, metricExporterCustomizer, closeables); + meterProviderBuilder = meterProviderCustomizer.apply(meterProviderBuilder, config); + meterProvider = meterProviderBuilder.build(); + } closeables.add(meterProvider); - SdkTracerProviderBuilder tracerProviderBuilder = SdkTracerProvider.builder(); - tracerProviderBuilder.setResource(resource); - TracerProviderConfiguration.configureTracerProvider( - tracerProviderBuilder, - config, - spiHelper, - meterProvider, - spanExporterCustomizer, - spanProcessorCustomizer, - samplerCustomizer, - closeables); - tracerProviderBuilder = tracerProviderCustomizer.apply(tracerProviderBuilder, config); - SdkTracerProvider tracerProvider = tracerProviderBuilder.build(); + SdkTracerProvider tracerProvider = + spiHelper.loadOptional(SdkTracerProvider.class).orElse(null); + if (tracerProvider == null) { + SdkTracerProviderBuilder tracerProviderBuilder = SdkTracerProvider.builder(); + tracerProviderBuilder.setResource(resource); + TracerProviderConfiguration.configureTracerProvider( + tracerProviderBuilder, + config, + spiHelper, + meterProvider, + spanExporterCustomizer, + spanProcessorCustomizer, + samplerCustomizer, + closeables); + tracerProviderBuilder = tracerProviderCustomizer.apply(tracerProviderBuilder, config); + tracerProvider = tracerProviderBuilder.build(); + } closeables.add(tracerProvider); - SdkLoggerProviderBuilder loggerProviderBuilder = SdkLoggerProvider.builder(); - loggerProviderBuilder.setResource(resource); - LoggerProviderConfiguration.configureLoggerProvider( - loggerProviderBuilder, - config, - spiHelper, - meterProvider, - logRecordExporterCustomizer, - logRecordProcessorCustomizer, - closeables); - loggerProviderBuilder = loggerProviderCustomizer.apply(loggerProviderBuilder, config); - SdkLoggerProvider loggerProvider = loggerProviderBuilder.build(); + SdkLoggerProvider loggerProvider = + spiHelper.loadOptional(SdkLoggerProvider.class).orElse(null); + if (loggerProvider == null) { + SdkLoggerProviderBuilder loggerProviderBuilder = SdkLoggerProvider.builder(); + loggerProviderBuilder.setResource(resource); + LoggerProviderConfiguration.configureLoggerProvider( + loggerProviderBuilder, + config, + spiHelper, + meterProvider, + logRecordExporterCustomizer, + logRecordProcessorCustomizer, + closeables); + loggerProviderBuilder = loggerProviderCustomizer.apply(loggerProviderBuilder, config); + loggerProvider = loggerProviderBuilder.build(); + } closeables.add(loggerProvider); ContextPropagators propagators = diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/ComponentLoader.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/ComponentLoader.java new file mode 100644 index 00000000000..6bbb92c2abf --- /dev/null +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/ComponentLoader.java @@ -0,0 +1,48 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.autoconfigure; + +import io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider; +import io.opentelemetry.sdk.autoconfigure.spi.Ordered; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; + +/** A loader for components that are discovered via SPI. */ +public interface ComponentLoader { + Iterable load(Class spiClass); + + default Optional loadOptional(Class spiClass) { + Iterable iterable = load(spiClass); + return StreamSupport.stream(iterable.spliterator(), false).findFirst(); + } + + /** + * Load implementations of an ordered SPI (i.e. implements {@link Ordered}). + * + * @param spiClass the SPI class + * @param the SPI type + * @return list of SPI implementations, in order + */ + default List loadOrdered(Class spiClass) { + return StreamSupport.stream(load(spiClass).spliterator(), false) + .sorted(Comparator.comparing(Ordered::order)) + .collect(Collectors.toList()); + } + + default Map loadConfigurableProviders( + Class spiClass) { + Map components = new HashMap<>(); + for (T component : load(spiClass)) { + components.put(component.getName(), component); + } + return components; + } +} diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfiguration.java index b0eeb2481c0..b576d8093bf 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfiguration.java @@ -80,7 +80,6 @@ static NamedSpiManager logRecordExporterSpiManager( ConfigProperties config, SpiHelper spiHelper) { return spiHelper.loadConfigurable( ConfigurableLogRecordExporterProvider.class, - ConfigurableLogRecordExporterProvider::getName, ConfigurableLogRecordExporterProvider::createExporter, config); } diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MeterProviderConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MeterProviderConfiguration.java index 525dc54974a..b269903030c 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MeterProviderConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MeterProviderConfiguration.java @@ -19,6 +19,7 @@ import java.util.Collections; import java.util.List; import java.util.Locale; +import java.util.Optional; import java.util.Set; import java.util.function.BiFunction; import java.util.stream.Collectors; @@ -33,20 +34,25 @@ static void configureMeterProvider( metricExporterCustomizer, List closeables) { - // Configure default exemplar filters. - String exemplarFilter = - config.getString("otel.metrics.exemplar.filter", "trace_based").toLowerCase(Locale.ROOT); - switch (exemplarFilter) { - case "always_off": - SdkMeterProviderUtil.setExemplarFilter(meterProviderBuilder, ExemplarFilter.alwaysOff()); - break; - case "always_on": - SdkMeterProviderUtil.setExemplarFilter(meterProviderBuilder, ExemplarFilter.alwaysOn()); - break; - case "trace_based": - default: - SdkMeterProviderUtil.setExemplarFilter(meterProviderBuilder, ExemplarFilter.traceBased()); - break; + Optional spiExemplarFilter = spiHelper.loadOptional(ExemplarFilter.class); + if (spiExemplarFilter.isPresent()) { + SdkMeterProviderUtil.setExemplarFilter(meterProviderBuilder, spiExemplarFilter.get()); + } else { + // Configure default exemplar filters. + String exemplarFilter = + config.getString("otel.metrics.exemplar.filter", "trace_based").toLowerCase(Locale.ROOT); + switch (exemplarFilter) { + case "always_off": + SdkMeterProviderUtil.setExemplarFilter(meterProviderBuilder, ExemplarFilter.alwaysOff()); + break; + case "always_on": + SdkMeterProviderUtil.setExemplarFilter(meterProviderBuilder, ExemplarFilter.alwaysOn()); + break; + case "trace_based": + default: + SdkMeterProviderUtil.setExemplarFilter(meterProviderBuilder, ExemplarFilter.traceBased()); + break; + } } int cardinalityLimit = diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfiguration.java index 2aa968a82bb..028b3dacde5 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfiguration.java @@ -82,7 +82,6 @@ static NamedSpiManager metricReadersSpiManager( ConfigProperties config, SpiHelper spiHelper) { return spiHelper.loadConfigurable( ConfigurableMetricReaderProvider.class, - ConfigurableMetricReaderProvider::getName, ConfigurableMetricReaderProvider::createMetricReader, config); } @@ -107,7 +106,6 @@ static NamedSpiManager metricExporterSpiManager( ConfigProperties config, SpiHelper spiHelper) { return spiHelper.loadConfigurable( ConfigurableMetricExporterProvider.class, - ConfigurableMetricExporterProvider::getName, ConfigurableMetricExporterProvider::createExporter, config); } diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/PropagatorConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/PropagatorConfiguration.java index fea60b18f80..ca992bd5fc2 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/PropagatorConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/PropagatorConfiguration.java @@ -35,7 +35,6 @@ static ContextPropagators configurePropagators( NamedSpiManager spiPropagatorsManager = spiHelper.loadConfigurable( ConfigurablePropagatorProvider.class, - ConfigurablePropagatorProvider::getName, ConfigurablePropagatorProvider::getPropagator, config); diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java index c5da0e0a045..68cec9f1ff6 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java @@ -80,7 +80,6 @@ static NamedSpiManager spanExporterSpiManager( ConfigProperties config, SpiHelper spiHelper) { return spiHelper.loadConfigurable( ConfigurableSpanExporterProvider.class, - ConfigurableSpanExporterProvider::getName, ConfigurableSpanExporterProvider::createExporter, config); } diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/TracerProviderConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/TracerProviderConfiguration.java index 1241acccc8d..7e61d16a41f 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/TracerProviderConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/TracerProviderConfiguration.java @@ -22,7 +22,6 @@ import io.opentelemetry.sdk.trace.samplers.Sampler; import java.io.Closeable; import java.time.Duration; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -56,7 +55,7 @@ static void configureTracerProvider( config, spiHelper, spanExporterCustomizer, closeables); List processors = - configureSpanProcessors(config, exportersByName, meterProvider, closeables); + configureSpanProcessors(config, exportersByName, meterProvider, closeables, spiHelper); for (SpanProcessor processor : processors) { SpanProcessor wrapped = spanProcessorCustomizer.apply(processor, config); if (wrapped != processor) { @@ -70,9 +69,10 @@ static List configureSpanProcessors( ConfigProperties config, Map exportersByName, MeterProvider meterProvider, - List closeables) { + List closeables, + SpiHelper spiHelper) { Map exportersByNameCopy = new HashMap<>(exportersByName); - List spanProcessors = new ArrayList<>(); + List spanProcessors = spiHelper.load(SpanProcessor.class); SpanExporter exporter = exportersByNameCopy.remove("logging"); if (exporter != null) { @@ -162,10 +162,7 @@ static SpanLimits configureSpanLimits(ConfigProperties config) { static Sampler configureSampler(String sampler, ConfigProperties config, SpiHelper spiHelper) { NamedSpiManager spiSamplersManager = spiHelper.loadConfigurable( - ConfigurableSamplerProvider.class, - ConfigurableSamplerProvider::getName, - ConfigurableSamplerProvider::createSampler, - config); + ConfigurableSamplerProvider.class, ConfigurableSamplerProvider::createSampler, config); switch (sampler) { case "always_on": @@ -173,21 +170,13 @@ static Sampler configureSampler(String sampler, ConfigProperties config, SpiHelp case "always_off": return Sampler.alwaysOff(); case "traceidratio": - { - double ratio = - config.getDouble("otel.traces.sampler.arg", DEFAULT_TRACEIDRATIO_SAMPLE_RATIO); - return Sampler.traceIdRatioBased(ratio); - } + return ratioSampler(config); case PARENTBASED_ALWAYS_ON: return Sampler.parentBased(Sampler.alwaysOn()); case "parentbased_always_off": return Sampler.parentBased(Sampler.alwaysOff()); case "parentbased_traceidratio": - { - double ratio = - config.getDouble("otel.traces.sampler.arg", DEFAULT_TRACEIDRATIO_SAMPLE_RATIO); - return Sampler.parentBased(Sampler.traceIdRatioBased(ratio)); - } + return Sampler.parentBased(ratioSampler(config)); case "parentbased_jaeger_remote": Sampler jaegerRemote = spiSamplersManager.getByName("jaeger_remote"); if (jaegerRemote == null) { @@ -205,5 +194,10 @@ static Sampler configureSampler(String sampler, ConfigProperties config, SpiHelp } } + private static Sampler ratioSampler(ConfigProperties config) { + double ratio = config.getDouble("otel.traces.sampler.arg", DEFAULT_TRACEIDRATIO_SAMPLE_RATIO); + return Sampler.traceIdRatioBased(ratio); + } + private TracerProviderConfiguration() {} } diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java index 4002ce65329..9d28aba18cd 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java @@ -5,20 +5,21 @@ package io.opentelemetry.sdk.autoconfigure.internal; +import io.opentelemetry.sdk.autoconfigure.ComponentLoader; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider; import io.opentelemetry.sdk.autoconfigure.spi.Ordered; import io.opentelemetry.sdk.autoconfigure.spi.internal.AutoConfigureListener; import java.util.ArrayList; import java.util.Collections; -import java.util.Comparator; import java.util.HashMap; import java.util.IdentityHashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.ServiceLoader; import java.util.Set; import java.util.function.BiFunction; -import java.util.function.Function; import java.util.function.Supplier; /** @@ -27,49 +28,47 @@ */ public final class SpiHelper { - private final ClassLoader classLoader; - private final SpiFinder spiFinder; + private final ComponentLoader componentLoader; private final Set listeners = Collections.newSetFromMap(new IdentityHashMap<>()); - // Visible for testing - SpiHelper(ClassLoader classLoader, SpiFinder spiFinder) { - this.classLoader = classLoader; - this.spiFinder = spiFinder; + private SpiHelper(ComponentLoader componentLoader) { + this.componentLoader = componentLoader; } /** Create a {@link SpiHelper} which loads SPIs using the {@code classLoader}. */ public static SpiHelper create(ClassLoader classLoader) { - return new SpiHelper(classLoader, ServiceLoader::load); + return new SpiHelper(new ServiceLoaderComponentLoader(classLoader)); + } + + public static SpiHelper create(ComponentLoader componentLoader) { + return new SpiHelper(componentLoader); } /** * Load implementations of an SPI which are configurable (i.e. they accept {@link * ConfigProperties}. * + * @param the configurable type + * @param the SPI type * @param spiClass the SPI class - * @param getName function returning the name of an SPI implementation * @param getConfigurable function returning a configured instance * @param config the configuration to pass to invocations of {@code #getConfigurable} - * @param the configurable type - * @param the SPI type * @return a {@link NamedSpiManager} used to access configured instances of the SPI by name */ - public NamedSpiManager loadConfigurable( + public NamedSpiManager loadConfigurable( Class spiClass, - Function getName, BiFunction getConfigurable, ConfigProperties config) { Map> nameToProvider = new HashMap<>(); - for (S provider : load(spiClass)) { - String name = getName.apply(provider); - nameToProvider.put( - name, - () -> { - T result = getConfigurable.apply(provider, config); - maybeAddListener(result); - return result; - }); + Map providers = componentLoader.loadConfigurableProviders(spiClass); + for (Map.Entry entry : providers.entrySet()) { + S provider = entry.getValue(); + String name = entry.getKey(); + // both the provider and the result may have a listener + maybeAddListener(provider); + + nameToProvider.put(name, () -> maybeAddListener(getConfigurable.apply(provider, config))); } return NamedSpiManager.create(nameToProvider); } @@ -82,9 +81,7 @@ public NamedSpiManager loadConfigurable( * @return list of SPI implementations, in order */ public List loadOrdered(Class spiClass) { - List result = load(spiClass); - result.sort(Comparator.comparing(Ordered::order)); - return result; + return init(componentLoader.loadOrdered(spiClass)); } /** @@ -95,18 +92,33 @@ public List loadOrdered(Class spiClass) { * @return list of SPI implementations */ public List load(Class spiClass) { + return init(componentLoader.load(spiClass)); + } + + /** + * Load implementations of an SPI. + * + * @param components the SPI implementations + * @param the SPI type + * @return list of SPI implementations + */ + private List init(Iterable components) { List result = new ArrayList<>(); - for (T service : spiFinder.load(spiClass, classLoader)) { - maybeAddListener(service); - result.add(service); + for (T service : components) { + result.add(maybeAddListener(service)); } return result; } - private void maybeAddListener(Object object) { + public Optional loadOptional(Class spiClass) { + return componentLoader.loadOptional(spiClass).map(this::maybeAddListener); + } + + private T maybeAddListener(T object) { if (object instanceof AutoConfigureListener) { listeners.add((AutoConfigureListener) object); } + return object; } /** Return the set of SPIs loaded which implement {@link AutoConfigureListener}. */ @@ -114,8 +126,16 @@ public Set getListeners() { return Collections.unmodifiableSet(listeners); } - // Visible for testing - interface SpiFinder { - Iterable load(Class spiClass, ClassLoader classLoader); + private static class ServiceLoaderComponentLoader implements ComponentLoader { + private final ClassLoader classLoader; + + private ServiceLoaderComponentLoader(ClassLoader classLoader) { + this.classLoader = classLoader; + } + + @Override + public Iterable load(Class spiClass) { + return ServiceLoader.load(spiClass, classLoader); + } } } diff --git a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelperTest.java b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelperTest.java index a2d5c870d4b..7af00b18dda 100644 --- a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelperTest.java +++ b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelperTest.java @@ -11,10 +11,13 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; +import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import io.opentelemetry.sdk.autoconfigure.ComponentLoader; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider; import io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider; import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import java.util.Collections; @@ -28,18 +31,15 @@ public class SpiHelperTest { @Test public void canRetrieveByName() { - SpiHelper.SpiFinder mockFinder = mock(SpiHelper.SpiFinder.class); - when(mockFinder.load(any(), any())) + ComponentLoader mockLoader = spy(ComponentLoader.class); + when(mockLoader.load(any())) .thenReturn(Collections.singletonList(new SpiExampleProviderImplementation())); - SpiHelper spiHelper = new SpiHelper(SpiHelperTest.class.getClassLoader(), mockFinder); + SpiHelper spiHelper = SpiHelper.create(mockLoader); NamedSpiManager spiProvider = spiHelper.loadConfigurable( - SpiExampleProvider.class, - SpiExampleProvider::getName, - SpiExampleProvider::createSpiExample, - EMPTY); + SpiExampleProvider.class, SpiExampleProvider::createSpiExample, EMPTY); assertThat(spiProvider.getByName(SpiExampleProviderImplementation.NAME)).isNotNull(); assertThat(spiProvider.getByName("invalid-provider")).isNull(); @@ -49,17 +49,14 @@ public void canRetrieveByName() { public void instantiatesImplementationsLazily() { SpiExampleProvider mockProvider = mock(SpiExampleProvider.class); when(mockProvider.getName()).thenReturn("lazy-init-example"); - SpiHelper.SpiFinder mockFinder = mock(SpiHelper.SpiFinder.class); - when(mockFinder.load(any(), any())).thenReturn(Collections.singletonList(mockProvider)); + ComponentLoader mockLoader = spy(ComponentLoader.class); + when(mockLoader.load(any())).thenReturn(Collections.singletonList(mockProvider)); - SpiHelper spiHelper = new SpiHelper(SpiHelperTest.class.getClassLoader(), mockFinder); + SpiHelper spiHelper = SpiHelper.create(mockLoader); NamedSpiManager spiProvider = spiHelper.loadConfigurable( - SpiExampleProvider.class, - SpiExampleProvider::getName, - SpiExampleProvider::createSpiExample, - EMPTY); + SpiExampleProvider.class, SpiExampleProvider::createSpiExample, EMPTY); verify(mockProvider, never()).createSpiExample(any()); // not requested yet spiProvider.getByName("lazy-init-example"); @@ -68,18 +65,15 @@ public void instantiatesImplementationsLazily() { @Test public void onlyInstantiatesOnce() { - SpiHelper.SpiFinder mockFinder = mock(SpiHelper.SpiFinder.class); - when(mockFinder.load(any(), any())) + ComponentLoader mockLoader = mock(ComponentLoader.class); + when(mockLoader.load(any())) .thenReturn(Collections.singletonList(new SpiExampleProviderImplementation())); - SpiHelper spiHelper = new SpiHelper(SpiHelperTest.class.getClassLoader(), mockFinder); + SpiHelper spiHelper = SpiHelper.create(mockLoader); NamedSpiManager spiProvider = spiHelper.loadConfigurable( - SpiExampleProvider.class, - SpiExampleProvider::getName, - SpiExampleProvider::createSpiExample, - EMPTY); + SpiExampleProvider.class, SpiExampleProvider::createSpiExample, EMPTY); SpiExample first = spiProvider.getByName(SpiExampleProviderImplementation.NAME); SpiExample second = spiProvider.getByName(SpiExampleProviderImplementation.NAME); @@ -93,17 +87,14 @@ public void failureToInitializeThrows() { when(mockProvider.getName()).thenReturn("init-failure-example"); when(mockProvider.createSpiExample(any())).thenThrow(new RuntimeException()); - SpiHelper.SpiFinder mockFinder = mock(SpiHelper.SpiFinder.class); - when(mockFinder.load(any(), any())).thenReturn(Collections.singletonList(mockProvider)); + ComponentLoader mockLoader = spy(ComponentLoader.class); + when(mockLoader.load(any())).thenReturn(Collections.singletonList(mockProvider)); - SpiHelper spiHelper = new SpiHelper(SpiHelperTest.class.getClassLoader(), mockFinder); + SpiHelper spiHelper = SpiHelper.create(mockLoader); NamedSpiManager spiProvider = spiHelper.loadConfigurable( - SpiExampleProvider.class, - SpiExampleProvider::getName, - SpiExampleProvider::createSpiExample, - EMPTY); + SpiExampleProvider.class, SpiExampleProvider::createSpiExample, EMPTY); assertThatThrownBy(() -> spiProvider.getByName("init-failure-example")) .withFailMessage(exceptionMessage) @@ -120,19 +111,19 @@ void loadsOrderedSpi() { when(spi2.order()).thenReturn(0); when(spi3.order()).thenReturn(1); - SpiHelper.SpiFinder mockFinder = mock(SpiHelper.SpiFinder.class); - when(mockFinder.load(ResourceProvider.class, SpiHelper.class.getClassLoader())) - .thenReturn(asList(spi1, spi2, spi3)); + ComponentLoader mockLoader = spy(ComponentLoader.class); + when(mockLoader.load(ResourceProvider.class)).thenReturn(asList(spi1, spi2, spi3)); - SpiHelper spiHelper = new SpiHelper(SpiHelperTest.class.getClassLoader(), mockFinder); + SpiHelper spiHelper = SpiHelper.create(mockLoader); List loadedSpi = spiHelper.loadOrdered(ResourceProvider.class); assertThat(loadedSpi).containsExactly(spi2, spi3, spi1); } - private interface SpiExampleProvider { + private interface SpiExampleProvider extends ConfigurableProvider { + @Override String getName(); SpiExample createSpiExample(ConfigProperties config); diff --git a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableSpanExporterTest.java b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableSpanExporterTest.java index ef533b82ac3..988a0ba22a8 100644 --- a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableSpanExporterTest.java +++ b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableSpanExporterTest.java @@ -146,7 +146,8 @@ void configureSpanProcessors_simpleSpanProcessor() { Collections.singletonMap("otel.traces.exporter", exporterName)), ImmutableMap.of(exporterName, LoggingSpanExporter.create()), MeterProvider.noop(), - closeables); + closeables, + spiHelper); cleanup.addCloseables(closeables); assertThat(spanProcessors).hasExactlyElementsOfTypes(SimpleSpanProcessor.class); @@ -164,7 +165,8 @@ void configureSpanProcessors_batchSpanProcessor() { Collections.singletonMap("otel.traces.exporter", exporterName)), ImmutableMap.of(exporterName, ZipkinSpanExporter.builder().build()), MeterProvider.noop(), - closeables); + closeables, + spiHelper); cleanup.addCloseables(closeables); assertThat(spanProcessors).hasExactlyElementsOfTypes(BatchSpanProcessor.class); @@ -185,7 +187,8 @@ void configureSpanProcessors_multipleExporters() { "zipkin", ZipkinSpanExporter.builder().build()), MeterProvider.noop(), - closeables); + closeables, + spiHelper); cleanup.addCloseables(closeables); assertThat(spanProcessors) @@ -227,7 +230,8 @@ void configureSpanProcessors_multipleExportersWithLogging() { "zipkin", ZipkinSpanExporter.builder().build()), MeterProvider.noop(), - closeables); + closeables, + spiHelper); cleanup.addCloseables(closeables); assertThat(spanProcessors) diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordExporterFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordExporterFactory.java index 3469ec61e36..f8849992831 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordExporterFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordExporterFactory.java @@ -107,7 +107,6 @@ private static NamedSpiManager logRecordExporterSpiManager( ConfigProperties config, SpiHelper spiHelper) { return spiHelper.loadConfigurable( ConfigurableLogRecordExporterProvider.class, - ConfigurableLogRecordExporterProvider::getName, ConfigurableLogRecordExporterProvider::createExporter, config); } diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricExporterFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricExporterFactory.java index 7d187f8a057..5f3785543f3 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricExporterFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricExporterFactory.java @@ -134,7 +134,6 @@ private static NamedSpiManager metricExporterSpiManager( ConfigProperties config, SpiHelper spiHelper) { return spiHelper.loadConfigurable( ConfigurableMetricExporterProvider.class, - ConfigurableMetricExporterProvider::getName, ConfigurableMetricExporterProvider::createExporter, config); } diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricReaderFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricReaderFactory.java index bcaafd6c6e3..0f89ec49880 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricReaderFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricReaderFactory.java @@ -108,7 +108,6 @@ public MetricReader create( metricReaderSpiManager(ConfigProperties config, SpiHelper spiHelper) { return spiHelper.loadConfigurable( ConfigurableMetricReaderProvider.class, - ConfigurableMetricReaderProvider::getName, ConfigurableMetricReaderProvider::createMetricReader, config); } diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SamplerFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SamplerFactory.java index 8d881c2d03e..767ba2604bd 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SamplerFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SamplerFactory.java @@ -130,7 +130,6 @@ private static NamedSpiManager samplerSpiManager( ConfigProperties config, SpiHelper spiHelper) { return spiHelper.loadConfigurable( ConfigurableSamplerProvider.class, - ConfigurableSamplerProvider::getName, ConfigurableSamplerProvider::createSampler, config); } diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanExporterFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanExporterFactory.java index 8a3b8cc6dce..45214db8f96 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanExporterFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanExporterFactory.java @@ -141,7 +141,6 @@ private static NamedSpiManager spanExporterSpiManager( ConfigProperties config, SpiHelper spiHelper) { return spiHelper.loadConfigurable( ConfigurableSpanExporterProvider.class, - ConfigurableSpanExporterProvider::getName, ConfigurableSpanExporterProvider::createExporter, config); } diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/TextMapPropagatorFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/TextMapPropagatorFactory.java index 4451ac98516..9616cc77cd4 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/TextMapPropagatorFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/TextMapPropagatorFactory.java @@ -49,7 +49,6 @@ public TextMapPropagator create( NamedSpiManager spiPropagatorsManager = spiHelper.loadConfigurable( ConfigurablePropagatorProvider.class, - ConfigurablePropagatorProvider::getName, ConfigurablePropagatorProvider::getPropagator, DefaultConfigProperties.createFromMap(Collections.emptyMap())); Set propagators = new LinkedHashSet<>(); diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordExporterFactoryTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordExporterFactoryTest.java index 721421c8552..349b5dca15e 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordExporterFactoryTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordExporterFactoryTest.java @@ -89,7 +89,7 @@ void create_OtlpDefaults() { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(ConfigProperties.class); verify(spiHelper) .loadConfigurable( - eq(ConfigurableLogRecordExporterProvider.class), any(), any(), configCaptor.capture()); + eq(ConfigurableLogRecordExporterProvider.class), any(), configCaptor.capture()); ConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("otel.exporter.otlp.logs.protocol")).isNull(); assertThat(configProperties.getString("otel.exporter.otlp.endpoint")).isNull(); @@ -154,7 +154,7 @@ void create_OtlpConfigured(@TempDir Path tempDir) ArgumentCaptor configCaptor = ArgumentCaptor.forClass(ConfigProperties.class); verify(spiHelper) .loadConfigurable( - eq(ConfigurableLogRecordExporterProvider.class), any(), any(), configCaptor.capture()); + eq(ConfigurableLogRecordExporterProvider.class), any(), configCaptor.capture()); ConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("otel.exporter.otlp.logs.protocol")) .isEqualTo("http/protobuf"); diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricExporterFactoryTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricExporterFactoryTest.java index 4b9b7520441..9f8344e2636 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricExporterFactoryTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricExporterFactoryTest.java @@ -88,7 +88,7 @@ void create_OtlpDefaults() { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(ConfigProperties.class); verify(spiHelper) .loadConfigurable( - eq(ConfigurableMetricExporterProvider.class), any(), any(), configCaptor.capture()); + eq(ConfigurableMetricExporterProvider.class), any(), configCaptor.capture()); ConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("otel.exporter.otlp.metrics.protocol")).isNull(); assertThat(configProperties.getString("otel.exporter.otlp.endpoint")).isNull(); @@ -162,7 +162,7 @@ void create_OtlpConfigured(@TempDir Path tempDir) ArgumentCaptor configCaptor = ArgumentCaptor.forClass(ConfigProperties.class); verify(spiHelper) .loadConfigurable( - eq(ConfigurableMetricExporterProvider.class), any(), any(), configCaptor.capture()); + eq(ConfigurableMetricExporterProvider.class), any(), configCaptor.capture()); ConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("otel.exporter.otlp.metrics.protocol")) .isEqualTo("http/protobuf"); diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricReaderFactoryTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricReaderFactoryTest.java index 64da70549a1..dbc23f93730 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricReaderFactoryTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricReaderFactoryTest.java @@ -145,7 +145,7 @@ void create_PullPrometheusDefault() throws IOException { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(ConfigProperties.class); verify(spiHelper) .loadConfigurable( - eq(ConfigurableMetricReaderProvider.class), any(), any(), configCaptor.capture()); + eq(ConfigurableMetricReaderProvider.class), any(), configCaptor.capture()); ConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("otel.exporter.prometheus.host")).isNull(); assertThat(configProperties.getInt("otel.exporter.prometheus.port")).isEqualTo(port); @@ -182,7 +182,7 @@ void create_PullPrometheusConfigured() throws IOException { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(ConfigProperties.class); verify(spiHelper) .loadConfigurable( - eq(ConfigurableMetricReaderProvider.class), any(), any(), configCaptor.capture()); + eq(ConfigurableMetricReaderProvider.class), any(), configCaptor.capture()); ConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("otel.exporter.prometheus.host")).isEqualTo("localhost"); assertThat(configProperties.getInt("otel.exporter.prometheus.port")).isEqualTo(port); diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanExporterFactoryTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanExporterFactoryTest.java index 09c47433003..828cc2ab574 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanExporterFactoryTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanExporterFactoryTest.java @@ -82,7 +82,7 @@ void create_OtlpDefaults() { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(ConfigProperties.class); verify(spiHelper) .loadConfigurable( - eq(ConfigurableSpanExporterProvider.class), any(), any(), configCaptor.capture()); + eq(ConfigurableSpanExporterProvider.class), any(), configCaptor.capture()); ConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("otel.exporter.otlp.traces.protocol")).isNull(); assertThat(configProperties.getString("otel.exporter.otlp.endpoint")).isNull(); @@ -147,7 +147,7 @@ void create_OtlpConfigured(@TempDir Path tempDir) ArgumentCaptor configCaptor = ArgumentCaptor.forClass(ConfigProperties.class); verify(spiHelper) .loadConfigurable( - eq(ConfigurableSpanExporterProvider.class), any(), any(), configCaptor.capture()); + eq(ConfigurableSpanExporterProvider.class), any(), configCaptor.capture()); ConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("otel.exporter.otlp.traces.protocol")) .isEqualTo("http/protobuf"); @@ -212,7 +212,7 @@ void create_ZipkinDefaults() { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(ConfigProperties.class); verify(spiHelper) .loadConfigurable( - eq(ConfigurableSpanExporterProvider.class), any(), any(), configCaptor.capture()); + eq(ConfigurableSpanExporterProvider.class), any(), configCaptor.capture()); ConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("otel.exporter.zipkin.endpoint")).isNull(); assertThat(configProperties.getDuration("otel.exporter.zipkin.timeout")).isNull(); @@ -248,7 +248,7 @@ void create_ZipkinConfigured() { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(ConfigProperties.class); verify(spiHelper) .loadConfigurable( - eq(ConfigurableSpanExporterProvider.class), any(), any(), configCaptor.capture()); + eq(ConfigurableSpanExporterProvider.class), any(), configCaptor.capture()); ConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("otel.exporter.zipkin.endpoint")) .isEqualTo("http://zipkin:9411/v1/v2/spans"); From 6d51896efd836b4860b217e64c1d86da3f80f492 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Tue, 13 Feb 2024 15:35:58 +0100 Subject: [PATCH 02/21] format --- .../sdk/extension/incubator/fileconfig/SamplerFactory.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SamplerFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SamplerFactory.java index 767ba2604bd..1ff2cfe17a4 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SamplerFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SamplerFactory.java @@ -129,8 +129,6 @@ public Sampler create( private static NamedSpiManager samplerSpiManager( ConfigProperties config, SpiHelper spiHelper) { return spiHelper.loadConfigurable( - ConfigurableSamplerProvider.class, - ConfigurableSamplerProvider::createSampler, - config); + ConfigurableSamplerProvider.class, ConfigurableSamplerProvider::createSampler, config); } } From 2b9fb2899c5ecd525dfa6be30ba73da10ec63e1d Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Tue, 13 Feb 2024 17:02:18 +0100 Subject: [PATCH 03/21] add loadOptional --- .../opentelemetry-sdk-extension-autoconfigure.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt index 8b1c020cd13..293c00f1fbb 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt @@ -9,5 +9,7 @@ Comparing source compatibility of against GENERIC TEMPLATES: +++ T:java.lang.Object +++* NEW METHOD: PUBLIC(+) java.util.Map loadConfigurableProviders(java.lang.Class) GENERIC TEMPLATES: +++ T:io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider + +++* NEW METHOD: PUBLIC(+) java.util.Optional loadOptional(java.lang.Class) + GENERIC TEMPLATES: +++ T:java.lang.Object +++* NEW METHOD: PUBLIC(+) java.util.List loadOrdered(java.lang.Class) GENERIC TEMPLATES: +++ T:io.opentelemetry.sdk.autoconfigure.spi.Ordered From e1352d67010dc5b992efa13935fbd7008ae21de6 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Mon, 19 Feb 2024 13:44:20 +0100 Subject: [PATCH 04/21] customizers are sufficient --- ...AutoConfiguredOpenTelemetrySdkBuilder.java | 74 ++++++++----------- 1 file changed, 31 insertions(+), 43 deletions(-) diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java index 0230acf37e4..c8712cfb9f6 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java @@ -409,53 +409,41 @@ public AutoConfiguredOpenTelemetrySdk build() { boolean sdkEnabled = !config.getBoolean("otel.sdk.disabled", false); if (sdkEnabled) { - SdkMeterProvider meterProvider = - spiHelper.loadOptional(SdkMeterProvider.class).orElse(null); - if (meterProvider == null) { - SdkMeterProviderBuilder meterProviderBuilder = SdkMeterProvider.builder(); - meterProviderBuilder.setResource(resource); - MeterProviderConfiguration.configureMeterProvider( - meterProviderBuilder, config, spiHelper, metricExporterCustomizer, closeables); - meterProviderBuilder = meterProviderCustomizer.apply(meterProviderBuilder, config); - meterProvider = meterProviderBuilder.build(); - } + SdkMeterProviderBuilder meterProviderBuilder = SdkMeterProvider.builder(); + meterProviderBuilder.setResource(resource); + MeterProviderConfiguration.configureMeterProvider( + meterProviderBuilder, config, spiHelper, metricExporterCustomizer, closeables); + meterProviderBuilder = meterProviderCustomizer.apply(meterProviderBuilder, config); + SdkMeterProvider meterProvider = meterProviderBuilder.build(); closeables.add(meterProvider); - SdkTracerProvider tracerProvider = - spiHelper.loadOptional(SdkTracerProvider.class).orElse(null); - if (tracerProvider == null) { - SdkTracerProviderBuilder tracerProviderBuilder = SdkTracerProvider.builder(); - tracerProviderBuilder.setResource(resource); - TracerProviderConfiguration.configureTracerProvider( - tracerProviderBuilder, - config, - spiHelper, - meterProvider, - spanExporterCustomizer, - spanProcessorCustomizer, - samplerCustomizer, - closeables); - tracerProviderBuilder = tracerProviderCustomizer.apply(tracerProviderBuilder, config); - tracerProvider = tracerProviderBuilder.build(); - } + SdkTracerProviderBuilder tracerProviderBuilder = SdkTracerProvider.builder(); + tracerProviderBuilder.setResource(resource); + TracerProviderConfiguration.configureTracerProvider( + tracerProviderBuilder, + config, + spiHelper, + meterProvider, + spanExporterCustomizer, + spanProcessorCustomizer, + samplerCustomizer, + closeables); + tracerProviderBuilder = tracerProviderCustomizer.apply(tracerProviderBuilder, config); + SdkTracerProvider tracerProvider = tracerProviderBuilder.build(); closeables.add(tracerProvider); - SdkLoggerProvider loggerProvider = - spiHelper.loadOptional(SdkLoggerProvider.class).orElse(null); - if (loggerProvider == null) { - SdkLoggerProviderBuilder loggerProviderBuilder = SdkLoggerProvider.builder(); - loggerProviderBuilder.setResource(resource); - LoggerProviderConfiguration.configureLoggerProvider( - loggerProviderBuilder, - config, - spiHelper, - meterProvider, - logRecordExporterCustomizer, - logRecordProcessorCustomizer, - closeables); - loggerProviderBuilder = loggerProviderCustomizer.apply(loggerProviderBuilder, config); - loggerProvider = loggerProviderBuilder.build(); - } + SdkLoggerProviderBuilder loggerProviderBuilder = SdkLoggerProvider.builder(); + loggerProviderBuilder.setResource(resource); + LoggerProviderConfiguration.configureLoggerProvider( + loggerProviderBuilder, + config, + spiHelper, + meterProvider, + logRecordExporterCustomizer, + logRecordProcessorCustomizer, + closeables); + loggerProviderBuilder = loggerProviderCustomizer.apply(loggerProviderBuilder, config); + SdkLoggerProvider loggerProvider = loggerProviderBuilder.build(); closeables.add(loggerProvider); ContextPropagators propagators = From 091b19bdbbed16dbfd1b459e8337c80bedcf41ea Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Mon, 19 Feb 2024 13:44:38 +0100 Subject: [PATCH 05/21] ExemplarFilter is going to be removed from public API, so don't expose it --- .../MeterProviderConfiguration.java | 34 ++++++++----------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MeterProviderConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MeterProviderConfiguration.java index b269903030c..525dc54974a 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MeterProviderConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MeterProviderConfiguration.java @@ -19,7 +19,6 @@ import java.util.Collections; import java.util.List; import java.util.Locale; -import java.util.Optional; import java.util.Set; import java.util.function.BiFunction; import java.util.stream.Collectors; @@ -34,25 +33,20 @@ static void configureMeterProvider( metricExporterCustomizer, List closeables) { - Optional spiExemplarFilter = spiHelper.loadOptional(ExemplarFilter.class); - if (spiExemplarFilter.isPresent()) { - SdkMeterProviderUtil.setExemplarFilter(meterProviderBuilder, spiExemplarFilter.get()); - } else { - // Configure default exemplar filters. - String exemplarFilter = - config.getString("otel.metrics.exemplar.filter", "trace_based").toLowerCase(Locale.ROOT); - switch (exemplarFilter) { - case "always_off": - SdkMeterProviderUtil.setExemplarFilter(meterProviderBuilder, ExemplarFilter.alwaysOff()); - break; - case "always_on": - SdkMeterProviderUtil.setExemplarFilter(meterProviderBuilder, ExemplarFilter.alwaysOn()); - break; - case "trace_based": - default: - SdkMeterProviderUtil.setExemplarFilter(meterProviderBuilder, ExemplarFilter.traceBased()); - break; - } + // Configure default exemplar filters. + String exemplarFilter = + config.getString("otel.metrics.exemplar.filter", "trace_based").toLowerCase(Locale.ROOT); + switch (exemplarFilter) { + case "always_off": + SdkMeterProviderUtil.setExemplarFilter(meterProviderBuilder, ExemplarFilter.alwaysOff()); + break; + case "always_on": + SdkMeterProviderUtil.setExemplarFilter(meterProviderBuilder, ExemplarFilter.alwaysOn()); + break; + case "trace_based": + default: + SdkMeterProviderUtil.setExemplarFilter(meterProviderBuilder, ExemplarFilter.traceBased()); + break; } int cardinalityLimit = From eac57ca4aed6cdda37fb2bbd7fe2c2127ac95922 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Mon, 19 Feb 2024 14:10:51 +0100 Subject: [PATCH 06/21] customizers are sufficient --- .../opentelemetry-sdk-extension-autoconfigure.txt | 10 ++++------ .../sdk/autoconfigure/ComponentLoader.java | 6 ------ .../sdk/autoconfigure/internal/SpiHelper.java | 5 ----- 3 files changed, 4 insertions(+), 17 deletions(-) diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt index 293c00f1fbb..5dec3f893c6 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt @@ -2,14 +2,12 @@ Comparing source compatibility of against *** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder (not serializable) === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder setComponentLoader(io.opentelemetry.sdk.autoconfigure.ComponentLoader) -+++* NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.autoconfigure.ComponentLoader (not serializable) ++++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.autoconfigure.ComponentLoader (not serializable) +++ CLASS FILE FORMAT VERSION: 52.0 <- n.a. +++ NEW SUPERCLASS: java.lang.Object - +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) java.lang.Iterable load(java.lang.Class) + +++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.lang.Iterable load(java.lang.Class) GENERIC TEMPLATES: +++ T:java.lang.Object - +++* NEW METHOD: PUBLIC(+) java.util.Map loadConfigurableProviders(java.lang.Class) + +++ NEW METHOD: PUBLIC(+) java.util.Map loadConfigurableProviders(java.lang.Class) GENERIC TEMPLATES: +++ T:io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider - +++* NEW METHOD: PUBLIC(+) java.util.Optional loadOptional(java.lang.Class) - GENERIC TEMPLATES: +++ T:java.lang.Object - +++* NEW METHOD: PUBLIC(+) java.util.List loadOrdered(java.lang.Class) + +++ NEW METHOD: PUBLIC(+) java.util.List loadOrdered(java.lang.Class) GENERIC TEMPLATES: +++ T:io.opentelemetry.sdk.autoconfigure.spi.Ordered diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/ComponentLoader.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/ComponentLoader.java index 6bbb92c2abf..712b7e20d54 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/ComponentLoader.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/ComponentLoader.java @@ -11,7 +11,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.StreamSupport; @@ -19,11 +18,6 @@ public interface ComponentLoader { Iterable load(Class spiClass); - default Optional loadOptional(Class spiClass) { - Iterable iterable = load(spiClass); - return StreamSupport.stream(iterable.spliterator(), false).findFirst(); - } - /** * Load implementations of an ordered SPI (i.e. implements {@link Ordered}). * diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java index 9d28aba18cd..523d2151f86 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java @@ -16,7 +16,6 @@ import java.util.IdentityHashMap; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.ServiceLoader; import java.util.Set; import java.util.function.BiFunction; @@ -110,10 +109,6 @@ private List init(Iterable components) { return result; } - public Optional loadOptional(Class spiClass) { - return componentLoader.loadOptional(spiClass).map(this::maybeAddListener); - } - private T maybeAddListener(T object) { if (object instanceof AutoConfigureListener) { listeners.add((AutoConfigureListener) object); From ae2c633fd78d2f8361c0b98fd25f0d6161f807d7 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Mon, 19 Feb 2024 14:11:05 +0100 Subject: [PATCH 07/21] add exception for jcmpapi --- buildSrc/src/main/kotlin/otel.japicmp-conventions.gradle.kts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/buildSrc/src/main/kotlin/otel.japicmp-conventions.gradle.kts b/buildSrc/src/main/kotlin/otel.japicmp-conventions.gradle.kts index c720b307486..f507940cf07 100644 --- a/buildSrc/src/main/kotlin/otel.japicmp-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/otel.japicmp-conventions.gradle.kts @@ -115,6 +115,8 @@ if (!project.hasProperty("otel.release") && !project.name.startsWith("bom")) { // Reproduce defaults from https://github.com/melix/japicmp-gradle-plugin/blob/09f52739ef1fccda6b4310cf3f4b19dc97377024/src/main/java/me/champeau/gradle/japicmp/report/ViolationsGenerator.java#L130 // with some changes. val exclusions = mutableListOf() + // Generics are not detected correctly + exclusions.add("CLASS_GENERIC_TEMPLATE_CHANGED") // Allow new default methods on interfaces exclusions.add("METHOD_NEW_DEFAULT") // Allow adding default implementations for default methods From 2bec27f6181b03da4284086c501fb50327a775bf Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Mon, 19 Feb 2024 14:37:49 +0100 Subject: [PATCH 08/21] jcmpapi --- ...emetry-sdk-extension-autoconfigure-spi.txt | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure-spi.txt b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure-spi.txt index df26146497b..d7afb9da560 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure-spi.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure-spi.txt @@ -1,2 +1,20 @@ Comparing source compatibility of against -No changes. \ No newline at end of file +*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.autoconfigure.spi.ConfigurablePropagatorProvider (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++ NEW INTERFACE: io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider ++++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider (not serializable) + +++ CLASS FILE FORMAT VERSION: 52.0 <- n.a. + +++ NEW SUPERCLASS: java.lang.Object + +++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.lang.String getName() +*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.autoconfigure.spi.logs.ConfigurableLogRecordExporterProvider (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++ NEW INTERFACE: io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider +*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++ NEW INTERFACE: io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider +*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSamplerProvider (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++ NEW INTERFACE: io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider +*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++ NEW INTERFACE: io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider From ad4047f21f166c98ed4677e58e7eedef15608c32 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Mon, 19 Feb 2024 15:31:02 +0100 Subject: [PATCH 09/21] test component loader is used --- .../AutoConfiguredOpenTelemetrySdkTest.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkTest.java b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkTest.java index 01047907fca..5ade66c1ac5 100644 --- a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkTest.java +++ b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkTest.java @@ -315,6 +315,44 @@ void builder_addSpanProcessorCustomizer() { verifyNoInteractions(spanExporter1); } + @Test + void builder_addSpanProcessorUsingComponentLoader() { + SpanProcessor spanProcessor = Mockito.mock(SpanProcessor.class); + doReturn(true).when(spanProcessor).isStartRequired(); + doReturn(true).when(spanProcessor).isEndRequired(); + Mockito.lenient().doReturn(CompletableResultCode.ofSuccess()).when(spanProcessor).shutdown(); + Mockito.lenient().when(spanExporter1.shutdown()).thenReturn(CompletableResultCode.ofSuccess()); + + SpiHelper spiHelper = + SpiHelper.create(AutoConfiguredOpenTelemetrySdkBuilder.class.getClassLoader()); + + SdkTracerProvider sdkTracerProvider = + builder + .setComponentLoader( + new ComponentLoader() { + @SuppressWarnings("unchecked") + @Override + public Iterable load(Class spiClass) { + if (spiClass.equals(SpanProcessor.class)) { + return Collections.singletonList((T) spanProcessor); + } + return spiHelper.load(spiClass); + } + }) + .build() + .getOpenTelemetrySdk() + .getSdkTracerProvider(); + + Span span = sdkTracerProvider.get("dummy-scope").spanBuilder("dummy-span").startSpan(); + + verify(spanProcessor).onStart(any(), same((ReadWriteSpan) span)); + + span.end(); + verify(spanProcessor).onEnd(same((ReadableSpan) span)); + + verifyNoInteractions(spanExporter1); + } + @Test void builder_addPropertiesSupplier() { AutoConfiguredOpenTelemetrySdk autoConfigured = From 5336d59e5932573806be9b201503e9f159eb94a7 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Mon, 19 Feb 2024 19:16:10 +0100 Subject: [PATCH 10/21] Revert "customizers are sufficient" This reverts commit 1a867b1178a2fb7e2006fa9d679cccdb6ea4420e. --- .../opentelemetry-sdk-extension-autoconfigure.txt | 10 ++++++---- .../sdk/autoconfigure/ComponentLoader.java | 6 ++++++ .../sdk/autoconfigure/internal/SpiHelper.java | 5 +++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt index 5dec3f893c6..293c00f1fbb 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt @@ -2,12 +2,14 @@ Comparing source compatibility of against *** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder (not serializable) === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder setComponentLoader(io.opentelemetry.sdk.autoconfigure.ComponentLoader) -+++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.autoconfigure.ComponentLoader (not serializable) ++++* NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.autoconfigure.ComponentLoader (not serializable) +++ CLASS FILE FORMAT VERSION: 52.0 <- n.a. +++ NEW SUPERCLASS: java.lang.Object - +++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.lang.Iterable load(java.lang.Class) + +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) java.lang.Iterable load(java.lang.Class) GENERIC TEMPLATES: +++ T:java.lang.Object - +++ NEW METHOD: PUBLIC(+) java.util.Map loadConfigurableProviders(java.lang.Class) + +++* NEW METHOD: PUBLIC(+) java.util.Map loadConfigurableProviders(java.lang.Class) GENERIC TEMPLATES: +++ T:io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider - +++ NEW METHOD: PUBLIC(+) java.util.List loadOrdered(java.lang.Class) + +++* NEW METHOD: PUBLIC(+) java.util.Optional loadOptional(java.lang.Class) + GENERIC TEMPLATES: +++ T:java.lang.Object + +++* NEW METHOD: PUBLIC(+) java.util.List loadOrdered(java.lang.Class) GENERIC TEMPLATES: +++ T:io.opentelemetry.sdk.autoconfigure.spi.Ordered diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/ComponentLoader.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/ComponentLoader.java index 712b7e20d54..6bbb92c2abf 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/ComponentLoader.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/ComponentLoader.java @@ -11,6 +11,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.StreamSupport; @@ -18,6 +19,11 @@ public interface ComponentLoader { Iterable load(Class spiClass); + default Optional loadOptional(Class spiClass) { + Iterable iterable = load(spiClass); + return StreamSupport.stream(iterable.spliterator(), false).findFirst(); + } + /** * Load implementations of an ordered SPI (i.e. implements {@link Ordered}). * diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java index 523d2151f86..9d28aba18cd 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java @@ -16,6 +16,7 @@ import java.util.IdentityHashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.ServiceLoader; import java.util.Set; import java.util.function.BiFunction; @@ -109,6 +110,10 @@ private List init(Iterable components) { return result; } + public Optional loadOptional(Class spiClass) { + return componentLoader.loadOptional(spiClass).map(this::maybeAddListener); + } + private T maybeAddListener(T object) { if (object instanceof AutoConfigureListener) { listeners.add((AutoConfigureListener) object); From 44df716e779189be51bb4b19de3a8da6958229ee Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Mon, 19 Feb 2024 19:25:14 +0100 Subject: [PATCH 11/21] add loader for ConfigProperties --- ...ntelemetry-sdk-extension-autoconfigure.txt | 10 +++++----- ...AutoConfiguredOpenTelemetrySdkBuilder.java | 19 +++++++++++++------ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt index 293c00f1fbb..b940794c347 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt @@ -2,14 +2,14 @@ Comparing source compatibility of against *** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder (not serializable) === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder setComponentLoader(io.opentelemetry.sdk.autoconfigure.ComponentLoader) -+++* NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.autoconfigure.ComponentLoader (not serializable) ++++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.autoconfigure.ComponentLoader (not serializable) +++ CLASS FILE FORMAT VERSION: 52.0 <- n.a. +++ NEW SUPERCLASS: java.lang.Object - +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) java.lang.Iterable load(java.lang.Class) + +++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.lang.Iterable load(java.lang.Class) GENERIC TEMPLATES: +++ T:java.lang.Object - +++* NEW METHOD: PUBLIC(+) java.util.Map loadConfigurableProviders(java.lang.Class) + +++ NEW METHOD: PUBLIC(+) java.util.Map loadConfigurableProviders(java.lang.Class) GENERIC TEMPLATES: +++ T:io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider - +++* NEW METHOD: PUBLIC(+) java.util.Optional loadOptional(java.lang.Class) + +++ NEW METHOD: PUBLIC(+) java.util.Optional loadOptional(java.lang.Class) GENERIC TEMPLATES: +++ T:java.lang.Object - +++* NEW METHOD: PUBLIC(+) java.util.List loadOrdered(java.lang.Class) + +++ NEW METHOD: PUBLIC(+) java.util.List loadOrdered(java.lang.Class) GENERIC TEMPLATES: +++ T:io.opentelemetry.sdk.autoconfigure.spi.Ordered diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java index c8712cfb9f6..c60b4ac5c43 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java @@ -569,12 +569,19 @@ private ConfigProperties getConfig() { } private ConfigProperties computeConfigProperties() { - DefaultConfigProperties properties = DefaultConfigProperties.create(propertiesSupplier.get()); - for (Function> customizer : propertiesCustomizers) { - Map overrides = customizer.apply(properties); - properties = properties.withOverrides(overrides); - } - return properties; + return spiHelper + .loadOptional(ConfigProperties.class) + .orElseGet( + () -> { + DefaultConfigProperties properties = + DefaultConfigProperties.create(propertiesSupplier.get()); + for (Function> customizer : + propertiesCustomizers) { + Map overrides = customizer.apply(properties); + properties = properties.withOverrides(overrides); + } + return properties; + }); } // Visible for testing From 74322cd514c2fc430916637fef79720ec4507851 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Tue, 20 Feb 2024 10:06:59 +0100 Subject: [PATCH 12/21] Revert "add loader for ConfigProperties" This reverts commit c1534b5513b29c6ce6b8020bbf05a5bead68e5a2. --- ...ntelemetry-sdk-extension-autoconfigure.txt | 10 +++++----- ...AutoConfiguredOpenTelemetrySdkBuilder.java | 19 ++++++------------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt index b940794c347..293c00f1fbb 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt @@ -2,14 +2,14 @@ Comparing source compatibility of against *** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder (not serializable) === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder setComponentLoader(io.opentelemetry.sdk.autoconfigure.ComponentLoader) -+++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.autoconfigure.ComponentLoader (not serializable) ++++* NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.autoconfigure.ComponentLoader (not serializable) +++ CLASS FILE FORMAT VERSION: 52.0 <- n.a. +++ NEW SUPERCLASS: java.lang.Object - +++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.lang.Iterable load(java.lang.Class) + +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) java.lang.Iterable load(java.lang.Class) GENERIC TEMPLATES: +++ T:java.lang.Object - +++ NEW METHOD: PUBLIC(+) java.util.Map loadConfigurableProviders(java.lang.Class) + +++* NEW METHOD: PUBLIC(+) java.util.Map loadConfigurableProviders(java.lang.Class) GENERIC TEMPLATES: +++ T:io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider - +++ NEW METHOD: PUBLIC(+) java.util.Optional loadOptional(java.lang.Class) + +++* NEW METHOD: PUBLIC(+) java.util.Optional loadOptional(java.lang.Class) GENERIC TEMPLATES: +++ T:java.lang.Object - +++ NEW METHOD: PUBLIC(+) java.util.List loadOrdered(java.lang.Class) + +++* NEW METHOD: PUBLIC(+) java.util.List loadOrdered(java.lang.Class) GENERIC TEMPLATES: +++ T:io.opentelemetry.sdk.autoconfigure.spi.Ordered diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java index c60b4ac5c43..c8712cfb9f6 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java @@ -569,19 +569,12 @@ private ConfigProperties getConfig() { } private ConfigProperties computeConfigProperties() { - return spiHelper - .loadOptional(ConfigProperties.class) - .orElseGet( - () -> { - DefaultConfigProperties properties = - DefaultConfigProperties.create(propertiesSupplier.get()); - for (Function> customizer : - propertiesCustomizers) { - Map overrides = customizer.apply(properties); - properties = properties.withOverrides(overrides); - } - return properties; - }); + DefaultConfigProperties properties = DefaultConfigProperties.create(propertiesSupplier.get()); + for (Function> customizer : propertiesCustomizers) { + Map overrides = customizer.apply(properties); + properties = properties.withOverrides(overrides); + } + return properties; } // Visible for testing From 57995898620077353e4ab7bbbed101fab69ff211 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Tue, 20 Feb 2024 10:08:29 +0100 Subject: [PATCH 13/21] Revert "Revert "customizers are sufficient"" This reverts commit 655d2e60113fa307750e9d5db44f036a065e46d6. --- .../opentelemetry-sdk-extension-autoconfigure.txt | 10 ++++------ .../sdk/autoconfigure/ComponentLoader.java | 6 ------ .../sdk/autoconfigure/internal/SpiHelper.java | 5 ----- 3 files changed, 4 insertions(+), 17 deletions(-) diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt index 293c00f1fbb..5dec3f893c6 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt @@ -2,14 +2,12 @@ Comparing source compatibility of against *** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder (not serializable) === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder setComponentLoader(io.opentelemetry.sdk.autoconfigure.ComponentLoader) -+++* NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.autoconfigure.ComponentLoader (not serializable) ++++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.autoconfigure.ComponentLoader (not serializable) +++ CLASS FILE FORMAT VERSION: 52.0 <- n.a. +++ NEW SUPERCLASS: java.lang.Object - +++* NEW METHOD: PUBLIC(+) ABSTRACT(+) java.lang.Iterable load(java.lang.Class) + +++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.lang.Iterable load(java.lang.Class) GENERIC TEMPLATES: +++ T:java.lang.Object - +++* NEW METHOD: PUBLIC(+) java.util.Map loadConfigurableProviders(java.lang.Class) + +++ NEW METHOD: PUBLIC(+) java.util.Map loadConfigurableProviders(java.lang.Class) GENERIC TEMPLATES: +++ T:io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider - +++* NEW METHOD: PUBLIC(+) java.util.Optional loadOptional(java.lang.Class) - GENERIC TEMPLATES: +++ T:java.lang.Object - +++* NEW METHOD: PUBLIC(+) java.util.List loadOrdered(java.lang.Class) + +++ NEW METHOD: PUBLIC(+) java.util.List loadOrdered(java.lang.Class) GENERIC TEMPLATES: +++ T:io.opentelemetry.sdk.autoconfigure.spi.Ordered diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/ComponentLoader.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/ComponentLoader.java index 6bbb92c2abf..712b7e20d54 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/ComponentLoader.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/ComponentLoader.java @@ -11,7 +11,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.StreamSupport; @@ -19,11 +18,6 @@ public interface ComponentLoader { Iterable load(Class spiClass); - default Optional loadOptional(Class spiClass) { - Iterable iterable = load(spiClass); - return StreamSupport.stream(iterable.spliterator(), false).findFirst(); - } - /** * Load implementations of an ordered SPI (i.e. implements {@link Ordered}). * diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java index 9d28aba18cd..523d2151f86 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java @@ -16,7 +16,6 @@ import java.util.IdentityHashMap; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.ServiceLoader; import java.util.Set; import java.util.function.BiFunction; @@ -110,10 +109,6 @@ private List init(Iterable components) { return result; } - public Optional loadOptional(Class spiClass) { - return componentLoader.loadOptional(spiClass).map(this::maybeAddListener); - } - private T maybeAddListener(T object) { if (object instanceof AutoConfigureListener) { listeners.add((AutoConfigureListener) object); From 3f574fbedc5648200887bd17e2f5de94212f1e16 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Tue, 20 Feb 2024 10:20:27 +0100 Subject: [PATCH 14/21] add loader for ConfigProperties --- .../opentelemetry-sdk-extension-autoconfigure.txt | 1 + .../autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt index 5dec3f893c6..55e5e4f2a22 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt @@ -2,6 +2,7 @@ Comparing source compatibility of against *** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder (not serializable) === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder setComponentLoader(io.opentelemetry.sdk.autoconfigure.ComponentLoader) + *** MODIFIED METHOD: PUBLIC (<- PACKAGE_PROTECTED) io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder setConfig(io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties) +++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.autoconfigure.ComponentLoader (not serializable) +++ CLASS FILE FORMAT VERSION: 52.0 <- n.a. +++ NEW SUPERCLASS: java.lang.Object diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java index c8712cfb9f6..7a3293ce81b 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java @@ -115,7 +115,7 @@ public final class AutoConfiguredOpenTelemetrySdkBuilder implements AutoConfigur * {@link #addPropertiesSupplier(Supplier)} and {@link #addPropertiesCustomizer(Function)} will * have no effect if this method is used. */ - AutoConfiguredOpenTelemetrySdkBuilder setConfig(ConfigProperties config) { + public AutoConfiguredOpenTelemetrySdkBuilder setConfig(ConfigProperties config) { requireNonNull(config, "config"); this.config = config; return this; From 6d06755f29988b9fea0865ceb02c9c76c71c5603 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Fri, 23 Feb 2024 18:10:11 +0100 Subject: [PATCH 15/21] make component loader internal to give it time to incubate --- .../opentelemetry-sdk-extension-autoconfigure.txt | 11 +---------- .../AutoConfiguredOpenTelemetrySdkBuilder.java | 1 + .../autoconfigure/{ => internal}/ComponentLoader.java | 9 +++++++-- .../sdk/autoconfigure/internal/SpiHelper.java | 1 - .../AutoConfiguredOpenTelemetrySdkTest.java | 1 + .../sdk/autoconfigure/internal/SpiHelperTest.java | 1 - 6 files changed, 10 insertions(+), 14 deletions(-) rename sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/{ => internal}/ComponentLoader.java (83%) diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt index 55e5e4f2a22..9411da9ac5d 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt @@ -1,14 +1,5 @@ Comparing source compatibility of against *** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder (not serializable) === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 - +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder setComponentLoader(io.opentelemetry.sdk.autoconfigure.ComponentLoader) + +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder setComponentLoader(io.opentelemetry.sdk.autoconfigure.internal.ComponentLoader) *** MODIFIED METHOD: PUBLIC (<- PACKAGE_PROTECTED) io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder setConfig(io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties) -+++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.autoconfigure.ComponentLoader (not serializable) - +++ CLASS FILE FORMAT VERSION: 52.0 <- n.a. - +++ NEW SUPERCLASS: java.lang.Object - +++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.lang.Iterable load(java.lang.Class) - GENERIC TEMPLATES: +++ T:java.lang.Object - +++ NEW METHOD: PUBLIC(+) java.util.Map loadConfigurableProviders(java.lang.Class) - GENERIC TEMPLATES: +++ T:io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider - +++ NEW METHOD: PUBLIC(+) java.util.List loadOrdered(java.lang.Class) - GENERIC TEMPLATES: +++ T:io.opentelemetry.sdk.autoconfigure.spi.Ordered diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java index 7a3293ce81b..7d315a317c8 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java @@ -13,6 +13,7 @@ import io.opentelemetry.context.propagation.TextMapPropagator; import io.opentelemetry.sdk.OpenTelemetrySdk; import io.opentelemetry.sdk.OpenTelemetrySdkBuilder; +import io.opentelemetry.sdk.autoconfigure.internal.ComponentLoader; import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizer; import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider; diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/ComponentLoader.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/ComponentLoader.java similarity index 83% rename from sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/ComponentLoader.java rename to sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/ComponentLoader.java index 712b7e20d54..b7143189e03 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/ComponentLoader.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/ComponentLoader.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.sdk.autoconfigure; +package io.opentelemetry.sdk.autoconfigure.internal; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider; import io.opentelemetry.sdk.autoconfigure.spi.Ordered; @@ -14,7 +14,12 @@ import java.util.stream.Collectors; import java.util.stream.StreamSupport; -/** A loader for components that are discovered via SPI. */ +/** + * A loader for components that are discovered via SPI. + * + *

This class is internal and is hence not for public use. Its APIs are unstable and can change + * at any time. + */ public interface ComponentLoader { Iterable load(Class spiClass); diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java index 523d2151f86..32a9b3b9125 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java @@ -5,7 +5,6 @@ package io.opentelemetry.sdk.autoconfigure.internal; -import io.opentelemetry.sdk.autoconfigure.ComponentLoader; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider; import io.opentelemetry.sdk.autoconfigure.spi.Ordered; diff --git a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkTest.java b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkTest.java index 5ade66c1ac5..8cd24fc1804 100644 --- a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkTest.java +++ b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkTest.java @@ -36,6 +36,7 @@ import io.opentelemetry.context.propagation.TextMapPropagator; import io.opentelemetry.internal.testing.slf4j.SuppressLogger; import io.opentelemetry.sdk.OpenTelemetrySdk; +import io.opentelemetry.sdk.autoconfigure.internal.ComponentLoader; import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; diff --git a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelperTest.java b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelperTest.java index 7af00b18dda..b61d5d2b47c 100644 --- a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelperTest.java +++ b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelperTest.java @@ -15,7 +15,6 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import io.opentelemetry.sdk.autoconfigure.ComponentLoader; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider; import io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider; From 42d6e1716adf75f72368c46c61da30ece1101969 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Wed, 28 Feb 2024 07:35:05 +0100 Subject: [PATCH 16/21] remove ConfigurableProvider remove SPI for SpanProcessor --- ...emetry-sdk-extension-autoconfigure-spi.txt | 22 +-------- .../spi/ConfigurablePropagatorProvider.java | 3 +- .../spi/ConfigurableProvider.java | 17 ------- .../ConfigurableMetricReaderProvider.java | 4 +- ...ConfigurableLogRecordExporterProvider.java | 4 +- .../ConfigurableMetricExporterProvider.java | 4 +- .../traces/ConfigurableSamplerProvider.java | 4 +- .../ConfigurableSpanExporterProvider.java | 4 +- .../LogRecordExporterConfiguration.java | 1 + .../MetricExporterConfiguration.java | 2 + .../PropagatorConfiguration.java | 1 + .../SpanExporterConfiguration.java | 1 + .../TracerProviderConfiguration.java | 13 +++-- .../internal/ComponentLoader.java | 12 ----- .../sdk/autoconfigure/internal/SpiHelper.java | 27 +++++----- .../AutoConfiguredOpenTelemetrySdkTest.java | 49 ++++++++----------- .../autoconfigure/internal/SpiHelperTest.java | 24 ++++++--- .../ConfigurableSpanExporterTest.java | 12 ++--- .../fileconfig/LogRecordExporterFactory.java | 1 + .../fileconfig/MetricExporterFactory.java | 1 + .../fileconfig/MetricReaderFactory.java | 1 + .../incubator/fileconfig/SamplerFactory.java | 5 +- .../fileconfig/SpanExporterFactory.java | 1 + .../fileconfig/TextMapPropagatorFactory.java | 1 + .../LogRecordExporterFactoryTest.java | 4 +- .../fileconfig/MetricExporterFactoryTest.java | 4 +- .../fileconfig/MetricReaderFactoryTest.java | 4 +- .../fileconfig/SpanExporterFactoryTest.java | 8 +-- 28 files changed, 96 insertions(+), 138 deletions(-) delete mode 100644 sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/ConfigurableProvider.java diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure-spi.txt b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure-spi.txt index d7afb9da560..3013553d6ea 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure-spi.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure-spi.txt @@ -1,20 +1,2 @@ -Comparing source compatibility of against -*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.autoconfigure.spi.ConfigurablePropagatorProvider (not serializable) - === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 - +++ NEW INTERFACE: io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider -+++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider (not serializable) - +++ CLASS FILE FORMAT VERSION: 52.0 <- n.a. - +++ NEW SUPERCLASS: java.lang.Object - +++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.lang.String getName() -*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.autoconfigure.spi.logs.ConfigurableLogRecordExporterProvider (not serializable) - === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 - +++ NEW INTERFACE: io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider -*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider (not serializable) - === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 - +++ NEW INTERFACE: io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider -*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSamplerProvider (not serializable) - === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 - +++ NEW INTERFACE: io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider -*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider (not serializable) - === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 - +++ NEW INTERFACE: io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider +Comparing source compatibility of against +No changes. diff --git a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/ConfigurablePropagatorProvider.java b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/ConfigurablePropagatorProvider.java index a2bfd57dcad..b5f693ed1f8 100644 --- a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/ConfigurablePropagatorProvider.java +++ b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/ConfigurablePropagatorProvider.java @@ -15,7 +15,7 @@ * #getPropagator(ConfigProperties)} will be enabled and available as part of {@link * OpenTelemetry#getPropagators()}. */ -public interface ConfigurablePropagatorProvider extends ConfigurableProvider { +public interface ConfigurablePropagatorProvider { /** * Returns a {@link TextMapPropagator} that can be registered to OpenTelemetry by providing the * property value specified by {@link #getName()}. @@ -27,6 +27,5 @@ public interface ConfigurablePropagatorProvider extends ConfigurableProvider { * property to enable it. If the name is the same as any other defined propagator name, it is * undefined which will be used. */ - @Override String getName(); } diff --git a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/ConfigurableProvider.java b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/ConfigurableProvider.java deleted file mode 100644 index f41910c4768..00000000000 --- a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/ConfigurableProvider.java +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.sdk.autoconfigure.spi; - -/** - * A named configurable provider. - * - *

It can be used to generically determine if a provider should be replaced by another provider - * with the same name. - */ -public interface ConfigurableProvider { - /** Returns the name of this provider. */ - String getName(); -} diff --git a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ConfigurableMetricReaderProvider.java b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ConfigurableMetricReaderProvider.java index 6e8febd7237..1a9feb4acb8 100644 --- a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ConfigurableMetricReaderProvider.java +++ b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ConfigurableMetricReaderProvider.java @@ -6,7 +6,6 @@ package io.opentelemetry.sdk.autoconfigure.spi.internal; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider; import io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider; import io.opentelemetry.sdk.metrics.export.MetricExporter; import io.opentelemetry.sdk.metrics.export.MetricReader; @@ -25,7 +24,7 @@ *

This class is internal and is hence not for public use. Its APIs are unstable and can change * at any time. */ -public interface ConfigurableMetricReaderProvider extends ConfigurableProvider { +public interface ConfigurableMetricReaderProvider { /** * Returns a {@link MetricReader} that can be registered to OpenTelemetry by providing the @@ -41,6 +40,5 @@ public interface ConfigurableMetricReaderProvider extends ConfigurableProvider { * name, the resulting behavior is undefined and it is explicitly unspecified which reader / * exporter will actually be used. */ - @Override String getName(); } diff --git a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/logs/ConfigurableLogRecordExporterProvider.java b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/logs/ConfigurableLogRecordExporterProvider.java index 300b0c15aa8..d4e3d2bc949 100644 --- a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/logs/ConfigurableLogRecordExporterProvider.java +++ b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/logs/ConfigurableLogRecordExporterProvider.java @@ -6,7 +6,6 @@ package io.opentelemetry.sdk.autoconfigure.spi.logs; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider; import io.opentelemetry.sdk.logs.export.LogRecordExporter; /** @@ -17,7 +16,7 @@ * * @since 1.19.0 */ -public interface ConfigurableLogRecordExporterProvider extends ConfigurableProvider { +public interface ConfigurableLogRecordExporterProvider { /** * Returns a {@link LogRecordExporter} that can be registered to OpenTelemetry by providing the @@ -31,6 +30,5 @@ public interface ConfigurableLogRecordExporterProvider extends ConfigurableProvi * the name does conflict with another exporter name, the resulting behavior is undefined and it * is explicitly unspecified which exporter will actually be used. */ - @Override String getName(); } diff --git a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/metrics/ConfigurableMetricExporterProvider.java b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/metrics/ConfigurableMetricExporterProvider.java index 0d66a502fc2..465366c4e29 100644 --- a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/metrics/ConfigurableMetricExporterProvider.java +++ b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/metrics/ConfigurableMetricExporterProvider.java @@ -6,7 +6,6 @@ package io.opentelemetry.sdk.autoconfigure.spi.metrics; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider; import io.opentelemetry.sdk.autoconfigure.spi.internal.ConfigurableMetricReaderProvider; import io.opentelemetry.sdk.metrics.export.MetricExporter; import io.opentelemetry.sdk.metrics.export.MetricReader; @@ -23,7 +22,7 @@ * * @since 1.15.0 */ -public interface ConfigurableMetricExporterProvider extends ConfigurableProvider { +public interface ConfigurableMetricExporterProvider { /** * Returns a {@link MetricExporter} that can be registered to OpenTelemetry by providing the @@ -39,6 +38,5 @@ public interface ConfigurableMetricExporterProvider extends ConfigurableProvider * name, the resulting behavior is undefined and it is explicitly unspecified which exporter / * reader will actually be used. */ - @Override String getName(); } diff --git a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/traces/ConfigurableSamplerProvider.java b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/traces/ConfigurableSamplerProvider.java index 5c20473bad0..b97d9eb4a43 100644 --- a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/traces/ConfigurableSamplerProvider.java +++ b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/traces/ConfigurableSamplerProvider.java @@ -6,7 +6,6 @@ package io.opentelemetry.sdk.autoconfigure.spi.traces; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider; import io.opentelemetry.sdk.trace.samplers.Sampler; /** @@ -15,7 +14,7 @@ * returned by {@link #getName()}, the sampler returned by {@link #createSampler(ConfigProperties)} * will be enabled and added to the SDK. */ -public interface ConfigurableSamplerProvider extends ConfigurableProvider { +public interface ConfigurableSamplerProvider { /** * Returns a {@link Sampler} that can be registered to OpenTelemetry by providing the property @@ -29,6 +28,5 @@ public interface ConfigurableSamplerProvider extends ConfigurableProvider { * the name does conflict with another exporter name, the resulting behavior is undefined and it * is explicitly unspecified which exporter will actually be used. */ - @Override String getName(); } diff --git a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/traces/ConfigurableSpanExporterProvider.java b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/traces/ConfigurableSpanExporterProvider.java index 576785776a5..94ac4cedafb 100644 --- a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/traces/ConfigurableSpanExporterProvider.java +++ b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/traces/ConfigurableSpanExporterProvider.java @@ -6,7 +6,6 @@ package io.opentelemetry.sdk.autoconfigure.spi.traces; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider; import io.opentelemetry.sdk.trace.export.SpanExporter; /** @@ -15,7 +14,7 @@ * is returned by {@link #getName()}, the exporter returned by {@link * #createExporter(ConfigProperties)} will be enabled and added to the SDK. */ -public interface ConfigurableSpanExporterProvider extends ConfigurableProvider { +public interface ConfigurableSpanExporterProvider { /** * Returns a {@link SpanExporter} that can be registered to OpenTelemetry by providing the @@ -29,6 +28,5 @@ public interface ConfigurableSpanExporterProvider extends ConfigurableProvider { * the name does conflict with another exporter name, the resulting behavior is undefined and it * is explicitly unspecified which exporter will actually be used. */ - @Override String getName(); } diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfiguration.java index b576d8093bf..b0eeb2481c0 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfiguration.java @@ -80,6 +80,7 @@ static NamedSpiManager logRecordExporterSpiManager( ConfigProperties config, SpiHelper spiHelper) { return spiHelper.loadConfigurable( ConfigurableLogRecordExporterProvider.class, + ConfigurableLogRecordExporterProvider::getName, ConfigurableLogRecordExporterProvider::createExporter, config); } diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfiguration.java index 028b3dacde5..2aa968a82bb 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfiguration.java @@ -82,6 +82,7 @@ static NamedSpiManager metricReadersSpiManager( ConfigProperties config, SpiHelper spiHelper) { return spiHelper.loadConfigurable( ConfigurableMetricReaderProvider.class, + ConfigurableMetricReaderProvider::getName, ConfigurableMetricReaderProvider::createMetricReader, config); } @@ -106,6 +107,7 @@ static NamedSpiManager metricExporterSpiManager( ConfigProperties config, SpiHelper spiHelper) { return spiHelper.loadConfigurable( ConfigurableMetricExporterProvider.class, + ConfigurableMetricExporterProvider::getName, ConfigurableMetricExporterProvider::createExporter, config); } diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/PropagatorConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/PropagatorConfiguration.java index ca992bd5fc2..fea60b18f80 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/PropagatorConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/PropagatorConfiguration.java @@ -35,6 +35,7 @@ static ContextPropagators configurePropagators( NamedSpiManager spiPropagatorsManager = spiHelper.loadConfigurable( ConfigurablePropagatorProvider.class, + ConfigurablePropagatorProvider::getName, ConfigurablePropagatorProvider::getPropagator, config); diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java index 68cec9f1ff6..c5da0e0a045 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java @@ -80,6 +80,7 @@ static NamedSpiManager spanExporterSpiManager( ConfigProperties config, SpiHelper spiHelper) { return spiHelper.loadConfigurable( ConfigurableSpanExporterProvider.class, + ConfigurableSpanExporterProvider::getName, ConfigurableSpanExporterProvider::createExporter, config); } diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/TracerProviderConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/TracerProviderConfiguration.java index 7e61d16a41f..b2e2a3858c8 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/TracerProviderConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/TracerProviderConfiguration.java @@ -22,6 +22,7 @@ import io.opentelemetry.sdk.trace.samplers.Sampler; import java.io.Closeable; import java.time.Duration; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -55,7 +56,7 @@ static void configureTracerProvider( config, spiHelper, spanExporterCustomizer, closeables); List processors = - configureSpanProcessors(config, exportersByName, meterProvider, closeables, spiHelper); + configureSpanProcessors(config, exportersByName, meterProvider, closeables); for (SpanProcessor processor : processors) { SpanProcessor wrapped = spanProcessorCustomizer.apply(processor, config); if (wrapped != processor) { @@ -69,10 +70,9 @@ static List configureSpanProcessors( ConfigProperties config, Map exportersByName, MeterProvider meterProvider, - List closeables, - SpiHelper spiHelper) { + List closeables) { Map exportersByNameCopy = new HashMap<>(exportersByName); - List spanProcessors = spiHelper.load(SpanProcessor.class); + List spanProcessors = new ArrayList<>(); SpanExporter exporter = exportersByNameCopy.remove("logging"); if (exporter != null) { @@ -162,7 +162,10 @@ static SpanLimits configureSpanLimits(ConfigProperties config) { static Sampler configureSampler(String sampler, ConfigProperties config, SpiHelper spiHelper) { NamedSpiManager spiSamplersManager = spiHelper.loadConfigurable( - ConfigurableSamplerProvider.class, ConfigurableSamplerProvider::createSampler, config); + ConfigurableSamplerProvider.class, + ConfigurableSamplerProvider::getName, + ConfigurableSamplerProvider::createSampler, + config); switch (sampler) { case "always_on": diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/ComponentLoader.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/ComponentLoader.java index b7143189e03..97fbbb843b1 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/ComponentLoader.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/ComponentLoader.java @@ -5,12 +5,9 @@ package io.opentelemetry.sdk.autoconfigure.internal; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider; import io.opentelemetry.sdk.autoconfigure.spi.Ordered; import java.util.Comparator; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.stream.Collectors; import java.util.stream.StreamSupport; @@ -35,13 +32,4 @@ default List loadOrdered(Class spiClass) { .sorted(Comparator.comparing(Ordered::order)) .collect(Collectors.toList()); } - - default Map loadConfigurableProviders( - Class spiClass) { - Map components = new HashMap<>(); - for (T component : load(spiClass)) { - components.put(component.getName(), component); - } - return components; - } } diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java index 32a9b3b9125..a6434eecabf 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java @@ -6,7 +6,6 @@ package io.opentelemetry.sdk.autoconfigure.internal; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider; import io.opentelemetry.sdk.autoconfigure.spi.Ordered; import io.opentelemetry.sdk.autoconfigure.spi.internal.AutoConfigureListener; import java.util.ArrayList; @@ -18,6 +17,7 @@ import java.util.ServiceLoader; import java.util.Set; import java.util.function.BiFunction; +import java.util.function.Function; import java.util.function.Supplier; /** @@ -47,26 +47,29 @@ public static SpiHelper create(ComponentLoader componentLoader) { * Load implementations of an SPI which are configurable (i.e. they accept {@link * ConfigProperties}. * - * @param the configurable type - * @param the SPI type * @param spiClass the SPI class + * @param getName function returning the name of an SPI implementation * @param getConfigurable function returning a configured instance * @param config the configuration to pass to invocations of {@code #getConfigurable} + * @param the configurable type + * @param the SPI type * @return a {@link NamedSpiManager} used to access configured instances of the SPI by name */ - public NamedSpiManager loadConfigurable( + public NamedSpiManager loadConfigurable( Class spiClass, + Function getName, BiFunction getConfigurable, ConfigProperties config) { Map> nameToProvider = new HashMap<>(); - Map providers = componentLoader.loadConfigurableProviders(spiClass); - for (Map.Entry entry : providers.entrySet()) { - S provider = entry.getValue(); - String name = entry.getKey(); - // both the provider and the result may have a listener - maybeAddListener(provider); - - nameToProvider.put(name, () -> maybeAddListener(getConfigurable.apply(provider, config))); + for (S provider : load(spiClass)) { + String name = getName.apply(provider); + nameToProvider.put( + name, + () -> { + T result = getConfigurable.apply(provider, config); + maybeAddListener(result); + return result; + }); } return NamedSpiManager.create(nameToProvider); } diff --git a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkTest.java b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkTest.java index 8cd24fc1804..deff47134cb 100644 --- a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkTest.java +++ b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkTest.java @@ -20,6 +20,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; +import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; import io.github.netmikey.logunit.api.LogCapturer; @@ -38,6 +39,7 @@ import io.opentelemetry.sdk.OpenTelemetrySdk; import io.opentelemetry.sdk.autoconfigure.internal.ComponentLoader; import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; +import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.autoconfigure.spi.internal.AutoConfigureListener; @@ -317,41 +319,30 @@ void builder_addSpanProcessorCustomizer() { } @Test - void builder_addSpanProcessorUsingComponentLoader() { - SpanProcessor spanProcessor = Mockito.mock(SpanProcessor.class); - doReturn(true).when(spanProcessor).isStartRequired(); - doReturn(true).when(spanProcessor).isEndRequired(); - Mockito.lenient().doReturn(CompletableResultCode.ofSuccess()).when(spanProcessor).shutdown(); - Mockito.lenient().when(spanExporter1.shutdown()).thenReturn(CompletableResultCode.ofSuccess()); + void builder_addAutoConfigurationCustomizerProviderUsingComponentLoader() { + AutoConfigurationCustomizerProvider customizerProvider = + mock(AutoConfigurationCustomizerProvider.class); SpiHelper spiHelper = SpiHelper.create(AutoConfiguredOpenTelemetrySdkBuilder.class.getClassLoader()); - SdkTracerProvider sdkTracerProvider = - builder - .setComponentLoader( - new ComponentLoader() { - @SuppressWarnings("unchecked") - @Override - public Iterable load(Class spiClass) { - if (spiClass.equals(SpanProcessor.class)) { - return Collections.singletonList((T) spanProcessor); - } - return spiHelper.load(spiClass); - } - }) - .build() - .getOpenTelemetrySdk() - .getSdkTracerProvider(); - - Span span = sdkTracerProvider.get("dummy-scope").spanBuilder("dummy-span").startSpan(); - - verify(spanProcessor).onStart(any(), same((ReadWriteSpan) span)); + builder + .setComponentLoader( + new ComponentLoader() { + @SuppressWarnings("unchecked") + @Override + public Iterable load(Class spiClass) { + if (spiClass.equals(AutoConfigurationCustomizerProvider.class)) { + return Collections.singletonList((T) customizerProvider); + } + return spiHelper.load(spiClass); + } + }) + .build(); - span.end(); - verify(spanProcessor).onEnd(same((ReadableSpan) span)); + verify(customizerProvider).customize(any()); - verifyNoInteractions(spanExporter1); + verifyNoMoreInteractions(customizerProvider); } @Test diff --git a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelperTest.java b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelperTest.java index b61d5d2b47c..ad7a96704e6 100644 --- a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelperTest.java +++ b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelperTest.java @@ -16,7 +16,6 @@ import static org.mockito.Mockito.when; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurableProvider; import io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider; import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import java.util.Collections; @@ -38,7 +37,10 @@ public void canRetrieveByName() { NamedSpiManager spiProvider = spiHelper.loadConfigurable( - SpiExampleProvider.class, SpiExampleProvider::createSpiExample, EMPTY); + SpiExampleProvider.class, + SpiExampleProvider::getName, + SpiExampleProvider::createSpiExample, + EMPTY); assertThat(spiProvider.getByName(SpiExampleProviderImplementation.NAME)).isNotNull(); assertThat(spiProvider.getByName("invalid-provider")).isNull(); @@ -55,7 +57,10 @@ public void instantiatesImplementationsLazily() { NamedSpiManager spiProvider = spiHelper.loadConfigurable( - SpiExampleProvider.class, SpiExampleProvider::createSpiExample, EMPTY); + SpiExampleProvider.class, + SpiExampleProvider::getName, + SpiExampleProvider::createSpiExample, + EMPTY); verify(mockProvider, never()).createSpiExample(any()); // not requested yet spiProvider.getByName("lazy-init-example"); @@ -72,7 +77,10 @@ public void onlyInstantiatesOnce() { NamedSpiManager spiProvider = spiHelper.loadConfigurable( - SpiExampleProvider.class, SpiExampleProvider::createSpiExample, EMPTY); + SpiExampleProvider.class, + SpiExampleProvider::getName, + SpiExampleProvider::createSpiExample, + EMPTY); SpiExample first = spiProvider.getByName(SpiExampleProviderImplementation.NAME); SpiExample second = spiProvider.getByName(SpiExampleProviderImplementation.NAME); @@ -93,7 +101,10 @@ public void failureToInitializeThrows() { NamedSpiManager spiProvider = spiHelper.loadConfigurable( - SpiExampleProvider.class, SpiExampleProvider::createSpiExample, EMPTY); + SpiExampleProvider.class, + SpiExampleProvider::getName, + SpiExampleProvider::createSpiExample, + EMPTY); assertThatThrownBy(() -> spiProvider.getByName("init-failure-example")) .withFailMessage(exceptionMessage) @@ -120,9 +131,8 @@ void loadsOrderedSpi() { assertThat(loadedSpi).containsExactly(spi2, spi3, spi1); } - private interface SpiExampleProvider extends ConfigurableProvider { + private interface SpiExampleProvider { - @Override String getName(); SpiExample createSpiExample(ConfigProperties config); diff --git a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableSpanExporterTest.java b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableSpanExporterTest.java index 988a0ba22a8..ef533b82ac3 100644 --- a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableSpanExporterTest.java +++ b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableSpanExporterTest.java @@ -146,8 +146,7 @@ void configureSpanProcessors_simpleSpanProcessor() { Collections.singletonMap("otel.traces.exporter", exporterName)), ImmutableMap.of(exporterName, LoggingSpanExporter.create()), MeterProvider.noop(), - closeables, - spiHelper); + closeables); cleanup.addCloseables(closeables); assertThat(spanProcessors).hasExactlyElementsOfTypes(SimpleSpanProcessor.class); @@ -165,8 +164,7 @@ void configureSpanProcessors_batchSpanProcessor() { Collections.singletonMap("otel.traces.exporter", exporterName)), ImmutableMap.of(exporterName, ZipkinSpanExporter.builder().build()), MeterProvider.noop(), - closeables, - spiHelper); + closeables); cleanup.addCloseables(closeables); assertThat(spanProcessors).hasExactlyElementsOfTypes(BatchSpanProcessor.class); @@ -187,8 +185,7 @@ void configureSpanProcessors_multipleExporters() { "zipkin", ZipkinSpanExporter.builder().build()), MeterProvider.noop(), - closeables, - spiHelper); + closeables); cleanup.addCloseables(closeables); assertThat(spanProcessors) @@ -230,8 +227,7 @@ void configureSpanProcessors_multipleExportersWithLogging() { "zipkin", ZipkinSpanExporter.builder().build()), MeterProvider.noop(), - closeables, - spiHelper); + closeables); cleanup.addCloseables(closeables); assertThat(spanProcessors) diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordExporterFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordExporterFactory.java index f8849992831..3469ec61e36 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordExporterFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordExporterFactory.java @@ -107,6 +107,7 @@ private static NamedSpiManager logRecordExporterSpiManager( ConfigProperties config, SpiHelper spiHelper) { return spiHelper.loadConfigurable( ConfigurableLogRecordExporterProvider.class, + ConfigurableLogRecordExporterProvider::getName, ConfigurableLogRecordExporterProvider::createExporter, config); } diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricExporterFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricExporterFactory.java index 5f3785543f3..7d187f8a057 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricExporterFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricExporterFactory.java @@ -134,6 +134,7 @@ private static NamedSpiManager metricExporterSpiManager( ConfigProperties config, SpiHelper spiHelper) { return spiHelper.loadConfigurable( ConfigurableMetricExporterProvider.class, + ConfigurableMetricExporterProvider::getName, ConfigurableMetricExporterProvider::createExporter, config); } diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricReaderFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricReaderFactory.java index 0f89ec49880..bcaafd6c6e3 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricReaderFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricReaderFactory.java @@ -108,6 +108,7 @@ public MetricReader create( metricReaderSpiManager(ConfigProperties config, SpiHelper spiHelper) { return spiHelper.loadConfigurable( ConfigurableMetricReaderProvider.class, + ConfigurableMetricReaderProvider::getName, ConfigurableMetricReaderProvider::createMetricReader, config); } diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SamplerFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SamplerFactory.java index 1ff2cfe17a4..8d881c2d03e 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SamplerFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SamplerFactory.java @@ -129,6 +129,9 @@ public Sampler create( private static NamedSpiManager samplerSpiManager( ConfigProperties config, SpiHelper spiHelper) { return spiHelper.loadConfigurable( - ConfigurableSamplerProvider.class, ConfigurableSamplerProvider::createSampler, config); + ConfigurableSamplerProvider.class, + ConfigurableSamplerProvider::getName, + ConfigurableSamplerProvider::createSampler, + config); } } diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanExporterFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanExporterFactory.java index 45214db8f96..8a3b8cc6dce 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanExporterFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanExporterFactory.java @@ -141,6 +141,7 @@ private static NamedSpiManager spanExporterSpiManager( ConfigProperties config, SpiHelper spiHelper) { return spiHelper.loadConfigurable( ConfigurableSpanExporterProvider.class, + ConfigurableSpanExporterProvider::getName, ConfigurableSpanExporterProvider::createExporter, config); } diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/TextMapPropagatorFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/TextMapPropagatorFactory.java index 9616cc77cd4..4451ac98516 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/TextMapPropagatorFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/TextMapPropagatorFactory.java @@ -49,6 +49,7 @@ public TextMapPropagator create( NamedSpiManager spiPropagatorsManager = spiHelper.loadConfigurable( ConfigurablePropagatorProvider.class, + ConfigurablePropagatorProvider::getName, ConfigurablePropagatorProvider::getPropagator, DefaultConfigProperties.createFromMap(Collections.emptyMap())); Set propagators = new LinkedHashSet<>(); diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordExporterFactoryTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordExporterFactoryTest.java index 349b5dca15e..721421c8552 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordExporterFactoryTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordExporterFactoryTest.java @@ -89,7 +89,7 @@ void create_OtlpDefaults() { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(ConfigProperties.class); verify(spiHelper) .loadConfigurable( - eq(ConfigurableLogRecordExporterProvider.class), any(), configCaptor.capture()); + eq(ConfigurableLogRecordExporterProvider.class), any(), any(), configCaptor.capture()); ConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("otel.exporter.otlp.logs.protocol")).isNull(); assertThat(configProperties.getString("otel.exporter.otlp.endpoint")).isNull(); @@ -154,7 +154,7 @@ void create_OtlpConfigured(@TempDir Path tempDir) ArgumentCaptor configCaptor = ArgumentCaptor.forClass(ConfigProperties.class); verify(spiHelper) .loadConfigurable( - eq(ConfigurableLogRecordExporterProvider.class), any(), configCaptor.capture()); + eq(ConfigurableLogRecordExporterProvider.class), any(), any(), configCaptor.capture()); ConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("otel.exporter.otlp.logs.protocol")) .isEqualTo("http/protobuf"); diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricExporterFactoryTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricExporterFactoryTest.java index 9f8344e2636..4b9b7520441 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricExporterFactoryTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricExporterFactoryTest.java @@ -88,7 +88,7 @@ void create_OtlpDefaults() { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(ConfigProperties.class); verify(spiHelper) .loadConfigurable( - eq(ConfigurableMetricExporterProvider.class), any(), configCaptor.capture()); + eq(ConfigurableMetricExporterProvider.class), any(), any(), configCaptor.capture()); ConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("otel.exporter.otlp.metrics.protocol")).isNull(); assertThat(configProperties.getString("otel.exporter.otlp.endpoint")).isNull(); @@ -162,7 +162,7 @@ void create_OtlpConfigured(@TempDir Path tempDir) ArgumentCaptor configCaptor = ArgumentCaptor.forClass(ConfigProperties.class); verify(spiHelper) .loadConfigurable( - eq(ConfigurableMetricExporterProvider.class), any(), configCaptor.capture()); + eq(ConfigurableMetricExporterProvider.class), any(), any(), configCaptor.capture()); ConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("otel.exporter.otlp.metrics.protocol")) .isEqualTo("http/protobuf"); diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricReaderFactoryTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricReaderFactoryTest.java index dbc23f93730..64da70549a1 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricReaderFactoryTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/MetricReaderFactoryTest.java @@ -145,7 +145,7 @@ void create_PullPrometheusDefault() throws IOException { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(ConfigProperties.class); verify(spiHelper) .loadConfigurable( - eq(ConfigurableMetricReaderProvider.class), any(), configCaptor.capture()); + eq(ConfigurableMetricReaderProvider.class), any(), any(), configCaptor.capture()); ConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("otel.exporter.prometheus.host")).isNull(); assertThat(configProperties.getInt("otel.exporter.prometheus.port")).isEqualTo(port); @@ -182,7 +182,7 @@ void create_PullPrometheusConfigured() throws IOException { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(ConfigProperties.class); verify(spiHelper) .loadConfigurable( - eq(ConfigurableMetricReaderProvider.class), any(), configCaptor.capture()); + eq(ConfigurableMetricReaderProvider.class), any(), any(), configCaptor.capture()); ConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("otel.exporter.prometheus.host")).isEqualTo("localhost"); assertThat(configProperties.getInt("otel.exporter.prometheus.port")).isEqualTo(port); diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanExporterFactoryTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanExporterFactoryTest.java index 828cc2ab574..09c47433003 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanExporterFactoryTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanExporterFactoryTest.java @@ -82,7 +82,7 @@ void create_OtlpDefaults() { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(ConfigProperties.class); verify(spiHelper) .loadConfigurable( - eq(ConfigurableSpanExporterProvider.class), any(), configCaptor.capture()); + eq(ConfigurableSpanExporterProvider.class), any(), any(), configCaptor.capture()); ConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("otel.exporter.otlp.traces.protocol")).isNull(); assertThat(configProperties.getString("otel.exporter.otlp.endpoint")).isNull(); @@ -147,7 +147,7 @@ void create_OtlpConfigured(@TempDir Path tempDir) ArgumentCaptor configCaptor = ArgumentCaptor.forClass(ConfigProperties.class); verify(spiHelper) .loadConfigurable( - eq(ConfigurableSpanExporterProvider.class), any(), configCaptor.capture()); + eq(ConfigurableSpanExporterProvider.class), any(), any(), configCaptor.capture()); ConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("otel.exporter.otlp.traces.protocol")) .isEqualTo("http/protobuf"); @@ -212,7 +212,7 @@ void create_ZipkinDefaults() { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(ConfigProperties.class); verify(spiHelper) .loadConfigurable( - eq(ConfigurableSpanExporterProvider.class), any(), configCaptor.capture()); + eq(ConfigurableSpanExporterProvider.class), any(), any(), configCaptor.capture()); ConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("otel.exporter.zipkin.endpoint")).isNull(); assertThat(configProperties.getDuration("otel.exporter.zipkin.timeout")).isNull(); @@ -248,7 +248,7 @@ void create_ZipkinConfigured() { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(ConfigProperties.class); verify(spiHelper) .loadConfigurable( - eq(ConfigurableSpanExporterProvider.class), any(), configCaptor.capture()); + eq(ConfigurableSpanExporterProvider.class), any(), any(), configCaptor.capture()); ConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("otel.exporter.zipkin.endpoint")) .isEqualTo("http://zipkin:9411/v1/v2/spans"); From d03a67fad6a693ab9b19f83e5cd60584885ef9db Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Wed, 28 Feb 2024 07:38:42 +0100 Subject: [PATCH 17/21] add javadoc --- .../opentelemetry-sdk-extension-autoconfigure-spi.txt | 4 ++-- .../AutoConfiguredOpenTelemetrySdkBuilder.java | 1 + .../sdk/autoconfigure/internal/ComponentLoader.java | 7 +++++++ .../sdk/autoconfigure/internal/SpiHelper.java | 1 + 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure-spi.txt b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure-spi.txt index 3013553d6ea..df26146497b 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure-spi.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure-spi.txt @@ -1,2 +1,2 @@ -Comparing source compatibility of against -No changes. +Comparing source compatibility of against +No changes. \ No newline at end of file diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java index 7d315a317c8..9c955f242da 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java @@ -369,6 +369,7 @@ public AutoConfiguredOpenTelemetrySdkBuilder setServiceClassLoader( return this; } + /** Sets the {@link ComponentLoader} to be used to load SPI implementations. */ public AutoConfiguredOpenTelemetrySdkBuilder setComponentLoader(ComponentLoader componentLoader) { requireNonNull(componentLoader, "componentLoader"); this.spiHelper = SpiHelper.create(componentLoader); diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/ComponentLoader.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/ComponentLoader.java index 97fbbb843b1..6ababaa5563 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/ComponentLoader.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/ComponentLoader.java @@ -18,6 +18,13 @@ * at any time. */ public interface ComponentLoader { + /** + * Load implementations of an SPI. + * + * @param spiClass the SPI class + * @param the SPI type + * @return iterable of SPI implementations + */ Iterable load(Class spiClass); /** diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java index a6434eecabf..1c871587ccb 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java @@ -39,6 +39,7 @@ public static SpiHelper create(ClassLoader classLoader) { return new SpiHelper(new ServiceLoaderComponentLoader(classLoader)); } + /** Create a {@link SpiHelper} which loads SPIs using the {@code componentLoader}. */ public static SpiHelper create(ComponentLoader componentLoader) { return new SpiHelper(componentLoader); } From 517d77337209d282b9678ee2d83f950d5e9eaa62 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Wed, 28 Feb 2024 17:11:09 +0100 Subject: [PATCH 18/21] make new methods experimental --- ...ntelemetry-sdk-extension-autoconfigure.txt | 5 +-- ...AutoConfiguredOpenTelemetrySdkBuilder.java | 4 +-- .../internal/AutoConfigureUtil.java | 31 +++++++++++++++++++ 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt index 9411da9ac5d..df26146497b 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-extension-autoconfigure.txt @@ -1,5 +1,2 @@ Comparing source compatibility of against -*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder (not serializable) - === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 - +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder setComponentLoader(io.opentelemetry.sdk.autoconfigure.internal.ComponentLoader) - *** MODIFIED METHOD: PUBLIC (<- PACKAGE_PROTECTED) io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder setConfig(io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties) +No changes. \ No newline at end of file diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java index 9c955f242da..d1066d195c8 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java @@ -116,7 +116,7 @@ public final class AutoConfiguredOpenTelemetrySdkBuilder implements AutoConfigur * {@link #addPropertiesSupplier(Supplier)} and {@link #addPropertiesCustomizer(Function)} will * have no effect if this method is used. */ - public AutoConfiguredOpenTelemetrySdkBuilder setConfig(ConfigProperties config) { + AutoConfiguredOpenTelemetrySdkBuilder setConfig(ConfigProperties config) { requireNonNull(config, "config"); this.config = config; return this; @@ -370,7 +370,7 @@ public AutoConfiguredOpenTelemetrySdkBuilder setServiceClassLoader( } /** Sets the {@link ComponentLoader} to be used to load SPI implementations. */ - public AutoConfiguredOpenTelemetrySdkBuilder setComponentLoader(ComponentLoader componentLoader) { + AutoConfiguredOpenTelemetrySdkBuilder setComponentLoader(ComponentLoader componentLoader) { requireNonNull(componentLoader, "componentLoader"); this.spiHelper = SpiHelper.create(componentLoader); return this; diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/AutoConfigureUtil.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/AutoConfigureUtil.java index e77620fc49a..af10db733ef 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/AutoConfigureUtil.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/AutoConfigureUtil.java @@ -6,6 +6,7 @@ package io.opentelemetry.sdk.autoconfigure.internal; import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk; +import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -30,4 +31,34 @@ public static ConfigProperties getConfig( "Error calling getConfig on AutoConfiguredOpenTelemetrySdk", e); } } + + /** Sets the {@link ComponentLoader} to be used in the auto-configuration process. */ + public static void setComponentLoader( + AutoConfiguredOpenTelemetrySdkBuilder builder, ComponentLoader componentLoader) { + try { + Method method = + AutoConfiguredOpenTelemetrySdkBuilder.class.getDeclaredMethod( + "setComponentLoader", ComponentLoader.class); + method.setAccessible(true); + method.invoke(builder, componentLoader); + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { + throw new IllegalStateException( + "Error calling setComponentLoader on AutoConfiguredOpenTelemetrySdkBuilder", e); + } + } + + /** Sets the {@link ConfigProperties} to be used in the auto-configuration process. */ + public static void setConfigProperties( + AutoConfiguredOpenTelemetrySdkBuilder builder, ConfigProperties config) { + try { + Method method = + AutoConfiguredOpenTelemetrySdkBuilder.class.getDeclaredMethod( + "setConfig", ConfigProperties.class); + method.setAccessible(true); + method.invoke(builder, config); + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { + throw new IllegalStateException( + "Error calling setConfig on AutoConfiguredOpenTelemetrySdkBuilder", e); + } + } } From e97c4f9d9240a6702fe0668172ce57f0cb1deac0 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 29 Feb 2024 09:09:30 +0100 Subject: [PATCH 19/21] don't make loadOrdered overridable --- .../internal/ComponentLoader.java | 19 --------------- .../sdk/autoconfigure/internal/SpiHelper.java | 24 +++++++------------ 2 files changed, 8 insertions(+), 35 deletions(-) diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/ComponentLoader.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/ComponentLoader.java index 6ababaa5563..49bfc4e52f2 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/ComponentLoader.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/ComponentLoader.java @@ -5,12 +5,6 @@ package io.opentelemetry.sdk.autoconfigure.internal; -import io.opentelemetry.sdk.autoconfigure.spi.Ordered; -import java.util.Comparator; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.StreamSupport; - /** * A loader for components that are discovered via SPI. * @@ -26,17 +20,4 @@ public interface ComponentLoader { * @return iterable of SPI implementations */ Iterable load(Class spiClass); - - /** - * Load implementations of an ordered SPI (i.e. implements {@link Ordered}). - * - * @param spiClass the SPI class - * @param the SPI type - * @return list of SPI implementations, in order - */ - default List loadOrdered(Class spiClass) { - return StreamSupport.stream(load(spiClass).spliterator(), false) - .sorted(Comparator.comparing(Ordered::order)) - .collect(Collectors.toList()); - } } diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java index 1c871587ccb..d54e526d44a 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/SpiHelper.java @@ -10,6 +10,7 @@ import io.opentelemetry.sdk.autoconfigure.spi.internal.AutoConfigureListener; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.IdentityHashMap; import java.util.List; @@ -83,7 +84,9 @@ public NamedSpiManager loadConfigurable( * @return list of SPI implementations, in order */ public List loadOrdered(Class spiClass) { - return init(componentLoader.loadOrdered(spiClass)); + List result = load(spiClass); + result.sort(Comparator.comparing(Ordered::order)); + return result; } /** @@ -94,29 +97,18 @@ public List loadOrdered(Class spiClass) { * @return list of SPI implementations */ public List load(Class spiClass) { - return init(componentLoader.load(spiClass)); - } - - /** - * Load implementations of an SPI. - * - * @param components the SPI implementations - * @param the SPI type - * @return list of SPI implementations - */ - private List init(Iterable components) { List result = new ArrayList<>(); - for (T service : components) { - result.add(maybeAddListener(service)); + for (T service : componentLoader.load(spiClass)) { + maybeAddListener(service); + result.add(service); } return result; } - private T maybeAddListener(T object) { + private void maybeAddListener(Object object) { if (object instanceof AutoConfigureListener) { listeners.add((AutoConfigureListener) object); } - return object; } /** Return the set of SPIs loaded which implement {@link AutoConfigureListener}. */ From 4519a7e90243e5b75b3a46a14c872de88b95a9a1 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 29 Feb 2024 09:31:13 +0100 Subject: [PATCH 20/21] add setConfigPropertiesCustomizer --- ...AutoConfiguredOpenTelemetrySdkBuilder.java | 20 ++++++++++++++++++- .../internal/AutoConfigureUtil.java | 15 ++++++++------ .../AutoConfiguredOpenTelemetrySdkTest.java | 19 ++++++++++++++++++ 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java index d1066d195c8..66317c4a8d2 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java @@ -100,6 +100,9 @@ public final class AutoConfiguredOpenTelemetrySdkBuilder implements AutoConfigur private final List>> propertiesCustomizers = new ArrayList<>(); + private Function configPropertiesCustomizer = + Function.identity(); + private SpiHelper spiHelper = SpiHelper.create(AutoConfiguredOpenTelemetrySdk.class.getClassLoader()); @@ -251,6 +254,21 @@ public AutoConfiguredOpenTelemetrySdkBuilder addPropertiesCustomizer( return this; } + /** + * Adds a {@link Function} to invoke the with the {@link ConfigProperties} to allow customization. + * + *

The argument to the function is the {@link ConfigProperties}, with the {@link + * #addPropertiesCustomizer(Function)} already applied. + * + *

The return value of the {@link Function} replace the {@link ConfigProperties} to be used. + */ + AutoConfiguredOpenTelemetrySdkBuilder setConfigPropertiesCustomizer( + Function configPropertiesCustomizer) { + requireNonNull(configPropertiesCustomizer, "configPropertiesCustomizer"); + this.configPropertiesCustomizer = configPropertiesCustomizer; + return this; + } + /** * Adds a {@link BiFunction} to invoke the with the {@link SdkMeterProviderBuilder} to allow * customization. The return value of the {@link BiFunction} will replace the passed-in argument. @@ -576,7 +594,7 @@ private ConfigProperties computeConfigProperties() { Map overrides = customizer.apply(properties); properties = properties.withOverrides(overrides); } - return properties; + return configPropertiesCustomizer.apply(properties); } // Visible for testing diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/AutoConfigureUtil.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/AutoConfigureUtil.java index af10db733ef..43e72d6c4cd 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/AutoConfigureUtil.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/AutoConfigureUtil.java @@ -10,6 +10,7 @@ import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.function.Function; /** * This class is internal and is hence not for public use. Its APIs are unstable and can change at @@ -47,18 +48,20 @@ public static void setComponentLoader( } } - /** Sets the {@link ConfigProperties} to be used in the auto-configuration process. */ - public static void setConfigProperties( - AutoConfiguredOpenTelemetrySdkBuilder builder, ConfigProperties config) { + /** Sets the {@link ConfigProperties} customizer to be used in the auto-configuration process. */ + public static void setConfigPropertiesCustomizer( + AutoConfiguredOpenTelemetrySdkBuilder builder, + Function customizer) { try { Method method = AutoConfiguredOpenTelemetrySdkBuilder.class.getDeclaredMethod( - "setConfig", ConfigProperties.class); + "setConfigPropertiesCustomizer", Function.class); method.setAccessible(true); - method.invoke(builder, config); + method.invoke(builder, customizer); } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { throw new IllegalStateException( - "Error calling setConfig on AutoConfiguredOpenTelemetrySdkBuilder", e); + "Error calling setConfigPropertiesCustomizer on AutoConfiguredOpenTelemetrySdkBuilder", + e); } } } diff --git a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkTest.java b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkTest.java index deff47134cb..0699601d76b 100644 --- a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkTest.java +++ b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkTest.java @@ -43,6 +43,7 @@ import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.autoconfigure.spi.internal.AutoConfigureListener; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import io.opentelemetry.sdk.common.CompletableResultCode; import io.opentelemetry.sdk.logs.LogRecordProcessor; import io.opentelemetry.sdk.logs.SdkLoggerProvider; @@ -386,6 +387,24 @@ void builder_addPropertiesCustomizer() { assertThat(autoConfigured.getConfig().getString("some.key")).isEqualTo("override-2"); } + @Test + void builder_setConfigPropertiesCustomizer() { + AutoConfiguredOpenTelemetrySdk autoConfigured = + builder + .addPropertiesCustomizer(config -> singletonMap("some-key", "defaultValue")) + .setConfigPropertiesCustomizer( + config -> { + assertThat(config.getString("some-key")).isEqualTo("defaultValue"); + + Map map = new HashMap<>(singletonMap("some-key", "override")); + map.putAll(disableExportPropertySupplier().get()); + return DefaultConfigProperties.createFromMap(map); + }) + .build(); + + assertThat(autoConfigured.getConfig().getString("some.key")).isEqualTo("override"); + } + @Test void builder_addMeterProviderCustomizer() { Mockito.lenient().when(metricReader.shutdown()).thenReturn(CompletableResultCode.ofSuccess()); From 22996e0ac545d229619b1152dd2f1c23bf409972 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Tue, 5 Mar 2024 08:45:49 +0100 Subject: [PATCH 21/21] add setConfigPropertiesCustomizer --- .../sdk/autoconfigure/internal/AutoConfigureUtil.java | 6 ++++-- .../AutoConfiguredOpenTelemetrySdkTest.java | 11 +++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/AutoConfigureUtil.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/AutoConfigureUtil.java index 43e72d6c4cd..8a50d782031 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/AutoConfigureUtil.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/internal/AutoConfigureUtil.java @@ -34,7 +34,7 @@ public static ConfigProperties getConfig( } /** Sets the {@link ComponentLoader} to be used in the auto-configuration process. */ - public static void setComponentLoader( + public static AutoConfiguredOpenTelemetrySdkBuilder setComponentLoader( AutoConfiguredOpenTelemetrySdkBuilder builder, ComponentLoader componentLoader) { try { Method method = @@ -42,6 +42,7 @@ public static void setComponentLoader( "setComponentLoader", ComponentLoader.class); method.setAccessible(true); method.invoke(builder, componentLoader); + return builder; } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { throw new IllegalStateException( "Error calling setComponentLoader on AutoConfiguredOpenTelemetrySdkBuilder", e); @@ -49,7 +50,7 @@ public static void setComponentLoader( } /** Sets the {@link ConfigProperties} customizer to be used in the auto-configuration process. */ - public static void setConfigPropertiesCustomizer( + public static AutoConfiguredOpenTelemetrySdkBuilder setConfigPropertiesCustomizer( AutoConfiguredOpenTelemetrySdkBuilder builder, Function customizer) { try { @@ -58,6 +59,7 @@ public static void setConfigPropertiesCustomizer( "setConfigPropertiesCustomizer", Function.class); method.setAccessible(true); method.invoke(builder, customizer); + return builder; } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { throw new IllegalStateException( "Error calling setConfigPropertiesCustomizer on AutoConfiguredOpenTelemetrySdkBuilder", diff --git a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkTest.java b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkTest.java index 0699601d76b..5e8ea677c7f 100644 --- a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkTest.java +++ b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkTest.java @@ -37,6 +37,7 @@ import io.opentelemetry.context.propagation.TextMapPropagator; import io.opentelemetry.internal.testing.slf4j.SuppressLogger; import io.opentelemetry.sdk.OpenTelemetrySdk; +import io.opentelemetry.sdk.autoconfigure.internal.AutoConfigureUtil; import io.opentelemetry.sdk.autoconfigure.internal.ComponentLoader; import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider; @@ -327,8 +328,8 @@ void builder_addAutoConfigurationCustomizerProviderUsingComponentLoader() { SpiHelper spiHelper = SpiHelper.create(AutoConfiguredOpenTelemetrySdkBuilder.class.getClassLoader()); - builder - .setComponentLoader( + AutoConfigureUtil.setComponentLoader( + builder, new ComponentLoader() { @SuppressWarnings("unchecked") @Override @@ -342,7 +343,6 @@ public Iterable load(Class spiClass) { .build(); verify(customizerProvider).customize(any()); - verifyNoMoreInteractions(customizerProvider); } @@ -390,9 +390,8 @@ void builder_addPropertiesCustomizer() { @Test void builder_setConfigPropertiesCustomizer() { AutoConfiguredOpenTelemetrySdk autoConfigured = - builder - .addPropertiesCustomizer(config -> singletonMap("some-key", "defaultValue")) - .setConfigPropertiesCustomizer( + AutoConfigureUtil.setConfigPropertiesCustomizer( + builder.addPropertiesCustomizer(config -> singletonMap("some-key", "defaultValue")), config -> { assertThat(config.getString("some-key")).isEqualTo("defaultValue");