Search in sources :

Example 1 with MetricExporter

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);
    }
}
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)

Example 2 with MetricExporter

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

Example 3 with MetricExporter

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

Example 4 with MetricExporter

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));
}
Also used : LoggingMetricExporter(io.opentelemetry.exporter.logging.LoggingMetricExporter) OtlpHttpMetricExporter(io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporter) OtlpGrpcMetricExporter(io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter) MetricExporter(io.opentelemetry.sdk.metrics.export.MetricExporter) ConfigurationException(io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException)

Example 5 with 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;
}
Also used : LoggingMetricExporter(io.opentelemetry.exporter.logging.LoggingMetricExporter) OtlpHttpMetricExporter(io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporter) OtlpGrpcMetricExporter(io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter) MetricExporter(io.opentelemetry.sdk.metrics.export.MetricExporter) ConfigProperties(io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties) LoggingMetricExporter(io.opentelemetry.exporter.logging.LoggingMetricExporter) ConfigurableMetricExporterProvider(io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider) PrometheusHttpServer(io.opentelemetry.exporter.prometheus.PrometheusHttpServer) DATA_TYPE_METRICS(io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.DATA_TYPE_METRICS) BiFunction(java.util.function.BiFunction) OtlpHttpMetricExporterBuilder(io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporterBuilder) ConfigurationException(io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException) PROTOCOL_GRPC(io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.PROTOCOL_GRPC) OtlpHttpMetricExporter(io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporter) PrometheusHttpServerBuilder(io.opentelemetry.exporter.prometheus.PrometheusHttpServerBuilder) RetryUtil(io.opentelemetry.exporter.internal.retry.RetryUtil) OtlpGrpcMetricExporter(io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter) SdkMeterProviderBuilder(io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder) PROTOCOL_HTTP_PROTOBUF(io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.PROTOCOL_HTTP_PROTOBUF) MetricReaderFactory(io.opentelemetry.sdk.metrics.export.MetricReaderFactory) Duration(java.time.Duration) PeriodicMetricReader(io.opentelemetry.sdk.metrics.export.PeriodicMetricReader) OtlpGrpcMetricExporterBuilder(io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporterBuilder) Nullable(javax.annotation.Nullable) MetricExporter(io.opentelemetry.sdk.metrics.export.MetricExporter) OtlpHttpMetricExporterBuilder(io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporterBuilder) OtlpGrpcMetricExporterBuilder(io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporterBuilder) ConfigurationException(io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException) Nullable(javax.annotation.Nullable)

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