From 766385547c8f697ac1c1cc61af2ccbbd2444e84d Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Wed, 20 Aug 2025 16:58:11 +0200 Subject: [PATCH 01/14] add exporter authenticator --- .../authenticator/ExporterAuthenticator.java | 9 ++++++++ .../internal/OtlpDeclarativeConfigUtil.java | 23 +++++++++++++++++++ ...rpcLogRecordExporterComponentProvider.java | 1 + ...lpGrpcMetricExporterComponentProvider.java | 1 + ...OtlpGrpcSpanExporterComponentProvider.java | 1 + ...ttpLogRecordExporterComponentProvider.java | 1 + ...lpHttpMetricExporterComponentProvider.java | 1 + ...OtlpHttpSpanExporterComponentProvider.java | 1 + 8 files changed, 38 insertions(+) create mode 100644 api/incubator/src/main/java/io/opentelemetry/api/incubator/authenticator/ExporterAuthenticator.java diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/authenticator/ExporterAuthenticator.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/authenticator/ExporterAuthenticator.java new file mode 100644 index 00000000000..35d968bfb58 --- /dev/null +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/authenticator/ExporterAuthenticator.java @@ -0,0 +1,9 @@ +package io.opentelemetry.api.incubator.authenticator; + +import java.util.Map; + +public interface ExporterAuthenticator { + String getName(); + + Map getAuthenticationHeaders(); +} diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpDeclarativeConfigUtil.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpDeclarativeConfigUtil.java index b2f174ae3df..a933c746812 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpDeclarativeConfigUtil.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpDeclarativeConfigUtil.java @@ -10,6 +10,7 @@ import static io.opentelemetry.exporter.otlp.internal.OtlpConfigUtil.readFileBytes; import static io.opentelemetry.exporter.otlp.internal.OtlpConfigUtil.validateEndpoint; +import io.opentelemetry.api.incubator.authenticator.ExporterAuthenticator; import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.common.ComponentLoader; import io.opentelemetry.exporter.internal.IncubatingExporterBuilderUtil; @@ -24,6 +25,7 @@ import java.util.List; import java.util.function.BiConsumer; import java.util.function.Consumer; +import java.util.stream.StreamSupport; /** * This class is internal and is hence not for public use. Its APIs are unstable and can change at @@ -51,6 +53,7 @@ public static void configureOtlpExporterBuilder( Consumer setComponentLoader, Consumer setEndpoint, BiConsumer addHeader, + Consumer setAuthenticator, Consumer setCompression, Consumer setTimeout, Consumer setTrustedCertificates, @@ -65,6 +68,26 @@ public static void configureOtlpExporterBuilder( setEndpoint.accept(endpoint.toString()); } + DeclarativeConfigProperties authenticator = config.getStructured("authenticator"); + if (authenticator != null) { + String authenticatorName = authenticator.getString("name"); + if (authenticatorName == null) { + throw new ConfigurationException( + "authenticator.name must be set when using an authenticator"); + } + Iterable authenticators = + config.getComponentLoader().load(ExporterAuthenticator.class); + ExporterAuthenticator exporterAuthenticator = + StreamSupport.stream(authenticators.spliterator(), false) + .filter(auth -> authenticatorName.equals(auth.getName())) + .findFirst() + .orElseThrow( + () -> + new ConfigurationException( + "Invalid authenticator specified: " + authenticatorName)); + setAuthenticator.accept(exporterAuthenticator); + } + String headerList = config.getString("headers_list"); if (headerList != null) { ConfigProperties headersListConfig = diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcLogRecordExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcLogRecordExporterComponentProvider.java index f8faab7a00a..72a64f3e3da 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcLogRecordExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcLogRecordExporterComponentProvider.java @@ -42,6 +42,7 @@ public LogRecordExporter create(DeclarativeConfigProperties config) { builder::setComponentLoader, builder::setEndpoint, builder::addHeader, + auth -> builder.setHeaders(auth::getAuthenticationHeaders), builder::setCompression, builder::setTimeout, builder::setTrustedCertificates, diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcMetricExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcMetricExporterComponentProvider.java index 25f8341fb07..ae95c73c52b 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcMetricExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcMetricExporterComponentProvider.java @@ -42,6 +42,7 @@ public MetricExporter create(DeclarativeConfigProperties config) { builder::setComponentLoader, builder::setEndpoint, builder::addHeader, + auth -> builder.setHeaders(auth::getAuthenticationHeaders), builder::setCompression, builder::setTimeout, builder::setTrustedCertificates, diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcSpanExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcSpanExporterComponentProvider.java index 84e230ca515..feab01f77c4 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcSpanExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcSpanExporterComponentProvider.java @@ -41,6 +41,7 @@ public SpanExporter create(DeclarativeConfigProperties config) { builder::setComponentLoader, builder::setEndpoint, builder::addHeader, + auth -> builder.setHeaders(auth::getAuthenticationHeaders), builder::setCompression, builder::setTimeout, builder::setTrustedCertificates, diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpLogRecordExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpLogRecordExporterComponentProvider.java index e6a513e8982..8d5c2065851 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpLogRecordExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpLogRecordExporterComponentProvider.java @@ -42,6 +42,7 @@ public LogRecordExporter create(DeclarativeConfigProperties config) { builder::setComponentLoader, builder::setEndpoint, builder::addHeader, + auth -> builder.setHeaders(auth::getAuthenticationHeaders), builder::setCompression, builder::setTimeout, builder::setTrustedCertificates, diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpMetricExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpMetricExporterComponentProvider.java index d6cc1bf62d1..c2ed35e2ec8 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpMetricExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpMetricExporterComponentProvider.java @@ -42,6 +42,7 @@ public MetricExporter create(DeclarativeConfigProperties config) { builder::setComponentLoader, builder::setEndpoint, builder::addHeader, + auth -> builder.setHeaders(auth::getAuthenticationHeaders), builder::setCompression, builder::setTimeout, builder::setTrustedCertificates, diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpSpanExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpSpanExporterComponentProvider.java index 752e9698dcf..c95670e7e5f 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpSpanExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpSpanExporterComponentProvider.java @@ -41,6 +41,7 @@ public SpanExporter create(DeclarativeConfigProperties config) { builder::setComponentLoader, builder::setEndpoint, builder::addHeader, + auth -> builder.setHeaders(auth::getAuthenticationHeaders), builder::setCompression, builder::setTimeout, builder::setTrustedCertificates, From aa6deb282fa10426090c17da91dc2ba2cfaf2080 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 21 Aug 2025 09:12:29 +0200 Subject: [PATCH 02/14] add ComponentProviderLoader --- ...outLogRecordExporterComponentProvider.java | 2 +- ...StdoutMetricExporterComponentProvider.java | 2 +- ...lpStdoutSpanExporterComponentProvider.java | 2 +- .../otlp/AbstractOtlpStdoutExporterTest.java | 2 +- ...oleLogRecordExporterComponentProvider.java | 2 +- ...onsoleMetricExporterComponentProvider.java | 2 +- .../ConsoleSpanExporterComponentProvider.java | 2 +- .../internal/OtlpDeclarativeConfigUtil.java | 26 ++++++++++++------- ...rpcLogRecordExporterComponentProvider.java | 4 ++- ...lpGrpcMetricExporterComponentProvider.java | 3 ++- ...OtlpGrpcSpanExporterComponentProvider.java | 3 ++- ...ttpLogRecordExporterComponentProvider.java | 4 ++- ...lpHttpMetricExporterComponentProvider.java | 3 ++- ...OtlpHttpSpanExporterComponentProvider.java | 3 ++- .../internal/PrometheusComponentProvider.java | 2 +- .../ZipkinSpanExporterComponentProvider.java | 2 +- .../internal/B3ComponentProvider.java | 2 +- .../internal/B3MultiComponentProvider.java | 2 +- .../internal/JaegerComponentProvider.java | 2 +- .../internal/OtTraceComponentProvider.java | 2 +- .../spi/internal/ComponentProvider.java | 12 +++++++-- sdk-extensions/incubator/build.gradle.kts | 11 ++------ .../fileconfig/DeclarativeConfigContext.java | 20 +++++++++++--- .../fileconfig/LogRecordExporterFactory.java | 3 ++- .../fileconfig/LogRecordProcessorFactory.java | 3 ++- .../fileconfig/MetricExporterFactory.java | 3 ++- .../fileconfig/MetricReaderFactory.java | 2 +- .../fileconfig/ResourceDetectorFactory.java | 2 +- .../incubator/fileconfig/SamplerFactory.java | 2 +- .../fileconfig/ServiceResourceDetector.java | 3 ++- .../fileconfig/SpanExporterFactory.java | 2 +- .../fileconfig/SpanProcessorFactory.java | 2 +- .../fileconfig/TextMapPropagatorFactory.java | 5 ++-- .../LogRecordExporterFactoryTest.java | 11 ++++---- .../fileconfig/MetricExporterFactoryTest.java | 11 ++++---- .../fileconfig/MetricReaderFactoryTest.java | 4 +-- .../ServiceResourceDetectorTest.java | 4 +-- .../fileconfig/SpanExporterFactoryTest.java | 18 ++++++++----- .../component/ContainerResourceProvider.java | 3 ++- .../component/HostResourceProvider.java | 3 ++- .../LogRecordExporterComponentProvider.java | 3 ++- .../LogRecordProcessorComponentProvider.java | 3 ++- .../MetricExporterComponentProvider.java | 3 ++- .../component/OsResourceProvider.java | 3 ++- .../component/ProcessResourceProvider.java | 3 ++- .../component/ResourceComponentProvider.java | 3 ++- .../ResourceFirstComponentProvider.java | 3 ++- .../ResourceSecondComponentProvider.java | 3 ++- .../component/SamplerComponentProvider.java | 3 ++- .../SpanExporterComponentProvider.java | 3 ++- .../SpanProcessorComponentProvider.java | 3 ++- .../TextMapPropagatorComponentProvider.java | 3 ++- .../JaegerRemoteSamplerComponentProvider.java | 2 +- 53 files changed, 143 insertions(+), 91 deletions(-) diff --git a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporterComponentProvider.java b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporterComponentProvider.java index ee6fbfe66ba..1af629fa7fe 100644 --- a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporterComponentProvider.java +++ b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporterComponentProvider.java @@ -30,7 +30,7 @@ public String getName() { } @Override - public LogRecordExporter create(DeclarativeConfigProperties config) { + public LogRecordExporter create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { OtlpStdoutLogRecordExporterBuilder builder = OtlpStdoutLogRecordExporter.builder(); IncubatingExporterBuilderUtil.configureExporterMemoryMode(config, builder::setMemoryMode); return builder.build(); diff --git a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/metrics/OtlpStdoutMetricExporterComponentProvider.java b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/metrics/OtlpStdoutMetricExporterComponentProvider.java index 70de404af14..19622678618 100644 --- a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/metrics/OtlpStdoutMetricExporterComponentProvider.java +++ b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/metrics/OtlpStdoutMetricExporterComponentProvider.java @@ -30,7 +30,7 @@ public String getName() { } @Override - public MetricExporter create(DeclarativeConfigProperties config) { + public MetricExporter create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { OtlpStdoutMetricExporterBuilder builder = OtlpStdoutMetricExporter.builder(); IncubatingExporterBuilderUtil.configureExporterMemoryMode(config, builder::setMemoryMode); IncubatingExporterBuilderUtil.configureOtlpAggregationTemporality( diff --git a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/traces/OtlpStdoutSpanExporterComponentProvider.java b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/traces/OtlpStdoutSpanExporterComponentProvider.java index e16ac868e3b..ead347033e1 100644 --- a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/traces/OtlpStdoutSpanExporterComponentProvider.java +++ b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/traces/OtlpStdoutSpanExporterComponentProvider.java @@ -30,7 +30,7 @@ public String getName() { } @Override - public SpanExporter create(DeclarativeConfigProperties config) { + public SpanExporter create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { OtlpStdoutSpanExporterBuilder builder = OtlpStdoutSpanExporter.builder(); IncubatingExporterBuilderUtil.configureExporterMemoryMode(config, builder::setMemoryMode); return builder.build(); diff --git a/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/AbstractOtlpStdoutExporterTest.java b/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/AbstractOtlpStdoutExporterTest.java index 44b046aca42..62edbe2de27 100644 --- a/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/AbstractOtlpStdoutExporterTest.java +++ b/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/AbstractOtlpStdoutExporterTest.java @@ -339,7 +339,7 @@ protected T exporterFromComponentProvider(DeclarativeConfigProperties properties }) .findFirst() .orElseThrow(() -> new IllegalStateException("No provider found")) - .create(properties); + .create(properties, null); } @SuppressWarnings("unchecked") diff --git a/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleLogRecordExporterComponentProvider.java b/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleLogRecordExporterComponentProvider.java index 2d8141cc4f2..5aa5640f280 100644 --- a/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleLogRecordExporterComponentProvider.java +++ b/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleLogRecordExporterComponentProvider.java @@ -30,7 +30,7 @@ public String getName() { } @Override - public LogRecordExporter create(DeclarativeConfigProperties config) { + public LogRecordExporter create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { return SystemOutLogRecordExporter.create(); } } diff --git a/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleMetricExporterComponentProvider.java b/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleMetricExporterComponentProvider.java index 6fab453403f..471c02e0ff2 100644 --- a/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleMetricExporterComponentProvider.java +++ b/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleMetricExporterComponentProvider.java @@ -30,7 +30,7 @@ public String getName() { } @Override - public MetricExporter create(DeclarativeConfigProperties config) { + public MetricExporter create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { return LoggingMetricExporter.create(); } } diff --git a/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleSpanExporterComponentProvider.java b/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleSpanExporterComponentProvider.java index fd65a5acad8..825d6dfaf93 100644 --- a/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleSpanExporterComponentProvider.java +++ b/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleSpanExporterComponentProvider.java @@ -29,7 +29,7 @@ public String getName() { } @Override - public SpanExporter create(DeclarativeConfigProperties config) { + public SpanExporter create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { return LoggingSpanExporter.create(); } } diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpDeclarativeConfigUtil.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpDeclarativeConfigUtil.java index a933c746812..be1395221da 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpDeclarativeConfigUtil.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpDeclarativeConfigUtil.java @@ -16,6 +16,7 @@ import io.opentelemetry.exporter.internal.IncubatingExporterBuilderUtil; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; +import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import io.opentelemetry.sdk.common.export.MemoryMode; import io.opentelemetry.sdk.common.export.RetryPolicy; @@ -25,7 +26,6 @@ import java.util.List; import java.util.function.BiConsumer; import java.util.function.Consumer; -import java.util.stream.StreamSupport; /** * This class is internal and is hence not for public use. Its APIs are unstable and can change at @@ -50,6 +50,7 @@ public static String getStructuredConfigOtlpProtocol(DeclarativeConfigProperties public static void configureOtlpExporterBuilder( String dataType, DeclarativeConfigProperties config, + ComponentProvider.ComponentProviderLoader componentProviderLoader, Consumer setComponentLoader, Consumer setEndpoint, BiConsumer addHeader, @@ -75,16 +76,21 @@ public static void configureOtlpExporterBuilder( throw new ConfigurationException( "authenticator.name must be set when using an authenticator"); } - Iterable authenticators = - config.getComponentLoader().load(ExporterAuthenticator.class); + // Iterable authenticators = + // config.getComponentLoader().load(ExporterAuthenticator.class); + // ExporterAuthenticator exporterAuthenticator = + // StreamSupport.stream(authenticators.spliterator(), false) + // .filter(auth -> authenticatorName.equals(auth.getName())) + // .findFirst() + // .orElseThrow( + // () -> + // new ConfigurationException( + // "Invalid authenticator specified: " + authenticatorName)); + ExporterAuthenticator exporterAuthenticator = - StreamSupport.stream(authenticators.spliterator(), false) - .filter(auth -> authenticatorName.equals(auth.getName())) - .findFirst() - .orElseThrow( - () -> - new ConfigurationException( - "Invalid authenticator specified: " + authenticatorName)); + componentProviderLoader.loadComponent( + ExporterAuthenticator.class, authenticatorName, authenticator); + setAuthenticator.accept(exporterAuthenticator); } diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcLogRecordExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcLogRecordExporterComponentProvider.java index 72a64f3e3da..779e1dde861 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcLogRecordExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcLogRecordExporterComponentProvider.java @@ -33,12 +33,14 @@ public String getName() { } @Override - public LogRecordExporter create(DeclarativeConfigProperties config) { + public LogRecordExporter create(DeclarativeConfigProperties config, + ComponentProviderLoader componentProviderLoader) { OtlpGrpcLogRecordExporterBuilder builder = grpcBuilder(); OtlpDeclarativeConfigUtil.configureOtlpExporterBuilder( DATA_TYPE_LOGS, config, + componentProviderLoader, builder::setComponentLoader, builder::setEndpoint, builder::addHeader, diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcMetricExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcMetricExporterComponentProvider.java index ae95c73c52b..310722c515e 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcMetricExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcMetricExporterComponentProvider.java @@ -33,12 +33,13 @@ public String getName() { } @Override - public MetricExporter create(DeclarativeConfigProperties config) { + public MetricExporter create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { OtlpGrpcMetricExporterBuilder builder = grpcBuilder(); OtlpDeclarativeConfigUtil.configureOtlpExporterBuilder( DATA_TYPE_METRICS, config, + componentProviderLoader, builder::setComponentLoader, builder::setEndpoint, builder::addHeader, diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcSpanExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcSpanExporterComponentProvider.java index feab01f77c4..bb91e07eb9e 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcSpanExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcSpanExporterComponentProvider.java @@ -32,12 +32,13 @@ public String getName() { } @Override - public SpanExporter create(DeclarativeConfigProperties config) { + public SpanExporter create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { OtlpGrpcSpanExporterBuilder builder = grpcBuilder(); OtlpDeclarativeConfigUtil.configureOtlpExporterBuilder( DATA_TYPE_TRACES, config, + componentProviderLoader, builder::setComponentLoader, builder::setEndpoint, builder::addHeader, diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpLogRecordExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpLogRecordExporterComponentProvider.java index 8d5c2065851..7e45a7b74c4 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpLogRecordExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpLogRecordExporterComponentProvider.java @@ -33,12 +33,14 @@ public String getName() { } @Override - public LogRecordExporter create(DeclarativeConfigProperties config) { + public LogRecordExporter create(DeclarativeConfigProperties config, + ComponentProviderLoader componentProviderLoader) { OtlpHttpLogRecordExporterBuilder builder = httpBuilder(); OtlpDeclarativeConfigUtil.configureOtlpExporterBuilder( DATA_TYPE_LOGS, config, + componentProviderLoader, builder::setComponentLoader, builder::setEndpoint, builder::addHeader, diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpMetricExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpMetricExporterComponentProvider.java index c2ed35e2ec8..c0987dda9f1 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpMetricExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpMetricExporterComponentProvider.java @@ -33,12 +33,13 @@ public String getName() { } @Override - public MetricExporter create(DeclarativeConfigProperties config) { + public MetricExporter create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { OtlpHttpMetricExporterBuilder builder = httpBuilder(); OtlpDeclarativeConfigUtil.configureOtlpExporterBuilder( DATA_TYPE_METRICS, config, + componentProviderLoader, builder::setComponentLoader, builder::setEndpoint, builder::addHeader, diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpSpanExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpSpanExporterComponentProvider.java index c95670e7e5f..0114368b7dd 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpSpanExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpSpanExporterComponentProvider.java @@ -32,12 +32,13 @@ public String getName() { } @Override - public SpanExporter create(DeclarativeConfigProperties config) { + public SpanExporter create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { OtlpHttpSpanExporterBuilder builder = httpBuilder(); OtlpDeclarativeConfigUtil.configureOtlpExporterBuilder( DATA_TYPE_TRACES, config, + componentProviderLoader, builder::setComponentLoader, builder::setEndpoint, builder::addHeader, diff --git a/exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/internal/PrometheusComponentProvider.java b/exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/internal/PrometheusComponentProvider.java index 25d069db7a8..711e5423443 100644 --- a/exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/internal/PrometheusComponentProvider.java +++ b/exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/internal/PrometheusComponentProvider.java @@ -32,7 +32,7 @@ public String getName() { } @Override - public MetricReader create(DeclarativeConfigProperties config) { + public MetricReader create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { PrometheusHttpServerBuilder prometheusBuilder = PrometheusHttpServer.builder(); Integer port = config.getInt("port"); diff --git a/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/internal/ZipkinSpanExporterComponentProvider.java b/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/internal/ZipkinSpanExporterComponentProvider.java index 42c43eef14a..928d9e21527 100644 --- a/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/internal/ZipkinSpanExporterComponentProvider.java +++ b/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/internal/ZipkinSpanExporterComponentProvider.java @@ -30,7 +30,7 @@ public String getName() { } @Override - public SpanExporter create(DeclarativeConfigProperties config) { + public SpanExporter create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { ZipkinSpanExporterBuilder builder = ZipkinSpanExporter.builder(); String endpoint = config.getString("endpoint"); diff --git a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/B3ComponentProvider.java b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/B3ComponentProvider.java index ebd766640f9..a9765043d5c 100644 --- a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/B3ComponentProvider.java +++ b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/B3ComponentProvider.java @@ -30,7 +30,7 @@ public String getName() { } @Override - public TextMapPropagator create(DeclarativeConfigProperties config) { + public TextMapPropagator create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { return B3Propagator.injectingSingleHeader(); } } diff --git a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/B3MultiComponentProvider.java b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/B3MultiComponentProvider.java index 0fb223d81a7..db80f7193a6 100644 --- a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/B3MultiComponentProvider.java +++ b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/B3MultiComponentProvider.java @@ -30,7 +30,7 @@ public String getName() { } @Override - public TextMapPropagator create(DeclarativeConfigProperties config) { + public TextMapPropagator create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { return B3Propagator.injectingMultiHeaders(); } } diff --git a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/JaegerComponentProvider.java b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/JaegerComponentProvider.java index 1326dd4cc83..c8cf66e50b1 100644 --- a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/JaegerComponentProvider.java +++ b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/JaegerComponentProvider.java @@ -29,7 +29,7 @@ public String getName() { } @Override - public TextMapPropagator create(DeclarativeConfigProperties config) { + public TextMapPropagator create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { return JaegerPropagator.getInstance(); } } diff --git a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/OtTraceComponentProvider.java b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/OtTraceComponentProvider.java index 261eb5f8585..5aa5c9c4491 100644 --- a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/OtTraceComponentProvider.java +++ b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/OtTraceComponentProvider.java @@ -30,7 +30,7 @@ public String getName() { } @Override - public TextMapPropagator create(DeclarativeConfigProperties config) { + public TextMapPropagator create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { return OtTracePropagator.getInstance(); } } diff --git a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ComponentProvider.java b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ComponentProvider.java index 5772a0a1797..65ae78651d6 100644 --- a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ComponentProvider.java +++ b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ComponentProvider.java @@ -21,7 +21,7 @@ * configuration. * *

NOTE: when {@link #getType()} is {@link Resource}, the {@link #getName()} is not (currently) - * used, and {@link #create(DeclarativeConfigProperties)} is (currently) called with an empty {@link + * used, and {@link #create(DeclarativeConfigProperties, ComponentProviderLoader)} is (currently) called with an empty {@link * DeclarativeConfigProperties}. * *

This class is internal and is hence not for public use. Its APIs are unstable and can change @@ -34,6 +34,14 @@ */ public interface ComponentProvider { + /** + *

This class is internal and is hence not for public use. Its APIs are unstable and can change + * at any time. + */ + interface ComponentProviderLoader { + T loadComponent(Class type, String name, Object model); + } + /** * The type of SDK extension component. For example, if providing instances of a custom span * exporter, the type would be {@link SpanExporter}. @@ -59,5 +67,5 @@ public interface ComponentProvider { */ // TODO (jack-berg): consider dynamic configuration use case before stabilizing in case that // affects any API decisions - T create(DeclarativeConfigProperties config); + T create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader); } diff --git a/sdk-extensions/incubator/build.gradle.kts b/sdk-extensions/incubator/build.gradle.kts index 1bb858d699a..d87fadc5c88 100644 --- a/sdk-extensions/incubator/build.gradle.kts +++ b/sdk-extensions/incubator/build.gradle.kts @@ -69,15 +69,8 @@ val downloadConfigurationSchema by tasks.registering(Download::class) { } val unzipConfigurationSchema by tasks.registering(Copy::class) { - dependsOn(downloadConfigurationSchema) - - from(zipTree(downloadConfigurationSchema.get().dest)) - eachFile(closureOf { - // Remove the top level folder "/opentelemetry-configuration-$configurationRef" - val pathParts = path.split("/") - path = pathParts.subList(1, pathParts.size).joinToString("/") - }) - into("$buildDirectory/configuration/") + from("/home/gregor/source/opentelemetry-configuration/schema") + into("$buildDirectory/configuration/schema/") } val deleteTypeDescriptions by tasks.registering(Delete::class) { diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigContext.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigContext.java index 9cc697ecaea..c59102db965 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigContext.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigContext.java @@ -42,13 +42,15 @@ List getCloseables() { /** * Find a registered {@link ComponentProvider} with {@link ComponentProvider#getType()} matching * {@code type}, {@link ComponentProvider#getName()} matching {@code name}, and call {@link - * ComponentProvider#create(DeclarativeConfigProperties)} with the given {@code model}. + * ComponentProvider#create(DeclarativeConfigProperties, + * ComponentProvider.ComponentProviderLoader)} with the given {@code model}. * * @throws DeclarativeConfigException if no matching providers are found, or if multiple are found - * (i.e. conflict), or if {@link ComponentProvider#create(DeclarativeConfigProperties)} throws + * (i.e. conflict), or if {@link ComponentProvider#create(DeclarativeConfigProperties, + * ComponentProvider.ComponentProviderLoader)} throws */ @SuppressWarnings({"unchecked", "rawtypes"}) - T loadComponent(Class type, String name, Object model) { + T loadComponent(Class type, String name, Object model, DeclarativeConfigContext context) { DeclarativeConfigProperties config = DeclarativeConfiguration.toConfigProperties(model, spiHelper.getComponentLoader()); @@ -82,10 +84,20 @@ T loadComponent(Class type, String name, Object model) { ComponentProvider provider = (ComponentProvider) matchedProviders.get(0); try { - return provider.create(config); + return provider.create(config, getComponentLoader(context)); } catch (Throwable throwable) { throw new DeclarativeConfigException( "Error configuring " + type.getName() + " with name \"" + name + "\"", throwable); } } + + private ComponentProvider.ComponentProviderLoader getComponentLoader( + DeclarativeConfigContext context) { + return new ComponentProvider.ComponentProviderLoader() { + @Override + public T loadComponent(Class type, String name, Object model) { + return context.loadComponent(type, name, model, context); + } + }; + } } 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 f2c6db8d42d..831877ab672 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 @@ -32,7 +32,8 @@ public LogRecordExporter create(LogRecordExporterModel model, DeclarativeConfigC Map.Entry keyValue = FileConfigUtil.getSingletonMapEntry(model.getAdditionalProperties(), "log record exporter"); LogRecordExporter logRecordExporter = - context.loadComponent(LogRecordExporter.class, keyValue.getKey(), keyValue.getValue()); + context.loadComponent( + LogRecordExporter.class, keyValue.getKey(), keyValue.getValue(), context); return context.addCloseable(logRecordExporter); } } diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordProcessorFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordProcessorFactory.java index 20f271a5568..4dab42e1567 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordProcessorFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordProcessorFactory.java @@ -70,7 +70,8 @@ public LogRecordProcessor create( FileConfigUtil.getSingletonMapEntry( model.getAdditionalProperties(), "log record processor"); LogRecordProcessor logRecordProcessor = - context.loadComponent(LogRecordProcessor.class, keyValue.getKey(), keyValue.getValue()); + context.loadComponent( + LogRecordProcessor.class, keyValue.getKey(), keyValue.getValue(), context); return context.addCloseable(logRecordProcessor); } } 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 6da48a4fef7..928b1bef487 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 @@ -32,7 +32,8 @@ public MetricExporter create(PushMetricExporterModel model, DeclarativeConfigCon Map.Entry keyValue = FileConfigUtil.getSingletonMapEntry(model.getAdditionalProperties(), "metric exporter"); MetricExporter metricExporter = - context.loadComponent(MetricExporter.class, keyValue.getKey(), keyValue.getValue()); + context.loadComponent( + MetricExporter.class, keyValue.getKey(), keyValue.getValue(), context); return context.addCloseable(metricExporter); } } 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 3c24c218eee..7004e1d2ab7 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 @@ -99,7 +99,7 @@ public MetricReaderAndCardinalityLimits create( if (prometheusModel != null) { MetricReader metricReader = context.addCloseable( - context.loadComponent(MetricReader.class, "prometheus", prometheusModel)); + context.loadComponent(MetricReader.class, "prometheus", prometheusModel, context)); CardinalityLimitSelector cardinalityLimitSelector = null; if (model.getCardinalityLimits() != null) { cardinalityLimitSelector = diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ResourceDetectorFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ResourceDetectorFactory.java index d16686fb0db..bc75aaf8150 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ResourceDetectorFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ResourceDetectorFactory.java @@ -25,6 +25,6 @@ public Resource create( ExperimentalResourceDetectorModel model, DeclarativeConfigContext context) { Map.Entry keyValue = FileConfigUtil.getSingletonMapEntry(model.getAdditionalProperties(), "resource detector"); - return context.loadComponent(Resource.class, keyValue.getKey(), keyValue.getValue()); + return context.loadComponent(Resource.class, keyValue.getKey(), keyValue.getValue(), context); } } 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 67336966657..63bc08e44fb 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 @@ -68,6 +68,6 @@ public Sampler create(SamplerModel model, DeclarativeConfigContext context) { Map.Entry keyValue = FileConfigUtil.getSingletonMapEntry(model.getAdditionalProperties(), "sampler"); - return context.loadComponent(Sampler.class, keyValue.getKey(), keyValue.getValue()); + return context.loadComponent(Sampler.class, keyValue.getKey(), keyValue.getValue(), context); } } diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ServiceResourceDetector.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ServiceResourceDetector.java index dcaeeee2718..7f41ad253c6 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ServiceResourceDetector.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ServiceResourceDetector.java @@ -35,7 +35,8 @@ public String getName() { } @Override - public Resource create(DeclarativeConfigProperties config) { + public Resource create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { ResourceBuilder builder = Resource.builder(); ConfigProperties properties = 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 03b008320b4..02cd3d1417f 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 @@ -33,7 +33,7 @@ public SpanExporter create(SpanExporterModel model, DeclarativeConfigContext con Map.Entry keyValue = FileConfigUtil.getSingletonMapEntry(model.getAdditionalProperties(), "span exporter"); SpanExporter spanExporter = - context.loadComponent(SpanExporter.class, keyValue.getKey(), keyValue.getValue()); + context.loadComponent(SpanExporter.class, keyValue.getKey(), keyValue.getValue(), context); return context.addCloseable(spanExporter); } } diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanProcessorFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanProcessorFactory.java index 5bfa617f570..52cad21ae28 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanProcessorFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanProcessorFactory.java @@ -62,7 +62,7 @@ public SpanProcessor create(SpanProcessorModel model, DeclarativeConfigContext c Map.Entry keyValue = FileConfigUtil.getSingletonMapEntry(model.getAdditionalProperties(), "span processor"); SpanProcessor spanProcessor = - context.loadComponent(SpanProcessor.class, keyValue.getKey(), keyValue.getValue()); + context.loadComponent(SpanProcessor.class, keyValue.getKey(), keyValue.getValue(), context); return context.addCloseable(spanProcessor); } } 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 6f0cb869bd1..860079cad4d 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 @@ -48,7 +48,8 @@ public TextMapPropagatorAndName create( Map.Entry keyValue = FileConfigUtil.getSingletonMapEntry(model.getAdditionalProperties(), "propagator"); TextMapPropagator propagator = - context.loadComponent(TextMapPropagator.class, keyValue.getKey(), keyValue.getValue()); + context.loadComponent( + TextMapPropagator.class, keyValue.getKey(), keyValue.getValue(), context); return TextMapPropagatorAndName.create(propagator, keyValue.getKey()); } @@ -60,7 +61,7 @@ static TextMapPropagatorAndName getPropagator(DeclarativeConfigContext context, textMapPropagator = W3CBaggagePropagator.getInstance(); } else { textMapPropagator = - context.loadComponent(TextMapPropagator.class, name, Collections.emptyMap()); + context.loadComponent(TextMapPropagator.class, name, Collections.emptyMap(), context); } return TextMapPropagatorAndName.create(textMapPropagator, name); } 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 d1964c15de3..f62e14e06c3 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 @@ -8,6 +8,7 @@ import static io.opentelemetry.sdk.extension.incubator.fileconfig.FileConfigTestUtil.createTempFileWithContent; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -112,7 +113,7 @@ void create_OtlpHttpDefaults() { ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = getComponentProvider("otlp_http", LogRecordExporter.class); - verify(componentProvider).create(configCaptor.capture()); + verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("protocol")).isNull(); assertThat(configProperties.getString("endpoint")).isNull(); @@ -178,7 +179,7 @@ void create_OtlpHttpConfigured(@TempDir Path tempDir) ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = getComponentProvider("otlp_http", LogRecordExporter.class); - verify(componentProvider).create(configCaptor.capture()); + verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isEqualTo("http://example:4318/v1/logs"); List headers = configProperties.getStructuredList("headers"); @@ -222,7 +223,7 @@ void create_OtlpGrpcDefaults() { ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = getComponentProvider("otlp_grpc", LogRecordExporter.class); - verify(componentProvider).create(configCaptor.capture()); + verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isNull(); assertThat(configProperties.getStructured("headers")).isNull(); @@ -287,7 +288,7 @@ void create_OtlpGrpcConfigured(@TempDir Path tempDir) ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = getComponentProvider("otlp_grpc", LogRecordExporter.class); - verify(componentProvider).create(configCaptor.capture()); + verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isEqualTo("http://example:4317"); List headers = configProperties.getStructuredList("headers"); @@ -331,7 +332,7 @@ void create_OtlpFile() { ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = getComponentProvider("otlp_file/development", LogRecordExporter.class); - verify(componentProvider).create(configCaptor.capture()); + verify(componentProvider).create(configCaptor.capture(), any()); } @Test 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 d5aa856877d..5541caf48fd 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 @@ -8,6 +8,7 @@ import static io.opentelemetry.sdk.extension.incubator.fileconfig.FileConfigTestUtil.createTempFileWithContent; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -117,7 +118,7 @@ void create_OtlpHttpDefaults() { ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = getComponentProvider("otlp_http", MetricExporter.class); - verify(componentProvider).create(configCaptor.capture()); + verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("protocol")).isNull(); assertThat(configProperties.getString("endpoint")).isNull(); @@ -194,7 +195,7 @@ void create_OtlpHttpConfigured(@TempDir Path tempDir) ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = getComponentProvider("otlp_http", MetricExporter.class); - verify(componentProvider).create(configCaptor.capture()); + verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isEqualTo("http://example:4318/v1/metrics"); List headers = configProperties.getStructuredList("headers"); @@ -240,7 +241,7 @@ void create_OtlpGrpcDefaults() { ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = getComponentProvider("otlp_grpc", MetricExporter.class); - verify(componentProvider).create(configCaptor.capture()); + verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isNull(); assertThat(configProperties.getStructured("headers")).isNull(); @@ -316,7 +317,7 @@ void create_OtlpGrpcConfigured(@TempDir Path tempDir) ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = getComponentProvider("otlp_grpc", MetricExporter.class); - verify(componentProvider).create(configCaptor.capture()); + verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isEqualTo("http://example:4317"); List headers = configProperties.getStructuredList("headers"); @@ -378,7 +379,7 @@ void create_OtlpFile() { ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = getComponentProvider("otlp_file/development", MetricExporter.class); - verify(componentProvider).create(configCaptor.capture()); + verify(componentProvider).create(configCaptor.capture(), any()); } @Test 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 b0e546ea702..c698b019381 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 @@ -153,7 +153,7 @@ void create_PullPrometheusDefault() throws IOException { assertThat(reader.toString()).isEqualTo(expectedReader.toString()); assertThat(readerAndCardinalityLimits.getCardinalityLimitsSelector()).isNull(); // TODO(jack-berg): validate prometheus component provider was invoked with correct arguments - verify(context).loadComponent(eq(MetricReader.class), eq("prometheus"), any()); + verify(context).loadComponent(eq(MetricReader.class), eq("prometheus"), any(), context); } @Test @@ -205,7 +205,7 @@ void create_PullPrometheusConfigured() throws IOException { .getCardinalityLimit(InstrumentType.COUNTER)) .isEqualTo(100); // TODO(jack-berg): validate prometheus component provider was invoked with correct arguments - verify(context).loadComponent(eq(MetricReader.class), eq("prometheus"), any()); + verify(context).loadComponent(eq(MetricReader.class), eq("prometheus"), any(), context); } @Test diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ServiceResourceDetectorTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ServiceResourceDetectorTest.java index 4778fe1b614..e125ca615b9 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ServiceResourceDetectorTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ServiceResourceDetectorTest.java @@ -32,7 +32,7 @@ void getTypeAndName() { void create_SystemPropertySet() { System.setProperty("otel.service.name", "test"); - assertThat(new ServiceResourceDetector().create(DeclarativeConfigProperties.empty())) + assertThat(new ServiceResourceDetector().create(DeclarativeConfigProperties.empty(), null)) .satisfies( resource -> { Attributes attributes = resource.getAttributes(); @@ -48,7 +48,7 @@ void create_SystemPropertySet() { @Test void create_NoSystemProperty() { - assertThat(new ServiceResourceDetector().create(DeclarativeConfigProperties.empty())) + assertThat(new ServiceResourceDetector().create(DeclarativeConfigProperties.empty(), null)) .satisfies( resource -> { Attributes attributes = resource.getAttributes(); 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 3bcd13c9731..85b5974c2ab 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 @@ -8,6 +8,7 @@ import static io.opentelemetry.sdk.extension.incubator.fileconfig.FileConfigTestUtil.createTempFileWithContent; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -25,6 +26,7 @@ import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; import io.opentelemetry.sdk.extension.incubator.fileconfig.component.SpanExporterComponentProvider; +import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.AuthenticatorModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.ConsoleExporterModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.ExperimentalOtlpFileExporterModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.NameStringValuePairModel; @@ -112,7 +114,7 @@ void create_OtlpHttpDefaults() { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = getComponentProvider("otlp_http", SpanExporter.class); - verify(componentProvider).create(configCaptor.capture()); + verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("protocol")).isNull(); assertThat(configProperties.getString("endpoint")).isNull(); @@ -177,7 +179,7 @@ void create_OtlpHttpConfigured(@TempDir Path tempDir) ArgumentCaptor configCaptor = ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = getComponentProvider("otlp_http", SpanExporter.class); - verify(componentProvider).create(configCaptor.capture()); + verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isEqualTo("http://example:4318/v1/traces"); List headers = configProperties.getStructuredList("headers"); @@ -217,7 +219,7 @@ void create_OtlpGrpcDefaults() { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = getComponentProvider("otlp_grpc", SpanExporter.class); - verify(componentProvider).create(configCaptor.capture()); + verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isNull(); assertThat(configProperties.getStructured("headers")).isNull(); @@ -267,6 +269,8 @@ void create_OtlpGrpcConfigured(@TempDir Path tempDir) new NameStringValuePairModel() .withName("key2") .withValue("value2"))) + .withAuthenticator( + new AuthenticatorModel().withAdditionalProperty("test_auth", null)) .withCompression("gzip") .withTimeout(15_000) .withCertificateFile(certificatePath) @@ -281,7 +285,7 @@ void create_OtlpGrpcConfigured(@TempDir Path tempDir) ArgumentCaptor configCaptor = ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = getComponentProvider("otlp_grpc", SpanExporter.class); - verify(componentProvider).create(configCaptor.capture()); + verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isEqualTo("http://example:4317"); List headers = configProperties.getStructuredList("headers"); @@ -337,7 +341,7 @@ void create_ZipkinDefaults() { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = getComponentProvider("zipkin", SpanExporter.class); - verify(componentProvider).create(configCaptor.capture()); + verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isNull(); assertThat(configProperties.getLong("timeout")).isNull(); @@ -370,7 +374,7 @@ void create_ZipkinConfigured() { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = getComponentProvider("zipkin", SpanExporter.class); - verify(componentProvider).create(configCaptor.capture()); + verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isEqualTo("http://zipkin:9411/v1/v2/spans"); assertThat(configProperties.getLong("timeout")).isEqualTo(15_000); @@ -397,7 +401,7 @@ void create_OtlpFile() { ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = getComponentProvider("otlp_file/development", SpanExporter.class); - verify(componentProvider).create(configCaptor.capture()); + verify(componentProvider).create(configCaptor.capture(), any()); } @Test diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ContainerResourceProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ContainerResourceProvider.java index a5d3a331003..4e35830cb53 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ContainerResourceProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ContainerResourceProvider.java @@ -24,7 +24,8 @@ public String getName() { } @Override - public Resource create(DeclarativeConfigProperties config) { + public Resource create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { return Resource.empty(); } } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/HostResourceProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/HostResourceProvider.java index bf8d978d9e6..aeed627c000 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/HostResourceProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/HostResourceProvider.java @@ -24,7 +24,8 @@ public String getName() { } @Override - public Resource create(DeclarativeConfigProperties config) { + public Resource create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { return Resource.empty(); } } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/LogRecordExporterComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/LogRecordExporterComponentProvider.java index f21c1d1bf09..a5b8cb684c5 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/LogRecordExporterComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/LogRecordExporterComponentProvider.java @@ -24,7 +24,8 @@ public String getName() { } @Override - public LogRecordExporter create(DeclarativeConfigProperties config) { + public LogRecordExporter create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { return new TestLogRecordExporter(config); } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/LogRecordProcessorComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/LogRecordProcessorComponentProvider.java index a44cd939c74..673576672a0 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/LogRecordProcessorComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/LogRecordProcessorComponentProvider.java @@ -24,7 +24,8 @@ public String getName() { } @Override - public LogRecordProcessor create(DeclarativeConfigProperties config) { + public LogRecordProcessor create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { return new TestLogRecordProcessor(config); } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/MetricExporterComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/MetricExporterComponentProvider.java index 80ea6b556ce..a23ad037d3d 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/MetricExporterComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/MetricExporterComponentProvider.java @@ -27,7 +27,8 @@ public String getName() { } @Override - public MetricExporter create(DeclarativeConfigProperties config) { + public MetricExporter create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { return new TestMetricExporter(config); } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/OsResourceProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/OsResourceProvider.java index 04114fe43bb..2f2576f267b 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/OsResourceProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/OsResourceProvider.java @@ -24,7 +24,8 @@ public String getName() { } @Override - public Resource create(DeclarativeConfigProperties config) { + public Resource create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { return Resource.empty(); } } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ProcessResourceProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ProcessResourceProvider.java index 06d02355f34..cef408b2b98 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ProcessResourceProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ProcessResourceProvider.java @@ -24,7 +24,8 @@ public String getName() { } @Override - public Resource create(DeclarativeConfigProperties config) { + public Resource create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { return Resource.empty(); } } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceComponentProvider.java index b5c9a6fd7a3..1ed1006fbda 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceComponentProvider.java @@ -21,7 +21,8 @@ public String getName() { } @Override - public Resource create(DeclarativeConfigProperties config) { + public Resource create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { return Resource.builder().put("shape", "square").put("color", "red").build(); } } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceFirstComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceFirstComponentProvider.java index 32381134e1b..2e1764b8e75 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceFirstComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceFirstComponentProvider.java @@ -21,7 +21,8 @@ public String getName() { } @Override - public Resource create(DeclarativeConfigProperties config) { + public Resource create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { return Resource.builder().put("order", "first").build(); } } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceSecondComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceSecondComponentProvider.java index e77c6726717..6e7ee474e12 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceSecondComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceSecondComponentProvider.java @@ -21,7 +21,8 @@ public String getName() { } @Override - public Resource create(DeclarativeConfigProperties config) { + public Resource create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { return Resource.builder().put("order", "second").build(); } } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SamplerComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SamplerComponentProvider.java index 3264dd91fc7..c1b141f0308 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SamplerComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SamplerComponentProvider.java @@ -27,7 +27,8 @@ public String getName() { } @Override - public Sampler create(DeclarativeConfigProperties config) { + public Sampler create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { return new TestSampler(config); } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SpanExporterComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SpanExporterComponentProvider.java index ddaca3ca4b9..d4bbf1ad266 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SpanExporterComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SpanExporterComponentProvider.java @@ -24,7 +24,8 @@ public String getName() { } @Override - public SpanExporter create(DeclarativeConfigProperties config) { + public SpanExporter create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { return new TestSpanExporter(config); } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SpanProcessorComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SpanProcessorComponentProvider.java index 3a1ddf9b13a..9ac02066136 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SpanProcessorComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SpanProcessorComponentProvider.java @@ -25,7 +25,8 @@ public String getName() { } @Override - public SpanProcessor create(DeclarativeConfigProperties config) { + public SpanProcessor create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { return new TestSpanProcessor(config); } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/TextMapPropagatorComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/TextMapPropagatorComponentProvider.java index 9c8e4e5ebbf..70a23412fc0 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/TextMapPropagatorComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/TextMapPropagatorComponentProvider.java @@ -27,7 +27,8 @@ public String getName() { } @Override - public TextMapPropagator create(DeclarativeConfigProperties config) { + public TextMapPropagator create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { return new TestTextMapPropagator(config); } diff --git a/sdk-extensions/jaeger-remote-sampler/src/main/java/io/opentelemetry/sdk/extension/trace/jaeger/sampler/internal/JaegerRemoteSamplerComponentProvider.java b/sdk-extensions/jaeger-remote-sampler/src/main/java/io/opentelemetry/sdk/extension/trace/jaeger/sampler/internal/JaegerRemoteSamplerComponentProvider.java index fd89f42cae9..ae12831644e 100644 --- a/sdk-extensions/jaeger-remote-sampler/src/main/java/io/opentelemetry/sdk/extension/trace/jaeger/sampler/internal/JaegerRemoteSamplerComponentProvider.java +++ b/sdk-extensions/jaeger-remote-sampler/src/main/java/io/opentelemetry/sdk/extension/trace/jaeger/sampler/internal/JaegerRemoteSamplerComponentProvider.java @@ -31,7 +31,7 @@ public String getName() { } @Override - public Sampler create(DeclarativeConfigProperties config) { + public Sampler create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { JaegerRemoteSamplerBuilder builder = JaegerRemoteSampler.builder(); // Optional configuration From 3781a2704747e7f41d6c606860fae43ef67feabd Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 21 Aug 2025 09:48:14 +0200 Subject: [PATCH 03/14] add ComponentProviderLoader --- .../authenticator/ExporterAuthenticator.java | 2 +- .../internal/OtlpDeclarativeConfigUtil.java | 22 +++++------ .../spi/internal/ComponentProvider.java | 2 +- .../fileconfig/DeclarativeConfigContext.java | 9 +++-- .../fileconfig/SpanExporterFactoryTest.java | 39 +++++++++++++++++++ 5 files changed, 56 insertions(+), 18 deletions(-) diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/authenticator/ExporterAuthenticator.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/authenticator/ExporterAuthenticator.java index 35d968bfb58..f1a194e0e2c 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/authenticator/ExporterAuthenticator.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/authenticator/ExporterAuthenticator.java @@ -3,7 +3,7 @@ import java.util.Map; public interface ExporterAuthenticator { - String getName(); + String getName(); // todo remove this method Map getAuthenticationHeaders(); } diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpDeclarativeConfigUtil.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpDeclarativeConfigUtil.java index be1395221da..ea58de4680f 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpDeclarativeConfigUtil.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpDeclarativeConfigUtil.java @@ -24,6 +24,7 @@ import java.time.Duration; import java.util.Collections; import java.util.List; +import java.util.Set; import java.util.function.BiConsumer; import java.util.function.Consumer; @@ -71,22 +72,17 @@ public static void configureOtlpExporterBuilder( DeclarativeConfigProperties authenticator = config.getStructured("authenticator"); if (authenticator != null) { - String authenticatorName = authenticator.getString("name"); - if (authenticatorName == null) { + Set propertyKeys = authenticator.getPropertyKeys(); + int size = propertyKeys.size(); + if (size != 1) { throw new ConfigurationException( - "authenticator.name must be set when using an authenticator"); + "authenticator must be a single structured property, but found " + + size + + " properties: " + + propertyKeys); } - // Iterable authenticators = - // config.getComponentLoader().load(ExporterAuthenticator.class); - // ExporterAuthenticator exporterAuthenticator = - // StreamSupport.stream(authenticators.spliterator(), false) - // .filter(auth -> authenticatorName.equals(auth.getName())) - // .findFirst() - // .orElseThrow( - // () -> - // new ConfigurationException( - // "Invalid authenticator specified: " + authenticatorName)); + String authenticatorName = propertyKeys.iterator().next(); ExporterAuthenticator exporterAuthenticator = componentProviderLoader.loadComponent( ExporterAuthenticator.class, authenticatorName, authenticator); diff --git a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ComponentProvider.java b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ComponentProvider.java index 65ae78651d6..54dad8368ee 100644 --- a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ComponentProvider.java +++ b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ComponentProvider.java @@ -39,7 +39,7 @@ public interface ComponentProvider { * at any time. */ interface ComponentProviderLoader { - T loadComponent(Class type, String name, Object model); + T loadComponent(Class type, String name, DeclarativeConfigProperties properties); } /** diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigContext.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigContext.java index c59102db965..a5c89f01891 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigContext.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigContext.java @@ -52,7 +52,9 @@ List getCloseables() { @SuppressWarnings({"unchecked", "rawtypes"}) T loadComponent(Class type, String name, Object model, DeclarativeConfigContext context) { DeclarativeConfigProperties config = - DeclarativeConfiguration.toConfigProperties(model, spiHelper.getComponentLoader()); + model instanceof DeclarativeConfigProperties + ? (DeclarativeConfigProperties) model + : DeclarativeConfiguration.toConfigProperties(model, spiHelper.getComponentLoader()); // TODO(jack-berg): cache loaded component providers List componentProviders = spiHelper.load(ComponentProvider.class); @@ -95,8 +97,9 @@ private ComponentProvider.ComponentProviderLoader getComponentLoader( DeclarativeConfigContext context) { return new ComponentProvider.ComponentProviderLoader() { @Override - public T loadComponent(Class type, String name, Object model) { - return context.loadComponent(type, name, model, context); + public T loadComponent( + Class type, String name, DeclarativeConfigProperties properties) { + return context.loadComponent(type, name, properties, context); } }; } 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 85b5974c2ab..d5733758b27 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 @@ -15,6 +15,7 @@ import com.google.common.collect.ImmutableMap; import com.linecorp.armeria.testing.junit5.server.SelfSignedCertificateExtension; +import io.opentelemetry.api.incubator.authenticator.ExporterAuthenticator; import io.opentelemetry.api.incubator.config.DeclarativeConfigException; import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.exporter.logging.LoggingSpanExporter; @@ -44,6 +45,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -71,6 +73,39 @@ class SpanExporterFactoryTest { private final SpiHelper spiHelper = spy(SpiHelper.create(SpanExporterFactoryTest.class.getClassLoader())); private final DeclarativeConfigContext context = new DeclarativeConfigContext(spiHelper); + + private static final ComponentProvider authenticatorComponentProvider = + new ComponentProvider() { + @Override + public Class getType() { + return ExporterAuthenticator.class; + } + + @Override + public String getName() { + return "test_auth"; + } + + @Override + public ExporterAuthenticator create( + DeclarativeConfigProperties config, + ComponentProviderLoader componentProviderLoader) { + return new ExporterAuthenticator() { + ; + + @Override + public String getName() { + return "test_auth"; + } + + @Override + public Map getAuthenticationHeaders() { + return Collections.singletonMap("auth_provider_key1", "value1"); + } + }; + } + }; + private List> loadedComponentProviders = Collections.emptyList(); @BeforeEach @@ -83,6 +118,7 @@ void setup() { (List>) invocation.callRealMethod(); loadedComponentProviders = result.stream().map(Mockito::spy).collect(Collectors.toList()); + loadedComponentProviders.add(authenticatorComponentProvider); return loadedComponentProviders; }); } @@ -239,6 +275,9 @@ void create_OtlpGrpcConfigured(@TempDir Path tempDir) .setEndpoint("http://example:4317") .addHeader("key1", "value1") .addHeader("key2", "value2") + .setHeaders( + () -> Collections.singletonMap("auth_provider_key1", "value1") + ) .setTimeout(Duration.ofSeconds(15)) .setCompression("gzip") .build(); From a8af24a021b4836c86deda9115c2a648f77fd09f Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 21 Aug 2025 09:51:45 +0200 Subject: [PATCH 04/14] fix --- .../fileconfig/DeclarativeConfigContext.java | 14 ++------------ .../fileconfig/LogRecordExporterFactory.java | 2 +- .../fileconfig/LogRecordProcessorFactory.java | 2 +- .../fileconfig/MetricExporterFactory.java | 2 +- .../incubator/fileconfig/MetricReaderFactory.java | 2 +- .../fileconfig/ResourceDetectorFactory.java | 2 +- .../incubator/fileconfig/SamplerFactory.java | 2 +- .../incubator/fileconfig/SpanExporterFactory.java | 2 +- .../incubator/fileconfig/SpanProcessorFactory.java | 2 +- .../fileconfig/TextMapPropagatorFactory.java | 4 ++-- .../fileconfig/MetricReaderFactoryTest.java | 4 ++-- 11 files changed, 14 insertions(+), 24 deletions(-) diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigContext.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigContext.java index a5c89f01891..960b3b56fc3 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigContext.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigContext.java @@ -50,7 +50,7 @@ List getCloseables() { * ComponentProvider.ComponentProviderLoader)} throws */ @SuppressWarnings({"unchecked", "rawtypes"}) - T loadComponent(Class type, String name, Object model, DeclarativeConfigContext context) { + T loadComponent(Class type, String name, Object model) { DeclarativeConfigProperties config = model instanceof DeclarativeConfigProperties ? (DeclarativeConfigProperties) model @@ -86,21 +86,11 @@ T loadComponent(Class type, String name, Object model, DeclarativeConfigC ComponentProvider provider = (ComponentProvider) matchedProviders.get(0); try { - return provider.create(config, getComponentLoader(context)); + return provider.create(config, this::loadComponent); } catch (Throwable throwable) { throw new DeclarativeConfigException( "Error configuring " + type.getName() + " with name \"" + name + "\"", throwable); } } - private ComponentProvider.ComponentProviderLoader getComponentLoader( - DeclarativeConfigContext context) { - return new ComponentProvider.ComponentProviderLoader() { - @Override - public T loadComponent( - Class type, String name, DeclarativeConfigProperties properties) { - return context.loadComponent(type, name, properties, context); - } - }; - } } 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 831877ab672..30ace6c71af 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 @@ -33,7 +33,7 @@ public LogRecordExporter create(LogRecordExporterModel model, DeclarativeConfigC FileConfigUtil.getSingletonMapEntry(model.getAdditionalProperties(), "log record exporter"); LogRecordExporter logRecordExporter = context.loadComponent( - LogRecordExporter.class, keyValue.getKey(), keyValue.getValue(), context); + LogRecordExporter.class, keyValue.getKey(), keyValue.getValue()); return context.addCloseable(logRecordExporter); } } diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordProcessorFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordProcessorFactory.java index 4dab42e1567..ef8ed841b7a 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordProcessorFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordProcessorFactory.java @@ -71,7 +71,7 @@ public LogRecordProcessor create( model.getAdditionalProperties(), "log record processor"); LogRecordProcessor logRecordProcessor = context.loadComponent( - LogRecordProcessor.class, keyValue.getKey(), keyValue.getValue(), context); + LogRecordProcessor.class, keyValue.getKey(), keyValue.getValue()); return context.addCloseable(logRecordProcessor); } } 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 928b1bef487..32de5b10675 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 @@ -33,7 +33,7 @@ public MetricExporter create(PushMetricExporterModel model, DeclarativeConfigCon FileConfigUtil.getSingletonMapEntry(model.getAdditionalProperties(), "metric exporter"); MetricExporter metricExporter = context.loadComponent( - MetricExporter.class, keyValue.getKey(), keyValue.getValue(), context); + MetricExporter.class, keyValue.getKey(), keyValue.getValue()); return context.addCloseable(metricExporter); } } 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 7004e1d2ab7..3c24c218eee 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 @@ -99,7 +99,7 @@ public MetricReaderAndCardinalityLimits create( if (prometheusModel != null) { MetricReader metricReader = context.addCloseable( - context.loadComponent(MetricReader.class, "prometheus", prometheusModel, context)); + context.loadComponent(MetricReader.class, "prometheus", prometheusModel)); CardinalityLimitSelector cardinalityLimitSelector = null; if (model.getCardinalityLimits() != null) { cardinalityLimitSelector = diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ResourceDetectorFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ResourceDetectorFactory.java index bc75aaf8150..d16686fb0db 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ResourceDetectorFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ResourceDetectorFactory.java @@ -25,6 +25,6 @@ public Resource create( ExperimentalResourceDetectorModel model, DeclarativeConfigContext context) { Map.Entry keyValue = FileConfigUtil.getSingletonMapEntry(model.getAdditionalProperties(), "resource detector"); - return context.loadComponent(Resource.class, keyValue.getKey(), keyValue.getValue(), context); + return context.loadComponent(Resource.class, keyValue.getKey(), keyValue.getValue()); } } 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 63bc08e44fb..67336966657 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 @@ -68,6 +68,6 @@ public Sampler create(SamplerModel model, DeclarativeConfigContext context) { Map.Entry keyValue = FileConfigUtil.getSingletonMapEntry(model.getAdditionalProperties(), "sampler"); - return context.loadComponent(Sampler.class, keyValue.getKey(), keyValue.getValue(), context); + return context.loadComponent(Sampler.class, keyValue.getKey(), keyValue.getValue()); } } 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 02cd3d1417f..03b008320b4 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 @@ -33,7 +33,7 @@ public SpanExporter create(SpanExporterModel model, DeclarativeConfigContext con Map.Entry keyValue = FileConfigUtil.getSingletonMapEntry(model.getAdditionalProperties(), "span exporter"); SpanExporter spanExporter = - context.loadComponent(SpanExporter.class, keyValue.getKey(), keyValue.getValue(), context); + context.loadComponent(SpanExporter.class, keyValue.getKey(), keyValue.getValue()); return context.addCloseable(spanExporter); } } diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanProcessorFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanProcessorFactory.java index 52cad21ae28..5bfa617f570 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanProcessorFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/SpanProcessorFactory.java @@ -62,7 +62,7 @@ public SpanProcessor create(SpanProcessorModel model, DeclarativeConfigContext c Map.Entry keyValue = FileConfigUtil.getSingletonMapEntry(model.getAdditionalProperties(), "span processor"); SpanProcessor spanProcessor = - context.loadComponent(SpanProcessor.class, keyValue.getKey(), keyValue.getValue(), context); + context.loadComponent(SpanProcessor.class, keyValue.getKey(), keyValue.getValue()); return context.addCloseable(spanProcessor); } } 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 860079cad4d..eb27afe2006 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,7 @@ public TextMapPropagatorAndName create( FileConfigUtil.getSingletonMapEntry(model.getAdditionalProperties(), "propagator"); TextMapPropagator propagator = context.loadComponent( - TextMapPropagator.class, keyValue.getKey(), keyValue.getValue(), context); + TextMapPropagator.class, keyValue.getKey(), keyValue.getValue()); return TextMapPropagatorAndName.create(propagator, keyValue.getKey()); } @@ -61,7 +61,7 @@ static TextMapPropagatorAndName getPropagator(DeclarativeConfigContext context, textMapPropagator = W3CBaggagePropagator.getInstance(); } else { textMapPropagator = - context.loadComponent(TextMapPropagator.class, name, Collections.emptyMap(), context); + context.loadComponent(TextMapPropagator.class, name, Collections.emptyMap()); } return TextMapPropagatorAndName.create(textMapPropagator, name); } 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 c698b019381..b0e546ea702 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 @@ -153,7 +153,7 @@ void create_PullPrometheusDefault() throws IOException { assertThat(reader.toString()).isEqualTo(expectedReader.toString()); assertThat(readerAndCardinalityLimits.getCardinalityLimitsSelector()).isNull(); // TODO(jack-berg): validate prometheus component provider was invoked with correct arguments - verify(context).loadComponent(eq(MetricReader.class), eq("prometheus"), any(), context); + verify(context).loadComponent(eq(MetricReader.class), eq("prometheus"), any()); } @Test @@ -205,7 +205,7 @@ void create_PullPrometheusConfigured() throws IOException { .getCardinalityLimit(InstrumentType.COUNTER)) .isEqualTo(100); // TODO(jack-berg): validate prometheus component provider was invoked with correct arguments - verify(context).loadComponent(eq(MetricReader.class), eq("prometheus"), any(), context); + verify(context).loadComponent(eq(MetricReader.class), eq("prometheus"), any()); } @Test From b5451db9a6faace3fe18cad109073937f258c69a Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 21 Aug 2025 09:58:01 +0200 Subject: [PATCH 05/14] cleanup --- .../fileconfig/SpanExporterFactoryTest.java | 35 ---------------- .../component/TestAuthComponentProvider.java | 42 +++++++++++++++++++ ...toconfigure.spi.internal.ComponentProvider | 1 + 3 files changed, 43 insertions(+), 35 deletions(-) create mode 100644 sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/TestAuthComponentProvider.java 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 d5733758b27..5ccf8fe90e8 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 @@ -15,7 +15,6 @@ import com.google.common.collect.ImmutableMap; import com.linecorp.armeria.testing.junit5.server.SelfSignedCertificateExtension; -import io.opentelemetry.api.incubator.authenticator.ExporterAuthenticator; import io.opentelemetry.api.incubator.config.DeclarativeConfigException; import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.exporter.logging.LoggingSpanExporter; @@ -45,7 +44,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.Map; import java.util.stream.Collectors; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -74,38 +72,6 @@ class SpanExporterFactoryTest { spy(SpiHelper.create(SpanExporterFactoryTest.class.getClassLoader())); private final DeclarativeConfigContext context = new DeclarativeConfigContext(spiHelper); - private static final ComponentProvider authenticatorComponentProvider = - new ComponentProvider() { - @Override - public Class getType() { - return ExporterAuthenticator.class; - } - - @Override - public String getName() { - return "test_auth"; - } - - @Override - public ExporterAuthenticator create( - DeclarativeConfigProperties config, - ComponentProviderLoader componentProviderLoader) { - return new ExporterAuthenticator() { - ; - - @Override - public String getName() { - return "test_auth"; - } - - @Override - public Map getAuthenticationHeaders() { - return Collections.singletonMap("auth_provider_key1", "value1"); - } - }; - } - }; - private List> loadedComponentProviders = Collections.emptyList(); @BeforeEach @@ -118,7 +84,6 @@ void setup() { (List>) invocation.callRealMethod(); loadedComponentProviders = result.stream().map(Mockito::spy).collect(Collectors.toList()); - loadedComponentProviders.add(authenticatorComponentProvider); return loadedComponentProviders; }); } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/TestAuthComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/TestAuthComponentProvider.java new file mode 100644 index 00000000000..26d84fb0230 --- /dev/null +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/TestAuthComponentProvider.java @@ -0,0 +1,42 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.extension.incubator.fileconfig.component; + +import io.opentelemetry.api.incubator.authenticator.ExporterAuthenticator; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; +import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; +import java.util.Collections; +import java.util.Map; + +public class TestAuthComponentProvider implements ComponentProvider { + @Override + public Class getType() { + return ExporterAuthenticator.class; + } + + @Override + public String getName() { + return "test_auth"; + } + + @Override + public ExporterAuthenticator create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + return new ExporterAuthenticator() { + ; + + @Override + public String getName() { + return "test_auth"; + } + + @Override + public Map getAuthenticationHeaders() { + return Collections.singletonMap("auth_provider_key1", "value1"); + } + }; + } +} diff --git a/sdk-extensions/incubator/src/test/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider b/sdk-extensions/incubator/src/test/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider index da5f7288070..aefb6ba65e1 100644 --- a/sdk-extensions/incubator/src/test/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider +++ b/sdk-extensions/incubator/src/test/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider @@ -12,3 +12,4 @@ io.opentelemetry.sdk.extension.incubator.fileconfig.component.ContainerResourceP io.opentelemetry.sdk.extension.incubator.fileconfig.component.HostResourceProvider io.opentelemetry.sdk.extension.incubator.fileconfig.component.OsResourceProvider io.opentelemetry.sdk.extension.incubator.fileconfig.component.ProcessResourceProvider +io.opentelemetry.sdk.extension.incubator.fileconfig.component.TestAuthComponentProvider From 8b01ee32af979ff95849cce03ac4b2b095273811 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 21 Aug 2025 10:25:08 +0200 Subject: [PATCH 06/14] fix --- .../fileconfig/SpanExporterFactoryTest.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) 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 5ccf8fe90e8..acf397d4b71 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,9 +82,14 @@ void setup() { invocation -> { List> result = (List>) invocation.callRealMethod(); - loadedComponentProviders = - result.stream().map(Mockito::spy).collect(Collectors.toList()); - return loadedComponentProviders; + + // only capture first invocation for exporter, not second for authenticator + if (loadedComponentProviders.isEmpty()) { + loadedComponentProviders = + result.stream().map(Mockito::spy).collect(Collectors.toList()); + return loadedComponentProviders; + } + return result; }); } @@ -240,9 +245,7 @@ void create_OtlpGrpcConfigured(@TempDir Path tempDir) .setEndpoint("http://example:4317") .addHeader("key1", "value1") .addHeader("key2", "value2") - .setHeaders( - () -> Collections.singletonMap("auth_provider_key1", "value1") - ) + .setHeaders(() -> Collections.singletonMap("auth_provider_key1", "value1")) .setTimeout(Duration.ofSeconds(15)) .setCompression("gzip") .build(); From f28bbdf30e7db0ac02673c2c9c49252c8ceddeee Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 21 Aug 2025 10:26:07 +0200 Subject: [PATCH 07/14] cleanup --- .../authenticator/ExporterAuthenticator.java | 2 -- .../component/TestAuthComponentProvider.java | 15 +-------------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/authenticator/ExporterAuthenticator.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/authenticator/ExporterAuthenticator.java index f1a194e0e2c..336e9e9708e 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/authenticator/ExporterAuthenticator.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/authenticator/ExporterAuthenticator.java @@ -3,7 +3,5 @@ import java.util.Map; public interface ExporterAuthenticator { - String getName(); // todo remove this method - Map getAuthenticationHeaders(); } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/TestAuthComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/TestAuthComponentProvider.java index 26d84fb0230..6068766c786 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/TestAuthComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/TestAuthComponentProvider.java @@ -9,7 +9,6 @@ import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; import java.util.Collections; -import java.util.Map; public class TestAuthComponentProvider implements ComponentProvider { @Override @@ -25,18 +24,6 @@ public String getName() { @Override public ExporterAuthenticator create( DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { - return new ExporterAuthenticator() { - ; - - @Override - public String getName() { - return "test_auth"; - } - - @Override - public Map getAuthenticationHeaders() { - return Collections.singletonMap("auth_provider_key1", "value1"); - } - }; + return () -> Collections.singletonMap("auth_provider_key1", "value1"); } } From b13e3f331e95bb7ad08865f44faca2b8bfaf217d Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 21 Aug 2025 14:55:08 +0200 Subject: [PATCH 08/14] update mode --- sdk-extensions/incubator/build.gradle.kts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/sdk-extensions/incubator/build.gradle.kts b/sdk-extensions/incubator/build.gradle.kts index d87fadc5c88..fa991a900a5 100644 --- a/sdk-extensions/incubator/build.gradle.kts +++ b/sdk-extensions/incubator/build.gradle.kts @@ -58,8 +58,9 @@ dependencies { // ... proceed with normal sourcesJar, compileJava, etc val configurationTag = "1.0.0-rc.1" -val configurationRef = "refs/tags/v$configurationTag" // Replace with commit SHA to point to experiment with a specific commit -val configurationRepoZip = "https://github.com/open-telemetry/opentelemetry-configuration/archive/$configurationRef.zip" +// todo revert this when config PR is merged: https://github.com/open-telemetry/opentelemetry-configuration/pull/275 +val configurationRef = "refs/heads/authenticator" // Replace with commit SHA to point to experiment with a specific commit +val configurationRepoZip = "https://github.com/zeitlinger/opentelemetry-configuration/archive/$configurationRef.zip" val buildDirectory = layout.buildDirectory.asFile.get() val downloadConfigurationSchema by tasks.registering(Download::class) { @@ -69,8 +70,15 @@ val downloadConfigurationSchema by tasks.registering(Download::class) { } val unzipConfigurationSchema by tasks.registering(Copy::class) { - from("/home/gregor/source/opentelemetry-configuration/schema") - into("$buildDirectory/configuration/schema/") + dependsOn(downloadConfigurationSchema) + + from(zipTree(downloadConfigurationSchema.get().dest)) + eachFile(closureOf { + // Remove the top level folder "/opentelemetry-configuration-$configurationRef" + val pathParts = path.split("/") + path = pathParts.subList(1, pathParts.size).joinToString("/") + }) + into("$buildDirectory/configuration/") } val deleteTypeDescriptions by tasks.registering(Delete::class) { From f95a87cba92e3f60ca51ade455888a6a7bebd9ae Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 21 Aug 2025 14:55:21 +0200 Subject: [PATCH 09/14] extract extension --- .../ComponentProviderExtension.java | 55 +++++++++++++++++ .../LogRecordExporterFactoryTest.java | 47 +++------------ .../fileconfig/MetricExporterFactoryTest.java | 33 ++-------- .../fileconfig/SpanExporterFactoryTest.java | 60 ++++--------------- 4 files changed, 81 insertions(+), 114 deletions(-) create mode 100644 sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ComponentProviderExtension.java diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ComponentProviderExtension.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ComponentProviderExtension.java new file mode 100644 index 00000000000..013d5482642 --- /dev/null +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ComponentProviderExtension.java @@ -0,0 +1,55 @@ +package io.opentelemetry.sdk.extension.incubator.fileconfig; + +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; +import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.mockito.Mockito; + +public class ComponentProviderExtension implements BeforeEachCallback { + + private final SpiHelper spiHelper = + spy(SpiHelper.create(SpanExporterFactoryTest.class.getClassLoader())); + private final DeclarativeConfigContext context = new DeclarativeConfigContext(spiHelper); + + private List> loadedComponentProviders = Collections.emptyList(); + + @SuppressWarnings("unchecked") + @Override + public void beforeEach(ExtensionContext context) throws Exception { + when(spiHelper.load(ComponentProvider.class)) + .thenAnswer( + invocation -> { + List> result = + (List>) invocation.callRealMethod(); + + // only capture first invocation for exporter, not second for authenticator + if (loadedComponentProviders.isEmpty()) { + loadedComponentProviders = + result.stream().map(Mockito::spy).collect(Collectors.toList()); + return loadedComponentProviders; + } + return result; + }); + } + + public DeclarativeConfigContext getContext() { + return context; + } + + public ComponentProvider getComponentProvider(String name, Class type) { + return loadedComponentProviders.stream() + .filter( + componentProvider -> + componentProvider.getName().equals(name) + && componentProvider.getType().equals(type)) + .findFirst() + .orElseThrow(IllegalStateException::new); + } +} 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 f62e14e06c3..dc7ddf8c5df 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 @@ -9,9 +9,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableMap; import com.linecorp.armeria.testing.junit5.server.SelfSignedCertificateExtension; @@ -21,7 +19,6 @@ import io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporter; import io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporter; import io.opentelemetry.internal.testing.CleanupExtension; -import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; import io.opentelemetry.sdk.extension.incubator.fileconfig.component.LogRecordExporterComponentProvider; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.ExperimentalOtlpFileExporterModel; @@ -37,16 +34,12 @@ import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.stream.Collectors; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.api.io.TempDir; import org.mockito.ArgumentCaptor; -import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoSettings; import org.mockito.quality.Strictness; @@ -63,34 +56,10 @@ class LogRecordExporterFactoryTest { @RegisterExtension CleanupExtension cleanup = new CleanupExtension(); - private final SpiHelper spiHelper = - spy(SpiHelper.create(SpanExporterFactoryTest.class.getClassLoader())); - private final DeclarativeConfigContext context = new DeclarativeConfigContext(spiHelper); - private List> loadedComponentProviders = Collections.emptyList(); - - @BeforeEach - @SuppressWarnings("unchecked") - void setup() { - when(spiHelper.load(ComponentProvider.class)) - .thenAnswer( - invocation -> { - List> result = - (List>) invocation.callRealMethod(); - loadedComponentProviders = - result.stream().map(Mockito::spy).collect(Collectors.toList()); - return loadedComponentProviders; - }); - } + @RegisterExtension + ComponentProviderExtension componentProviderExtension = new ComponentProviderExtension(); - private ComponentProvider getComponentProvider(String name, Class type) { - return loadedComponentProviders.stream() - .filter( - componentProvider -> - componentProvider.getName().equals(name) - && componentProvider.getType().equals(type)) - .findFirst() - .orElseThrow(IllegalStateException::new); - } + private final DeclarativeConfigContext context = componentProviderExtension.getContext(); @Test void create_OtlpHttpDefaults() { @@ -112,7 +81,7 @@ void create_OtlpHttpDefaults() { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = - getComponentProvider("otlp_http", LogRecordExporter.class); + componentProviderExtension.getComponentProvider("otlp_http", LogRecordExporter.class); verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("protocol")).isNull(); @@ -178,7 +147,7 @@ void create_OtlpHttpConfigured(@TempDir Path tempDir) ArgumentCaptor configCaptor = ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = - getComponentProvider("otlp_http", LogRecordExporter.class); + componentProviderExtension.getComponentProvider("otlp_http", LogRecordExporter.class); verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isEqualTo("http://example:4318/v1/logs"); @@ -222,7 +191,7 @@ void create_OtlpGrpcDefaults() { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = - getComponentProvider("otlp_grpc", LogRecordExporter.class); + componentProviderExtension.getComponentProvider("otlp_grpc", LogRecordExporter.class); verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isNull(); @@ -287,7 +256,7 @@ void create_OtlpGrpcConfigured(@TempDir Path tempDir) ArgumentCaptor configCaptor = ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = - getComponentProvider("otlp_grpc", LogRecordExporter.class); + componentProviderExtension.getComponentProvider("otlp_grpc", LogRecordExporter.class); verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isEqualTo("http://example:4317"); @@ -331,7 +300,7 @@ void create_OtlpFile() { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = - getComponentProvider("otlp_file/development", LogRecordExporter.class); + componentProviderExtension.getComponentProvider("otlp_file/development", LogRecordExporter.class); verify(componentProvider).create(configCaptor.capture(), any()); } 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 5541caf48fd..45aafe4778d 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 @@ -69,34 +69,11 @@ class MetricExporterFactoryTest { @RegisterExtension CleanupExtension cleanup = new CleanupExtension(); - private final SpiHelper spiHelper = - spy(SpiHelper.create(SpanExporterFactoryTest.class.getClassLoader())); - private final DeclarativeConfigContext context = new DeclarativeConfigContext(spiHelper); - private List> loadedComponentProviders = Collections.emptyList(); - - @BeforeEach - @SuppressWarnings("unchecked") - void setup() { - when(spiHelper.load(ComponentProvider.class)) - .thenAnswer( - invocation -> { - List> result = - (List>) invocation.callRealMethod(); - loadedComponentProviders = - result.stream().map(Mockito::spy).collect(Collectors.toList()); - return loadedComponentProviders; - }); - } + @RegisterExtension + ComponentProviderExtension componentProviderExtension = new ComponentProviderExtension(); - private ComponentProvider getComponentProvider(String name, Class type) { - return loadedComponentProviders.stream() - .filter( - componentProvider -> - componentProvider.getName().equals(name) - && componentProvider.getType().equals(type)) - .findFirst() - .orElseThrow(IllegalStateException::new); - } + private final DeclarativeConfigContext context = + componentProviderExtension.getContext(); @Test void create_OtlpHttpDefaults() { @@ -117,7 +94,7 @@ void create_OtlpHttpDefaults() { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = - getComponentProvider("otlp_http", MetricExporter.class); + componentProviderExtension.getComponentProvider("otlp_http", MetricExporter.class); verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("protocol")).isNull(); 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 acf397d4b71..03bba8e9281 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 @@ -9,9 +9,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableMap; import com.linecorp.armeria.testing.junit5.server.SelfSignedCertificateExtension; @@ -23,7 +21,6 @@ import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter; import io.opentelemetry.exporter.zipkin.ZipkinSpanExporter; import io.opentelemetry.internal.testing.CleanupExtension; -import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; import io.opentelemetry.sdk.extension.incubator.fileconfig.component.SpanExporterComponentProvider; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.AuthenticatorModel; @@ -44,14 +41,11 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.stream.Collectors; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.api.io.TempDir; import org.mockito.ArgumentCaptor; -import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoSettings; import org.mockito.quality.Strictness; @@ -68,40 +62,10 @@ class SpanExporterFactoryTest { @RegisterExtension CleanupExtension cleanup = new CleanupExtension(); - private final SpiHelper spiHelper = - spy(SpiHelper.create(SpanExporterFactoryTest.class.getClassLoader())); - private final DeclarativeConfigContext context = new DeclarativeConfigContext(spiHelper); - - private List> loadedComponentProviders = Collections.emptyList(); - - @BeforeEach - @SuppressWarnings("unchecked") - void setup() { - when(spiHelper.load(ComponentProvider.class)) - .thenAnswer( - invocation -> { - List> result = - (List>) invocation.callRealMethod(); - - // only capture first invocation for exporter, not second for authenticator - if (loadedComponentProviders.isEmpty()) { - loadedComponentProviders = - result.stream().map(Mockito::spy).collect(Collectors.toList()); - return loadedComponentProviders; - } - return result; - }); - } + @RegisterExtension + ComponentProviderExtension componentProviderExtension = new ComponentProviderExtension(); - private ComponentProvider getComponentProvider(String name, Class type) { - return loadedComponentProviders.stream() - .filter( - componentProvider -> - componentProvider.getName().equals(name) - && componentProvider.getType().equals(type)) - .findFirst() - .orElseThrow(IllegalStateException::new); - } + private final DeclarativeConfigContext context = componentProviderExtension.getContext(); @Test void create_OtlpHttpDefaults() { @@ -111,7 +75,9 @@ void create_OtlpHttpDefaults() { SpanExporter exporter = SpanExporterFactory.getInstance() - .create(new SpanExporterModel().withOtlpHttp(new OtlpHttpExporterModel()), context); + .create( + new SpanExporterModel().withOtlpHttp(new OtlpHttpExporterModel()), + context); cleanup.addCloseable(exporter); cleanup.addCloseables(closeables); @@ -119,7 +85,7 @@ void create_OtlpHttpDefaults() { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(DeclarativeConfigProperties.class); - ComponentProvider componentProvider = getComponentProvider("otlp_http", SpanExporter.class); + ComponentProvider componentProvider = componentProviderExtension.getComponentProvider("otlp_http", SpanExporter.class); verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("protocol")).isNull(); @@ -184,7 +150,7 @@ void create_OtlpHttpConfigured(@TempDir Path tempDir) ArgumentCaptor configCaptor = ArgumentCaptor.forClass(DeclarativeConfigProperties.class); - ComponentProvider componentProvider = getComponentProvider("otlp_http", SpanExporter.class); + ComponentProvider componentProvider = componentProviderExtension.getComponentProvider("otlp_http", SpanExporter.class); verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isEqualTo("http://example:4318/v1/traces"); @@ -224,7 +190,7 @@ void create_OtlpGrpcDefaults() { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(DeclarativeConfigProperties.class); - ComponentProvider componentProvider = getComponentProvider("otlp_grpc", SpanExporter.class); + ComponentProvider componentProvider = componentProviderExtension.getComponentProvider("otlp_grpc", SpanExporter.class); verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isNull(); @@ -291,7 +257,7 @@ void create_OtlpGrpcConfigured(@TempDir Path tempDir) ArgumentCaptor configCaptor = ArgumentCaptor.forClass(DeclarativeConfigProperties.class); - ComponentProvider componentProvider = getComponentProvider("otlp_grpc", SpanExporter.class); + ComponentProvider componentProvider = componentProviderExtension.getComponentProvider("otlp_grpc", SpanExporter.class); verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isEqualTo("http://example:4317"); @@ -347,7 +313,7 @@ void create_ZipkinDefaults() { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(DeclarativeConfigProperties.class); - ComponentProvider componentProvider = getComponentProvider("zipkin", SpanExporter.class); + ComponentProvider componentProvider = componentProviderExtension.getComponentProvider("zipkin", SpanExporter.class); verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isNull(); @@ -380,7 +346,7 @@ void create_ZipkinConfigured() { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(DeclarativeConfigProperties.class); - ComponentProvider componentProvider = getComponentProvider("zipkin", SpanExporter.class); + ComponentProvider componentProvider = componentProviderExtension.getComponentProvider("zipkin", SpanExporter.class); verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isEqualTo("http://zipkin:9411/v1/v2/spans"); @@ -407,7 +373,7 @@ void create_OtlpFile() { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = - getComponentProvider("otlp_file/development", SpanExporter.class); + componentProviderExtension.getComponentProvider("otlp_file/development", SpanExporter.class); verify(componentProvider).create(configCaptor.capture(), any()); } From a5166719528e96c18d6938c9d1dacd18c938a022 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 21 Aug 2025 16:34:37 +0200 Subject: [PATCH 10/14] add exporter authenticator --- .../fileconfig/DeclarativeConfigContext.java | 1 - .../fileconfig/LogRecordExporterFactory.java | 3 +- .../fileconfig/LogRecordProcessorFactory.java | 3 +- .../fileconfig/MetricExporterFactory.java | 3 +- .../fileconfig/TextMapPropagatorFactory.java | 3 +- .../ComponentProviderExtension.java | 9 ++++-- .../LogRecordExporterFactoryTest.java | 11 +++++++- .../fileconfig/MetricExporterFactoryTest.java | 25 +++++++++-------- .../fileconfig/SpanExporterFactoryTest.java | 28 ++++++++++++------- 9 files changed, 52 insertions(+), 34 deletions(-) diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigContext.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigContext.java index 960b3b56fc3..a0391b9e35b 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigContext.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigContext.java @@ -92,5 +92,4 @@ T loadComponent(Class type, String name, Object model) { "Error configuring " + type.getName() + " with name \"" + name + "\"", throwable); } } - } 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 30ace6c71af..f2c6db8d42d 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 @@ -32,8 +32,7 @@ public LogRecordExporter create(LogRecordExporterModel model, DeclarativeConfigC Map.Entry keyValue = FileConfigUtil.getSingletonMapEntry(model.getAdditionalProperties(), "log record exporter"); LogRecordExporter logRecordExporter = - context.loadComponent( - LogRecordExporter.class, keyValue.getKey(), keyValue.getValue()); + context.loadComponent(LogRecordExporter.class, keyValue.getKey(), keyValue.getValue()); return context.addCloseable(logRecordExporter); } } diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordProcessorFactory.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordProcessorFactory.java index ef8ed841b7a..20f271a5568 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordProcessorFactory.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/LogRecordProcessorFactory.java @@ -70,8 +70,7 @@ public LogRecordProcessor create( FileConfigUtil.getSingletonMapEntry( model.getAdditionalProperties(), "log record processor"); LogRecordProcessor logRecordProcessor = - context.loadComponent( - LogRecordProcessor.class, keyValue.getKey(), keyValue.getValue()); + context.loadComponent(LogRecordProcessor.class, keyValue.getKey(), keyValue.getValue()); return context.addCloseable(logRecordProcessor); } } 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 32de5b10675..6da48a4fef7 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 @@ -32,8 +32,7 @@ public MetricExporter create(PushMetricExporterModel model, DeclarativeConfigCon Map.Entry keyValue = FileConfigUtil.getSingletonMapEntry(model.getAdditionalProperties(), "metric exporter"); MetricExporter metricExporter = - context.loadComponent( - MetricExporter.class, keyValue.getKey(), keyValue.getValue()); + context.loadComponent(MetricExporter.class, keyValue.getKey(), keyValue.getValue()); return context.addCloseable(metricExporter); } } 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 eb27afe2006..6f0cb869bd1 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 @@ -48,8 +48,7 @@ public TextMapPropagatorAndName create( Map.Entry keyValue = FileConfigUtil.getSingletonMapEntry(model.getAdditionalProperties(), "propagator"); TextMapPropagator propagator = - context.loadComponent( - TextMapPropagator.class, keyValue.getKey(), keyValue.getValue()); + context.loadComponent(TextMapPropagator.class, keyValue.getKey(), keyValue.getValue()); return TextMapPropagatorAndName.create(propagator, keyValue.getKey()); } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ComponentProviderExtension.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ComponentProviderExtension.java index 013d5482642..916fa51e306 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ComponentProviderExtension.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ComponentProviderExtension.java @@ -1,3 +1,8 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + package io.opentelemetry.sdk.extension.incubator.fileconfig; import static org.mockito.Mockito.spy; @@ -39,11 +44,11 @@ public void beforeEach(ExtensionContext context) throws Exception { }); } - public DeclarativeConfigContext getContext() { + DeclarativeConfigContext getContext() { return context; } - public ComponentProvider getComponentProvider(String name, Class type) { + ComponentProvider getComponentProvider(String name, Class type) { return loadedComponentProviders.stream() .filter( componentProvider -> 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 dc7ddf8c5df..45c1f6aaf1e 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 @@ -21,6 +21,7 @@ import io.opentelemetry.internal.testing.CleanupExtension; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; import io.opentelemetry.sdk.extension.incubator.fileconfig.component.LogRecordExporterComponentProvider; +import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.AuthenticatorModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.ExperimentalOtlpFileExporterModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.LogRecordExporterModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.NameStringValuePairModel; @@ -34,6 +35,7 @@ import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -103,6 +105,7 @@ void create_OtlpHttpConfigured(@TempDir Path tempDir) .setEndpoint("http://example:4318/v1/logs") .addHeader("key1", "value1") .addHeader("key2", "value2") + .setHeaders(() -> Collections.singletonMap("auth_provider_key1", "value1")) .setTimeout(Duration.ofSeconds(15)) .setCompression("gzip") .build(); @@ -133,6 +136,8 @@ void create_OtlpHttpConfigured(@TempDir Path tempDir) new NameStringValuePairModel() .withName("key2") .withValue("value2"))) + .withAuthenticator( + new AuthenticatorModel().withAdditionalProperty("test_auth", null)) .withCompression("gzip") .withTimeout(15_000) .withCertificateFile(certificatePath) @@ -212,6 +217,7 @@ void create_OtlpGrpcConfigured(@TempDir Path tempDir) .setEndpoint("http://example:4317") .addHeader("key1", "value1") .addHeader("key2", "value2") + .setHeaders(() -> Collections.singletonMap("auth_provider_key1", "value1")) .setTimeout(Duration.ofSeconds(15)) .setCompression("gzip") .build(); @@ -242,6 +248,8 @@ void create_OtlpGrpcConfigured(@TempDir Path tempDir) new NameStringValuePairModel() .withName("key2") .withValue("value2"))) + .withAuthenticator( + new AuthenticatorModel().withAdditionalProperty("test_auth", null)) .withCompression("gzip") .withTimeout(15_000) .withCertificateFile(certificatePath) @@ -300,7 +308,8 @@ void create_OtlpFile() { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = - componentProviderExtension.getComponentProvider("otlp_file/development", LogRecordExporter.class); + componentProviderExtension.getComponentProvider( + "otlp_file/development", LogRecordExporter.class); verify(componentProvider).create(configCaptor.capture(), any()); } 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 45aafe4778d..f0a43688a43 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 @@ -9,9 +9,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableMap; import com.linecorp.armeria.testing.junit5.server.SelfSignedCertificateExtension; @@ -22,9 +20,9 @@ import io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporter; import io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter; import io.opentelemetry.internal.testing.CleanupExtension; -import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; import io.opentelemetry.sdk.extension.incubator.fileconfig.component.MetricExporterComponentProvider; +import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.AuthenticatorModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.ConsoleExporterModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.ExperimentalOtlpFileMetricExporterModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.NameStringValuePairModel; @@ -45,14 +43,11 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.stream.Collectors; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.api.io.TempDir; import org.mockito.ArgumentCaptor; -import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoSettings; import org.mockito.quality.Strictness; @@ -72,8 +67,7 @@ class MetricExporterFactoryTest { @RegisterExtension ComponentProviderExtension componentProviderExtension = new ComponentProviderExtension(); - private final DeclarativeConfigContext context = - componentProviderExtension.getContext(); + private final DeclarativeConfigContext context = componentProviderExtension.getContext(); @Test void create_OtlpHttpDefaults() { @@ -118,6 +112,7 @@ void create_OtlpHttpConfigured(@TempDir Path tempDir) .setEndpoint("http://example:4318/v1/metrics") .addHeader("key1", "value1") .addHeader("key2", "value2") + .setHeaders(() -> Collections.singletonMap("auth_provider_key1", "value1")) .setTimeout(Duration.ofSeconds(15)) .setCompression("gzip") .setAggregationTemporalitySelector(AggregationTemporalitySelector.deltaPreferred()) @@ -152,6 +147,8 @@ void create_OtlpHttpConfigured(@TempDir Path tempDir) new NameStringValuePairModel() .withName("key2") .withValue("value2"))) + .withAuthenticator( + new AuthenticatorModel().withAdditionalProperty("test_auth", null)) .withCompression("gzip") .withTimeout(15_000) .withCertificateFile(certificatePath) @@ -171,7 +168,7 @@ void create_OtlpHttpConfigured(@TempDir Path tempDir) ArgumentCaptor configCaptor = ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = - getComponentProvider("otlp_http", MetricExporter.class); + componentProviderExtension.getComponentProvider("otlp_http", MetricExporter.class); verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isEqualTo("http://example:4318/v1/metrics"); @@ -217,7 +214,7 @@ void create_OtlpGrpcDefaults() { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = - getComponentProvider("otlp_grpc", MetricExporter.class); + componentProviderExtension.getComponentProvider("otlp_grpc", MetricExporter.class); verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isNull(); @@ -240,6 +237,7 @@ void create_OtlpGrpcConfigured(@TempDir Path tempDir) .setEndpoint("http://example:4317") .addHeader("key1", "value1") .addHeader("key2", "value2") + .setHeaders(() -> Collections.singletonMap("auth_provider_key1", "value1")) .setTimeout(Duration.ofSeconds(15)) .setCompression("gzip") .setAggregationTemporalitySelector(AggregationTemporalitySelector.deltaPreferred()) @@ -274,6 +272,8 @@ void create_OtlpGrpcConfigured(@TempDir Path tempDir) new NameStringValuePairModel() .withName("key2") .withValue("value2"))) + .withAuthenticator( + new AuthenticatorModel().withAdditionalProperty("test_auth", null)) .withCompression("gzip") .withTimeout(15_000) .withCertificateFile(certificatePath) @@ -293,7 +293,7 @@ void create_OtlpGrpcConfigured(@TempDir Path tempDir) ArgumentCaptor configCaptor = ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = - getComponentProvider("otlp_grpc", MetricExporter.class); + componentProviderExtension.getComponentProvider("otlp_grpc", MetricExporter.class); verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isEqualTo("http://example:4317"); @@ -355,7 +355,8 @@ void create_OtlpFile() { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = - getComponentProvider("otlp_file/development", MetricExporter.class); + componentProviderExtension.getComponentProvider( + "otlp_file/development", MetricExporter.class); verify(componentProvider).create(configCaptor.capture(), any()); } 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 03bba8e9281..c0294138a45 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 @@ -75,9 +75,7 @@ void create_OtlpHttpDefaults() { SpanExporter exporter = SpanExporterFactory.getInstance() - .create( - new SpanExporterModel().withOtlpHttp(new OtlpHttpExporterModel()), - context); + .create(new SpanExporterModel().withOtlpHttp(new OtlpHttpExporterModel()), context); cleanup.addCloseable(exporter); cleanup.addCloseables(closeables); @@ -85,7 +83,8 @@ void create_OtlpHttpDefaults() { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(DeclarativeConfigProperties.class); - ComponentProvider componentProvider = componentProviderExtension.getComponentProvider("otlp_http", SpanExporter.class); + ComponentProvider componentProvider = + componentProviderExtension.getComponentProvider("otlp_http", SpanExporter.class); verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("protocol")).isNull(); @@ -107,6 +106,7 @@ void create_OtlpHttpConfigured(@TempDir Path tempDir) .setEndpoint("http://example:4318/v1/traces") .addHeader("key1", "value1") .addHeader("key2", "value2") + .setHeaders(() -> Collections.singletonMap("auth_provider_key1", "value1")) .setTimeout(Duration.ofSeconds(15)) .setCompression("gzip") .build(); @@ -137,6 +137,8 @@ void create_OtlpHttpConfigured(@TempDir Path tempDir) new NameStringValuePairModel() .withName("key2") .withValue("value2"))) + .withAuthenticator( + new AuthenticatorModel().withAdditionalProperty("test_auth", null)) .withCompression("gzip") .withTimeout(15_000) .withCertificateFile(certificatePath) @@ -150,7 +152,8 @@ void create_OtlpHttpConfigured(@TempDir Path tempDir) ArgumentCaptor configCaptor = ArgumentCaptor.forClass(DeclarativeConfigProperties.class); - ComponentProvider componentProvider = componentProviderExtension.getComponentProvider("otlp_http", SpanExporter.class); + ComponentProvider componentProvider = + componentProviderExtension.getComponentProvider("otlp_http", SpanExporter.class); verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isEqualTo("http://example:4318/v1/traces"); @@ -190,7 +193,8 @@ void create_OtlpGrpcDefaults() { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(DeclarativeConfigProperties.class); - ComponentProvider componentProvider = componentProviderExtension.getComponentProvider("otlp_grpc", SpanExporter.class); + ComponentProvider componentProvider = + componentProviderExtension.getComponentProvider("otlp_grpc", SpanExporter.class); verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isNull(); @@ -257,7 +261,8 @@ void create_OtlpGrpcConfigured(@TempDir Path tempDir) ArgumentCaptor configCaptor = ArgumentCaptor.forClass(DeclarativeConfigProperties.class); - ComponentProvider componentProvider = componentProviderExtension.getComponentProvider("otlp_grpc", SpanExporter.class); + ComponentProvider componentProvider = + componentProviderExtension.getComponentProvider("otlp_grpc", SpanExporter.class); verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isEqualTo("http://example:4317"); @@ -313,7 +318,8 @@ void create_ZipkinDefaults() { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(DeclarativeConfigProperties.class); - ComponentProvider componentProvider = componentProviderExtension.getComponentProvider("zipkin", SpanExporter.class); + ComponentProvider componentProvider = + componentProviderExtension.getComponentProvider("zipkin", SpanExporter.class); verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isNull(); @@ -346,7 +352,8 @@ void create_ZipkinConfigured() { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(DeclarativeConfigProperties.class); - ComponentProvider componentProvider = componentProviderExtension.getComponentProvider("zipkin", SpanExporter.class); + ComponentProvider componentProvider = + componentProviderExtension.getComponentProvider("zipkin", SpanExporter.class); verify(componentProvider).create(configCaptor.capture(), any()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isEqualTo("http://zipkin:9411/v1/v2/spans"); @@ -373,7 +380,8 @@ void create_OtlpFile() { ArgumentCaptor configCaptor = ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = - componentProviderExtension.getComponentProvider("otlp_file/development", SpanExporter.class); + componentProviderExtension.getComponentProvider( + "otlp_file/development", SpanExporter.class); verify(componentProvider).create(configCaptor.capture(), any()); } From ff3a4b055a76ba590555b1203d99a0fb40d5dbca Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Tue, 26 Aug 2025 15:47:43 +0200 Subject: [PATCH 11/14] cleanup --- .../exporter/otlp/internal/OtlpDeclarativeConfigUtil.java | 6 ++++-- .../OtlpGrpcLogRecordExporterComponentProvider.java | 2 +- .../internal/OtlpGrpcMetricExporterComponentProvider.java | 2 +- .../internal/OtlpGrpcSpanExporterComponentProvider.java | 2 +- .../OtlpHttpLogRecordExporterComponentProvider.java | 2 +- .../internal/OtlpHttpMetricExporterComponentProvider.java | 2 +- .../internal/OtlpHttpSpanExporterComponentProvider.java | 2 +- 7 files changed, 10 insertions(+), 8 deletions(-) diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpDeclarativeConfigUtil.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpDeclarativeConfigUtil.java index ea58de4680f..f935f867e69 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpDeclarativeConfigUtil.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpDeclarativeConfigUtil.java @@ -24,9 +24,11 @@ import java.time.Duration; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.function.BiConsumer; import java.util.function.Consumer; +import java.util.function.Supplier; /** * This class is internal and is hence not for public use. Its APIs are unstable and can change at @@ -55,7 +57,7 @@ public static void configureOtlpExporterBuilder( Consumer setComponentLoader, Consumer setEndpoint, BiConsumer addHeader, - Consumer setAuthenticator, + Consumer>> setHeaders, Consumer setCompression, Consumer setTimeout, Consumer setTrustedCertificates, @@ -87,7 +89,7 @@ public static void configureOtlpExporterBuilder( componentProviderLoader.loadComponent( ExporterAuthenticator.class, authenticatorName, authenticator); - setAuthenticator.accept(exporterAuthenticator); + setHeaders.accept(exporterAuthenticator::getAuthenticationHeaders); } String headerList = config.getString("headers_list"); diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcLogRecordExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcLogRecordExporterComponentProvider.java index 779e1dde861..6f8eebb691f 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcLogRecordExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcLogRecordExporterComponentProvider.java @@ -44,7 +44,7 @@ public LogRecordExporter create(DeclarativeConfigProperties config, builder::setComponentLoader, builder::setEndpoint, builder::addHeader, - auth -> builder.setHeaders(auth::getAuthenticationHeaders), + builder::setHeaders, builder::setCompression, builder::setTimeout, builder::setTrustedCertificates, diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcMetricExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcMetricExporterComponentProvider.java index 310722c515e..3790ef7f90e 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcMetricExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcMetricExporterComponentProvider.java @@ -43,7 +43,7 @@ public MetricExporter create(DeclarativeConfigProperties config, ComponentProvid builder::setComponentLoader, builder::setEndpoint, builder::addHeader, - auth -> builder.setHeaders(auth::getAuthenticationHeaders), + builder::setHeaders, builder::setCompression, builder::setTimeout, builder::setTrustedCertificates, diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcSpanExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcSpanExporterComponentProvider.java index bb91e07eb9e..39fc5337bb9 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcSpanExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcSpanExporterComponentProvider.java @@ -42,7 +42,7 @@ public SpanExporter create(DeclarativeConfigProperties config, ComponentProvider builder::setComponentLoader, builder::setEndpoint, builder::addHeader, - auth -> builder.setHeaders(auth::getAuthenticationHeaders), + builder::setHeaders, builder::setCompression, builder::setTimeout, builder::setTrustedCertificates, diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpLogRecordExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpLogRecordExporterComponentProvider.java index 7e45a7b74c4..0133ca531a3 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpLogRecordExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpLogRecordExporterComponentProvider.java @@ -44,7 +44,7 @@ public LogRecordExporter create(DeclarativeConfigProperties config, builder::setComponentLoader, builder::setEndpoint, builder::addHeader, - auth -> builder.setHeaders(auth::getAuthenticationHeaders), + builder::setHeaders, builder::setCompression, builder::setTimeout, builder::setTrustedCertificates, diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpMetricExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpMetricExporterComponentProvider.java index c0987dda9f1..e00349d49ab 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpMetricExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpMetricExporterComponentProvider.java @@ -43,7 +43,7 @@ public MetricExporter create(DeclarativeConfigProperties config, ComponentProvid builder::setComponentLoader, builder::setEndpoint, builder::addHeader, - auth -> builder.setHeaders(auth::getAuthenticationHeaders), + builder::setHeaders, builder::setCompression, builder::setTimeout, builder::setTrustedCertificates, diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpSpanExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpSpanExporterComponentProvider.java index 0114368b7dd..deb5a64267a 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpSpanExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpSpanExporterComponentProvider.java @@ -42,7 +42,7 @@ public SpanExporter create(DeclarativeConfigProperties config, ComponentProvider builder::setComponentLoader, builder::setEndpoint, builder::addHeader, - auth -> builder.setHeaders(auth::getAuthenticationHeaders), + builder::setHeaders, builder::setCompression, builder::setTimeout, builder::setTrustedCertificates, From 67e16e13db905e7f0c97185cd9084d269e5c8e98 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Tue, 26 Aug 2025 17:06:47 +0200 Subject: [PATCH 12/14] format --- .../incubator/authenticator/ExporterAuthenticator.java | 5 +++++ .../OtlpStdoutLogRecordExporterComponentProvider.java | 3 ++- .../OtlpStdoutMetricExporterComponentProvider.java | 3 ++- .../traces/OtlpStdoutSpanExporterComponentProvider.java | 3 ++- .../ConsoleLogRecordExporterComponentProvider.java | 3 ++- .../internal/ConsoleMetricExporterComponentProvider.java | 3 ++- .../internal/ConsoleSpanExporterComponentProvider.java | 3 ++- .../OtlpGrpcLogRecordExporterComponentProvider.java | 4 ++-- .../internal/OtlpGrpcMetricExporterComponentProvider.java | 3 ++- .../internal/OtlpGrpcSpanExporterComponentProvider.java | 3 ++- .../OtlpHttpLogRecordExporterComponentProvider.java | 4 ++-- .../internal/OtlpHttpMetricExporterComponentProvider.java | 3 ++- .../internal/OtlpHttpSpanExporterComponentProvider.java | 3 ++- .../prometheus/internal/PrometheusComponentProvider.java | 3 ++- .../internal/ZipkinSpanExporterComponentProvider.java | 3 ++- .../trace/propagation/internal/B3ComponentProvider.java | 3 ++- .../propagation/internal/B3MultiComponentProvider.java | 3 ++- .../propagation/internal/JaegerComponentProvider.java | 3 ++- .../propagation/internal/OtTraceComponentProvider.java | 3 ++- .../sdk/autoconfigure/spi/internal/ComponentProvider.java | 8 ++++---- .../internal/JaegerRemoteSamplerComponentProvider.java | 3 ++- 21 files changed, 47 insertions(+), 25 deletions(-) diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/authenticator/ExporterAuthenticator.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/authenticator/ExporterAuthenticator.java index 336e9e9708e..0235dd33615 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/authenticator/ExporterAuthenticator.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/authenticator/ExporterAuthenticator.java @@ -1,3 +1,8 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + package io.opentelemetry.api.incubator.authenticator; import java.util.Map; diff --git a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporterComponentProvider.java b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporterComponentProvider.java index 1af629fa7fe..13fd8834dd0 100644 --- a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporterComponentProvider.java +++ b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporterComponentProvider.java @@ -30,7 +30,8 @@ public String getName() { } @Override - public LogRecordExporter create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public LogRecordExporter create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { OtlpStdoutLogRecordExporterBuilder builder = OtlpStdoutLogRecordExporter.builder(); IncubatingExporterBuilderUtil.configureExporterMemoryMode(config, builder::setMemoryMode); return builder.build(); diff --git a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/metrics/OtlpStdoutMetricExporterComponentProvider.java b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/metrics/OtlpStdoutMetricExporterComponentProvider.java index 19622678618..8afebd889fd 100644 --- a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/metrics/OtlpStdoutMetricExporterComponentProvider.java +++ b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/metrics/OtlpStdoutMetricExporterComponentProvider.java @@ -30,7 +30,8 @@ public String getName() { } @Override - public MetricExporter create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public MetricExporter create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { OtlpStdoutMetricExporterBuilder builder = OtlpStdoutMetricExporter.builder(); IncubatingExporterBuilderUtil.configureExporterMemoryMode(config, builder::setMemoryMode); IncubatingExporterBuilderUtil.configureOtlpAggregationTemporality( diff --git a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/traces/OtlpStdoutSpanExporterComponentProvider.java b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/traces/OtlpStdoutSpanExporterComponentProvider.java index ead347033e1..48cb31a5023 100644 --- a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/traces/OtlpStdoutSpanExporterComponentProvider.java +++ b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/traces/OtlpStdoutSpanExporterComponentProvider.java @@ -30,7 +30,8 @@ public String getName() { } @Override - public SpanExporter create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public SpanExporter create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { OtlpStdoutSpanExporterBuilder builder = OtlpStdoutSpanExporter.builder(); IncubatingExporterBuilderUtil.configureExporterMemoryMode(config, builder::setMemoryMode); return builder.build(); diff --git a/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleLogRecordExporterComponentProvider.java b/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleLogRecordExporterComponentProvider.java index 5aa5640f280..f3ddbff6017 100644 --- a/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleLogRecordExporterComponentProvider.java +++ b/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleLogRecordExporterComponentProvider.java @@ -30,7 +30,8 @@ public String getName() { } @Override - public LogRecordExporter create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public LogRecordExporter create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { return SystemOutLogRecordExporter.create(); } } diff --git a/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleMetricExporterComponentProvider.java b/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleMetricExporterComponentProvider.java index 471c02e0ff2..a62ad6b0dc1 100644 --- a/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleMetricExporterComponentProvider.java +++ b/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleMetricExporterComponentProvider.java @@ -30,7 +30,8 @@ public String getName() { } @Override - public MetricExporter create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public MetricExporter create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { return LoggingMetricExporter.create(); } } diff --git a/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleSpanExporterComponentProvider.java b/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleSpanExporterComponentProvider.java index 825d6dfaf93..f97352e848b 100644 --- a/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleSpanExporterComponentProvider.java +++ b/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleSpanExporterComponentProvider.java @@ -29,7 +29,8 @@ public String getName() { } @Override - public SpanExporter create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public SpanExporter create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { return LoggingSpanExporter.create(); } } diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcLogRecordExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcLogRecordExporterComponentProvider.java index 6f8eebb691f..253dd0751aa 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcLogRecordExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcLogRecordExporterComponentProvider.java @@ -33,8 +33,8 @@ public String getName() { } @Override - public LogRecordExporter create(DeclarativeConfigProperties config, - ComponentProviderLoader componentProviderLoader) { + public LogRecordExporter create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { OtlpGrpcLogRecordExporterBuilder builder = grpcBuilder(); OtlpDeclarativeConfigUtil.configureOtlpExporterBuilder( diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcMetricExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcMetricExporterComponentProvider.java index 3790ef7f90e..327a6ee2555 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcMetricExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcMetricExporterComponentProvider.java @@ -33,7 +33,8 @@ public String getName() { } @Override - public MetricExporter create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public MetricExporter create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { OtlpGrpcMetricExporterBuilder builder = grpcBuilder(); OtlpDeclarativeConfigUtil.configureOtlpExporterBuilder( diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcSpanExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcSpanExporterComponentProvider.java index 39fc5337bb9..93edc160d3a 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcSpanExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcSpanExporterComponentProvider.java @@ -32,7 +32,8 @@ public String getName() { } @Override - public SpanExporter create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public SpanExporter create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { OtlpGrpcSpanExporterBuilder builder = grpcBuilder(); OtlpDeclarativeConfigUtil.configureOtlpExporterBuilder( diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpLogRecordExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpLogRecordExporterComponentProvider.java index 0133ca531a3..3cc3cff410f 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpLogRecordExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpLogRecordExporterComponentProvider.java @@ -33,8 +33,8 @@ public String getName() { } @Override - public LogRecordExporter create(DeclarativeConfigProperties config, - ComponentProviderLoader componentProviderLoader) { + public LogRecordExporter create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { OtlpHttpLogRecordExporterBuilder builder = httpBuilder(); OtlpDeclarativeConfigUtil.configureOtlpExporterBuilder( diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpMetricExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpMetricExporterComponentProvider.java index e00349d49ab..8bfd60edb9f 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpMetricExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpMetricExporterComponentProvider.java @@ -33,7 +33,8 @@ public String getName() { } @Override - public MetricExporter create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public MetricExporter create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { OtlpHttpMetricExporterBuilder builder = httpBuilder(); OtlpDeclarativeConfigUtil.configureOtlpExporterBuilder( diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpSpanExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpSpanExporterComponentProvider.java index deb5a64267a..c619440b20f 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpSpanExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpSpanExporterComponentProvider.java @@ -32,7 +32,8 @@ public String getName() { } @Override - public SpanExporter create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public SpanExporter create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { OtlpHttpSpanExporterBuilder builder = httpBuilder(); OtlpDeclarativeConfigUtil.configureOtlpExporterBuilder( diff --git a/exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/internal/PrometheusComponentProvider.java b/exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/internal/PrometheusComponentProvider.java index 711e5423443..0280ae2f2eb 100644 --- a/exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/internal/PrometheusComponentProvider.java +++ b/exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/internal/PrometheusComponentProvider.java @@ -32,7 +32,8 @@ public String getName() { } @Override - public MetricReader create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public MetricReader create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { PrometheusHttpServerBuilder prometheusBuilder = PrometheusHttpServer.builder(); Integer port = config.getInt("port"); diff --git a/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/internal/ZipkinSpanExporterComponentProvider.java b/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/internal/ZipkinSpanExporterComponentProvider.java index 928d9e21527..9faeb631d3f 100644 --- a/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/internal/ZipkinSpanExporterComponentProvider.java +++ b/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/internal/ZipkinSpanExporterComponentProvider.java @@ -30,7 +30,8 @@ public String getName() { } @Override - public SpanExporter create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public SpanExporter create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { ZipkinSpanExporterBuilder builder = ZipkinSpanExporter.builder(); String endpoint = config.getString("endpoint"); diff --git a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/B3ComponentProvider.java b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/B3ComponentProvider.java index a9765043d5c..f600bb02c1e 100644 --- a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/B3ComponentProvider.java +++ b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/B3ComponentProvider.java @@ -30,7 +30,8 @@ public String getName() { } @Override - public TextMapPropagator create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public TextMapPropagator create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { return B3Propagator.injectingSingleHeader(); } } diff --git a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/B3MultiComponentProvider.java b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/B3MultiComponentProvider.java index db80f7193a6..b1abe9f7130 100644 --- a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/B3MultiComponentProvider.java +++ b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/B3MultiComponentProvider.java @@ -30,7 +30,8 @@ public String getName() { } @Override - public TextMapPropagator create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public TextMapPropagator create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { return B3Propagator.injectingMultiHeaders(); } } diff --git a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/JaegerComponentProvider.java b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/JaegerComponentProvider.java index c8cf66e50b1..147bc016d2e 100644 --- a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/JaegerComponentProvider.java +++ b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/JaegerComponentProvider.java @@ -29,7 +29,8 @@ public String getName() { } @Override - public TextMapPropagator create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public TextMapPropagator create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { return JaegerPropagator.getInstance(); } } diff --git a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/OtTraceComponentProvider.java b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/OtTraceComponentProvider.java index 5aa5c9c4491..c1e86d8e314 100644 --- a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/OtTraceComponentProvider.java +++ b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/OtTraceComponentProvider.java @@ -30,7 +30,8 @@ public String getName() { } @Override - public TextMapPropagator create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public TextMapPropagator create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { return OtTracePropagator.getInstance(); } } diff --git a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ComponentProvider.java b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ComponentProvider.java index 54dad8368ee..2c7137d1003 100644 --- a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ComponentProvider.java +++ b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ComponentProvider.java @@ -21,8 +21,8 @@ * configuration. * *

NOTE: when {@link #getType()} is {@link Resource}, the {@link #getName()} is not (currently) - * used, and {@link #create(DeclarativeConfigProperties, ComponentProviderLoader)} is (currently) called with an empty {@link - * DeclarativeConfigProperties}. + * used, and {@link #create(DeclarativeConfigProperties, ComponentProviderLoader)} is (currently) + * called with an empty {@link DeclarativeConfigProperties}. * *

This class is internal and is hence not for public use. Its APIs are unstable and can change * at any time. @@ -35,8 +35,8 @@ public interface ComponentProvider { /** - *

This class is internal and is hence not for public use. Its APIs are unstable and can change - * at any time. + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. */ interface ComponentProviderLoader { T loadComponent(Class type, String name, DeclarativeConfigProperties properties); diff --git a/sdk-extensions/jaeger-remote-sampler/src/main/java/io/opentelemetry/sdk/extension/trace/jaeger/sampler/internal/JaegerRemoteSamplerComponentProvider.java b/sdk-extensions/jaeger-remote-sampler/src/main/java/io/opentelemetry/sdk/extension/trace/jaeger/sampler/internal/JaegerRemoteSamplerComponentProvider.java index ae12831644e..4ce37d0d189 100644 --- a/sdk-extensions/jaeger-remote-sampler/src/main/java/io/opentelemetry/sdk/extension/trace/jaeger/sampler/internal/JaegerRemoteSamplerComponentProvider.java +++ b/sdk-extensions/jaeger-remote-sampler/src/main/java/io/opentelemetry/sdk/extension/trace/jaeger/sampler/internal/JaegerRemoteSamplerComponentProvider.java @@ -31,7 +31,8 @@ public String getName() { } @Override - public Sampler create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public Sampler create( + DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { JaegerRemoteSamplerBuilder builder = JaegerRemoteSampler.builder(); // Optional configuration From ebe9f14649bb8f1b0907176756d2a117544a0e65 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Wed, 27 Aug 2025 12:54:44 +0200 Subject: [PATCH 13/14] add exporter authenticator --- .../config/ComponentProviderLoader.java | 14 +++ .../config/DeclarativeConfigProperties.java | 4 + .../config/EmptyComponentProviderLoader.java | 22 +++++ ...outLogRecordExporterComponentProvider.java | 3 +- ...StdoutMetricExporterComponentProvider.java | 3 +- ...lpStdoutSpanExporterComponentProvider.java | 3 +- .../otlp/AbstractOtlpStdoutExporterTest.java | 2 +- ...oleLogRecordExporterComponentProvider.java | 3 +- ...onsoleMetricExporterComponentProvider.java | 3 +- .../ConsoleSpanExporterComponentProvider.java | 3 +- .../internal/OtlpDeclarativeConfigUtil.java | 7 +- ...rpcLogRecordExporterComponentProvider.java | 4 +- ...lpGrpcMetricExporterComponentProvider.java | 4 +- ...OtlpGrpcSpanExporterComponentProvider.java | 4 +- ...ttpLogRecordExporterComponentProvider.java | 4 +- ...lpHttpMetricExporterComponentProvider.java | 4 +- ...OtlpHttpSpanExporterComponentProvider.java | 4 +- .../internal/PrometheusComponentProvider.java | 3 +- .../ZipkinSpanExporterComponentProvider.java | 3 +- .../internal/B3ComponentProvider.java | 3 +- .../internal/B3MultiComponentProvider.java | 3 +- .../internal/JaegerComponentProvider.java | 3 +- .../internal/OtTraceComponentProvider.java | 3 +- .../spi/internal/ComponentProvider.java | 14 +-- .../fileconfig/DeclarativeConfigContext.java | 17 ++-- ...PropertiesWithComponentProviderLoader.java | 88 +++++++++++++++++++ .../fileconfig/ServiceResourceDetector.java | 3 +- .../YamlDeclarativeConfigProperties.java | 1 + .../LogRecordExporterFactoryTest.java | 11 ++- .../fileconfig/MetricExporterFactoryTest.java | 11 ++- .../ServiceResourceDetectorTest.java | 4 +- .../fileconfig/SpanExporterFactoryTest.java | 15 ++-- .../component/ContainerResourceProvider.java | 3 +- .../component/HostResourceProvider.java | 3 +- .../LogRecordExporterComponentProvider.java | 3 +- .../LogRecordProcessorComponentProvider.java | 3 +- .../MetricExporterComponentProvider.java | 3 +- .../component/OsResourceProvider.java | 3 +- .../component/ProcessResourceProvider.java | 3 +- .../component/ResourceComponentProvider.java | 3 +- .../ResourceFirstComponentProvider.java | 3 +- .../ResourceSecondComponentProvider.java | 3 +- .../component/SamplerComponentProvider.java | 3 +- .../SpanExporterComponentProvider.java | 3 +- .../SpanProcessorComponentProvider.java | 3 +- .../component/TestAuthComponentProvider.java | 3 +- .../TextMapPropagatorComponentProvider.java | 3 +- .../JaegerRemoteSamplerComponentProvider.java | 3 +- 48 files changed, 199 insertions(+), 122 deletions(-) create mode 100644 api/incubator/src/main/java/io/opentelemetry/api/incubator/config/ComponentProviderLoader.java create mode 100644 api/incubator/src/main/java/io/opentelemetry/api/incubator/config/EmptyComponentProviderLoader.java create mode 100644 sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigPropertiesWithComponentProviderLoader.java diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/config/ComponentProviderLoader.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/config/ComponentProviderLoader.java new file mode 100644 index 00000000000..cf68847fa20 --- /dev/null +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/config/ComponentProviderLoader.java @@ -0,0 +1,14 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.api.incubator.config; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +public interface ComponentProviderLoader { + T loadComponent(Class type, String name, DeclarativeConfigProperties properties); +} diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/config/DeclarativeConfigProperties.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/config/DeclarativeConfigProperties.java index cf98312c9e8..f92d33fe0fc 100644 --- a/api/incubator/src/main/java/io/opentelemetry/api/incubator/config/DeclarativeConfigProperties.java +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/config/DeclarativeConfigProperties.java @@ -232,4 +232,8 @@ default List getStructuredList( /** Return a {@link ComponentLoader} that should be used to load SPIs. */ ComponentLoader getComponentLoader(); + + default ComponentProviderLoader getComponentProviderLoader() { + return EmptyComponentProviderLoader.getInstance(); + } } diff --git a/api/incubator/src/main/java/io/opentelemetry/api/incubator/config/EmptyComponentProviderLoader.java b/api/incubator/src/main/java/io/opentelemetry/api/incubator/config/EmptyComponentProviderLoader.java new file mode 100644 index 00000000000..c1293168e13 --- /dev/null +++ b/api/incubator/src/main/java/io/opentelemetry/api/incubator/config/EmptyComponentProviderLoader.java @@ -0,0 +1,22 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.api.incubator.config; + +final class EmptyComponentProviderLoader implements ComponentProviderLoader { + + private static final EmptyComponentProviderLoader INSTANCE = new EmptyComponentProviderLoader(); + + EmptyComponentProviderLoader() {} + + static ComponentProviderLoader getInstance() { + return INSTANCE; + } + + @Override + public T loadComponent(Class type, String name, DeclarativeConfigProperties properties) { + throw new UnsupportedOperationException("Empty ComponentProviderLoader is not implemented"); + } +} diff --git a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporterComponentProvider.java b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporterComponentProvider.java index 13fd8834dd0..ee6fbfe66ba 100644 --- a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporterComponentProvider.java +++ b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/logs/OtlpStdoutLogRecordExporterComponentProvider.java @@ -30,8 +30,7 @@ public String getName() { } @Override - public LogRecordExporter create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public LogRecordExporter create(DeclarativeConfigProperties config) { OtlpStdoutLogRecordExporterBuilder builder = OtlpStdoutLogRecordExporter.builder(); IncubatingExporterBuilderUtil.configureExporterMemoryMode(config, builder::setMemoryMode); return builder.build(); diff --git a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/metrics/OtlpStdoutMetricExporterComponentProvider.java b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/metrics/OtlpStdoutMetricExporterComponentProvider.java index 8afebd889fd..70de404af14 100644 --- a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/metrics/OtlpStdoutMetricExporterComponentProvider.java +++ b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/metrics/OtlpStdoutMetricExporterComponentProvider.java @@ -30,8 +30,7 @@ public String getName() { } @Override - public MetricExporter create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public MetricExporter create(DeclarativeConfigProperties config) { OtlpStdoutMetricExporterBuilder builder = OtlpStdoutMetricExporter.builder(); IncubatingExporterBuilderUtil.configureExporterMemoryMode(config, builder::setMemoryMode); IncubatingExporterBuilderUtil.configureOtlpAggregationTemporality( diff --git a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/traces/OtlpStdoutSpanExporterComponentProvider.java b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/traces/OtlpStdoutSpanExporterComponentProvider.java index 48cb31a5023..e16ac868e3b 100644 --- a/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/traces/OtlpStdoutSpanExporterComponentProvider.java +++ b/exporters/logging-otlp/src/main/java/io/opentelemetry/exporter/logging/otlp/internal/traces/OtlpStdoutSpanExporterComponentProvider.java @@ -30,8 +30,7 @@ public String getName() { } @Override - public SpanExporter create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public SpanExporter create(DeclarativeConfigProperties config) { OtlpStdoutSpanExporterBuilder builder = OtlpStdoutSpanExporter.builder(); IncubatingExporterBuilderUtil.configureExporterMemoryMode(config, builder::setMemoryMode); return builder.build(); diff --git a/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/AbstractOtlpStdoutExporterTest.java b/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/AbstractOtlpStdoutExporterTest.java index 62edbe2de27..44b046aca42 100644 --- a/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/AbstractOtlpStdoutExporterTest.java +++ b/exporters/logging-otlp/src/test/java/io/opentelemetry/exporter/logging/otlp/AbstractOtlpStdoutExporterTest.java @@ -339,7 +339,7 @@ protected T exporterFromComponentProvider(DeclarativeConfigProperties properties }) .findFirst() .orElseThrow(() -> new IllegalStateException("No provider found")) - .create(properties, null); + .create(properties); } @SuppressWarnings("unchecked") diff --git a/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleLogRecordExporterComponentProvider.java b/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleLogRecordExporterComponentProvider.java index f3ddbff6017..2d8141cc4f2 100644 --- a/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleLogRecordExporterComponentProvider.java +++ b/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleLogRecordExporterComponentProvider.java @@ -30,8 +30,7 @@ public String getName() { } @Override - public LogRecordExporter create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public LogRecordExporter create(DeclarativeConfigProperties config) { return SystemOutLogRecordExporter.create(); } } diff --git a/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleMetricExporterComponentProvider.java b/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleMetricExporterComponentProvider.java index a62ad6b0dc1..6fab453403f 100644 --- a/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleMetricExporterComponentProvider.java +++ b/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleMetricExporterComponentProvider.java @@ -30,8 +30,7 @@ public String getName() { } @Override - public MetricExporter create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public MetricExporter create(DeclarativeConfigProperties config) { return LoggingMetricExporter.create(); } } diff --git a/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleSpanExporterComponentProvider.java b/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleSpanExporterComponentProvider.java index f97352e848b..fd65a5acad8 100644 --- a/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleSpanExporterComponentProvider.java +++ b/exporters/logging/src/main/java/io/opentelemetry/exporter/logging/internal/ConsoleSpanExporterComponentProvider.java @@ -29,8 +29,7 @@ public String getName() { } @Override - public SpanExporter create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public SpanExporter create(DeclarativeConfigProperties config) { return LoggingSpanExporter.create(); } } diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpDeclarativeConfigUtil.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpDeclarativeConfigUtil.java index f935f867e69..b827a9af13d 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpDeclarativeConfigUtil.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpDeclarativeConfigUtil.java @@ -16,7 +16,6 @@ import io.opentelemetry.exporter.internal.IncubatingExporterBuilderUtil; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; -import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import io.opentelemetry.sdk.common.export.MemoryMode; import io.opentelemetry.sdk.common.export.RetryPolicy; @@ -53,7 +52,6 @@ public static String getStructuredConfigOtlpProtocol(DeclarativeConfigProperties public static void configureOtlpExporterBuilder( String dataType, DeclarativeConfigProperties config, - ComponentProvider.ComponentProviderLoader componentProviderLoader, Consumer setComponentLoader, Consumer setEndpoint, BiConsumer addHeader, @@ -86,8 +84,9 @@ public static void configureOtlpExporterBuilder( String authenticatorName = propertyKeys.iterator().next(); ExporterAuthenticator exporterAuthenticator = - componentProviderLoader.loadComponent( - ExporterAuthenticator.class, authenticatorName, authenticator); + config + .getComponentProviderLoader() + .loadComponent(ExporterAuthenticator.class, authenticatorName, authenticator); setHeaders.accept(exporterAuthenticator::getAuthenticationHeaders); } diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcLogRecordExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcLogRecordExporterComponentProvider.java index 253dd0751aa..e65f24aeb2d 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcLogRecordExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcLogRecordExporterComponentProvider.java @@ -33,14 +33,12 @@ public String getName() { } @Override - public LogRecordExporter create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public LogRecordExporter create(DeclarativeConfigProperties config) { OtlpGrpcLogRecordExporterBuilder builder = grpcBuilder(); OtlpDeclarativeConfigUtil.configureOtlpExporterBuilder( DATA_TYPE_LOGS, config, - componentProviderLoader, builder::setComponentLoader, builder::setEndpoint, builder::addHeader, diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcMetricExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcMetricExporterComponentProvider.java index 327a6ee2555..5c51e9c9c4e 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcMetricExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcMetricExporterComponentProvider.java @@ -33,14 +33,12 @@ public String getName() { } @Override - public MetricExporter create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public MetricExporter create(DeclarativeConfigProperties config) { OtlpGrpcMetricExporterBuilder builder = grpcBuilder(); OtlpDeclarativeConfigUtil.configureOtlpExporterBuilder( DATA_TYPE_METRICS, config, - componentProviderLoader, builder::setComponentLoader, builder::setEndpoint, builder::addHeader, diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcSpanExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcSpanExporterComponentProvider.java index 93edc160d3a..13a92c62fe8 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcSpanExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpGrpcSpanExporterComponentProvider.java @@ -32,14 +32,12 @@ public String getName() { } @Override - public SpanExporter create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public SpanExporter create(DeclarativeConfigProperties config) { OtlpGrpcSpanExporterBuilder builder = grpcBuilder(); OtlpDeclarativeConfigUtil.configureOtlpExporterBuilder( DATA_TYPE_TRACES, config, - componentProviderLoader, builder::setComponentLoader, builder::setEndpoint, builder::addHeader, diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpLogRecordExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpLogRecordExporterComponentProvider.java index 3cc3cff410f..e75a784714e 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpLogRecordExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpLogRecordExporterComponentProvider.java @@ -33,14 +33,12 @@ public String getName() { } @Override - public LogRecordExporter create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public LogRecordExporter create(DeclarativeConfigProperties config) { OtlpHttpLogRecordExporterBuilder builder = httpBuilder(); OtlpDeclarativeConfigUtil.configureOtlpExporterBuilder( DATA_TYPE_LOGS, config, - componentProviderLoader, builder::setComponentLoader, builder::setEndpoint, builder::addHeader, diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpMetricExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpMetricExporterComponentProvider.java index 8bfd60edb9f..94c6c67253c 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpMetricExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpMetricExporterComponentProvider.java @@ -33,14 +33,12 @@ public String getName() { } @Override - public MetricExporter create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public MetricExporter create(DeclarativeConfigProperties config) { OtlpHttpMetricExporterBuilder builder = httpBuilder(); OtlpDeclarativeConfigUtil.configureOtlpExporterBuilder( DATA_TYPE_METRICS, config, - componentProviderLoader, builder::setComponentLoader, builder::setEndpoint, builder::addHeader, diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpSpanExporterComponentProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpSpanExporterComponentProvider.java index c619440b20f..911173a769d 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpSpanExporterComponentProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpHttpSpanExporterComponentProvider.java @@ -32,14 +32,12 @@ public String getName() { } @Override - public SpanExporter create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public SpanExporter create(DeclarativeConfigProperties config) { OtlpHttpSpanExporterBuilder builder = httpBuilder(); OtlpDeclarativeConfigUtil.configureOtlpExporterBuilder( DATA_TYPE_TRACES, config, - componentProviderLoader, builder::setComponentLoader, builder::setEndpoint, builder::addHeader, diff --git a/exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/internal/PrometheusComponentProvider.java b/exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/internal/PrometheusComponentProvider.java index 0280ae2f2eb..25d069db7a8 100644 --- a/exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/internal/PrometheusComponentProvider.java +++ b/exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/internal/PrometheusComponentProvider.java @@ -32,8 +32,7 @@ public String getName() { } @Override - public MetricReader create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public MetricReader create(DeclarativeConfigProperties config) { PrometheusHttpServerBuilder prometheusBuilder = PrometheusHttpServer.builder(); Integer port = config.getInt("port"); diff --git a/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/internal/ZipkinSpanExporterComponentProvider.java b/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/internal/ZipkinSpanExporterComponentProvider.java index 9faeb631d3f..42c43eef14a 100644 --- a/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/internal/ZipkinSpanExporterComponentProvider.java +++ b/exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/internal/ZipkinSpanExporterComponentProvider.java @@ -30,8 +30,7 @@ public String getName() { } @Override - public SpanExporter create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public SpanExporter create(DeclarativeConfigProperties config) { ZipkinSpanExporterBuilder builder = ZipkinSpanExporter.builder(); String endpoint = config.getString("endpoint"); diff --git a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/B3ComponentProvider.java b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/B3ComponentProvider.java index f600bb02c1e..ebd766640f9 100644 --- a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/B3ComponentProvider.java +++ b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/B3ComponentProvider.java @@ -30,8 +30,7 @@ public String getName() { } @Override - public TextMapPropagator create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public TextMapPropagator create(DeclarativeConfigProperties config) { return B3Propagator.injectingSingleHeader(); } } diff --git a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/B3MultiComponentProvider.java b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/B3MultiComponentProvider.java index b1abe9f7130..0fb223d81a7 100644 --- a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/B3MultiComponentProvider.java +++ b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/B3MultiComponentProvider.java @@ -30,8 +30,7 @@ public String getName() { } @Override - public TextMapPropagator create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public TextMapPropagator create(DeclarativeConfigProperties config) { return B3Propagator.injectingMultiHeaders(); } } diff --git a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/JaegerComponentProvider.java b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/JaegerComponentProvider.java index 147bc016d2e..1326dd4cc83 100644 --- a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/JaegerComponentProvider.java +++ b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/JaegerComponentProvider.java @@ -29,8 +29,7 @@ public String getName() { } @Override - public TextMapPropagator create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public TextMapPropagator create(DeclarativeConfigProperties config) { return JaegerPropagator.getInstance(); } } diff --git a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/OtTraceComponentProvider.java b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/OtTraceComponentProvider.java index c1e86d8e314..261eb5f8585 100644 --- a/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/OtTraceComponentProvider.java +++ b/extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/internal/OtTraceComponentProvider.java @@ -30,8 +30,7 @@ public String getName() { } @Override - public TextMapPropagator create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public TextMapPropagator create(DeclarativeConfigProperties config) { return OtTracePropagator.getInstance(); } } diff --git a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ComponentProvider.java b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ComponentProvider.java index 2c7137d1003..5772a0a1797 100644 --- a/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ComponentProvider.java +++ b/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ComponentProvider.java @@ -21,8 +21,8 @@ * configuration. * *

NOTE: when {@link #getType()} is {@link Resource}, the {@link #getName()} is not (currently) - * used, and {@link #create(DeclarativeConfigProperties, ComponentProviderLoader)} is (currently) - * called with an empty {@link DeclarativeConfigProperties}. + * used, and {@link #create(DeclarativeConfigProperties)} is (currently) called with an empty {@link + * DeclarativeConfigProperties}. * *

This class is internal and is hence not for public use. Its APIs are unstable and can change * at any time. @@ -34,14 +34,6 @@ */ public interface ComponentProvider { - /** - * This class is internal and is hence not for public use. Its APIs are unstable and can change at - * any time. - */ - interface ComponentProviderLoader { - T loadComponent(Class type, String name, DeclarativeConfigProperties properties); - } - /** * The type of SDK extension component. For example, if providing instances of a custom span * exporter, the type would be {@link SpanExporter}. @@ -67,5 +59,5 @@ interface ComponentProviderLoader { */ // TODO (jack-berg): consider dynamic configuration use case before stabilizing in case that // affects any API decisions - T create(DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader); + T create(DeclarativeConfigProperties config); } diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigContext.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigContext.java index a0391b9e35b..ffd7c2d3ea9 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigContext.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigContext.java @@ -42,19 +42,20 @@ List getCloseables() { /** * Find a registered {@link ComponentProvider} with {@link ComponentProvider#getType()} matching * {@code type}, {@link ComponentProvider#getName()} matching {@code name}, and call {@link - * ComponentProvider#create(DeclarativeConfigProperties, - * ComponentProvider.ComponentProviderLoader)} with the given {@code model}. + * ComponentProvider#create(DeclarativeConfigProperties)} with the given {@code model}. * * @throws DeclarativeConfigException if no matching providers are found, or if multiple are found - * (i.e. conflict), or if {@link ComponentProvider#create(DeclarativeConfigProperties, - * ComponentProvider.ComponentProviderLoader)} throws + * (i.e. conflict), or if {@link ComponentProvider#create(DeclarativeConfigProperties)} throws */ @SuppressWarnings({"unchecked", "rawtypes"}) T loadComponent(Class type, String name, Object model) { DeclarativeConfigProperties config = - model instanceof DeclarativeConfigProperties - ? (DeclarativeConfigProperties) model - : DeclarativeConfiguration.toConfigProperties(model, spiHelper.getComponentLoader()); + new DeclarativeConfigPropertiesWithComponentProviderLoader( + model instanceof DeclarativeConfigProperties + ? (DeclarativeConfigProperties) model + : DeclarativeConfiguration.toConfigProperties( + model, spiHelper.getComponentLoader()), + this::loadComponent); // TODO(jack-berg): cache loaded component providers List componentProviders = spiHelper.load(ComponentProvider.class); @@ -86,7 +87,7 @@ T loadComponent(Class type, String name, Object model) { ComponentProvider provider = (ComponentProvider) matchedProviders.get(0); try { - return provider.create(config, this::loadComponent); + return provider.create(config); } catch (Throwable throwable) { throw new DeclarativeConfigException( "Error configuring " + type.getName() + " with name \"" + name + "\"", throwable); diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigPropertiesWithComponentProviderLoader.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigPropertiesWithComponentProviderLoader.java new file mode 100644 index 00000000000..5ec30239ab7 --- /dev/null +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigPropertiesWithComponentProviderLoader.java @@ -0,0 +1,88 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.extension.incubator.fileconfig; + +import io.opentelemetry.api.incubator.config.ComponentProviderLoader; +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; +import io.opentelemetry.common.ComponentLoader; +import java.util.List; +import java.util.Set; +import javax.annotation.Nullable; + +class DeclarativeConfigPropertiesWithComponentProviderLoader + implements DeclarativeConfigProperties { + private final DeclarativeConfigProperties properties; + private final ComponentProviderLoader componentProviderLoader; + + DeclarativeConfigPropertiesWithComponentProviderLoader( + DeclarativeConfigProperties properties, ComponentProviderLoader componentProviderLoader) { + this.properties = properties; + this.componentProviderLoader = componentProviderLoader; + } + + @Nullable + @Override + public String getString(String name) { + return properties.getString(name); + } + + @Nullable + @Override + public Boolean getBoolean(String name) { + return properties.getBoolean(name); + } + + @Nullable + @Override + public Integer getInt(String name) { + return properties.getInt(name); + } + + @Nullable + @Override + public Long getLong(String name) { + return properties.getLong(name); + } + + @Nullable + @Override + public Double getDouble(String name) { + return properties.getDouble(name); + } + + @Nullable + @Override + public List getScalarList(String name, Class scalarType) { + return properties.getScalarList(name, scalarType); + } + + @Nullable + @Override + public DeclarativeConfigProperties getStructured(String name) { + return properties.getStructured(name); + } + + @Nullable + @Override + public List getStructuredList(String name) { + return properties.getStructuredList(name); + } + + @Override + public Set getPropertyKeys() { + return properties.getPropertyKeys(); + } + + @Override + public ComponentLoader getComponentLoader() { + return properties.getComponentLoader(); + } + + @Override + public ComponentProviderLoader getComponentProviderLoader() { + return componentProviderLoader; + } +} diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ServiceResourceDetector.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ServiceResourceDetector.java index 7f41ad253c6..dcaeeee2718 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ServiceResourceDetector.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ServiceResourceDetector.java @@ -35,8 +35,7 @@ public String getName() { } @Override - public Resource create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public Resource create(DeclarativeConfigProperties config) { ResourceBuilder builder = Resource.builder(); ConfigProperties properties = diff --git a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/YamlDeclarativeConfigProperties.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/YamlDeclarativeConfigProperties.java index 4be956af593..2ca7c3fd50a 100644 --- a/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/YamlDeclarativeConfigProperties.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/YamlDeclarativeConfigProperties.java @@ -106,6 +106,7 @@ public static YamlDeclarativeConfigProperties create( + "\" has unrecognized object type " + value.getClass().getName()); } + return new YamlDeclarativeConfigProperties( simpleEntries, listEntries, mapEntries, componentLoader); } 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 45c1f6aaf1e..c553d9d73dd 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 @@ -8,7 +8,6 @@ import static io.opentelemetry.sdk.extension.incubator.fileconfig.FileConfigTestUtil.createTempFileWithContent; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.verify; import com.google.common.collect.ImmutableMap; @@ -84,7 +83,7 @@ void create_OtlpHttpDefaults() { ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = componentProviderExtension.getComponentProvider("otlp_http", LogRecordExporter.class); - verify(componentProvider).create(configCaptor.capture(), any()); + verify(componentProvider).create(configCaptor.capture()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("protocol")).isNull(); assertThat(configProperties.getString("endpoint")).isNull(); @@ -153,7 +152,7 @@ void create_OtlpHttpConfigured(@TempDir Path tempDir) ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = componentProviderExtension.getComponentProvider("otlp_http", LogRecordExporter.class); - verify(componentProvider).create(configCaptor.capture(), any()); + verify(componentProvider).create(configCaptor.capture()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isEqualTo("http://example:4318/v1/logs"); List headers = configProperties.getStructuredList("headers"); @@ -197,7 +196,7 @@ void create_OtlpGrpcDefaults() { ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = componentProviderExtension.getComponentProvider("otlp_grpc", LogRecordExporter.class); - verify(componentProvider).create(configCaptor.capture(), any()); + verify(componentProvider).create(configCaptor.capture()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isNull(); assertThat(configProperties.getStructured("headers")).isNull(); @@ -265,7 +264,7 @@ void create_OtlpGrpcConfigured(@TempDir Path tempDir) ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = componentProviderExtension.getComponentProvider("otlp_grpc", LogRecordExporter.class); - verify(componentProvider).create(configCaptor.capture(), any()); + verify(componentProvider).create(configCaptor.capture()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isEqualTo("http://example:4317"); List headers = configProperties.getStructuredList("headers"); @@ -310,7 +309,7 @@ void create_OtlpFile() { ComponentProvider componentProvider = componentProviderExtension.getComponentProvider( "otlp_file/development", LogRecordExporter.class); - verify(componentProvider).create(configCaptor.capture(), any()); + verify(componentProvider).create(configCaptor.capture()); } @Test 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 f0a43688a43..6a8ebc14cde 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 @@ -8,7 +8,6 @@ import static io.opentelemetry.sdk.extension.incubator.fileconfig.FileConfigTestUtil.createTempFileWithContent; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.verify; import com.google.common.collect.ImmutableMap; @@ -89,7 +88,7 @@ void create_OtlpHttpDefaults() { ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = componentProviderExtension.getComponentProvider("otlp_http", MetricExporter.class); - verify(componentProvider).create(configCaptor.capture(), any()); + verify(componentProvider).create(configCaptor.capture()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("protocol")).isNull(); assertThat(configProperties.getString("endpoint")).isNull(); @@ -169,7 +168,7 @@ void create_OtlpHttpConfigured(@TempDir Path tempDir) ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = componentProviderExtension.getComponentProvider("otlp_http", MetricExporter.class); - verify(componentProvider).create(configCaptor.capture(), any()); + verify(componentProvider).create(configCaptor.capture()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isEqualTo("http://example:4318/v1/metrics"); List headers = configProperties.getStructuredList("headers"); @@ -215,7 +214,7 @@ void create_OtlpGrpcDefaults() { ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = componentProviderExtension.getComponentProvider("otlp_grpc", MetricExporter.class); - verify(componentProvider).create(configCaptor.capture(), any()); + verify(componentProvider).create(configCaptor.capture()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isNull(); assertThat(configProperties.getStructured("headers")).isNull(); @@ -294,7 +293,7 @@ void create_OtlpGrpcConfigured(@TempDir Path tempDir) ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = componentProviderExtension.getComponentProvider("otlp_grpc", MetricExporter.class); - verify(componentProvider).create(configCaptor.capture(), any()); + verify(componentProvider).create(configCaptor.capture()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isEqualTo("http://example:4317"); List headers = configProperties.getStructuredList("headers"); @@ -357,7 +356,7 @@ void create_OtlpFile() { ComponentProvider componentProvider = componentProviderExtension.getComponentProvider( "otlp_file/development", MetricExporter.class); - verify(componentProvider).create(configCaptor.capture(), any()); + verify(componentProvider).create(configCaptor.capture()); } @Test diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ServiceResourceDetectorTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ServiceResourceDetectorTest.java index e125ca615b9..4778fe1b614 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ServiceResourceDetectorTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/ServiceResourceDetectorTest.java @@ -32,7 +32,7 @@ void getTypeAndName() { void create_SystemPropertySet() { System.setProperty("otel.service.name", "test"); - assertThat(new ServiceResourceDetector().create(DeclarativeConfigProperties.empty(), null)) + assertThat(new ServiceResourceDetector().create(DeclarativeConfigProperties.empty())) .satisfies( resource -> { Attributes attributes = resource.getAttributes(); @@ -48,7 +48,7 @@ void create_SystemPropertySet() { @Test void create_NoSystemProperty() { - assertThat(new ServiceResourceDetector().create(DeclarativeConfigProperties.empty(), null)) + assertThat(new ServiceResourceDetector().create(DeclarativeConfigProperties.empty())) .satisfies( resource -> { Attributes attributes = resource.getAttributes(); 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 c0294138a45..eae5d25825c 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 @@ -8,7 +8,6 @@ import static io.opentelemetry.sdk.extension.incubator.fileconfig.FileConfigTestUtil.createTempFileWithContent; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.verify; import com.google.common.collect.ImmutableMap; @@ -85,7 +84,7 @@ void create_OtlpHttpDefaults() { ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = componentProviderExtension.getComponentProvider("otlp_http", SpanExporter.class); - verify(componentProvider).create(configCaptor.capture(), any()); + verify(componentProvider).create(configCaptor.capture()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("protocol")).isNull(); assertThat(configProperties.getString("endpoint")).isNull(); @@ -154,7 +153,7 @@ void create_OtlpHttpConfigured(@TempDir Path tempDir) ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = componentProviderExtension.getComponentProvider("otlp_http", SpanExporter.class); - verify(componentProvider).create(configCaptor.capture(), any()); + verify(componentProvider).create(configCaptor.capture()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isEqualTo("http://example:4318/v1/traces"); List headers = configProperties.getStructuredList("headers"); @@ -195,7 +194,7 @@ void create_OtlpGrpcDefaults() { ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = componentProviderExtension.getComponentProvider("otlp_grpc", SpanExporter.class); - verify(componentProvider).create(configCaptor.capture(), any()); + verify(componentProvider).create(configCaptor.capture()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isNull(); assertThat(configProperties.getStructured("headers")).isNull(); @@ -263,7 +262,7 @@ void create_OtlpGrpcConfigured(@TempDir Path tempDir) ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = componentProviderExtension.getComponentProvider("otlp_grpc", SpanExporter.class); - verify(componentProvider).create(configCaptor.capture(), any()); + verify(componentProvider).create(configCaptor.capture()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isEqualTo("http://example:4317"); List headers = configProperties.getStructuredList("headers"); @@ -320,7 +319,7 @@ void create_ZipkinDefaults() { ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = componentProviderExtension.getComponentProvider("zipkin", SpanExporter.class); - verify(componentProvider).create(configCaptor.capture(), any()); + verify(componentProvider).create(configCaptor.capture()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isNull(); assertThat(configProperties.getLong("timeout")).isNull(); @@ -354,7 +353,7 @@ void create_ZipkinConfigured() { ArgumentCaptor.forClass(DeclarativeConfigProperties.class); ComponentProvider componentProvider = componentProviderExtension.getComponentProvider("zipkin", SpanExporter.class); - verify(componentProvider).create(configCaptor.capture(), any()); + verify(componentProvider).create(configCaptor.capture()); DeclarativeConfigProperties configProperties = configCaptor.getValue(); assertThat(configProperties.getString("endpoint")).isEqualTo("http://zipkin:9411/v1/v2/spans"); assertThat(configProperties.getLong("timeout")).isEqualTo(15_000); @@ -382,7 +381,7 @@ void create_OtlpFile() { ComponentProvider componentProvider = componentProviderExtension.getComponentProvider( "otlp_file/development", SpanExporter.class); - verify(componentProvider).create(configCaptor.capture(), any()); + verify(componentProvider).create(configCaptor.capture()); } @Test diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ContainerResourceProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ContainerResourceProvider.java index 4e35830cb53..a5d3a331003 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ContainerResourceProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ContainerResourceProvider.java @@ -24,8 +24,7 @@ public String getName() { } @Override - public Resource create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public Resource create(DeclarativeConfigProperties config) { return Resource.empty(); } } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/HostResourceProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/HostResourceProvider.java index aeed627c000..bf8d978d9e6 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/HostResourceProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/HostResourceProvider.java @@ -24,8 +24,7 @@ public String getName() { } @Override - public Resource create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public Resource create(DeclarativeConfigProperties config) { return Resource.empty(); } } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/LogRecordExporterComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/LogRecordExporterComponentProvider.java index a5b8cb684c5..f21c1d1bf09 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/LogRecordExporterComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/LogRecordExporterComponentProvider.java @@ -24,8 +24,7 @@ public String getName() { } @Override - public LogRecordExporter create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public LogRecordExporter create(DeclarativeConfigProperties config) { return new TestLogRecordExporter(config); } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/LogRecordProcessorComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/LogRecordProcessorComponentProvider.java index 673576672a0..a44cd939c74 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/LogRecordProcessorComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/LogRecordProcessorComponentProvider.java @@ -24,8 +24,7 @@ public String getName() { } @Override - public LogRecordProcessor create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public LogRecordProcessor create(DeclarativeConfigProperties config) { return new TestLogRecordProcessor(config); } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/MetricExporterComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/MetricExporterComponentProvider.java index a23ad037d3d..80ea6b556ce 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/MetricExporterComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/MetricExporterComponentProvider.java @@ -27,8 +27,7 @@ public String getName() { } @Override - public MetricExporter create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public MetricExporter create(DeclarativeConfigProperties config) { return new TestMetricExporter(config); } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/OsResourceProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/OsResourceProvider.java index 2f2576f267b..04114fe43bb 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/OsResourceProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/OsResourceProvider.java @@ -24,8 +24,7 @@ public String getName() { } @Override - public Resource create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public Resource create(DeclarativeConfigProperties config) { return Resource.empty(); } } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ProcessResourceProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ProcessResourceProvider.java index cef408b2b98..06d02355f34 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ProcessResourceProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ProcessResourceProvider.java @@ -24,8 +24,7 @@ public String getName() { } @Override - public Resource create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public Resource create(DeclarativeConfigProperties config) { return Resource.empty(); } } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceComponentProvider.java index 1ed1006fbda..b5c9a6fd7a3 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceComponentProvider.java @@ -21,8 +21,7 @@ public String getName() { } @Override - public Resource create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public Resource create(DeclarativeConfigProperties config) { return Resource.builder().put("shape", "square").put("color", "red").build(); } } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceFirstComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceFirstComponentProvider.java index 2e1764b8e75..32381134e1b 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceFirstComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceFirstComponentProvider.java @@ -21,8 +21,7 @@ public String getName() { } @Override - public Resource create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public Resource create(DeclarativeConfigProperties config) { return Resource.builder().put("order", "first").build(); } } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceSecondComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceSecondComponentProvider.java index 6e7ee474e12..e77c6726717 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceSecondComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/ResourceSecondComponentProvider.java @@ -21,8 +21,7 @@ public String getName() { } @Override - public Resource create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public Resource create(DeclarativeConfigProperties config) { return Resource.builder().put("order", "second").build(); } } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SamplerComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SamplerComponentProvider.java index c1b141f0308..3264dd91fc7 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SamplerComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SamplerComponentProvider.java @@ -27,8 +27,7 @@ public String getName() { } @Override - public Sampler create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public Sampler create(DeclarativeConfigProperties config) { return new TestSampler(config); } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SpanExporterComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SpanExporterComponentProvider.java index d4bbf1ad266..ddaca3ca4b9 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SpanExporterComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SpanExporterComponentProvider.java @@ -24,8 +24,7 @@ public String getName() { } @Override - public SpanExporter create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public SpanExporter create(DeclarativeConfigProperties config) { return new TestSpanExporter(config); } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SpanProcessorComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SpanProcessorComponentProvider.java index 9ac02066136..3a1ddf9b13a 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SpanProcessorComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/SpanProcessorComponentProvider.java @@ -25,8 +25,7 @@ public String getName() { } @Override - public SpanProcessor create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public SpanProcessor create(DeclarativeConfigProperties config) { return new TestSpanProcessor(config); } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/TestAuthComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/TestAuthComponentProvider.java index 6068766c786..6ca909e91d5 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/TestAuthComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/TestAuthComponentProvider.java @@ -22,8 +22,7 @@ public String getName() { } @Override - public ExporterAuthenticator create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public ExporterAuthenticator create(DeclarativeConfigProperties config) { return () -> Collections.singletonMap("auth_provider_key1", "value1"); } } diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/TextMapPropagatorComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/TextMapPropagatorComponentProvider.java index 70a23412fc0..9c8e4e5ebbf 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/TextMapPropagatorComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/TextMapPropagatorComponentProvider.java @@ -27,8 +27,7 @@ public String getName() { } @Override - public TextMapPropagator create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public TextMapPropagator create(DeclarativeConfigProperties config) { return new TestTextMapPropagator(config); } diff --git a/sdk-extensions/jaeger-remote-sampler/src/main/java/io/opentelemetry/sdk/extension/trace/jaeger/sampler/internal/JaegerRemoteSamplerComponentProvider.java b/sdk-extensions/jaeger-remote-sampler/src/main/java/io/opentelemetry/sdk/extension/trace/jaeger/sampler/internal/JaegerRemoteSamplerComponentProvider.java index 4ce37d0d189..fd89f42cae9 100644 --- a/sdk-extensions/jaeger-remote-sampler/src/main/java/io/opentelemetry/sdk/extension/trace/jaeger/sampler/internal/JaegerRemoteSamplerComponentProvider.java +++ b/sdk-extensions/jaeger-remote-sampler/src/main/java/io/opentelemetry/sdk/extension/trace/jaeger/sampler/internal/JaegerRemoteSamplerComponentProvider.java @@ -31,8 +31,7 @@ public String getName() { } @Override - public Sampler create( - DeclarativeConfigProperties config, ComponentProviderLoader componentProviderLoader) { + public Sampler create(DeclarativeConfigProperties config) { JaegerRemoteSamplerBuilder builder = JaegerRemoteSampler.builder(); // Optional configuration From 8e150348ec92337dc251eab22774914ba1ade577 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Wed, 27 Aug 2025 16:48:20 +0200 Subject: [PATCH 14/14] fix --- .../DeclarativeConfigurationParseTest.java | 12 ++++++++++++ .../fileconfig/LogRecordExporterFactoryTest.java | 6 ++++-- .../fileconfig/MetricExporterFactoryTest.java | 6 ++++-- .../fileconfig/SpanExporterFactoryTest.java | 6 ++++-- .../component/TestAuthComponentProvider.java | 2 +- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigurationParseTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigurationParseTest.java index 18284627324..9c662f55905 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigurationParseTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigurationParseTest.java @@ -14,6 +14,7 @@ import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.AlwaysOnSamplerModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.AttributeLimitsModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.AttributeNameValueModel; +import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.AuthenticatorModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.B3MultiPropagatorModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.B3PropagatorModel; import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.BaggagePropagatorModel; @@ -237,6 +238,11 @@ void parse_KitchenSinkExampleFile() throws IOException { .withConfig(new ExperimentalTracerConfigModel().withDisabled(false)))); tracerProvider.withTracerConfiguratorDevelopment(tracerConfigurator); + Map authAttributes = new HashMap<>(); + authAttributes.put("tenant", "foo"); + authAttributes.put("region", "bar"); + AuthenticatorModel authenticator = + new AuthenticatorModel().withAdditionalProperty("rainy_cloud", authAttributes); SpanProcessorModel spanProcessor1 = new SpanProcessorModel() .withBatch( @@ -259,6 +265,7 @@ void parse_KitchenSinkExampleFile() throws IOException { .withName("api-key") .withValue("1234"))) .withHeadersList("api-key=1234") + .withAuthenticator(authenticator) .withCompression("gzip") .withTimeout(10_000) .withEncoding( @@ -281,6 +288,7 @@ void parse_KitchenSinkExampleFile() throws IOException { .withName("api-key") .withValue("1234"))) .withHeadersList("api-key=1234") + .withAuthenticator(authenticator) .withCompression("gzip") .withTimeout(10_000) .withInsecure(false)))); @@ -368,6 +376,7 @@ void parse_KitchenSinkExampleFile() throws IOException { .withName("api-key") .withValue("1234"))) .withHeadersList("api-key=1234") + .withAuthenticator(authenticator) .withCompression("gzip") .withTimeout(10_000) .withEncoding( @@ -390,6 +399,7 @@ void parse_KitchenSinkExampleFile() throws IOException { .withName("api-key") .withValue("1234"))) .withHeadersList("api-key=1234") + .withAuthenticator(authenticator) .withCompression("gzip") .withTimeout(10_000) .withInsecure(false)))); @@ -483,6 +493,7 @@ void parse_KitchenSinkExampleFile() throws IOException { .withName("api-key") .withValue("1234"))) .withHeadersList("api-key=1234") + .withAuthenticator(authenticator) .withCompression("gzip") .withTimeout(10_000) .withEncoding(OtlpHttpExporterModel.OtlpHttpEncoding.PROTOBUF) @@ -524,6 +535,7 @@ void parse_KitchenSinkExampleFile() throws IOException { .withName("api-key") .withValue("1234"))) .withHeadersList("api-key=1234") + .withAuthenticator(authenticator) .withCompression("gzip") .withTimeout(10_000) .withInsecure(false) 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 c553d9d73dd..4c4e8d44193 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 @@ -136,7 +136,8 @@ void create_OtlpHttpConfigured(@TempDir Path tempDir) .withName("key2") .withValue("value2"))) .withAuthenticator( - new AuthenticatorModel().withAdditionalProperty("test_auth", null)) + new AuthenticatorModel() + .withAdditionalProperty("rainy_cloud", null)) .withCompression("gzip") .withTimeout(15_000) .withCertificateFile(certificatePath) @@ -248,7 +249,8 @@ void create_OtlpGrpcConfigured(@TempDir Path tempDir) .withName("key2") .withValue("value2"))) .withAuthenticator( - new AuthenticatorModel().withAdditionalProperty("test_auth", null)) + new AuthenticatorModel() + .withAdditionalProperty("rainy_cloud", null)) .withCompression("gzip") .withTimeout(15_000) .withCertificateFile(certificatePath) 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 6a8ebc14cde..2d983090060 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 @@ -147,7 +147,8 @@ void create_OtlpHttpConfigured(@TempDir Path tempDir) .withName("key2") .withValue("value2"))) .withAuthenticator( - new AuthenticatorModel().withAdditionalProperty("test_auth", null)) + new AuthenticatorModel() + .withAdditionalProperty("rainy_cloud", null)) .withCompression("gzip") .withTimeout(15_000) .withCertificateFile(certificatePath) @@ -272,7 +273,8 @@ void create_OtlpGrpcConfigured(@TempDir Path tempDir) .withName("key2") .withValue("value2"))) .withAuthenticator( - new AuthenticatorModel().withAdditionalProperty("test_auth", null)) + new AuthenticatorModel() + .withAdditionalProperty("rainy_cloud", null)) .withCompression("gzip") .withTimeout(15_000) .withCertificateFile(certificatePath) 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 eae5d25825c..4e96fe42dfe 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 @@ -137,7 +137,8 @@ void create_OtlpHttpConfigured(@TempDir Path tempDir) .withName("key2") .withValue("value2"))) .withAuthenticator( - new AuthenticatorModel().withAdditionalProperty("test_auth", null)) + new AuthenticatorModel() + .withAdditionalProperty("rainy_cloud", null)) .withCompression("gzip") .withTimeout(15_000) .withCertificateFile(certificatePath) @@ -246,7 +247,8 @@ void create_OtlpGrpcConfigured(@TempDir Path tempDir) .withName("key2") .withValue("value2"))) .withAuthenticator( - new AuthenticatorModel().withAdditionalProperty("test_auth", null)) + new AuthenticatorModel() + .withAdditionalProperty("rainy_cloud", null)) .withCompression("gzip") .withTimeout(15_000) .withCertificateFile(certificatePath) diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/TestAuthComponentProvider.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/TestAuthComponentProvider.java index 6ca909e91d5..c540be42a4b 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/TestAuthComponentProvider.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component/TestAuthComponentProvider.java @@ -18,7 +18,7 @@ public Class getType() { @Override public String getName() { - return "test_auth"; + return "rainy_cloud"; } @Override