Search in sources :

Example 6 with MetricExporter

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);
}
Also used : MetricExporter(io.opentelemetry.sdk.metrics.export.MetricExporter) ConfigProperties(io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties) MetricReaderFactory(io.opentelemetry.sdk.metrics.export.MetricReaderFactory) SdkMeterProviderBuilder(io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder) Test(org.junit.jupiter.api.Test)

Example 7 with MetricExporter

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"));
    }
}
Also used : MetricExporter(io.opentelemetry.sdk.metrics.export.MetricExporter) ConfigProperties(io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties) SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) HashMap(java.util.HashMap) LogExporter(io.opentelemetry.sdk.logs.export.LogExporter) Test(org.junit.jupiter.api.Test)

Example 8 with MetricExporter

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"));
}
Also used : MetricExporter(io.opentelemetry.sdk.metrics.export.MetricExporter) ConfigProperties(io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties) SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) HashMap(java.util.HashMap) LogExporter(io.opentelemetry.sdk.logs.export.LogExporter) Test(org.junit.jupiter.api.Test)

Example 9 with MetricExporter

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"));
}
Also used : MetricExporter(io.opentelemetry.sdk.metrics.export.MetricExporter) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 10 with MetricExporter

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);
    }
}
Also used : MetricExporter(io.opentelemetry.sdk.metrics.export.MetricExporter) HashMap(java.util.HashMap) SuppressLogger(io.opentelemetry.internal.testing.slf4j.SuppressLogger) Test(org.junit.jupiter.api.Test)

Aggregations

MetricExporter (io.opentelemetry.sdk.metrics.export.MetricExporter)12 Test (org.junit.jupiter.api.Test)8 HashMap (java.util.HashMap)6 ConfigProperties (io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties)5 OtlpHttpMetricExporter (io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporter)4 OtlpGrpcMetricExporter (io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter)4 LoggingMetricExporter (io.opentelemetry.exporter.logging.LoggingMetricExporter)2 SuppressLogger (io.opentelemetry.internal.testing.slf4j.SuppressLogger)2 ConfigurationException (io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException)2 LogExporter (io.opentelemetry.sdk.logs.export.LogExporter)2 SdkMeterProviderBuilder (io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder)2 MetricReaderFactory (io.opentelemetry.sdk.metrics.export.MetricReaderFactory)2 SpanExporter (io.opentelemetry.sdk.trace.export.SpanExporter)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 ValueSource (org.junit.jupiter.params.provider.ValueSource)2 RetryUtil (io.opentelemetry.exporter.internal.retry.RetryUtil)1 OtlpHttpMetricExporterBuilder (io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporterBuilder)1 OtlpGrpcMetricExporterBuilder (io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporterBuilder)1 PrometheusHttpServer (io.opentelemetry.exporter.prometheus.PrometheusHttpServer)1 PrometheusHttpServerBuilder (io.opentelemetry.exporter.prometheus.PrometheusHttpServerBuilder)1