From 1b7588dd37dd947bda249583a7a390542686f87d Mon Sep 17 00:00:00 2001 From: Jack Berg Date: Wed, 30 Nov 2022 14:55:51 -0600 Subject: [PATCH 1/3] Implement otlp exporter providers --- exporters/otlp/all/build.gradle.kts | 1 + .../internal/OtlpMetricExporterProvider.java | 82 ++++++++++++ .../internal/OtlpSpanExporterProvider.java | 73 ++++++++++ ...metrics.ConfigurableMetricExporterProvider | 1 + ...pi.traces.ConfigurableSpanExporterProvider | 1 + exporters/otlp/common/build.gradle.kts | 2 + .../internal/otlp}/OtlpConfigUtil.java | 54 +++++--- .../internal/otlp}/OtlpConfigUtilTest.java | 14 +- exporters/otlp/logs/build.gradle.kts | 1 + .../OtlpLogRecordExporterProvider.java | 74 ++++++++++ ...logs.ConfigurableLogRecordExporterProvider | 1 + sdk-extensions/autoconfigure/build.gradle.kts | 11 +- .../LogRecordExporterConfiguration.java | 120 +++-------------- .../LoggerProviderConfiguration.java | 3 +- .../MeterProviderConfiguration.java | 2 +- .../MetricExporterConfiguration.java | 126 +++++------------- .../SpanExporterConfiguration.java | 61 +-------- .../LogRecordExporterConfigurationTest.java | 16 --- .../sdk/autoconfigure/NotOnClasspathTest.java | 122 +++++------------ .../ConfigurableLogRecordExporterTest.java | 17 +-- .../ConfigurableMetricExporterTest.java | 26 ++-- .../MetricExporterConfigurationTest.java | 9 +- .../SpanExporterConfigurationTest.java | 29 ++-- .../sdk/autoconfigure/OtlpGrpcConfigTest.java | 90 ++++++++++--- .../sdk/autoconfigure/OtlpGrpcRetryTest.java | 21 ++- .../sdk/autoconfigure/OtlpHttpConfigTest.java | 91 ++++++++++--- .../sdk/autoconfigure/OtlpHttpRetryTest.java | 21 ++- 27 files changed, 585 insertions(+), 484 deletions(-) create mode 100644 exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpMetricExporterProvider.java create mode 100644 exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpSpanExporterProvider.java create mode 100644 exporters/otlp/all/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider create mode 100644 exporters/otlp/all/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider rename {sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure => exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp}/OtlpConfigUtil.java (85%) rename {sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure => exporters/otlp/common/src/test/java/io/opentelemetry/exporter/internal/otlp}/OtlpConfigUtilTest.java (96%) create mode 100644 exporters/otlp/logs/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpLogRecordExporterProvider.java create mode 100644 exporters/otlp/logs/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.logs.ConfigurableLogRecordExporterProvider diff --git a/exporters/otlp/all/build.gradle.kts b/exporters/otlp/all/build.gradle.kts index 35fb7695015..e3529c57ca9 100644 --- a/exporters/otlp/all/build.gradle.kts +++ b/exporters/otlp/all/build.gradle.kts @@ -15,6 +15,7 @@ dependencies { api(project(":sdk:metrics")) implementation(project(":exporters:otlp:common")) + implementation(project(":sdk-extensions:autoconfigure-spi")) compileOnly("io.grpc:grpc-stub") diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpMetricExporterProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpMetricExporterProvider.java new file mode 100644 index 00000000000..8cdfb47dc2e --- /dev/null +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpMetricExporterProvider.java @@ -0,0 +1,82 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.exporter.otlp.internal; + +import static io.opentelemetry.exporter.internal.otlp.OtlpConfigUtil.DATA_TYPE_METRICS; +import static io.opentelemetry.exporter.internal.otlp.OtlpConfigUtil.PROTOCOL_GRPC; +import static io.opentelemetry.exporter.internal.otlp.OtlpConfigUtil.PROTOCOL_HTTP_PROTOBUF; + +import io.opentelemetry.exporter.internal.otlp.OtlpConfigUtil; +import io.opentelemetry.exporter.internal.retry.RetryUtil; +import io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporter; +import io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporterBuilder; +import io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter; +import io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporterBuilder; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; +import io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider; +import io.opentelemetry.sdk.metrics.export.MetricExporter; + +/** + * {@link MetricExporter} SPI implementation for {@link OtlpGrpcMetricExporter} and {@link + * OtlpHttpMetricExporter}. + * + *

This class is internal and is hence not for public use. Its APIs are unstable and can change + * at any time. + */ +public class OtlpMetricExporterProvider implements ConfigurableMetricExporterProvider { + @Override + public MetricExporter createExporter(ConfigProperties config) { + String protocol = OtlpConfigUtil.getOtlpProtocol(DATA_TYPE_METRICS, config); + + if (protocol.equals(PROTOCOL_HTTP_PROTOBUF)) { + OtlpHttpMetricExporterBuilder builder = OtlpHttpMetricExporter.builder(); + + OtlpConfigUtil.configureOtlpExporterBuilder( + DATA_TYPE_METRICS, + config, + builder::setEndpoint, + builder::addHeader, + builder::setCompression, + builder::setTimeout, + builder::setTrustedCertificates, + builder::setClientTls, + retryPolicy -> RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy)); + OtlpConfigUtil.configureOtlpAggregationTemporality( + config, builder::setAggregationTemporalitySelector); + OtlpConfigUtil.configureOtlpHistogramDefaultAggregation( + config, builder::setDefaultAggregationSelector); + + return builder.build(); + } else if (protocol.equals(PROTOCOL_GRPC)) { + OtlpGrpcMetricExporterBuilder builder = OtlpGrpcMetricExporter.builder(); + + OtlpConfigUtil.configureOtlpExporterBuilder( + DATA_TYPE_METRICS, + config, + builder::setEndpoint, + builder::addHeader, + builder::setCompression, + builder::setTimeout, + builder::setTrustedCertificates, + builder::setClientTls, + retryPolicy -> RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy)); + OtlpConfigUtil.configureOtlpAggregationTemporality( + config, builder::setAggregationTemporalitySelector); + OtlpConfigUtil.configureOtlpHistogramDefaultAggregation( + config, builder::setDefaultAggregationSelector); + + return builder.build(); + } else { + throw new ConfigurationException("Unsupported OTLP metrics protocol: " + protocol); + } + } + + @Override + public String getName() { + return "otlp"; + } +} diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpSpanExporterProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpSpanExporterProvider.java new file mode 100644 index 00000000000..2917edd4820 --- /dev/null +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpSpanExporterProvider.java @@ -0,0 +1,73 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.exporter.otlp.internal; + +import static io.opentelemetry.exporter.internal.otlp.OtlpConfigUtil.DATA_TYPE_TRACES; +import static io.opentelemetry.exporter.internal.otlp.OtlpConfigUtil.PROTOCOL_GRPC; +import static io.opentelemetry.exporter.internal.otlp.OtlpConfigUtil.PROTOCOL_HTTP_PROTOBUF; + +import io.opentelemetry.exporter.internal.otlp.OtlpConfigUtil; +import io.opentelemetry.exporter.internal.retry.RetryUtil; +import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter; +import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder; +import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter; +import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; +import io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider; +import io.opentelemetry.sdk.trace.export.SpanExporter; + +/** + * {@link SpanExporter} SPI implementation for {@link OtlpGrpcSpanExporter} and {@link + * OtlpHttpSpanExporter}. + * + *

This class is internal and is hence not for public use. Its APIs are unstable and can change + * at any time. + */ +public class OtlpSpanExporterProvider implements ConfigurableSpanExporterProvider { + @Override + public SpanExporter createExporter(ConfigProperties config) { + String protocol = OtlpConfigUtil.getOtlpProtocol(DATA_TYPE_TRACES, config); + if (protocol.equals(PROTOCOL_HTTP_PROTOBUF)) { + OtlpHttpSpanExporterBuilder builder = OtlpHttpSpanExporter.builder(); + + OtlpConfigUtil.configureOtlpExporterBuilder( + DATA_TYPE_TRACES, + config, + builder::setEndpoint, + builder::addHeader, + builder::setCompression, + builder::setTimeout, + builder::setTrustedCertificates, + builder::setClientTls, + retryPolicy -> RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy)); + + return builder.build(); + } else if (protocol.equals(PROTOCOL_GRPC)) { + OtlpGrpcSpanExporterBuilder builder = OtlpGrpcSpanExporter.builder(); + + OtlpConfigUtil.configureOtlpExporterBuilder( + DATA_TYPE_TRACES, + config, + builder::setEndpoint, + builder::addHeader, + builder::setCompression, + builder::setTimeout, + builder::setTrustedCertificates, + builder::setClientTls, + retryPolicy -> RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy)); + + return builder.build(); + } else { + throw new ConfigurationException("Unsupported OTLP traces protocol: " + protocol); + } + } + + @Override + public String getName() { + return "otlp"; + } +} diff --git a/exporters/otlp/all/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider b/exporters/otlp/all/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider new file mode 100644 index 00000000000..93d8d0ee99a --- /dev/null +++ b/exporters/otlp/all/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider @@ -0,0 +1 @@ +io.opentelemetry.exporter.otlp.internal.OtlpMetricExporterProvider diff --git a/exporters/otlp/all/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider b/exporters/otlp/all/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider new file mode 100644 index 00000000000..29112b59867 --- /dev/null +++ b/exporters/otlp/all/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider @@ -0,0 +1 @@ +io.opentelemetry.exporter.otlp.internal.OtlpSpanExporterProvider diff --git a/exporters/otlp/common/build.gradle.kts b/exporters/otlp/common/build.gradle.kts index d85d2688789..9d7a7c7ce4b 100644 --- a/exporters/otlp/common/build.gradle.kts +++ b/exporters/otlp/common/build.gradle.kts @@ -17,6 +17,8 @@ dependencies { api(project(":exporters:common")) + implementation(project(":sdk-extensions:autoconfigure-spi")) + compileOnly(project(":sdk:metrics")) compileOnly(project(":sdk:trace")) compileOnly(project(":sdk:logs")) diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/OtlpConfigUtil.java b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/OtlpConfigUtil.java similarity index 85% rename from sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/OtlpConfigUtil.java rename to exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/OtlpConfigUtil.java index 6fd8e1d7fb7..979bc57d825 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/OtlpConfigUtil.java +++ b/exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/OtlpConfigUtil.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.sdk.autoconfigure; +package io.opentelemetry.exporter.internal.otlp; import io.opentelemetry.exporter.internal.retry.RetryPolicy; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; @@ -13,28 +13,32 @@ import io.opentelemetry.sdk.metrics.export.AggregationTemporalitySelector; import io.opentelemetry.sdk.metrics.export.DefaultAggregationSelector; import io.opentelemetry.sdk.metrics.internal.view.ExponentialHistogramAggregation; +import java.io.File; import java.io.IOException; +import java.io.RandomAccessFile; import java.net.MalformedURLException; import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; import java.time.Duration; import java.util.Map; import java.util.function.BiConsumer; import java.util.function.Consumer; import javax.annotation.Nullable; -final class OtlpConfigUtil { +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +public final class OtlpConfigUtil { - static final String DATA_TYPE_TRACES = "traces"; - static final String DATA_TYPE_METRICS = "metrics"; - static final String DATA_TYPE_LOGS = "logs"; + public static final String DATA_TYPE_TRACES = "traces"; + public static final String DATA_TYPE_METRICS = "metrics"; + public static final String DATA_TYPE_LOGS = "logs"; - static final String PROTOCOL_GRPC = "grpc"; - static final String PROTOCOL_HTTP_PROTOBUF = "http/protobuf"; + public static final String PROTOCOL_GRPC = "grpc"; + public static final String PROTOCOL_HTTP_PROTOBUF = "http/protobuf"; - static String getOtlpProtocol(String dataType, ConfigProperties config) { + /** Determine the configured OTLP protocol for the {@code dataType}. */ + public static String getOtlpProtocol(String dataType, ConfigProperties config) { String protocol = config.getString("otel.exporter.otlp." + dataType + ".protocol"); if (protocol != null) { return protocol; @@ -42,7 +46,8 @@ static String getOtlpProtocol(String dataType, ConfigProperties config) { return config.getString("otel.exporter.otlp.protocol", PROTOCOL_GRPC); } - static void configureOtlpExporterBuilder( + /** Invoke the setters with the OTLP configuration for the {@code dataType}. */ + public static void configureOtlpExporterBuilder( String dataType, ConfigProperties config, Consumer setEndpoint, @@ -133,7 +138,11 @@ static void configureOtlpExporterBuilder( } } - static void configureOtlpAggregationTemporality( + /** + * Invoke the {@code aggregationTemporalitySelectorConsumer} with the configured {@link + * AggregationTemporality}. + */ + public static void configureOtlpAggregationTemporality( ConfigProperties config, Consumer aggregationTemporalitySelectorConsumer) { String temporalityStr = config.getString("otel.exporter.otlp.metrics.temporality.preference"); @@ -154,7 +163,11 @@ static void configureOtlpAggregationTemporality( aggregationTemporalitySelectorConsumer.accept(temporalitySelector); } - static void configureOtlpHistogramDefaultAggregation( + /** + * Invoke the {@code defaultAggregationSelectorConsumer} with the configured {@link + * DefaultAggregationSelector}. + */ + public static void configureOtlpHistogramDefaultAggregation( ConfigProperties config, Consumer defaultAggregationSelectorConsumer) { String defaultHistogramAggregation = @@ -215,14 +228,17 @@ private static byte[] readFileBytes(@Nullable String filePath) { if (filePath == null) { return null; } - Path path = Paths.get(filePath); - if (!Files.exists(path)) { - throw new ConfigurationException("Invalid OTLP certificate/key path: " + path); + File file = new File(filePath); + if (!file.exists()) { + throw new ConfigurationException("Invalid OTLP certificate/key path: " + filePath); } try { - return Files.readAllBytes(path); + RandomAccessFile raf = new RandomAccessFile(file, "r"); + byte[] bytes = new byte[(int) raf.length()]; + raf.readFully(bytes); + return bytes; } catch (IOException e) { - throw new ConfigurationException("Error reading content of file (" + path + ")", e); + throw new ConfigurationException("Error reading content of file (" + filePath + ")", e); } } diff --git a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/OtlpConfigUtilTest.java b/exporters/otlp/common/src/test/java/io/opentelemetry/exporter/internal/otlp/OtlpConfigUtilTest.java similarity index 96% rename from sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/OtlpConfigUtilTest.java rename to exporters/otlp/common/src/test/java/io/opentelemetry/exporter/internal/otlp/OtlpConfigUtilTest.java index de795f50e08..b4f93f7a87b 100644 --- a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/OtlpConfigUtilTest.java +++ b/exporters/otlp/common/src/test/java/io/opentelemetry/exporter/internal/otlp/OtlpConfigUtilTest.java @@ -3,14 +3,14 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.sdk.autoconfigure; +package io.opentelemetry.exporter.internal.otlp; -import static io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.DATA_TYPE_LOGS; -import static io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.DATA_TYPE_METRICS; -import static io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.DATA_TYPE_TRACES; -import static io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.PROTOCOL_GRPC; -import static io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.PROTOCOL_HTTP_PROTOBUF; -import static org.assertj.core.api.Assertions.assertThat; +import static io.opentelemetry.exporter.internal.otlp.OtlpConfigUtil.DATA_TYPE_LOGS; +import static io.opentelemetry.exporter.internal.otlp.OtlpConfigUtil.DATA_TYPE_METRICS; +import static io.opentelemetry.exporter.internal.otlp.OtlpConfigUtil.DATA_TYPE_TRACES; +import static io.opentelemetry.exporter.internal.otlp.OtlpConfigUtil.PROTOCOL_GRPC; +import static io.opentelemetry.exporter.internal.otlp.OtlpConfigUtil.PROTOCOL_HTTP_PROTOBUF; +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatThrownBy; diff --git a/exporters/otlp/logs/build.gradle.kts b/exporters/otlp/logs/build.gradle.kts index 000b8e5da3e..2f33efe34d7 100644 --- a/exporters/otlp/logs/build.gradle.kts +++ b/exporters/otlp/logs/build.gradle.kts @@ -12,6 +12,7 @@ dependencies { api(project(":sdk:logs")) implementation(project(":exporters:otlp:common")) + implementation(project(":sdk-extensions:autoconfigure-spi")) compileOnly("io.grpc:grpc-stub") diff --git a/exporters/otlp/logs/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpLogRecordExporterProvider.java b/exporters/otlp/logs/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpLogRecordExporterProvider.java new file mode 100644 index 00000000000..961166f79f3 --- /dev/null +++ b/exporters/otlp/logs/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpLogRecordExporterProvider.java @@ -0,0 +1,74 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.exporter.otlp.internal; + +import static io.opentelemetry.exporter.internal.otlp.OtlpConfigUtil.DATA_TYPE_LOGS; +import static io.opentelemetry.exporter.internal.otlp.OtlpConfigUtil.PROTOCOL_GRPC; +import static io.opentelemetry.exporter.internal.otlp.OtlpConfigUtil.PROTOCOL_HTTP_PROTOBUF; + +import io.opentelemetry.exporter.internal.otlp.OtlpConfigUtil; +import io.opentelemetry.exporter.internal.retry.RetryUtil; +import io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporter; +import io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporterBuilder; +import io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporter; +import io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporterBuilder; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; +import io.opentelemetry.sdk.autoconfigure.spi.logs.ConfigurableLogRecordExporterProvider; +import io.opentelemetry.sdk.logs.export.LogRecordExporter; + +/** + * {@link LogRecordExporter} SPI implementation for {@link OtlpGrpcLogRecordExporter} and {@link + * OtlpHttpLogRecordExporter}. + * + *

This class is internal and is hence not for public use. Its APIs are unstable and can change + * at any time. + */ +public class OtlpLogRecordExporterProvider implements ConfigurableLogRecordExporterProvider { + @Override + public LogRecordExporter createExporter(ConfigProperties config) { + String protocol = OtlpConfigUtil.getOtlpProtocol(DATA_TYPE_LOGS, config); + + if (protocol.equals(PROTOCOL_HTTP_PROTOBUF)) { + OtlpHttpLogRecordExporterBuilder builder = OtlpHttpLogRecordExporter.builder(); + + OtlpConfigUtil.configureOtlpExporterBuilder( + DATA_TYPE_LOGS, + config, + builder::setEndpoint, + builder::addHeader, + builder::setCompression, + builder::setTimeout, + builder::setTrustedCertificates, + builder::setClientTls, + retryPolicy -> RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy)); + + return builder.build(); + } else if (protocol.equals(PROTOCOL_GRPC)) { + OtlpGrpcLogRecordExporterBuilder builder = OtlpGrpcLogRecordExporter.builder(); + + OtlpConfigUtil.configureOtlpExporterBuilder( + DATA_TYPE_LOGS, + config, + builder::setEndpoint, + builder::addHeader, + builder::setCompression, + builder::setTimeout, + builder::setTrustedCertificates, + builder::setClientTls, + retryPolicy -> RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy)); + + return builder.build(); + } else { + throw new ConfigurationException("Unsupported OTLP logs protocol: " + protocol); + } + } + + @Override + public String getName() { + return "otlp"; + } +} diff --git a/exporters/otlp/logs/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.logs.ConfigurableLogRecordExporterProvider b/exporters/otlp/logs/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.logs.ConfigurableLogRecordExporterProvider new file mode 100644 index 00000000000..d789ed482c7 --- /dev/null +++ b/exporters/otlp/logs/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.logs.ConfigurableLogRecordExporterProvider @@ -0,0 +1 @@ +io.opentelemetry.exporter.otlp.internal.OtlpLogRecordExporterProvider diff --git a/sdk-extensions/autoconfigure/build.gradle.kts b/sdk-extensions/autoconfigure/build.gradle.kts index 984dd1ae24c..0a331f58783 100644 --- a/sdk-extensions/autoconfigure/build.gradle.kts +++ b/sdk-extensions/autoconfigure/build.gradle.kts @@ -13,24 +13,17 @@ dependencies { api(project(":sdk-extensions:autoconfigure-spi")) implementation(project(":semconv")) - implementation(project(":exporters:common")) compileOnly(project(":exporters:jaeger")) - compileOnly(project(":exporters:otlp:all")) - compileOnly(project(":exporters:otlp:logs")) - compileOnly(project(":exporters:otlp:common")) compileOnly(project(":exporters:prometheus")) annotationProcessor("com.google.auto.value:auto-value") testImplementation(project(":sdk:trace-shaded-deps")) - testImplementation(project(":sdk:testing")) - testImplementation("com.linecorp.armeria:armeria-junit5") - testImplementation("com.linecorp.armeria:armeria-grpc") + + testImplementation("com.google.guava:guava") testImplementation("edu.berkeley.cs.jqf:jqf-fuzz") - testRuntimeOnly("io.grpc:grpc-netty-shaded") - testImplementation("io.opentelemetry.proto:opentelemetry-proto") } testing { diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfiguration.java index 0d7a38b3097..f00a56bbb2e 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfiguration.java @@ -5,16 +5,6 @@ package io.opentelemetry.sdk.autoconfigure; -import static io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.DATA_TYPE_LOGS; -import static io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.PROTOCOL_GRPC; -import static io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.PROTOCOL_HTTP_PROTOBUF; - -import io.opentelemetry.api.metrics.MeterProvider; -import io.opentelemetry.exporter.internal.retry.RetryUtil; -import io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporter; -import io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporterBuilder; -import io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporter; -import io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporterBuilder; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; @@ -25,7 +15,6 @@ import java.util.Map; import java.util.Set; import java.util.function.BiFunction; -import javax.annotation.Nullable; class LogRecordExporterConfiguration { @@ -36,13 +25,13 @@ class LogRecordExporterConfiguration { EXPORTER_ARTIFACT_ID_BY_NAME = new HashMap<>(); EXPORTER_ARTIFACT_ID_BY_NAME.put("logging", "opentelemetry-exporter-logging"); EXPORTER_ARTIFACT_ID_BY_NAME.put("logging-otlp", "opentelemetry-exporter-logging-otlp"); + EXPORTER_ARTIFACT_ID_BY_NAME.put("otlp", "opentelemetry-exporter-otlp"); } // Visible for test static Map configureLogRecordExporters( ConfigProperties config, ClassLoader serviceClassLoader, - MeterProvider meterProvider, BiFunction logRecordExporterCustomizer) { Set exporterNames = DefaultConfigProperties.getSet(config, "otel.logs.exporter"); @@ -65,13 +54,10 @@ static Map configureLogRecordExporters( Map exportersByName = new HashMap<>(); for (String name : exporterNames) { - LogRecordExporter logRecordExporter = - configureExporter(name, config, spiExportersManager, meterProvider); - if (logRecordExporter != null) { - LogRecordExporter customizedLogRecordExporter = - logRecordExporterCustomizer.apply(logRecordExporter, config); - exportersByName.put(name, customizedLogRecordExporter); - } + LogRecordExporter logRecordExporter = configureExporter(name, spiExportersManager); + LogRecordExporter customizedLogRecordExporter = + logRecordExporterCustomizer.apply(logRecordExporter, config); + exportersByName.put(name, customizedLogRecordExporter); } return Collections.unmodifiableMap(exportersByName); @@ -89,92 +75,22 @@ static NamedSpiManager logRecordExporterSpiManager( } // Visible for testing - @Nullable static LogRecordExporter configureExporter( - String name, - ConfigProperties config, - NamedSpiManager spiExportersManager, - MeterProvider meterProvider) { - switch (name) { - case "otlp": - return configureOtlpLogs(config, meterProvider); - default: - LogRecordExporter spiExporter = spiExportersManager.getByName(name); - if (spiExporter == null) { - String artifactId = EXPORTER_ARTIFACT_ID_BY_NAME.get(name); - if (artifactId != null) { - throw new ConfigurationException( - "otel.logs.exporter set to \"" - + name - + "\" but " - + artifactId - + " not found on classpath. Make sure to add it as a dependency."); - } - throw new ConfigurationException("Unrecognized value for otel.logs.exporter: " + name); - } - return spiExporter; - } - } - - // Visible for testing - @Nullable - static LogRecordExporter configureOtlpLogs(ConfigProperties config, MeterProvider meterProvider) { - String protocol = OtlpConfigUtil.getOtlpProtocol(DATA_TYPE_LOGS, config); - - if (protocol.equals(PROTOCOL_HTTP_PROTOBUF)) { - try { - ClasspathUtil.checkClassExists( - "io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporter", - "OTLP HTTP Log Exporter", - "opentelemetry-exporter-otlp-http-logs"); - } catch (ConfigurationException e) { - // Squash this for now until logs are stable - return null; - } - OtlpHttpLogRecordExporterBuilder builder = OtlpHttpLogRecordExporter.builder(); - - OtlpConfigUtil.configureOtlpExporterBuilder( - DATA_TYPE_LOGS, - config, - builder::setEndpoint, - builder::addHeader, - builder::setCompression, - builder::setTimeout, - builder::setTrustedCertificates, - builder::setClientTls, - retryPolicy -> RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy)); - - builder.setMeterProvider(meterProvider); - - return builder.build(); - } else if (protocol.equals(PROTOCOL_GRPC)) { - try { - ClasspathUtil.checkClassExists( - "io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogRecordExporter", - "OTLP gRPC Log Exporter", - "opentelemetry-exporter-otlp-logs"); - } catch (ConfigurationException e) { - // Squash this for now until logs are stable - return null; + String name, NamedSpiManager spiExportersManager) { + LogRecordExporter spiExporter = spiExportersManager.getByName(name); + if (spiExporter == null) { + String artifactId = EXPORTER_ARTIFACT_ID_BY_NAME.get(name); + if (artifactId != null) { + throw new ConfigurationException( + "otel.logs.exporter set to \"" + + name + + "\" but " + + artifactId + + " not found on classpath. Make sure to add it as a dependency."); } - OtlpGrpcLogRecordExporterBuilder builder = OtlpGrpcLogRecordExporter.builder(); - - OtlpConfigUtil.configureOtlpExporterBuilder( - DATA_TYPE_LOGS, - config, - builder::setEndpoint, - builder::addHeader, - builder::setCompression, - builder::setTimeout, - builder::setTrustedCertificates, - builder::setClientTls, - retryPolicy -> RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy)); - builder.setMeterProvider(meterProvider); - - return builder.build(); - } else { - throw new ConfigurationException("Unsupported OTLP logs protocol: " + protocol); + throw new ConfigurationException("Unrecognized value for otel.logs.exporter: " + name); } + return spiExporter; } private LogRecordExporterConfiguration() {} diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LoggerProviderConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LoggerProviderConfiguration.java index 1ebddd5b0e0..1f31f70defa 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LoggerProviderConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/LoggerProviderConfiguration.java @@ -37,8 +37,7 @@ static void configureLoggerProvider( loggerProviderBuilder.setLogLimits(() -> configureLogLimits(config)); Map exportersByName = - configureLogRecordExporters( - config, serviceClassLoader, meterProvider, logRecordExporterCustomizer); + configureLogRecordExporters(config, serviceClassLoader, logRecordExporterCustomizer); configureLogRecordProcessors(config, exportersByName, meterProvider) .forEach(loggerProviderBuilder::addLogRecordProcessor); diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MeterProviderConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MeterProviderConfiguration.java index 40dd14c0a7c..fac7c3ac2bf 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MeterProviderConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MeterProviderConfiguration.java @@ -68,7 +68,7 @@ static List configureMetricReaders( return exporterNames.stream() .map( exporterName -> - MetricExporterConfiguration.configureExporter( + MetricExporterConfiguration.configureReader( exporterName, config, serviceClassLoader, metricExporterCustomizer)) .collect(Collectors.toList()); } diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfiguration.java index 11d9d45061d..eec05b99efd 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfiguration.java @@ -5,15 +5,6 @@ package io.opentelemetry.sdk.autoconfigure; -import static io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.DATA_TYPE_METRICS; -import static io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.PROTOCOL_GRPC; -import static io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.PROTOCOL_HTTP_PROTOBUF; - -import io.opentelemetry.exporter.internal.retry.RetryUtil; -import io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporter; -import io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporterBuilder; -import io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter; -import io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporterBuilder; import io.opentelemetry.exporter.prometheus.PrometheusHttpServer; import io.opentelemetry.exporter.prometheus.PrometheusHttpServerBuilder; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; @@ -26,7 +17,6 @@ import java.util.HashMap; import java.util.Map; import java.util.function.BiFunction; -import javax.annotation.Nullable; final class MetricExporterConfiguration { @@ -37,9 +27,10 @@ final class MetricExporterConfiguration { EXPORTER_ARTIFACT_ID_BY_NAME = new HashMap<>(); EXPORTER_ARTIFACT_ID_BY_NAME.put("logging", "opentelemetry-exporter-logging"); EXPORTER_ARTIFACT_ID_BY_NAME.put("logging-otlp", "opentelemetry-exporter-logging-otlp"); + EXPORTER_ARTIFACT_ID_BY_NAME.put("otlp", "opentelemetry-exporter-otlp"); } - static MetricReader configureExporter( + static MetricReader configureReader( String name, ConfigProperties config, ClassLoader serviceClassLoader, @@ -49,99 +40,42 @@ static MetricReader configureExporter( return configurePrometheusMetricReader(config); } - MetricExporter metricExporter; - switch (name) { - case "otlp": - metricExporter = configureOtlpMetrics(config); - break; - default: - MetricExporter spiExporter = configureSpiExporter(name, config, serviceClassLoader); - if (spiExporter == null) { - String artifactId = EXPORTER_ARTIFACT_ID_BY_NAME.get(name); - if (artifactId != null) { - throw new ConfigurationException( - "otel.metrics.exporter set to \"" - + name - + "\" but " - + artifactId - + " not found on classpath. Make sure to add it as a dependency."); - } - throw new ConfigurationException("Unrecognized value for otel.metrics.exporter: " + name); - } - metricExporter = spiExporter; - } + NamedSpiManager spiExportersManager = + metricExporterSpiManager(config, serviceClassLoader); + MetricExporter metricExporter = configureExporter(name, spiExportersManager); metricExporter = metricExporterCustomizer.apply(metricExporter, config); return configurePeriodicMetricReader(config, metricExporter); } - // Visible for testing. - @Nullable - static MetricExporter configureSpiExporter( - String name, ConfigProperties config, ClassLoader serviceClassLoader) { - NamedSpiManager spiExportersManager = - SpiUtil.loadConfigurable( - ConfigurableMetricExporterProvider.class, - ConfigurableMetricExporterProvider::getName, - ConfigurableMetricExporterProvider::createExporter, - config, - serviceClassLoader); - return spiExportersManager.getByName(name); - } - // Visible for testing - static MetricExporter configureOtlpMetrics(ConfigProperties config) { - String protocol = OtlpConfigUtil.getOtlpProtocol(DATA_TYPE_METRICS, config); - - if (protocol.equals(PROTOCOL_HTTP_PROTOBUF)) { - ClasspathUtil.checkClassExists( - "io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporter", - "OTLP HTTP Metrics Exporter", - "opentelemetry-exporter-otlp-http-metrics"); - OtlpHttpMetricExporterBuilder builder = OtlpHttpMetricExporter.builder(); - - OtlpConfigUtil.configureOtlpExporterBuilder( - DATA_TYPE_METRICS, - config, - builder::setEndpoint, - builder::addHeader, - builder::setCompression, - builder::setTimeout, - builder::setTrustedCertificates, - builder::setClientTls, - retryPolicy -> RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy)); - OtlpConfigUtil.configureOtlpAggregationTemporality( - config, builder::setAggregationTemporalitySelector); - OtlpConfigUtil.configureOtlpHistogramDefaultAggregation( - config, builder::setDefaultAggregationSelector); - - return builder.build(); - } else if (protocol.equals(PROTOCOL_GRPC)) { - ClasspathUtil.checkClassExists( - "io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter", - "OTLP gRPC Metrics Exporter", - "opentelemetry-exporter-otlp"); - OtlpGrpcMetricExporterBuilder builder = OtlpGrpcMetricExporter.builder(); - - OtlpConfigUtil.configureOtlpExporterBuilder( - DATA_TYPE_METRICS, - config, - builder::setEndpoint, - builder::addHeader, - builder::setCompression, - builder::setTimeout, - builder::setTrustedCertificates, - builder::setClientTls, - retryPolicy -> RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy)); - OtlpConfigUtil.configureOtlpAggregationTemporality( - config, builder::setAggregationTemporalitySelector); - OtlpConfigUtil.configureOtlpHistogramDefaultAggregation( - config, builder::setDefaultAggregationSelector); + static NamedSpiManager metricExporterSpiManager( + ConfigProperties config, ClassLoader serviceClassLoader) { + return SpiUtil.loadConfigurable( + ConfigurableMetricExporterProvider.class, + ConfigurableMetricExporterProvider::getName, + ConfigurableMetricExporterProvider::createExporter, + config, + serviceClassLoader); + } - return builder.build(); - } else { - throw new ConfigurationException("Unsupported OTLP metrics protocol: " + protocol); + // Visible for testing. + static MetricExporter configureExporter( + String name, NamedSpiManager spiExportersManager) { + MetricExporter metricExporter = spiExportersManager.getByName(name); + if (metricExporter == null) { + String artifactId = EXPORTER_ARTIFACT_ID_BY_NAME.get(name); + if (artifactId != null) { + throw new ConfigurationException( + "otel.metrics.exporter set to \"" + + name + + "\" but " + + artifactId + + " not found on classpath. Make sure to add it as a dependency."); + } + throw new ConfigurationException("Unrecognized value for otel.metrics.exporter: " + name); } + return metricExporter; } private static PeriodicMetricReader configurePeriodicMetricReader( diff --git a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java index b7644f760aa..482e867a3f7 100644 --- a/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java +++ b/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfiguration.java @@ -5,19 +5,11 @@ package io.opentelemetry.sdk.autoconfigure; -import static io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.DATA_TYPE_TRACES; -import static io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.PROTOCOL_GRPC; -import static io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.PROTOCOL_HTTP_PROTOBUF; import static java.util.stream.Collectors.toMap; import io.opentelemetry.api.metrics.MeterProvider; -import io.opentelemetry.exporter.internal.retry.RetryUtil; import io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporter; import io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporterBuilder; -import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter; -import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder; -import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter; -import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; @@ -40,6 +32,7 @@ final class SpanExporterConfiguration { EXPORTER_ARTIFACT_ID_BY_NAME = new HashMap<>(); EXPORTER_ARTIFACT_ID_BY_NAME.put("logging", "opentelemetry-exporter-logging"); EXPORTER_ARTIFACT_ID_BY_NAME.put("logging-otlp", "opentelemetry-exporter-logging-otlp"); + EXPORTER_ARTIFACT_ID_BY_NAME.put("otlp", "opentelemetry-exporter-otlp"); EXPORTER_ARTIFACT_ID_BY_NAME.put("zipkin", "opentelemetry-exporter-zipkin"); } @@ -99,8 +92,6 @@ static SpanExporter configureExporter( NamedSpiManager spiExportersManager, MeterProvider meterProvider) { switch (name) { - case "otlp": - return configureOtlp(config, meterProvider); case "jaeger": return configureJaeger(config, meterProvider); default: @@ -121,56 +112,6 @@ static SpanExporter configureExporter( } } - // Visible for testing - static SpanExporter configureOtlp(ConfigProperties config, MeterProvider meterProvider) { - String protocol = OtlpConfigUtil.getOtlpProtocol(DATA_TYPE_TRACES, config); - - if (protocol.equals(PROTOCOL_HTTP_PROTOBUF)) { - ClasspathUtil.checkClassExists( - "io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter", - "OTLP HTTP Trace Exporter", - "opentelemetry-exporter-otlp-http-trace"); - OtlpHttpSpanExporterBuilder builder = OtlpHttpSpanExporter.builder(); - - OtlpConfigUtil.configureOtlpExporterBuilder( - DATA_TYPE_TRACES, - config, - builder::setEndpoint, - builder::addHeader, - builder::setCompression, - builder::setTimeout, - builder::setTrustedCertificates, - builder::setClientTls, - retryPolicy -> RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy)); - - builder.setMeterProvider(meterProvider); - - return builder.build(); - } else if (protocol.equals(PROTOCOL_GRPC)) { - ClasspathUtil.checkClassExists( - "io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter", - "OTLP gRPC Trace Exporter", - "opentelemetry-exporter-otlp"); - OtlpGrpcSpanExporterBuilder builder = OtlpGrpcSpanExporter.builder(); - - OtlpConfigUtil.configureOtlpExporterBuilder( - DATA_TYPE_TRACES, - config, - builder::setEndpoint, - builder::addHeader, - builder::setCompression, - builder::setTimeout, - builder::setTrustedCertificates, - builder::setClientTls, - retryPolicy -> RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy)); - builder.setMeterProvider(meterProvider); - - return builder.build(); - } else { - throw new ConfigurationException("Unsupported OTLP traces protocol: " + protocol); - } - } - private static SpanExporter configureJaeger( ConfigProperties config, MeterProvider meterProvider) { ClasspathUtil.checkClassExists( diff --git a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfigurationTest.java b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfigurationTest.java index d5f7d1146fe..3b2a311a287 100644 --- a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfigurationTest.java +++ b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfigurationTest.java @@ -8,7 +8,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import com.google.common.collect.ImmutableMap; -import io.opentelemetry.api.metrics.MeterProvider; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; @@ -26,7 +25,6 @@ void configureLogRecordExporters_duplicates() { LogRecordExporterConfiguration.configureLogRecordExporters( config, LogRecordExporterConfiguration.class.getClassLoader(), - MeterProvider.noop(), (a, unused) -> a)) .isInstanceOf(ConfigurationException.class) .hasMessageContaining("otel.logs.exporter contains duplicates: [otlp]"); @@ -42,7 +40,6 @@ void configureLogRecordExporters_unrecognized() { LogRecordExporterConfiguration.configureLogRecordExporters( config, LogRecordExporterConfiguration.class.getClassLoader(), - MeterProvider.noop(), (a, unused) -> a)) .isInstanceOf(ConfigurationException.class) .hasMessageContaining("Unrecognized value for otel.logs.exporter: foo"); @@ -58,21 +55,8 @@ void configureLogRecordExporters_multipleWithNone() { LogRecordExporterConfiguration.configureLogRecordExporters( config, LogRecordExporterConfiguration.class.getClassLoader(), - MeterProvider.noop(), (a, unused) -> a)) .isInstanceOf(ConfigurationException.class) .hasMessageContaining("otel.logs.exporter contains none along with other exporters"); } - - @Test - void configureOtlpLogs_unsupportedProtocol() { - assertThatThrownBy( - () -> - LogRecordExporterConfiguration.configureOtlpLogs( - DefaultConfigProperties.createForTest( - ImmutableMap.of("otel.exporter.otlp.protocol", "foo")), - MeterProvider.noop())) - .isInstanceOf(ConfigurationException.class) - .hasMessageContaining("Unsupported OTLP logs protocol: foo"); - } } diff --git a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/NotOnClasspathTest.java b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/NotOnClasspathTest.java index e82c58aeddd..b2b65aed06f 100644 --- a/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/NotOnClasspathTest.java +++ b/sdk-extensions/autoconfigure/src/test/java/io/opentelemetry/sdk/autoconfigure/NotOnClasspathTest.java @@ -12,6 +12,9 @@ import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; +import io.opentelemetry.sdk.logs.export.LogRecordExporter; +import io.opentelemetry.sdk.metrics.export.MetricExporter; +import io.opentelemetry.sdk.trace.export.SpanExporter; import java.util.Collections; import org.junit.jupiter.api.Test; @@ -19,32 +22,26 @@ class NotOnClasspathTest { private static final ConfigProperties EMPTY = DefaultConfigProperties.createForTest(Collections.emptyMap()); - - @Test - void otlpGrpcSpans() { - assertThatThrownBy( - () -> - SpanExporterConfiguration.configureExporter( - "otlp", EMPTY, NamedSpiManager.createEmpty(), MeterProvider.noop())) - .isInstanceOf(ConfigurationException.class) - .hasMessageContaining( - "OTLP gRPC Trace Exporter enabled but opentelemetry-exporter-otlp not found on " - + "classpath"); - } - - @Test - void otlpHttpSpans() { - ConfigProperties config = - DefaultConfigProperties.createForTest( - Collections.singletonMap("otel.exporter.otlp.protocol", "http/protobuf")); + private static final NamedSpiManager SPAN_EXPORTER_SPI_MANAGER = + SpanExporterConfiguration.spanExporterSpiManager( + EMPTY, NotOnClasspathTest.class.getClassLoader()); + private static final NamedSpiManager METRIC_EXPORTER_SPI_MANAGER = + MetricExporterConfiguration.metricExporterSpiManager( + EMPTY, NotOnClasspathTest.class.getClassLoader()); + private static final NamedSpiManager LOG_RECORD_EXPORTER_SPI_MANAGER = + LogRecordExporterConfiguration.logRecordExporterSpiManager( + EMPTY, NotOnClasspathTest.class.getClassLoader()); + + @Test + void otlpSpans() { assertThatThrownBy( () -> SpanExporterConfiguration.configureExporter( - "otlp", config, NamedSpiManager.createEmpty(), MeterProvider.noop())) + "otlp", EMPTY, SPAN_EXPORTER_SPI_MANAGER, MeterProvider.noop())) .isInstanceOf(ConfigurationException.class) .hasMessageContaining( - "OTLP HTTP Trace Exporter enabled but opentelemetry-exporter-otlp-http-trace not found on " - + "classpath"); + "otel.traces.exporter set to \"otlp\" but opentelemetry-exporter-otlp not found on classpath." + + " Make sure to add it as a dependency."); } @Test @@ -52,7 +49,7 @@ void jaeger() { assertThatThrownBy( () -> SpanExporterConfiguration.configureExporter( - "jaeger", EMPTY, NamedSpiManager.createEmpty(), MeterProvider.noop())) + "jaeger", EMPTY, SPAN_EXPORTER_SPI_MANAGER, MeterProvider.noop())) .isInstanceOf(ConfigurationException.class) .hasMessageContaining( "Jaeger gRPC Exporter enabled but opentelemetry-exporter-jaeger not found on " @@ -64,7 +61,7 @@ void zipkin() { assertThatThrownBy( () -> SpanExporterConfiguration.configureExporter( - "zipkin", EMPTY, NamedSpiManager.createEmpty(), MeterProvider.noop())) + "zipkin", EMPTY, SPAN_EXPORTER_SPI_MANAGER, MeterProvider.noop())) .isInstanceOf(ConfigurationException.class) .hasMessageContaining( "otel.traces.exporter set to \"zipkin\" but opentelemetry-exporter-zipkin not found on classpath." @@ -76,7 +73,7 @@ void loggingSpans() { assertThatThrownBy( () -> SpanExporterConfiguration.configureExporter( - "logging", EMPTY, NamedSpiManager.createEmpty(), MeterProvider.noop())) + "logging", EMPTY, SPAN_EXPORTER_SPI_MANAGER, MeterProvider.noop())) .isInstanceOf(ConfigurationException.class) .hasMessageContaining( "otel.traces.exporter set to \"logging\" but opentelemetry-exporter-logging not found on classpath." @@ -88,12 +85,7 @@ void loggingSpansOtlp() { assertThatThrownBy( () -> SpanExporterConfiguration.configureExporter( - "logging-otlp", - EMPTY, - SpanExporterConfiguration.spanExporterSpiManager( - DefaultConfigProperties.createForTest(Collections.emptyMap()), - NotOnClasspathTest.class.getClassLoader()), - MeterProvider.noop())) + "logging-otlp", EMPTY, SPAN_EXPORTER_SPI_MANAGER, MeterProvider.noop())) .isInstanceOf(ConfigurationException.class) .hasMessageContaining( "otel.traces.exporter set to \"logging-otlp\" but opentelemetry-exporter-logging-otlp not found on classpath." @@ -105,10 +97,7 @@ void loggingMetrics() { assertThatThrownBy( () -> MetricExporterConfiguration.configureExporter( - "logging", - EMPTY, - MetricExporterConfiguration.class.getClassLoader(), - (a, unused) -> a)) + "logging", METRIC_EXPORTER_SPI_MANAGER)) .isInstanceOf(ConfigurationException.class) .hasMessageContaining( "otel.metrics.exporter set to \"logging\" but opentelemetry-exporter-logging not found on classpath." @@ -120,10 +109,7 @@ void loggingMetricsOtlp() { assertThatThrownBy( () -> MetricExporterConfiguration.configureExporter( - "logging-otlp", - EMPTY, - MetricExporterConfiguration.class.getClassLoader(), - (a, unused) -> a)) + "logging-otlp", METRIC_EXPORTER_SPI_MANAGER)) .isInstanceOf(ConfigurationException.class) .hasMessageContaining( "otel.metrics.exporter set to \"logging-otlp\" but opentelemetry-exporter-logging-otlp not found on classpath." @@ -135,7 +121,7 @@ void loggingLogs() { assertThatThrownBy( () -> LogRecordExporterConfiguration.configureExporter( - "logging", EMPTY, NamedSpiManager.createEmpty(), MeterProvider.noop())) + "logging", LOG_RECORD_EXPORTER_SPI_MANAGER)) .isInstanceOf(ConfigurationException.class) .hasMessageContaining( "otel.logs.exporter set to \"logging\" but opentelemetry-exporter-logging not found on classpath." @@ -147,12 +133,7 @@ void loggingLogsOtlp() { assertThatThrownBy( () -> LogRecordExporterConfiguration.configureExporter( - "logging-otlp", - EMPTY, - LogRecordExporterConfiguration.logRecordExporterSpiManager( - DefaultConfigProperties.createForTest(Collections.emptyMap()), - NotOnClasspathTest.class.getClassLoader()), - MeterProvider.noop())) + "logging-otlp", LOG_RECORD_EXPORTER_SPI_MANAGER)) .isInstanceOf(ConfigurationException.class) .hasMessageContaining( "otel.logs.exporter set to \"logging-otlp\" but opentelemetry-exporter-logging-otlp not found on classpath." @@ -160,44 +141,24 @@ void loggingLogsOtlp() { } @Test - void otlpGrpcMetrics() { + void otlpMetrics() { assertThatCode( () -> - MetricExporterConfiguration.configureExporter( - "otlp", - EMPTY, - MetricExporterConfiguration.class.getClassLoader(), - (a, unused) -> a)) + MetricExporterConfiguration.configureExporter("otlp", METRIC_EXPORTER_SPI_MANAGER)) .isInstanceOf(ConfigurationException.class) .hasMessageContaining( - "OTLP gRPC Metrics Exporter enabled but opentelemetry-exporter-otlp not found on " - + "classpath"); - } - - @Test - void otlpHttpMetrics() { - ConfigProperties config = - DefaultConfigProperties.createForTest( - Collections.singletonMap("otel.exporter.otlp.protocol", "http/protobuf")); - assertThatCode( - () -> - MetricExporterConfiguration.configureExporter( - "otlp", - config, - MetricExporterConfiguration.class.getClassLoader(), - (a, unused) -> a)) - .hasMessageContaining( - "OTLP HTTP Metrics Exporter enabled but opentelemetry-exporter-otlp-http-metrics not found on classpath"); + "otel.metrics.exporter set to \"otlp\" but opentelemetry-exporter-otlp not found on classpath." + + " Make sure to add it as a dependency."); } @Test void prometheus() { assertThatThrownBy( () -> - MetricExporterConfiguration.configureExporter( + MetricExporterConfiguration.configureReader( "prometheus", EMPTY, - MetricExporterConfiguration.class.getClassLoader(), + NotOnClasspathTest.class.getClassLoader(), (a, unused) -> a)) .isInstanceOf(ConfigurationException.class) .hasMessageContaining( @@ -223,19 +184,10 @@ void otlpGrpcLogs() { assertThatCode( () -> LogRecordExporterConfiguration.configureExporter( - "otlp", EMPTY, NamedSpiManager.createEmpty(), MeterProvider.noop())) - .doesNotThrowAnyException(); - } - - @Test - void otlpHttpLogs() { - ConfigProperties config = - DefaultConfigProperties.createForTest( - Collections.singletonMap("otel.exporter.otlp.protocol", "http/protobuf")); - assertThatCode( - () -> - LogRecordExporterConfiguration.configureExporter( - "otlp", config, NamedSpiManager.createEmpty(), MeterProvider.noop())) - .doesNotThrowAnyException(); + "otlp", LOG_RECORD_EXPORTER_SPI_MANAGER)) + .isInstanceOf(ConfigurationException.class) + .hasMessageContaining( + "otel.logs.exporter set to \"otlp\" but opentelemetry-exporter-otlp not found on classpath." + + " Make sure to add it as a dependency."); } } diff --git a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableLogRecordExporterTest.java b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableLogRecordExporterTest.java index 39a0f186126..82ec5b679d5 100644 --- a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableLogRecordExporterTest.java +++ b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableLogRecordExporterTest.java @@ -9,14 +9,12 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import com.google.common.collect.ImmutableMap; -import io.opentelemetry.api.metrics.MeterProvider; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import io.opentelemetry.sdk.logs.export.LogRecordExporter; import java.net.URL; import java.net.URLClassLoader; -import java.util.Collections; import java.util.Map; import org.junit.jupiter.api.Test; @@ -29,10 +27,7 @@ void configureLogRecordExporters_spiExporter() { ImmutableMap.of("test.option", "true", "otel.logs.exporter", "testExporter")); Map exportersByName = LogRecordExporterConfiguration.configureLogRecordExporters( - config, - LogRecordExporterConfiguration.class.getClassLoader(), - MeterProvider.noop(), - (a, unused) -> a); + config, LogRecordExporterConfiguration.class.getClassLoader(), (a, unused) -> a); assertThat(exportersByName) .hasSize(1) @@ -51,10 +46,7 @@ void configureLogRecordExporters_emptyClassLoader() { assertThatThrownBy( () -> LogRecordExporterConfiguration.configureLogRecordExporters( - config, - new URLClassLoader(new URL[0], null), - MeterProvider.noop(), - (a, unused) -> a)) + config, new URLClassLoader(new URL[0], null), (a, unused) -> a)) .isInstanceOf(ConfigurationException.class) .hasMessageContaining("testExporter"); } @@ -64,10 +56,7 @@ void configureExporter_NotFound() { assertThatThrownBy( () -> LogRecordExporterConfiguration.configureExporter( - "catExporter", - DefaultConfigProperties.createForTest(Collections.emptyMap()), - NamedSpiManager.createEmpty(), - MeterProvider.noop())) + "catExporter", NamedSpiManager.createEmpty())) .isInstanceOf(ConfigurationException.class) .hasMessageContaining("catExporter"); } diff --git a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableMetricExporterTest.java b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableMetricExporterTest.java index 999c6ea27a1..bdfb28aa9c3 100644 --- a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableMetricExporterTest.java +++ b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableMetricExporterTest.java @@ -14,7 +14,6 @@ import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; -import io.opentelemetry.sdk.metrics.SdkMeterProvider; import io.opentelemetry.sdk.metrics.export.MetricExporter; import io.opentelemetry.sdk.metrics.export.PeriodicMetricReader; import java.net.URL; @@ -30,8 +29,10 @@ void configuration() { ConfigProperties config = DefaultConfigProperties.createForTest(ImmutableMap.of("test.option", "true")); MetricExporter metricExporter = - MetricExporterConfiguration.configureSpiExporter( - "testExporter", config, MetricExporterConfiguration.class.getClassLoader()); + MetricExporterConfiguration.configureExporter( + "testExporter", + MetricExporterConfiguration.metricExporterSpiManager( + config, ConfigurableMetricExporterTest.class.getClassLoader())); assertThat(metricExporter) .isInstanceOf(TestConfigurableMetricExporterProvider.TestMetricExporter.class) @@ -45,9 +46,9 @@ void emptyClassLoader() { () -> MetricExporterConfiguration.configureExporter( "testExporter", - DefaultConfigProperties.createForTest(Collections.emptyMap()), - new URLClassLoader(new URL[0], null), - (a, unused) -> a)) + MetricExporterConfiguration.metricExporterSpiManager( + DefaultConfigProperties.createForTest(Collections.emptyMap()), + new URLClassLoader(new URL[] {}, null)))) .isInstanceOf(ConfigurationException.class) .hasMessageContaining("testExporter"); } @@ -58,25 +59,24 @@ void exporterNotFound() { () -> MetricExporterConfiguration.configureExporter( "catExporter", - DefaultConfigProperties.createForTest(Collections.emptyMap()), - MetricExporterConfiguration.class.getClassLoader(), - (a, unused) -> a)) + MetricExporterConfiguration.metricExporterSpiManager( + DefaultConfigProperties.createForTest(Collections.emptyMap()), + ConfigurableMetricExporterTest.class.getClassLoader()))) .isInstanceOf(ConfigurationException.class) .hasMessageContaining("catExporter"); } @Test - void configureMetricExporters_multipleWithNone() { + void configureMetricReaders_multipleWithNone() { ConfigProperties config = DefaultConfigProperties.createForTest( ImmutableMap.of("otel.metrics.exporter", "otlp,none")); assertThatThrownBy( () -> - MeterProviderConfiguration.configureMeterProvider( - SdkMeterProvider.builder(), + MeterProviderConfiguration.configureMetricReaders( config, - MetricExporterConfiguration.class.getClassLoader(), + ConfigurableMetricExporterTest.class.getClassLoader(), (a, unused) -> a)) .isInstanceOf(ConfigurationException.class) .hasMessageContaining("otel.metrics.exporter contains none along with other exporters"); diff --git a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfigurationTest.java b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfigurationTest.java index 6be98b6f069..68d3a8afb5f 100644 --- a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfigurationTest.java +++ b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfigurationTest.java @@ -18,9 +18,12 @@ public class MetricExporterConfigurationTest { void configureOtlpMetricsUnsupportedProtocol() { assertThatThrownBy( () -> - MetricExporterConfiguration.configureOtlpMetrics( - DefaultConfigProperties.createForTest( - ImmutableMap.of("otel.exporter.otlp.protocol", "foo")))) + MetricExporterConfiguration.configureExporter( + "otlp", + MetricExporterConfiguration.metricExporterSpiManager( + DefaultConfigProperties.createForTest( + ImmutableMap.of("otel.exporter.otlp.protocol", "foo")), + MetricExporterConfigurationTest.class.getClassLoader()))) .isInstanceOf(ConfigurationException.class) .hasMessageContaining("Unsupported OTLP metrics protocol: foo"); } diff --git a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfigurationTest.java b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfigurationTest.java index 6fce08e43d0..18440536319 100644 --- a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfigurationTest.java +++ b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfigurationTest.java @@ -23,11 +23,16 @@ class SpanExporterConfigurationTest { @Test void configureOtlpSpansUnsupportedProtocol() { + ConfigProperties config = + DefaultConfigProperties.createForTest( + ImmutableMap.of("otel.exporter.otlp.protocol", "foo")); assertThatThrownBy( () -> - SpanExporterConfiguration.configureOtlp( - DefaultConfigProperties.createForTest( - ImmutableMap.of("otel.exporter.otlp.protocol", "foo")), + SpanExporterConfiguration.configureExporter( + "otlp", + config, + SpanExporterConfiguration.spanExporterSpiManager( + config, SpanExporterConfigurationTest.class.getClassLoader()), MeterProvider.noop())) .isInstanceOf(ConfigurationException.class) .hasMessageContaining("Unsupported OTLP traces protocol: foo"); @@ -36,12 +41,15 @@ void configureOtlpSpansUnsupportedProtocol() { // Timeout difficult to test using real exports so just check implementation detail here. @Test void configureOtlpTimeout() { + ConfigProperties config = + DefaultConfigProperties.createForTest( + Collections.singletonMap("otel.exporter.otlp.timeout", "10")); SpanExporter exporter = SpanExporterConfiguration.configureExporter( "otlp", - DefaultConfigProperties.createForTest( - Collections.singletonMap("otel.exporter.otlp.timeout", "10")), - NamedSpiManager.createEmpty(), + config, + SpanExporterConfiguration.spanExporterSpiManager( + config, SpanExporterConfigurationTest.class.getClassLoader()), MeterProvider.noop()); try { assertThat(exporter) @@ -57,12 +65,15 @@ void configureOtlpTimeout() { // Timeout difficult to test using real exports so just check implementation detail here. @Test void configureJaegerTimeout() { + ConfigProperties config = + DefaultConfigProperties.createForTest( + Collections.singletonMap("otel.exporter.jaeger.timeout", "10")); SpanExporter exporter = SpanExporterConfiguration.configureExporter( "jaeger", - DefaultConfigProperties.createForTest( - Collections.singletonMap("otel.exporter.jaeger.timeout", "10")), - NamedSpiManager.createEmpty(), + config, + SpanExporterConfiguration.spanExporterSpiManager( + config, SpanExporterConfigurationTest.class.getClassLoader()), MeterProvider.noop()); try { assertThat(exporter) diff --git a/sdk-extensions/autoconfigure/src/testOtlp/java/io/opentelemetry/sdk/autoconfigure/OtlpGrpcConfigTest.java b/sdk-extensions/autoconfigure/src/testOtlp/java/io/opentelemetry/sdk/autoconfigure/OtlpGrpcConfigTest.java index b5bbd792612..100814a0f58 100644 --- a/sdk-extensions/autoconfigure/src/testOtlp/java/io/opentelemetry/sdk/autoconfigure/OtlpGrpcConfigTest.java +++ b/sdk-extensions/autoconfigure/src/testOtlp/java/io/opentelemetry/sdk/autoconfigure/OtlpGrpcConfigTest.java @@ -82,11 +82,21 @@ void configureExportersGeneral() { ConfigProperties properties = DefaultConfigProperties.createForTest(props); try (SpanExporter spanExporter = SpanExporterConfiguration.configureExporter( - "otlp", properties, NamedSpiManager.createEmpty(), MeterProvider.noop()); + "otlp", + properties, + SpanExporterConfiguration.spanExporterSpiManager( + properties, OtlpGrpcConfigTest.class.getClassLoader()), + MeterProvider.noop()); MetricExporter metricExporter = - MetricExporterConfiguration.configureOtlpMetrics(properties); + MetricExporterConfiguration.configureExporter( + "otlp", + MetricExporterConfiguration.metricExporterSpiManager( + properties, OtlpGrpcConfigTest.class.getClassLoader())); LogRecordExporter logRecordExporter = - LogRecordExporterConfiguration.configureOtlpLogs(properties, MeterProvider.noop())) { + LogRecordExporterConfiguration.configureExporter( + "otlp", + LogRecordExporterConfiguration.logRecordExporterSpiManager( + properties, OtlpGrpcConfigTest.class.getClassLoader()))) { assertThat(spanExporter) .extracting("delegate.client.callTimeoutMillis", INTEGER) .isEqualTo(TimeUnit.SECONDS.toMillis(15)); @@ -147,11 +157,13 @@ void configureSpanExporter() { props.put("otel.exporter.otlp.traces.headers", "header-key=header-value"); props.put("otel.exporter.otlp.traces.compression", "gzip"); props.put("otel.exporter.otlp.traces.timeout", "15s"); + ConfigProperties properties = DefaultConfigProperties.createForTest(props); try (SpanExporter spanExporter = SpanExporterConfiguration.configureExporter( "otlp", - DefaultConfigProperties.createForTest(props), - NamedSpiManager.createEmpty(), + properties, + SpanExporterConfiguration.spanExporterSpiManager( + properties, OtlpGrpcConfigTest.class.getClassLoader()), MeterProvider.noop())) { assertThat(spanExporter) .extracting("delegate.client.callTimeoutMillis", INTEGER) @@ -184,9 +196,12 @@ public void configureMetricExporter() { props.put("otel.exporter.otlp.metrics.compression", "gzip"); props.put("otel.exporter.otlp.metrics.timeout", "15s"); props.put("otel.exporter.otlp.metrics.temporality.preference", "DELTA"); + ConfigProperties properties = DefaultConfigProperties.createForTest(props); try (MetricExporter metricExporter = - MetricExporterConfiguration.configureOtlpMetrics( - DefaultConfigProperties.createForTest(props))) { + MetricExporterConfiguration.configureExporter( + "otlp", + MetricExporterConfiguration.metricExporterSpiManager( + properties, OtlpGrpcConfigTest.class.getClassLoader()))) { assertThat(metricExporter) .extracting("delegate.client.callTimeoutMillis", INTEGER) @@ -225,9 +240,12 @@ public void configureLogRecordExporter() { props.put("otel.exporter.otlp.logs.headers", "header-key=header-value"); props.put("otel.exporter.otlp.logs.compression", "gzip"); props.put("otel.exporter.otlp.logs.timeout", "15s"); + ConfigProperties properties = DefaultConfigProperties.createForTest(props); try (LogRecordExporter logRecordExporter = - LogRecordExporterConfiguration.configureOtlpLogs( - DefaultConfigProperties.createForTest(props), MeterProvider.noop())) { + LogRecordExporterConfiguration.configureExporter( + "otlp", + LogRecordExporterConfiguration.logRecordExporterSpiManager( + properties, OtlpGrpcConfigTest.class.getClassLoader()))) { assertThat(logRecordExporter) .extracting("delegate.client.callTimeoutMillis", INTEGER) @@ -254,17 +272,29 @@ void configureTlsInvalidCertificatePath() { assertThatThrownBy( () -> SpanExporterConfiguration.configureExporter( - "otlp", properties, NamedSpiManager.createEmpty(), MeterProvider.noop())) + "otlp", + properties, + SpanExporterConfiguration.spanExporterSpiManager( + properties, OtlpGrpcConfigTest.class.getClassLoader()), + MeterProvider.noop())) .isInstanceOf(ConfigurationException.class) .hasMessageContaining("Invalid OTLP certificate/key path:"); - assertThatThrownBy(() -> MetricExporterConfiguration.configureOtlpMetrics(properties)) + assertThatThrownBy( + () -> + MetricExporterConfiguration.configureExporter( + "otlp", + MetricExporterConfiguration.metricExporterSpiManager( + properties, OtlpGrpcConfigTest.class.getClassLoader()))) .isInstanceOf(ConfigurationException.class) .hasMessageContaining("Invalid OTLP certificate/key path:"); assertThatThrownBy( () -> - LogRecordExporterConfiguration.configureOtlpLogs(properties, MeterProvider.noop())) + LogRecordExporterConfiguration.configureExporter( + "otlp", + LogRecordExporterConfiguration.logRecordExporterSpiManager( + properties, OtlpGrpcConfigTest.class.getClassLoader()))) .isInstanceOf(ConfigurationException.class) .hasMessageContaining("Invalid OTLP certificate/key path:"); } @@ -278,17 +308,29 @@ void configureTlsMissingClientCertificatePath() { assertThatThrownBy( () -> SpanExporterConfiguration.configureExporter( - "otlp", properties, NamedSpiManager.createEmpty(), MeterProvider.noop())) + "otlp", + properties, + SpanExporterConfiguration.spanExporterSpiManager( + properties, OtlpGrpcConfigTest.class.getClassLoader()), + MeterProvider.noop())) .isInstanceOf(ConfigurationException.class) .hasMessageContaining("Client key provided but certification chain is missing"); - assertThatThrownBy(() -> MetricExporterConfiguration.configureOtlpMetrics(properties)) + assertThatThrownBy( + () -> + MetricExporterConfiguration.configureExporter( + "otlp", + MetricExporterConfiguration.metricExporterSpiManager( + properties, OtlpGrpcConfigTest.class.getClassLoader()))) .isInstanceOf(ConfigurationException.class) .hasMessageContaining("Client key provided but certification chain is missing"); assertThatThrownBy( () -> - LogRecordExporterConfiguration.configureOtlpLogs(properties, MeterProvider.noop())) + LogRecordExporterConfiguration.configureExporter( + "otlp", + LogRecordExporterConfiguration.logRecordExporterSpiManager( + properties, OtlpGrpcConfigTest.class.getClassLoader()))) .isInstanceOf(ConfigurationException.class) .hasMessageContaining("Client key provided but certification chain is missing"); } @@ -302,17 +344,29 @@ void configureTlsMissingClientKeyPath() { assertThatThrownBy( () -> SpanExporterConfiguration.configureExporter( - "otlp", properties, NamedSpiManager.createEmpty(), MeterProvider.noop())) + "otlp", + properties, + SpanExporterConfiguration.spanExporterSpiManager( + properties, OtlpGrpcConfigTest.class.getClassLoader()), + MeterProvider.noop())) .isInstanceOf(ConfigurationException.class) .hasMessageContaining("Client key chain provided but key is missing"); - assertThatThrownBy(() -> MetricExporterConfiguration.configureOtlpMetrics(properties)) + assertThatThrownBy( + () -> + MetricExporterConfiguration.configureExporter( + "otlp", + MetricExporterConfiguration.metricExporterSpiManager( + properties, OtlpGrpcConfigTest.class.getClassLoader()))) .isInstanceOf(ConfigurationException.class) .hasMessageContaining("Client key chain provided but key is missing"); assertThatThrownBy( () -> - LogRecordExporterConfiguration.configureOtlpLogs(properties, MeterProvider.noop())) + LogRecordExporterConfiguration.configureExporter( + "otlp", + LogRecordExporterConfiguration.logRecordExporterSpiManager( + properties, OtlpGrpcConfigTest.class.getClassLoader()))) .isInstanceOf(ConfigurationException.class) .hasMessageContaining("Client key chain provided but key is missing"); } diff --git a/sdk-extensions/autoconfigure/src/testOtlp/java/io/opentelemetry/sdk/autoconfigure/OtlpGrpcRetryTest.java b/sdk-extensions/autoconfigure/src/testOtlp/java/io/opentelemetry/sdk/autoconfigure/OtlpGrpcRetryTest.java index 731bf9a4a13..40caedcc1fd 100644 --- a/sdk-extensions/autoconfigure/src/testOtlp/java/io/opentelemetry/sdk/autoconfigure/OtlpGrpcRetryTest.java +++ b/sdk-extensions/autoconfigure/src/testOtlp/java/io/opentelemetry/sdk/autoconfigure/OtlpGrpcRetryTest.java @@ -18,6 +18,7 @@ import io.opentelemetry.exporter.internal.retry.RetryPolicy; import io.opentelemetry.exporter.internal.retry.RetryUtil; import io.opentelemetry.internal.testing.slf4j.SuppressLogger; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import io.opentelemetry.sdk.common.CompletableResultCode; import io.opentelemetry.sdk.logs.data.LogRecordData; @@ -60,11 +61,13 @@ void configureSpanExporterRetryPolicy() { props.put( "otel.exporter.otlp.traces.certificate", certificate.certificateFile().getAbsolutePath()); props.put("otel.experimental.exporter.otlp.retry.enabled", "true"); + ConfigProperties properties = DefaultConfigProperties.createForTest(props); try (SpanExporter spanExporter = SpanExporterConfiguration.configureExporter( "otlp", - DefaultConfigProperties.createForTest(props), - NamedSpiManager.createEmpty(), + properties, + SpanExporterConfiguration.spanExporterSpiManager( + properties, OtlpGrpcRetryTest.class.getClassLoader()), MeterProvider.noop())) { testRetryableStatusCodes(() -> SPAN_DATA, spanExporter::export, server.traceRequests::size); @@ -81,8 +84,11 @@ void configureMetricExporterRetryPolicy() { "otel.exporter.otlp.metrics.certificate", certificate.certificateFile().getAbsolutePath()); props.put("otel.experimental.exporter.otlp.retry.enabled", "true"); try (MetricExporter metricExporter = - MetricExporterConfiguration.configureOtlpMetrics( - DefaultConfigProperties.createForTest(props))) { + MetricExporterConfiguration.configureExporter( + "otlp", + MetricExporterConfiguration.metricExporterSpiManager( + DefaultConfigProperties.createForTest(props), + OtlpGrpcRetryTest.class.getClassLoader()))) { testRetryableStatusCodes( () -> METRIC_DATA, metricExporter::export, server.metricRequests::size); @@ -100,8 +106,11 @@ void configureLogRecordExporterRetryPolicy() { "otel.exporter.otlp.logs.certificate", certificate.certificateFile().getAbsolutePath()); props.put("otel.experimental.exporter.otlp.retry.enabled", "true"); try (LogRecordExporter logRecordExporter = - LogRecordExporterConfiguration.configureOtlpLogs( - DefaultConfigProperties.createForTest(props), MeterProvider.noop())) { + LogRecordExporterConfiguration.configureExporter( + "otlp", + LogRecordExporterConfiguration.logRecordExporterSpiManager( + DefaultConfigProperties.createForTest(props), + OtlpGrpcConfigTest.class.getClassLoader()))) { testRetryableStatusCodes( () -> LOG_RECORD_DATA, logRecordExporter::export, server.logRequests::size); testDefaultRetryPolicy( diff --git a/sdk-extensions/autoconfigure/src/testOtlp/java/io/opentelemetry/sdk/autoconfigure/OtlpHttpConfigTest.java b/sdk-extensions/autoconfigure/src/testOtlp/java/io/opentelemetry/sdk/autoconfigure/OtlpHttpConfigTest.java index f9f3bf66d4b..4e05f75efe0 100644 --- a/sdk-extensions/autoconfigure/src/testOtlp/java/io/opentelemetry/sdk/autoconfigure/OtlpHttpConfigTest.java +++ b/sdk-extensions/autoconfigure/src/testOtlp/java/io/opentelemetry/sdk/autoconfigure/OtlpHttpConfigTest.java @@ -69,10 +69,21 @@ void configureExportersGeneral() { ConfigProperties properties = DefaultConfigProperties.createForTest(props); SpanExporter spanExporter = SpanExporterConfiguration.configureExporter( - "otlp", properties, NamedSpiManager.createEmpty(), MeterProvider.noop()); - MetricExporter metricExporter = MetricExporterConfiguration.configureOtlpMetrics(properties); + "otlp", + properties, + SpanExporterConfiguration.spanExporterSpiManager( + properties, OtlpHttpConfigTest.class.getClassLoader()), + MeterProvider.noop()); + MetricExporter metricExporter = + MetricExporterConfiguration.configureExporter( + "otlp", + MetricExporterConfiguration.metricExporterSpiManager( + properties, OtlpHttpConfigTest.class.getClassLoader())); LogRecordExporter logRecordExporter = - LogRecordExporterConfiguration.configureOtlpLogs(properties, MeterProvider.noop()); + LogRecordExporterConfiguration.configureExporter( + "otlp", + LogRecordExporterConfiguration.logRecordExporterSpiManager( + properties, OtlpHttpConfigTest.class.getClassLoader())); assertThat(spanExporter) .extracting("delegate.client", as(InstanceOfAssertFactories.type(OkHttpClient.class))) @@ -150,11 +161,13 @@ void configureSpanExporter() { props.put("otel.exporter.otlp.traces.headers", "header-key=header-value"); props.put("otel.exporter.otlp.traces.compression", "gzip"); props.put("otel.exporter.otlp.traces.timeout", "15s"); + ConfigProperties properties = DefaultConfigProperties.createForTest(props); SpanExporter spanExporter = SpanExporterConfiguration.configureExporter( "otlp", - DefaultConfigProperties.createForTest(props), - NamedSpiManager.createEmpty(), + properties, + SpanExporterConfiguration.spanExporterSpiManager( + properties, OtlpHttpConfigTest.class.getClassLoader()), MeterProvider.noop()); assertThat(spanExporter) @@ -199,8 +212,11 @@ public void configureMetricExporter() { props.put("otel.exporter.otlp.metrics.timeout", "15s"); props.put("otel.exporter.otlp.metrics.temporality.preference", "DELTA"); MetricExporter metricExporter = - MetricExporterConfiguration.configureOtlpMetrics( - DefaultConfigProperties.createForTest(props)); + MetricExporterConfiguration.configureExporter( + "otlp", + MetricExporterConfiguration.metricExporterSpiManager( + DefaultConfigProperties.createForTest(props), + OtlpHttpConfigTest.class.getClassLoader())); assertThat(metricExporter) .extracting("delegate.client", as(InstanceOfAssertFactories.type(OkHttpClient.class))) @@ -243,8 +259,11 @@ public void configureLogRecordExporter() { props.put("otel.exporter.otlp.logs.compression", "gzip"); props.put("otel.exporter.otlp.logs.timeout", "15s"); LogRecordExporter logRecordExporter = - LogRecordExporterConfiguration.configureOtlpLogs( - DefaultConfigProperties.createForTest(props), MeterProvider.noop()); + LogRecordExporterConfiguration.configureExporter( + "otlp", + LogRecordExporterConfiguration.logRecordExporterSpiManager( + DefaultConfigProperties.createForTest(props), + OtlpHttpConfigTest.class.getClassLoader())); assertThat(logRecordExporter) .extracting("delegate.client", as(InstanceOfAssertFactories.type(OkHttpClient.class))) @@ -274,17 +293,29 @@ void configureTlsInvalidCertificatePath() { assertThatThrownBy( () -> SpanExporterConfiguration.configureExporter( - "otlp", properties, NamedSpiManager.createEmpty(), MeterProvider.noop())) + "otlp", + properties, + SpanExporterConfiguration.spanExporterSpiManager( + properties, OtlpHttpConfigTest.class.getClassLoader()), + MeterProvider.noop())) .isInstanceOf(ConfigurationException.class) .hasMessageContaining("Invalid OTLP certificate/key path:"); - assertThatThrownBy(() -> MetricExporterConfiguration.configureOtlpMetrics(properties)) + assertThatThrownBy( + () -> + MetricExporterConfiguration.configureExporter( + "otlp", + MetricExporterConfiguration.metricExporterSpiManager( + properties, OtlpHttpConfigTest.class.getClassLoader()))) .isInstanceOf(ConfigurationException.class) .hasMessageContaining("Invalid OTLP certificate/key path:"); assertThatThrownBy( () -> - LogRecordExporterConfiguration.configureOtlpLogs(properties, MeterProvider.noop())) + LogRecordExporterConfiguration.configureExporter( + "otlp", + LogRecordExporterConfiguration.logRecordExporterSpiManager( + properties, OtlpHttpConfigTest.class.getClassLoader()))) .isInstanceOf(ConfigurationException.class) .hasMessageContaining("Invalid OTLP certificate/key path:"); } @@ -299,17 +330,29 @@ void configureTlsMissingClientCertificatePath() { assertThatThrownBy( () -> SpanExporterConfiguration.configureExporter( - "otlp", properties, NamedSpiManager.createEmpty(), MeterProvider.noop())) + "otlp", + properties, + SpanExporterConfiguration.spanExporterSpiManager( + properties, OtlpHttpConfigTest.class.getClassLoader()), + MeterProvider.noop())) .isInstanceOf(ConfigurationException.class) .hasMessageContaining("Client key provided but certification chain is missing"); - assertThatThrownBy(() -> MetricExporterConfiguration.configureOtlpMetrics(properties)) + assertThatThrownBy( + () -> + MetricExporterConfiguration.configureExporter( + "otlp", + MetricExporterConfiguration.metricExporterSpiManager( + properties, OtlpHttpConfigTest.class.getClassLoader()))) .isInstanceOf(ConfigurationException.class) .hasMessageContaining("Client key provided but certification chain is missing"); assertThatThrownBy( () -> - LogRecordExporterConfiguration.configureOtlpLogs(properties, MeterProvider.noop())) + LogRecordExporterConfiguration.configureExporter( + "otlp", + LogRecordExporterConfiguration.logRecordExporterSpiManager( + properties, OtlpHttpConfigTest.class.getClassLoader()))) .isInstanceOf(ConfigurationException.class) .hasMessageContaining("Client key provided but certification chain is missing"); } @@ -324,17 +367,29 @@ void configureTlsMissingClientKeyPath() { assertThatThrownBy( () -> SpanExporterConfiguration.configureExporter( - "otlp", properties, NamedSpiManager.createEmpty(), MeterProvider.noop())) + "otlp", + properties, + SpanExporterConfiguration.spanExporterSpiManager( + properties, OtlpHttpConfigTest.class.getClassLoader()), + MeterProvider.noop())) .isInstanceOf(ConfigurationException.class) .hasMessageContaining("Client key chain provided but key is missing"); - assertThatThrownBy(() -> MetricExporterConfiguration.configureOtlpMetrics(properties)) + assertThatThrownBy( + () -> + MetricExporterConfiguration.configureExporter( + "otlp", + MetricExporterConfiguration.metricExporterSpiManager( + properties, OtlpHttpConfigTest.class.getClassLoader()))) .isInstanceOf(ConfigurationException.class) .hasMessageContaining("Client key chain provided but key is missing"); assertThatThrownBy( () -> - LogRecordExporterConfiguration.configureOtlpLogs(properties, MeterProvider.noop())) + LogRecordExporterConfiguration.configureExporter( + "otlp", + LogRecordExporterConfiguration.logRecordExporterSpiManager( + properties, OtlpHttpConfigTest.class.getClassLoader()))) .isInstanceOf(ConfigurationException.class) .hasMessageContaining("Client key chain provided but key is missing"); } diff --git a/sdk-extensions/autoconfigure/src/testOtlp/java/io/opentelemetry/sdk/autoconfigure/OtlpHttpRetryTest.java b/sdk-extensions/autoconfigure/src/testOtlp/java/io/opentelemetry/sdk/autoconfigure/OtlpHttpRetryTest.java index 08a23a07af1..0459e33e25f 100644 --- a/sdk-extensions/autoconfigure/src/testOtlp/java/io/opentelemetry/sdk/autoconfigure/OtlpHttpRetryTest.java +++ b/sdk-extensions/autoconfigure/src/testOtlp/java/io/opentelemetry/sdk/autoconfigure/OtlpHttpRetryTest.java @@ -19,6 +19,7 @@ import io.opentelemetry.exporter.internal.retry.RetryPolicy; import io.opentelemetry.exporter.internal.retry.RetryUtil; import io.opentelemetry.internal.testing.slf4j.SuppressLogger; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; import io.opentelemetry.sdk.common.CompletableResultCode; import io.opentelemetry.sdk.logs.data.LogRecordData; @@ -59,11 +60,13 @@ void configureSpanExporterRetryPolicy() { "otel.exporter.otlp.traces.certificate", server.selfSignedCertificate.certificate().getPath()); props.put("otel.experimental.exporter.otlp.retry.enabled", "true"); + ConfigProperties properties = DefaultConfigProperties.createForTest(props); try (SpanExporter spanExporter = SpanExporterConfiguration.configureExporter( "otlp", - DefaultConfigProperties.createForTest(props), - NamedSpiManager.createEmpty(), + properties, + SpanExporterConfiguration.spanExporterSpiManager( + properties, OtlpHttpRetryTest.class.getClassLoader()), MeterProvider.noop())) { testRetryableStatusCodes(() -> SPAN_DATA, spanExporter::export, server.traceRequests::size); @@ -84,8 +87,11 @@ void configureMetricExporterRetryPolicy() { server.selfSignedCertificate.certificate().getPath()); props.put("otel.experimental.exporter.otlp.retry.enabled", "true"); try (MetricExporter metricExporter = - MetricExporterConfiguration.configureOtlpMetrics( - DefaultConfigProperties.createForTest(props))) { + MetricExporterConfiguration.configureExporter( + "otlp", + MetricExporterConfiguration.metricExporterSpiManager( + DefaultConfigProperties.createForTest(props), + OtlpHttpRetryTest.class.getClassLoader()))) { testRetryableStatusCodes( () -> METRIC_DATA, metricExporter::export, server.metricRequests::size); @@ -106,8 +112,11 @@ void configureLogRecordExporterRetryPolicy() { server.selfSignedCertificate.certificate().getPath()); props.put("otel.experimental.exporter.otlp.retry.enabled", "true"); try (LogRecordExporter logRecordExporter = - LogRecordExporterConfiguration.configureOtlpLogs( - DefaultConfigProperties.createForTest(props), MeterProvider.noop())) { + LogRecordExporterConfiguration.configureExporter( + "otlp", + LogRecordExporterConfiguration.logRecordExporterSpiManager( + DefaultConfigProperties.createForTest(props), + OtlpHttpRetryTest.class.getClassLoader()))) { testRetryableStatusCodes( () -> LOG_RECORD_DATA, logRecordExporter::export, server.logRequests::size); testDefaultRetryPolicy( From 8f63af0624096ddff8a988503d2a30596680d7fa Mon Sep 17 00:00:00 2001 From: Jack Berg Date: Fri, 2 Dec 2022 13:41:35 -0600 Subject: [PATCH 2/3] Remove redundant else --- .../exporter/otlp/internal/OtlpMetricExporterProvider.java | 3 +-- .../exporter/otlp/internal/OtlpSpanExporterProvider.java | 3 +-- .../exporter/otlp/internal/OtlpLogRecordExporterProvider.java | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpMetricExporterProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpMetricExporterProvider.java index 8cdfb47dc2e..daa54293903 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpMetricExporterProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpMetricExporterProvider.java @@ -70,9 +70,8 @@ public MetricExporter createExporter(ConfigProperties config) { config, builder::setDefaultAggregationSelector); return builder.build(); - } else { - throw new ConfigurationException("Unsupported OTLP metrics protocol: " + protocol); } + throw new ConfigurationException("Unsupported OTLP metrics protocol: " + protocol); } @Override diff --git a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpSpanExporterProvider.java b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpSpanExporterProvider.java index 2917edd4820..084998f4f8a 100644 --- a/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpSpanExporterProvider.java +++ b/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpSpanExporterProvider.java @@ -61,9 +61,8 @@ public SpanExporter createExporter(ConfigProperties config) { retryPolicy -> RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy)); return builder.build(); - } else { - throw new ConfigurationException("Unsupported OTLP traces protocol: " + protocol); } + throw new ConfigurationException("Unsupported OTLP traces protocol: " + protocol); } @Override diff --git a/exporters/otlp/logs/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpLogRecordExporterProvider.java b/exporters/otlp/logs/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpLogRecordExporterProvider.java index 961166f79f3..d212b80e5d3 100644 --- a/exporters/otlp/logs/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpLogRecordExporterProvider.java +++ b/exporters/otlp/logs/src/main/java/io/opentelemetry/exporter/otlp/internal/OtlpLogRecordExporterProvider.java @@ -62,9 +62,8 @@ public LogRecordExporter createExporter(ConfigProperties config) { retryPolicy -> RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy)); return builder.build(); - } else { - throw new ConfigurationException("Unsupported OTLP logs protocol: " + protocol); } + throw new ConfigurationException("Unsupported OTLP logs protocol: " + protocol); } @Override From 459dfe7598d4bc581a83f4759fee1125691a49df Mon Sep 17 00:00:00 2001 From: Jack Berg Date: Sat, 17 Dec 2022 16:07:14 -0600 Subject: [PATCH 3/3] Restore unsupported protocol test --- .../LogRecordExporterConfigurationTest.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfigurationTest.java diff --git a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfigurationTest.java b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfigurationTest.java new file mode 100644 index 00000000000..89674433bd3 --- /dev/null +++ b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/LogRecordExporterConfigurationTest.java @@ -0,0 +1,30 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.autoconfigure; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import com.google.common.collect.ImmutableMap; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; +import org.junit.jupiter.api.Test; + +public class LogRecordExporterConfigurationTest { + + @Test + void configureExporter_UnsupportedOtlpProtocol() { + assertThatThrownBy( + () -> + LogRecordExporterConfiguration.configureExporter( + "otlp", + LogRecordExporterConfiguration.logRecordExporterSpiManager( + DefaultConfigProperties.createForTest( + ImmutableMap.of("otel.exporter.otlp.protocol", "foo")), + LogRecordExporterConfiguration.class.getClassLoader()))) + .isInstanceOf(ConfigurationException.class) + .hasMessageContaining("Unsupported OTLP logs protocol: foo"); + } +}