Search in sources :

Example 1 with SdkLogEmitterProviderBuilder

use of io.opentelemetry.sdk.logs.SdkLogEmitterProviderBuilder in project opentelemetry-java by open-telemetry.

the class LogEmitterProviderConfigurationTest method configureLogEmitterProvider.

@Test
void configureLogEmitterProvider() {
    Map<String, String> properties = Collections.singletonMap("otel.logs.exporter", "otlp");
    SdkLogEmitterProviderBuilder builder = SdkLogEmitterProvider.builder();
    LogEmitterProviderConfiguration.configureLogEmitterProvider(builder, DefaultConfigProperties.createForTest(properties), MeterProvider.noop(), (a, unused) -> a);
    SdkLogEmitterProvider logEmitterProvider = builder.build();
    try {
        assertThat(logEmitterProvider).extracting("sharedState").satisfies(sharedState -> assertThat(sharedState).extracting("logProcessor").isInstanceOf(BatchLogProcessor.class).extracting("worker").satisfies(worker -> {
            assertThat(worker).extracting("scheduleDelayNanos").isEqualTo(TimeUnit.MILLISECONDS.toNanos(200));
            assertThat(worker).extracting("exporterTimeoutNanos").isEqualTo(TimeUnit.MILLISECONDS.toNanos(30000));
            assertThat(worker).extracting("maxExportBatchSize").isEqualTo(512);
            assertThat(worker).extracting("queue").isInstanceOfSatisfying(ArrayBlockingQueue.class, queue -> assertThat(queue.remainingCapacity()).isEqualTo(2048));
        }));
    } finally {
        logEmitterProvider.shutdown();
    }
}
Also used : SdkLogEmitterProviderBuilder(io.opentelemetry.sdk.logs.SdkLogEmitterProviderBuilder) LogExporter(io.opentelemetry.sdk.logs.export.LogExporter) OtlpGrpcLogExporter(io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogExporter) ImmutableMap(com.google.common.collect.ImmutableMap) SdkLogEmitterProvider(io.opentelemetry.sdk.logs.SdkLogEmitterProvider) SimpleLogProcessor(io.opentelemetry.sdk.logs.export.SimpleLogProcessor) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SystemOutLogExporter(io.opentelemetry.exporter.logging.SystemOutLogExporter) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) BatchLogProcessor(io.opentelemetry.sdk.logs.export.BatchLogProcessor) Map(java.util.Map) MeterProvider(io.opentelemetry.api.metrics.MeterProvider) Collections(java.util.Collections) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) BatchLogProcessor(io.opentelemetry.sdk.logs.export.BatchLogProcessor) SdkLogEmitterProvider(io.opentelemetry.sdk.logs.SdkLogEmitterProvider) SdkLogEmitterProviderBuilder(io.opentelemetry.sdk.logs.SdkLogEmitterProviderBuilder) Test(org.junit.jupiter.api.Test)

Example 2 with SdkLogEmitterProviderBuilder

use of io.opentelemetry.sdk.logs.SdkLogEmitterProviderBuilder 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);
}
Also used : SdkTracerProviderBuilder(io.opentelemetry.sdk.trace.SdkTracerProviderBuilder) ConfigProperties(io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties) SdkMeterProvider(io.opentelemetry.sdk.metrics.SdkMeterProvider) ContextPropagators(io.opentelemetry.context.propagation.ContextPropagators) Resource(io.opentelemetry.sdk.resources.Resource) SdkTracerProvider(io.opentelemetry.sdk.trace.SdkTracerProvider) OpenTelemetrySdkBuilder(io.opentelemetry.sdk.OpenTelemetrySdkBuilder) ArrayList(java.util.ArrayList) List(java.util.List) AutoConfigurationCustomizerProvider(io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider) SdkMeterProviderBuilder(io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder) SdkLogEmitterProvider(io.opentelemetry.sdk.logs.SdkLogEmitterProvider) OpenTelemetrySdk(io.opentelemetry.sdk.OpenTelemetrySdk) SdkLogEmitterProviderBuilder(io.opentelemetry.sdk.logs.SdkLogEmitterProviderBuilder)

Aggregations

SdkLogEmitterProvider (io.opentelemetry.sdk.logs.SdkLogEmitterProvider)2 SdkLogEmitterProviderBuilder (io.opentelemetry.sdk.logs.SdkLogEmitterProviderBuilder)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 MeterProvider (io.opentelemetry.api.metrics.MeterProvider)1 ContextPropagators (io.opentelemetry.context.propagation.ContextPropagators)1 SystemOutLogExporter (io.opentelemetry.exporter.logging.SystemOutLogExporter)1 OtlpGrpcLogExporter (io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogExporter)1 OpenTelemetrySdk (io.opentelemetry.sdk.OpenTelemetrySdk)1 OpenTelemetrySdkBuilder (io.opentelemetry.sdk.OpenTelemetrySdkBuilder)1 AutoConfigurationCustomizerProvider (io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider)1 ConfigProperties (io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties)1 BatchLogProcessor (io.opentelemetry.sdk.logs.export.BatchLogProcessor)1 LogExporter (io.opentelemetry.sdk.logs.export.LogExporter)1 SimpleLogProcessor (io.opentelemetry.sdk.logs.export.SimpleLogProcessor)1 SdkMeterProvider (io.opentelemetry.sdk.metrics.SdkMeterProvider)1 SdkMeterProviderBuilder (io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder)1 Resource (io.opentelemetry.sdk.resources.Resource)1 SdkTracerProvider (io.opentelemetry.sdk.trace.SdkTracerProvider)1 SdkTracerProviderBuilder (io.opentelemetry.sdk.trace.SdkTracerProviderBuilder)1 ArrayList (java.util.ArrayList)1