Search in sources :

Example 1 with ConfigurationException

use of io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException in project opentelemetry-java by open-telemetry.

the class ViewConfig method loadViewConfig.

// Visible for testing
@SuppressWarnings("unchecked")
static List<ViewConfigSpecification> loadViewConfig(InputStream inputStream) {
    Yaml yaml = new Yaml();
    try {
        List<ViewConfigSpecification> result = new ArrayList<>();
        List<Map<String, Object>> viewConfigs = yaml.load(inputStream);
        for (Map<String, Object> viewConfigSpecMap : viewConfigs) {
            Map<String, Object> selectorSpecMap = requireNonNull(getAsType(viewConfigSpecMap, "selector", Map.class), "selector is required");
            Map<String, Object> viewSpecMap = requireNonNull(getAsType(viewConfigSpecMap, "view", Map.class), "view is required");
            InstrumentType instrumentType = Optional.ofNullable(getAsType(selectorSpecMap, "instrument_type", String.class)).map(InstrumentType::valueOf).orElse(null);
            List<String> attributeKeys = Optional.ofNullable(((List<Object>) getAsType(viewSpecMap, "attribute_keys", List.class))).map(objects -> objects.stream().map(String::valueOf).collect(toList())).orElse(null);
            result.add(ViewConfigSpecification.builder().selectorSpecification(SelectorSpecification.builder().instrumentName(getAsType(selectorSpecMap, "instrument_name", String.class)).instrumentType(instrumentType).meterName(getAsType(selectorSpecMap, "meter_name", String.class)).meterVersion(getAsType(selectorSpecMap, "meter_version", String.class)).meterSchemaUrl(getAsType(selectorSpecMap, "meter_schema_url", String.class)).build()).viewSpecification(ViewSpecification.builder().name(getAsType(viewSpecMap, "name", String.class)).description(getAsType(viewSpecMap, "description", String.class)).aggregation(getAsType(viewSpecMap, "aggregation", String.class)).attributeKeys(attributeKeys).build()).build());
        }
        return result;
    } catch (RuntimeException e) {
        throw new ConfigurationException("Failed to parse view config", e);
    }
}
Also used : Set(java.util.Set) InstrumentType(io.opentelemetry.sdk.metrics.common.InstrumentType) Aggregation(io.opentelemetry.sdk.metrics.view.Aggregation) InstrumentSelector(io.opentelemetry.sdk.metrics.view.InstrumentSelector) ConfigurationException(io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException) ViewBuilder(io.opentelemetry.sdk.metrics.view.ViewBuilder) ArrayList(java.util.ArrayList) Yaml(org.yaml.snakeyaml.Yaml) HashSet(java.util.HashSet) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) View(io.opentelemetry.sdk.metrics.view.View) SdkMeterProviderBuilder(io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder) InstrumentSelectorBuilder(io.opentelemetry.sdk.metrics.view.InstrumentSelectorBuilder) Objects.requireNonNull(java.util.Objects.requireNonNull) Map(java.util.Map) Optional(java.util.Optional) Nullable(javax.annotation.Nullable) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) InstrumentType(io.opentelemetry.sdk.metrics.common.InstrumentType) Yaml(org.yaml.snakeyaml.Yaml) ConfigurationException(io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Map(java.util.Map)

Example 2 with ConfigurationException

use of io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException in project opentelemetry-java by open-telemetry.

the class DefaultConfigProperties method getDuration.

@Override
@Nullable
@SuppressWarnings("UnusedException")
public Duration getDuration(String name) {
    String value = config.get(name);
    if (value == null || value.isEmpty()) {
        return null;
    }
    String unitString = getUnitString(value);
    // TODO: Environment variables have unknown encoding.  `trim()` may cut codepoints oddly
    // but likely we'll fail for malformed unit string either way.
    String numberString = value.substring(0, value.length() - unitString.length());
    try {
        long rawNumber = Long.parseLong(numberString.trim());
        TimeUnit unit = getDurationUnit(unitString.trim());
        return Duration.ofMillis(TimeUnit.MILLISECONDS.convert(rawNumber, unit));
    } catch (NumberFormatException ex) {
        throw new ConfigurationException("Invalid duration property " + name + "=" + value + ". Expected number, found: " + numberString, ex);
    } catch (ConfigurationException ex) {
        throw new ConfigurationException("Invalid duration property " + name + "=" + value + ". " + ex.getMessage());
    }
}
Also used : ConfigurationException(io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException) TimeUnit(java.util.concurrent.TimeUnit) Nullable(javax.annotation.Nullable)

Example 3 with ConfigurationException

use of io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException in project opentelemetry-java by open-telemetry.

the class SpanExporterConfiguration method configureOtlp.

// Visible for testing
static SpanExporter configureOtlp(ConfigProperties config, MeterProvider meterProvider) {
    String protocol = OtlpConfigUtil.getOtlpProtocol(DATA_TYPE_TRACES, config);
    if (protocol.equals(PROTOCOL_HTTP_PROTOBUF)) {
        ClasspathUtil.checkClassExists("io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter", "OTLP HTTP Trace Exporter", "opentelemetry-exporter-otlp-http-trace");
        OtlpHttpSpanExporterBuilder builder = OtlpHttpSpanExporter.builder();
        OtlpConfigUtil.configureOtlpExporterBuilder(DATA_TYPE_TRACES, config, builder::setEndpoint, builder::addHeader, builder::setCompression, builder::setTimeout, builder::setTrustedCertificates, retryPolicy -> RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy));
        builder.setMeterProvider(meterProvider);
        return builder.build();
    } else if (protocol.equals(PROTOCOL_GRPC)) {
        ClasspathUtil.checkClassExists("io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter", "OTLP gRPC Trace Exporter", "opentelemetry-exporter-otlp");
        OtlpGrpcSpanExporterBuilder builder = OtlpGrpcSpanExporter.builder();
        OtlpConfigUtil.configureOtlpExporterBuilder(DATA_TYPE_TRACES, config, builder::setEndpoint, builder::addHeader, builder::setCompression, builder::setTimeout, builder::setTrustedCertificates, retryPolicy -> RetryUtil.setRetryPolicyOnDelegate(builder, retryPolicy));
        builder.setMeterProvider(meterProvider);
        return builder.build();
    } else {
        throw new ConfigurationException("Unsupported OTLP traces protocol: " + protocol);
    }
}
Also used : ConfigProperties(io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties) BiFunction(java.util.function.BiFunction) OtlpHttpSpanExporter(io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter) Function(java.util.function.Function) PROTOCOL_GRPC(io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.PROTOCOL_GRPC) Collectors.toMap(java.util.stream.Collectors.toMap) PROTOCOL_HTTP_PROTOBUF(io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.PROTOCOL_HTTP_PROTOBUF) Duration(java.time.Duration) Map(java.util.Map) OtlpGrpcSpanExporterBuilder(io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder) ZipkinSpanExporter(io.opentelemetry.exporter.zipkin.ZipkinSpanExporter) OtlpGrpcSpanExporter(io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter) DATA_TYPE_TRACES(io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.DATA_TYPE_TRACES) JaegerGrpcSpanExporterBuilder(io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporterBuilder) ConfigurableSpanExporterProvider(io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider) SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) Set(java.util.Set) ConfigurationException(io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException) OtlpHttpSpanExporterBuilder(io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder) RetryUtil(io.opentelemetry.exporter.internal.retry.RetryUtil) LoggingSpanExporter(io.opentelemetry.exporter.logging.LoggingSpanExporter) ZipkinSpanExporterBuilder(io.opentelemetry.exporter.zipkin.ZipkinSpanExporterBuilder) JaegerGrpcSpanExporter(io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporter) MeterProvider(io.opentelemetry.api.metrics.MeterProvider) Collections(java.util.Collections) OtlpGrpcSpanExporterBuilder(io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder) ConfigurationException(io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException) OtlpHttpSpanExporterBuilder(io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder)

Example 4 with ConfigurationException

use of io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException in project opentelemetry-java by open-telemetry.

the class SpanExporterConfiguration method configureSpanExporters.

// Visible for testing
static Map<String, SpanExporter> configureSpanExporters(ConfigProperties config, ClassLoader serviceClassLoader, MeterProvider meterProvider, BiFunction<? super SpanExporter, ConfigProperties, ? extends SpanExporter> spanExporterCustomizer) {
    Set<String> exporterNames = DefaultConfigProperties.getSet(config, "otel.traces.exporter");
    if (exporterNames.contains(EXPORTER_NONE)) {
        if (exporterNames.size() > 1) {
            throw new ConfigurationException("otel.traces.exporter contains " + EXPORTER_NONE + " along with other exporters");
        }
        SpanExporter noop = SpanExporter.composite();
        SpanExporter customized = spanExporterCustomizer.apply(noop, config);
        if (customized == noop) {
            return Collections.emptyMap();
        }
        return Collections.singletonMap(EXPORTER_NONE, customized);
    }
    if (exporterNames.isEmpty()) {
        exporterNames = Collections.singleton("otlp");
    }
    NamedSpiManager<SpanExporter> spiExportersManager = SpiUtil.loadConfigurable(ConfigurableSpanExporterProvider.class, ConfigurableSpanExporterProvider::getName, ConfigurableSpanExporterProvider::createExporter, config, serviceClassLoader);
    return exporterNames.stream().collect(toMap(Function.identity(), exporterName -> spanExporterCustomizer.apply(configureExporter(exporterName, config, spiExportersManager, meterProvider), config)));
}
Also used : ConfigProperties(io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties) BiFunction(java.util.function.BiFunction) OtlpHttpSpanExporter(io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter) Function(java.util.function.Function) PROTOCOL_GRPC(io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.PROTOCOL_GRPC) Collectors.toMap(java.util.stream.Collectors.toMap) PROTOCOL_HTTP_PROTOBUF(io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.PROTOCOL_HTTP_PROTOBUF) Duration(java.time.Duration) Map(java.util.Map) OtlpGrpcSpanExporterBuilder(io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder) ZipkinSpanExporter(io.opentelemetry.exporter.zipkin.ZipkinSpanExporter) OtlpGrpcSpanExporter(io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter) DATA_TYPE_TRACES(io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.DATA_TYPE_TRACES) JaegerGrpcSpanExporterBuilder(io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporterBuilder) ConfigurableSpanExporterProvider(io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider) SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) Set(java.util.Set) ConfigurationException(io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException) OtlpHttpSpanExporterBuilder(io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder) RetryUtil(io.opentelemetry.exporter.internal.retry.RetryUtil) LoggingSpanExporter(io.opentelemetry.exporter.logging.LoggingSpanExporter) ZipkinSpanExporterBuilder(io.opentelemetry.exporter.zipkin.ZipkinSpanExporterBuilder) JaegerGrpcSpanExporter(io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporter) MeterProvider(io.opentelemetry.api.metrics.MeterProvider) Collections(java.util.Collections) ConfigurableSpanExporterProvider(io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider) OtlpHttpSpanExporter(io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter) ZipkinSpanExporter(io.opentelemetry.exporter.zipkin.ZipkinSpanExporter) OtlpGrpcSpanExporter(io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter) SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) LoggingSpanExporter(io.opentelemetry.exporter.logging.LoggingSpanExporter) JaegerGrpcSpanExporter(io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporter) ConfigurationException(io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException)

Example 5 with ConfigurationException

use of io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException in project opentelemetry-java by open-telemetry.

the class LogExporterConfiguration method configureLogExporters.

// Visible for test
static Map<String, LogExporter> configureLogExporters(ConfigProperties config, MeterProvider meterProvider, BiFunction<? super LogExporter, ConfigProperties, ? extends LogExporter> logExporterCustomizer) {
    Set<String> exporterNames = DefaultConfigProperties.getSet(config, "otel.logs.exporter");
    // Default to no exporter
    if (exporterNames.isEmpty()) {
        exporterNames = Collections.singleton(EXPORTER_NONE);
    }
    if (exporterNames.contains(EXPORTER_NONE)) {
        if (exporterNames.size() > 1) {
            throw new ConfigurationException("otel.logs.exporter contains " + EXPORTER_NONE + " along with other exporters");
        }
        return Collections.emptyMap();
    }
    Map<String, LogExporter> exportersByName = new HashMap<>();
    for (String name : exporterNames) {
        LogExporter logExporter = configureExporter(name, config, meterProvider);
        if (logExporter != null) {
            LogExporter customizedLogExporter = logExporterCustomizer.apply(logExporter, config);
            exportersByName.put(name, customizedLogExporter);
        }
    }
    return Collections.unmodifiableMap(exportersByName);
}
Also used : ConfigurationException(io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException) HashMap(java.util.HashMap) LogExporter(io.opentelemetry.sdk.logs.export.LogExporter) OtlpGrpcLogExporter(io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogExporter) OtlpHttpLogExporter(io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogExporter) SystemOutLogExporter(io.opentelemetry.exporter.logging.SystemOutLogExporter)

Aggregations

ConfigurationException (io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException)11 Nullable (javax.annotation.Nullable)5 RetryUtil (io.opentelemetry.exporter.internal.retry.RetryUtil)4 PROTOCOL_GRPC (io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.PROTOCOL_GRPC)4 PROTOCOL_HTTP_PROTOBUF (io.opentelemetry.sdk.autoconfigure.OtlpConfigUtil.PROTOCOL_HTTP_PROTOBUF)4 ConfigProperties (io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties)4 Duration (java.time.Duration)4 Map (java.util.Map)4 Set (java.util.Set)4 BiFunction (java.util.function.BiFunction)4 MeterProvider (io.opentelemetry.api.metrics.MeterProvider)3 Collections (java.util.Collections)3 JaegerGrpcSpanExporter (io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporter)2 JaegerGrpcSpanExporterBuilder (io.opentelemetry.exporter.jaeger.JaegerGrpcSpanExporterBuilder)2 LoggingMetricExporter (io.opentelemetry.exporter.logging.LoggingMetricExporter)2 LoggingSpanExporter (io.opentelemetry.exporter.logging.LoggingSpanExporter)2 SystemOutLogExporter (io.opentelemetry.exporter.logging.SystemOutLogExporter)2 OtlpHttpLogExporter (io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogExporter)2 OtlpHttpMetricExporter (io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporter)2 OtlpHttpSpanExporter (io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter)2