use of io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder in project opentelemetry-java by open-telemetry.
the class ViewConfigTest method registerViews_FullConfig.
@Test
void registerViews_FullConfig() {
SdkMeterProviderBuilder builder = SdkMeterProvider.builder();
ViewConfig.registerViews(builder, resourceFileInputStream("full-config.yaml"));
assertThat(builder).extracting("viewRegistryBuilder", as(InstanceOfAssertFactories.type(ViewRegistryBuilder.class))).extracting("orderedViews", as(InstanceOfAssertFactories.list(Object.class))).hasSize(2);
}
use of io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder 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);
}
use of io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder in project opentelemetry-java by open-telemetry.
the class AutoConfiguredOpenTelemetrySdkBuilder method build.
/**
* Returns a new {@link AutoConfiguredOpenTelemetrySdk} holding components auto-configured using
* the settings of this {@link AutoConfiguredOpenTelemetrySdkBuilder}.
*/
public AutoConfiguredOpenTelemetrySdk build() {
if (!customized) {
customized = true;
mergeSdkTracerProviderConfigurer();
for (AutoConfigurationCustomizerProvider customizer : ServiceLoader.load(AutoConfigurationCustomizerProvider.class, serviceClassLoader)) {
customizer.customize(this);
}
}
ConfigProperties config = getConfig();
Resource resource = ResourceConfiguration.configureResource(config, serviceClassLoader, resourceCustomizer);
SdkMeterProviderBuilder meterProviderBuilder = SdkMeterProvider.builder();
meterProviderBuilder.setResource(resource);
MeterProviderConfiguration.configureMeterProvider(meterProviderBuilder, config, serviceClassLoader, metricExporterCustomizer);
meterProviderBuilder = meterProviderCustomizer.apply(meterProviderBuilder, config);
SdkMeterProvider meterProvider = meterProviderBuilder.build();
SdkTracerProviderBuilder tracerProviderBuilder = SdkTracerProvider.builder();
tracerProviderBuilder.setResource(resource);
TracerProviderConfiguration.configureTracerProvider(tracerProviderBuilder, config, serviceClassLoader, meterProvider, spanExporterCustomizer, samplerCustomizer);
tracerProviderBuilder = tracerProviderCustomizer.apply(tracerProviderBuilder, config);
SdkTracerProvider tracerProvider = tracerProviderBuilder.build();
SdkLogEmitterProviderBuilder logEmitterProviderBuilder = SdkLogEmitterProvider.builder();
logEmitterProviderBuilder.setResource(resource);
LogEmitterProviderConfiguration.configureLogEmitterProvider(logEmitterProviderBuilder, config, meterProvider, logExporterCustomizer);
logEmitterProviderBuilder = logEmitterProviderCustomizer.apply(logEmitterProviderBuilder, config);
SdkLogEmitterProvider logEmitterProvider = logEmitterProviderBuilder.build();
if (registerShutdownHook) {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
List<CompletableResultCode> shutdown = new ArrayList<>();
shutdown.add(tracerProvider.shutdown());
shutdown.add(meterProvider.shutdown());
shutdown.add(logEmitterProvider.shutdown());
CompletableResultCode.ofAll(shutdown).join(10, TimeUnit.SECONDS);
}));
}
ContextPropagators propagators = PropagatorConfiguration.configurePropagators(config, serviceClassLoader, propagatorCustomizer);
OpenTelemetrySdkBuilder sdkBuilder = OpenTelemetrySdk.builder().setTracerProvider(tracerProvider).setLogEmitterProvider(logEmitterProvider).setMeterProvider(meterProvider).setPropagators(propagators);
OpenTelemetrySdk openTelemetrySdk = sdkBuilder.build();
if (setResultAsGlobal) {
GlobalOpenTelemetry.set(openTelemetrySdk);
logger.log(Level.FINE, "Global OpenTelemetrySdk set to {0} by autoconfiguration", openTelemetrySdk);
}
return AutoConfiguredOpenTelemetrySdk.create(openTelemetrySdk, resource, config);
}
Aggregations