use of io.opentelemetry.sdk.metrics.export.MetricExporter in project opentelemetry-java by open-telemetry.
the class ConfigurableMetricExporterTest method configureExporter_OtlpHttpExporterNotOnClasspath.
@Test
void configureExporter_OtlpHttpExporterNotOnClasspath() {
// Use the OTLP http/protobuf exporter which is not on the classpath
ConfigProperties configProperties = DefaultConfigProperties.createForTest(ImmutableMap.of("otel.exporter.otlp.protocol", PROTOCOL_HTTP_PROTOBUF));
SdkMeterProviderBuilder meterProviderBuilder = SdkMeterProvider.builder();
BiFunction<? super MetricExporter, ConfigProperties, ? extends MetricExporter> metricCustomizer = spy(new BiFunction<MetricExporter, ConfigProperties, MetricExporter>() {
@Override
public MetricExporter apply(MetricExporter metricExporter, ConfigProperties configProperties) {
return metricExporter;
}
});
MetricExporterConfiguration.configureExporter("otlp", configProperties, MetricExporterConfiguration.class.getClassLoader(), meterProviderBuilder, metricCustomizer);
// Should not call customizer or register a metric reader
verify(metricCustomizer, never()).apply(any(), any());
assertThat(meterProviderBuilder).extracting("metricReaders", as(InstanceOfAssertFactories.list(MetricReaderFactory.class))).hasSize(0);
}
use of io.opentelemetry.sdk.metrics.export.MetricExporter in project opentelemetry-java by open-telemetry.
the class OtlpGrpcConfigTest method configureExportersGeneral.
@Test
void configureExportersGeneral() {
Map<String, String> props = new HashMap<>();
props.put("otel.exporter.otlp.endpoint", "https://localhost:" + server.httpsPort());
props.put("otel.exporter.otlp.certificate", certificate.certificateFile().getAbsolutePath());
props.put("otel.exporter.otlp.headers", "header-key=header-value");
props.put("otel.exporter.otlp.compression", "gzip");
props.put("otel.exporter.otlp.timeout", "15s");
ConfigProperties properties = DefaultConfigProperties.createForTest(props);
try (SpanExporter spanExporter = SpanExporterConfiguration.configureExporter("otlp", properties, NamedSpiManager.createEmpty(), MeterProvider.noop());
MetricExporter metricExporter = MetricExporterConfiguration.configureOtlpMetrics(properties);
LogExporter logExporter = LogExporterConfiguration.configureOtlpLogs(properties, MeterProvider.noop())) {
assertThat(spanExporter).extracting("delegate.timeoutNanos").isEqualTo(TimeUnit.SECONDS.toNanos(15));
assertThat(spanExporter.export(SPAN_DATA).join(15, TimeUnit.SECONDS).isSuccess()).isTrue();
assertThat(server.traceRequests).hasSize(1);
assertThat(server.requestHeaders).anyMatch(headers -> headers.contains(":path", "/opentelemetry.proto.collector.trace.v1.TraceService/Export") && headers.contains("header-key", "header-value") && headers.contains("grpc-encoding", "gzip"));
assertThat(metricExporter).extracting("delegate.timeoutNanos").isEqualTo(TimeUnit.SECONDS.toNanos(15));
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"));
assertThat(logExporter).extracting("delegate.timeoutNanos").isEqualTo(TimeUnit.SECONDS.toNanos(15));
assertThat(logExporter.export(LOG_DATA).join(15, TimeUnit.SECONDS).isSuccess()).isTrue();
assertThat(server.logRequests).hasSize(1);
assertThat(server.requestHeaders).anyMatch(headers -> headers.contains(":path", "/opentelemetry.proto.collector.logs.v1.LogsService/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 OtlpHttpConfigTest method configureExportersGeneral.
@Test
void configureExportersGeneral() {
Map<String, String> props = new HashMap<>();
props.put("otel.exporter.otlp.protocol", "http/protobuf");
props.put("otel.exporter.otlp.endpoint", "https://localhost:" + server.httpsPort());
props.put("otel.exporter.otlp.certificate", server.selfSignedCertificate.certificate().getPath());
props.put("otel.exporter.otlp.headers", "header-key=header-value");
props.put("otel.exporter.otlp.compression", "gzip");
props.put("otel.exporter.otlp.timeout", "15s");
ConfigProperties properties = DefaultConfigProperties.createForTest(props);
SpanExporter spanExporter = SpanExporterConfiguration.configureExporter("otlp", properties, NamedSpiManager.createEmpty(), MeterProvider.noop());
MetricExporter metricExporter = MetricExporterConfiguration.configureOtlpMetrics(properties);
LogExporter logExporter = LogExporterConfiguration.configureOtlpLogs(properties, MeterProvider.noop());
assertThat(spanExporter).extracting("delegate.client", as(InstanceOfAssertFactories.type(OkHttpClient.class))).extracting(OkHttpClient::callTimeoutMillis).isEqualTo((int) TimeUnit.SECONDS.toMillis(15));
assertThat(spanExporter.export(Lists.newArrayList(generateFakeSpan())).join(15, TimeUnit.SECONDS).isSuccess()).isTrue();
assertThat(server.traceRequests).hasSize(1);
assertThat(server.requestHeaders).anyMatch(headers -> headers.contains(":path", "/v1/traces") && headers.contains("header-key", "header-value") && headers.contains("content-encoding", "gzip"));
assertThat(metricExporter).extracting("delegate.client", as(InstanceOfAssertFactories.type(OkHttpClient.class))).extracting(OkHttpClient::callTimeoutMillis).isEqualTo((int) TimeUnit.SECONDS.toMillis(15));
assertThat(metricExporter.export(Lists.newArrayList(generateFakeMetric())).join(15, TimeUnit.SECONDS).isSuccess()).isTrue();
assertThat(server.metricRequests).hasSize(1);
assertThat(server.requestHeaders).anyMatch(headers -> headers.contains(":path", "/v1/metrics") && headers.contains("header-key", "header-value") && headers.contains("content-encoding", "gzip"));
assertThat(logExporter).extracting("delegate.client", as(InstanceOfAssertFactories.type(OkHttpClient.class))).extracting(OkHttpClient::callTimeoutMillis).isEqualTo((int) TimeUnit.SECONDS.toMillis(15));
assertThat(logExporter.export(Lists.newArrayList(generateFakeLog())).join(15, TimeUnit.SECONDS).isSuccess()).isTrue();
assertThat(server.logRequests).hasSize(1);
assertThat(server.requestHeaders).anyMatch(headers -> headers.contains(":path", "/v1/logs") && headers.contains("header-key", "header-value") && headers.contains("content-encoding", "gzip"));
}
use of io.opentelemetry.sdk.metrics.export.MetricExporter in project opentelemetry-java by open-telemetry.
the class OtlpHttpConfigTest 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.protocol", "grpc");
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", "foo");
props.put("otel.exporter.otlp.timeout", "10s");
props.put("otel.exporter.otlp.metrics.protocol", "http/protobuf");
props.put("otel.exporter.otlp.metrics.endpoint", "https://localhost:" + server.httpsPort() + "/v1/metrics");
props.put("otel.exporter.otlp.metrics.certificate", server.selfSignedCertificate.certificate().getPath());
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");
MetricExporter metricExporter = MetricExporterConfiguration.configureOtlpMetrics(DefaultConfigProperties.createForTest(props));
assertThat(metricExporter).extracting("delegate.client", as(InstanceOfAssertFactories.type(OkHttpClient.class))).extracting(OkHttpClient::callTimeoutMillis).isEqualTo((int) TimeUnit.SECONDS.toMillis(15));
assertThat(metricExporter.getPreferredTemporality()).isEqualTo(AggregationTemporality.DELTA);
assertThat(metricExporter.export(Lists.newArrayList(generateFakeMetric())).join(15, TimeUnit.SECONDS).isSuccess()).isTrue();
assertThat(server.metricRequests).hasSize(1);
assertThat(server.requestHeaders).anyMatch(headers -> headers.contains(":path", "/v1/metrics") && headers.contains("header-key", "header-value"));
}
use of io.opentelemetry.sdk.metrics.export.MetricExporter in project opentelemetry-java by open-telemetry.
the class OtlpHttpRetryTest method configureMetricExporterRetryPolicy.
@Test
@SuppressLogger(OkHttpGrpcExporter.class)
void configureMetricExporterRetryPolicy() {
Map<String, String> props = new HashMap<>();
props.put("otel.exporter.otlp.metrics.protocol", "http/protobuf");
props.put("otel.exporter.otlp.metrics.endpoint", "https://localhost:" + server.httpsPort() + "/v1/metrics");
props.put("otel.exporter.otlp.metrics.certificate", server.selfSignedCertificate.certificate().getPath());
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);
}
}
Aggregations