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