Search in sources :

Example 1 with DATA_TYPE_METRICS

use of io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.DATA_TYPE_METRICS 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

RetryUtil (io.opentelemetry.exporter.internal.retry.RetryUtil)1 LoggingMetricExporter (io.opentelemetry.exporter.logging.LoggingMetricExporter)1 OtlpHttpMetricExporter (io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporter)1 OtlpHttpMetricExporterBuilder (io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporterBuilder)1 OtlpGrpcMetricExporter (io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter)1 OtlpGrpcMetricExporterBuilder (io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporterBuilder)1 PrometheusHttpServer (io.opentelemetry.exporter.prometheus.PrometheusHttpServer)1 PrometheusHttpServerBuilder (io.opentelemetry.exporter.prometheus.PrometheusHttpServerBuilder)1 DATA_TYPE_METRICS (io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.DATA_TYPE_METRICS)1 PROTOCOL_GRPC (io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.PROTOCOL_GRPC)1 PROTOCOL_HTTP_PROTOBUF (io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.PROTOCOL_HTTP_PROTOBUF)1 ConfigProperties (io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties)1 ConfigurationException (io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException)1 ConfigurableMetricExporterProvider (io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider)1 SdkMeterProviderBuilder (io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder)1 MetricExporter (io.opentelemetry.sdk.metrics.export.MetricExporter)1 MetricReaderFactory (io.opentelemetry.sdk.metrics.export.MetricReaderFactory)1 PeriodicMetricReader (io.opentelemetry.sdk.metrics.export.PeriodicMetricReader)1 Duration (java.time.Duration)1 BiFunction (java.util.function.BiFunction)1