Ignore classpath error when otlp is set as metrics exporter but is no… (#2960)
* Ignore classpath error when otlp is set as metrics exporter but is not on the classpath since the default value is otlp but metrics is alpha. * Update sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/MetricExporterConfiguration.java Co-authored-by: Nikita Salnikov-Tarnovski <gnikem@gmail.com> Co-authored-by: Bogdan Drutu <lazy@splunk.com> Co-authored-by: Nikita Salnikov-Tarnovski <gnikem@gmail.com>
This commit is contained in:
parent
4e342fdea9
commit
c670b859d6
|
|
@ -17,6 +17,7 @@ import io.prometheus.client.exporter.HTTPServer;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
final class MetricExporterConfiguration {
|
final class MetricExporterConfiguration {
|
||||||
|
|
||||||
|
|
@ -48,12 +49,19 @@ final class MetricExporterConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Visible for testing
|
// Visible for testing
|
||||||
|
@Nullable
|
||||||
static OtlpGrpcMetricExporter configureOtlpMetrics(
|
static OtlpGrpcMetricExporter configureOtlpMetrics(
|
||||||
ConfigProperties config, SdkMeterProvider meterProvider) {
|
ConfigProperties config, SdkMeterProvider meterProvider) {
|
||||||
|
try {
|
||||||
ClasspathUtil.checkClassExists(
|
ClasspathUtil.checkClassExists(
|
||||||
"io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter",
|
"io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter",
|
||||||
"OTLP Metrics Exporter",
|
"OTLP Metrics Exporter",
|
||||||
"opentelemetry-exporter-otlp-metrics");
|
"opentelemetry-exporter-otlp-metrics");
|
||||||
|
} catch (ConfigurationException e) {
|
||||||
|
// Squash this for now, until metrics are stable and included in the `exporter-otlp` artifact
|
||||||
|
// by default,
|
||||||
|
return null;
|
||||||
|
}
|
||||||
OtlpGrpcMetricExporterBuilder builder = OtlpGrpcMetricExporter.builder();
|
OtlpGrpcMetricExporterBuilder builder = OtlpGrpcMetricExporter.builder();
|
||||||
|
|
||||||
String endpoint = config.getString("otel.exporter.otlp.endpoint");
|
String endpoint = config.getString("otel.exporter.otlp.endpoint");
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ final class SpanExporterConfiguration {
|
||||||
ClasspathUtil.checkClassExists(
|
ClasspathUtil.checkClassExists(
|
||||||
"io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter",
|
"io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter",
|
||||||
"OTLP Trace Exporter",
|
"OTLP Trace Exporter",
|
||||||
"opentelemetry-exporter-otlp-trace");
|
"opentelemetry-exporter-otlp");
|
||||||
OtlpGrpcSpanExporterBuilder builder = OtlpGrpcSpanExporter.builder();
|
OtlpGrpcSpanExporterBuilder builder = OtlpGrpcSpanExporter.builder();
|
||||||
|
|
||||||
String endpoint = config.getString("otel.exporter.otlp.endpoint");
|
String endpoint = config.getString("otel.exporter.otlp.endpoint");
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
package io.opentelemetry.sdk.autoconfigure;
|
package io.opentelemetry.sdk.autoconfigure;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
|
|
||||||
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
|
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
|
||||||
|
|
@ -21,7 +22,7 @@ class NotOnClasspathTest {
|
||||||
assertThatThrownBy(() -> SpanExporterConfiguration.configureExporter("otlp", EMPTY))
|
assertThatThrownBy(() -> SpanExporterConfiguration.configureExporter("otlp", EMPTY))
|
||||||
.isInstanceOf(ConfigurationException.class)
|
.isInstanceOf(ConfigurationException.class)
|
||||||
.hasMessageContaining(
|
.hasMessageContaining(
|
||||||
"OTLP Trace Exporter enabled but opentelemetry-exporter-otlp-trace not found on "
|
"OTLP Trace Exporter enabled but opentelemetry-exporter-otlp not found on "
|
||||||
+ "classpath");
|
+ "classpath");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -65,14 +66,11 @@ class NotOnClasspathTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void otlpMetrics() {
|
void otlpMetrics() {
|
||||||
assertThatThrownBy(
|
assertThatCode(
|
||||||
() ->
|
() ->
|
||||||
MetricExporterConfiguration.configureExporter(
|
MetricExporterConfiguration.configureExporter(
|
||||||
"otlp", EMPTY, SdkMeterProvider.builder().build()))
|
"otlp", EMPTY, SdkMeterProvider.builder().build()))
|
||||||
.isInstanceOf(ConfigurationException.class)
|
.doesNotThrowAnyException();
|
||||||
.hasMessageContaining(
|
|
||||||
"OTLP Metrics Exporter enabled but opentelemetry-exporter-otlp-metrics not found on "
|
|
||||||
+ "classpath");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue