use of io.opentelemetry.sdk.metrics.export.MetricExporter in project opentelemetry-java by open-telemetry.
the class OtlpGrpcRetryTest method configureMetricExporterRetryPolicy.
@Test
@SuppressLogger(DefaultGrpcExporter.class)
void configureMetricExporterRetryPolicy() {
Map<String, String> props = new HashMap<>();
props.put("otel.exporter.otlp.metrics.endpoint", "https://localhost:" + server.httpsPort());
props.put("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))) {
testRetryableStatusCodes(() -> METRIC_DATA, metricExporter::export, server.metricRequests::size);
testDefaultRetryPolicy(() -> METRIC_DATA, metricExporter::export, server.metricRequests::size);
}
}
use of io.opentelemetry.sdk.metrics.export.MetricExporter in project opentelemetry-java by open-telemetry.
the class OtlpGrpcConfigTest method configureMetricExporter.
@Test
public void configureMetricExporter() {
// Set values for general and signal specific properties. Signal specific should override
// general.
Map<String, String> props = new HashMap<>();
props.put("otel.exporter.otlp.endpoint", "http://foo.bar");
props.put("otel.exporter.otlp.certificate", Paths.get("foo", "bar", "baz").toString());
props.put("otel.exporter.otlp.headers", "header-key=dummy-value");
props.put("otel.exporter.otlp.compression", "gzip");
props.put("otel.exporter.otlp.timeout", "10s");
props.put("otel.exporter.otlp.metrics.endpoint", "https://localhost:" + server.httpsPort());
props.put("otel.exporter.otlp.metrics.certificate", certificate.certificateFile().getAbsolutePath());
props.put("otel.exporter.otlp.metrics.headers", "header-key=header-value");
props.put("otel.exporter.otlp.metrics.compression", "gzip");
props.put("otel.exporter.otlp.metrics.timeout", "15s");
props.put("otel.exporter.otlp.metrics.temporality", "DELTA");
try (MetricExporter metricExporter = MetricExporterConfiguration.configureOtlpMetrics(DefaultConfigProperties.createForTest(props))) {
assertThat(metricExporter).extracting("delegate.timeoutNanos").isEqualTo(TimeUnit.SECONDS.toNanos(15));
assertThat(metricExporter.getPreferredTemporality()).isEqualTo(AggregationTemporality.DELTA);
assertThat(metricExporter.export(METRIC_DATA).join(15, TimeUnit.SECONDS).isSuccess()).isTrue();
assertThat(server.metricRequests).hasSize(1);
assertThat(server.requestHeaders).anyMatch(headers -> headers.contains(":path", "/opentelemetry.proto.collector.metrics.v1.MetricsService/Export") && headers.contains("header-key", "header-value") && headers.contains("grpc-encoding", "gzip"));
}
}
use of io.opentelemetry.sdk.metrics.export.MetricExporter in project opentelemetry-java by open-telemetry.
the class ConfigurableMetricExporterTest method configuration.
@Test
void configuration() {
ConfigProperties config = DefaultConfigProperties.createForTest(ImmutableMap.of("test.option", "true"));
MetricExporter metricExporter = MetricExporterConfiguration.configureSpiExporter("testExporter", config, MetricExporterConfiguration.class.getClassLoader());
assertThat(metricExporter).isInstanceOf(TestConfigurableMetricExporterProvider.TestMetricExporter.class).extracting("config").isSameAs(config);
}
use of io.opentelemetry.sdk.metrics.export.MetricExporter in project opentelemetry-java by open-telemetry.
the class MetricExporterConfiguration method configureExporter.
static void configureExporter(String name, ConfigProperties config, ClassLoader serviceClassLoader, SdkMeterProviderBuilder sdkMeterProviderBuilder, BiFunction<? super MetricExporter, ConfigProperties, ? extends MetricExporter> metricExporterCustomizer) {
if (name.equals("prometheus")) {
sdkMeterProviderBuilder.registerMetricReader(configurePrometheusMetricReader(config));
return;
}
MetricExporter metricExporter;
switch(name) {
case "otlp":
metricExporter = configureOtlpMetrics(config);
break;
case "logging":
metricExporter = configureLoggingExporter();
break;
default:
MetricExporter spiExporter = configureSpiExporter(name, config, serviceClassLoader);
if (spiExporter == null) {
throw new ConfigurationException("Unrecognized value for otel.metrics.exporter: " + name);
}
metricExporter = spiExporter;
}
// exporter may be null in otlp case
if (metricExporter == null) {
return;
}
metricExporter = metricExporterCustomizer.apply(metricExporter, config);
sdkMeterProviderBuilder.registerMetricReader(configurePeriodicMetricReader(config, metricExporter));
}
use of io.opentelemetry.sdk.metrics.export.MetricExporter in project opentelemetry-java by open-telemetry.
the class MetricExporterConfiguration method configureOtlpMetrics.
// Visible for testing
@Nullable
static MetricExporter configureOtlpMetrics(ConfigProperties config) {
String protocol = OtlpConfigUtil.getOtlpProtocol(DATA_TYPE_METRICS, config);
MetricExporter exporter;
if (protocol.equals(PROTOCOL_HTTP_PROTOBUF)) {
try {
ClasspathUtil.checkClassExists("io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporter", "OTLP HTTP Metrics Exporter", "opentelemetry-exporter-otlp-http-metrics");
} catch (ConfigurationException e) {
// Squash this for now, until metrics are stable
return null;
}
OtlpHttpMetricExporterBuilder builder = OtlpHttpMetricExporter.builder();
OtlpConfigUtil.configureOtlpExporterBuilder(DATA_TYPE_METRICS, config, builder::setEndpoint, builder::addHeader, builder::setCompression, builder::setTimeout, builder::setTrustedCertificates, retryPolicy -> RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy));
OtlpConfigUtil.configureOtlpAggregationTemporality(config, builder::setPreferredTemporality);
exporter = builder.build();
} else if (protocol.equals(PROTOCOL_GRPC)) {
try {
ClasspathUtil.checkClassExists("io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter", "OTLP gRPC Metrics Exporter", "opentelemetry-exporter-otlp-metrics");
} catch (ConfigurationException e) {
// by default,
return null;
}
OtlpGrpcMetricExporterBuilder builder = OtlpGrpcMetricExporter.builder();
OtlpConfigUtil.configureOtlpExporterBuilder(DATA_TYPE_METRICS, config, builder::setEndpoint, builder::addHeader, builder::setCompression, builder::setTimeout, builder::setTrustedCertificates, retryPolicy -> RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy));
OtlpConfigUtil.configureOtlpAggregationTemporality(config, builder::setPreferredTemporality);
exporter = builder.build();
} else {
throw new ConfigurationException("Unsupported OTLP metrics protocol: " + protocol);
}
return exporter;
}
Aggregations