Search in sources :

Example 1 with SdkLogEmitterProvider

use of io.opentelemetry.sdk.logs.SdkLogEmitterProvider 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 SdkLogEmitterProvider

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

the class OpenTelemetrySdkBuilder method build.

/**
 * Returns a new {@link OpenTelemetrySdk} built with the configuration of this {@link
 * OpenTelemetrySdkBuilder}. This SDK is not registered as the global {@link
 * io.opentelemetry.api.OpenTelemetry}. It is recommended that you register one SDK using {@link
 * OpenTelemetrySdkBuilder#buildAndRegisterGlobal()} for use by instrumentation that requires
 * access to a global instance of {@link io.opentelemetry.api.OpenTelemetry}.
 *
 * @see GlobalOpenTelemetry
 */
public OpenTelemetrySdk build() {
    SdkTracerProvider tracerProvider = this.tracerProvider;
    if (tracerProvider == null) {
        tracerProvider = SdkTracerProvider.builder().build();
    }
    SdkMeterProvider meterProvider = this.meterProvider;
    if (meterProvider == null) {
        meterProvider = SdkMeterProvider.builder().build();
    }
    SdkLogEmitterProvider logEmitterProvider = this.logEmitterProvider;
    if (logEmitterProvider == null) {
        logEmitterProvider = SdkLogEmitterProvider.builder().build();
    }
    return new OpenTelemetrySdk(tracerProvider, meterProvider, logEmitterProvider, propagators);
}
Also used : SdkMeterProvider(io.opentelemetry.sdk.metrics.SdkMeterProvider) SdkLogEmitterProvider(io.opentelemetry.sdk.logs.SdkLogEmitterProvider) SdkTracerProvider(io.opentelemetry.sdk.trace.SdkTracerProvider)

Example 3 with SdkLogEmitterProvider

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

the class BatchLogProcessorTest method emitLogsToMultipleExporters.

@Test
void emitLogsToMultipleExporters() {
    WaitingLogExporter waitingLogExporter1 = new WaitingLogExporter(2, CompletableResultCode.ofSuccess());
    WaitingLogExporter waitingLogExporter2 = new WaitingLogExporter(2, CompletableResultCode.ofSuccess());
    SdkLogEmitterProvider sdkLogEmitterProvider = SdkLogEmitterProvider.builder().addLogProcessor(BatchLogProcessor.builder(LogExporter.composite(Arrays.asList(waitingLogExporter1, waitingLogExporter2))).setScheduleDelay(MAX_SCHEDULE_DELAY_MILLIS, TimeUnit.MILLISECONDS).build()).build();
    emitLog(sdkLogEmitterProvider, LOG_MESSAGE_1);
    emitLog(sdkLogEmitterProvider, LOG_MESSAGE_2);
    List<LogData> exported1 = waitingLogExporter1.waitForExport();
    List<LogData> exported2 = waitingLogExporter2.waitForExport();
    assertThat(exported1).hasSize(2).satisfiesExactly(logData -> assertThat(logData).hasBody(LOG_MESSAGE_1), logData -> assertThat(logData).hasBody(LOG_MESSAGE_2));
    assertThat(exported2).hasSize(2).satisfiesExactly(logData -> assertThat(logData).hasBody(LOG_MESSAGE_1), logData -> assertThat(logData).hasBody(LOG_MESSAGE_2));
}
Also used : LogData(io.opentelemetry.sdk.logs.data.LogData) SdkLogEmitterProvider(io.opentelemetry.sdk.logs.SdkLogEmitterProvider) Test(org.junit.jupiter.api.Test)

Example 4 with SdkLogEmitterProvider

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

the class BatchLogProcessorTest method exporterThrowsException.

@Test
@SuppressLogger(MultiLogExporter.class)
void exporterThrowsException() {
    WaitingLogExporter waitingLogExporter = new WaitingLogExporter(1, CompletableResultCode.ofSuccess());
    doThrow(new IllegalArgumentException("No export for you.")).when(mockLogExporter).export(anyList());
    SdkLogEmitterProvider sdkLogEmitterProvider = SdkLogEmitterProvider.builder().addLogProcessor(BatchLogProcessor.builder(LogExporter.composite(Arrays.asList(mockLogExporter, waitingLogExporter))).setScheduleDelay(MAX_SCHEDULE_DELAY_MILLIS, TimeUnit.MILLISECONDS).build()).build();
    emitLog(sdkLogEmitterProvider, LOG_MESSAGE_1);
    List<LogData> exported = waitingLogExporter.waitForExport();
    assertThat(exported).satisfiesExactly(logData -> assertThat(logData).hasBody(LOG_MESSAGE_1));
    waitingLogExporter.reset();
    // Continue to export after the exception was received.
    emitLog(sdkLogEmitterProvider, LOG_MESSAGE_2);
    exported = waitingLogExporter.waitForExport();
    assertThat(exported).satisfiesExactly(logData -> assertThat(logData).hasBody(LOG_MESSAGE_2));
}
Also used : LogData(io.opentelemetry.sdk.logs.data.LogData) SdkLogEmitterProvider(io.opentelemetry.sdk.logs.SdkLogEmitterProvider) SuppressLogger(io.opentelemetry.internal.testing.slf4j.SuppressLogger) Test(org.junit.jupiter.api.Test)

Example 5 with SdkLogEmitterProvider

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

the class BatchLogProcessorTest method shutdownFlushes.

@Test
@Timeout(10)
void shutdownFlushes() {
    WaitingLogExporter waitingLogExporter = new WaitingLogExporter(1, CompletableResultCode.ofSuccess());
    // Set the export delay to large value, in order to confirm the #flush() below works
    SdkLogEmitterProvider sdkLogEmitterProvider = SdkLogEmitterProvider.builder().addLogProcessor(BatchLogProcessor.builder(waitingLogExporter).setScheduleDelay(10, TimeUnit.SECONDS).build()).build();
    emitLog(sdkLogEmitterProvider, LOG_MESSAGE_2);
    // Force a shutdown, which forces processing of all remaining logs.
    sdkLogEmitterProvider.shutdown().join(10, TimeUnit.SECONDS);
    List<LogData> exported = waitingLogExporter.getExported();
    assertThat(exported).satisfiesExactly(logData -> assertThat(logData).hasBody(LOG_MESSAGE_2));
    ;
    assertThat(waitingLogExporter.shutDownCalled.get()).isTrue();
}
Also used : LogData(io.opentelemetry.sdk.logs.data.LogData) SdkLogEmitterProvider(io.opentelemetry.sdk.logs.SdkLogEmitterProvider) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Aggregations

SdkLogEmitterProvider (io.opentelemetry.sdk.logs.SdkLogEmitterProvider)16 Test (org.junit.jupiter.api.Test)10 LogData (io.opentelemetry.sdk.logs.data.LogData)8 CompletableResultCode (io.opentelemetry.sdk.common.CompletableResultCode)4 List (java.util.List)4 TimeUnit (java.util.concurrent.TimeUnit)4 SuppressLogger (io.opentelemetry.internal.testing.slf4j.SuppressLogger)3 OpenTelemetrySdk (io.opentelemetry.sdk.OpenTelemetrySdk)3 SdkMeterProvider (io.opentelemetry.sdk.metrics.SdkMeterProvider)3 SdkTracerProvider (io.opentelemetry.sdk.trace.SdkTracerProvider)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 Timeout (org.junit.jupiter.api.Timeout)3 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)3 Mock (org.mockito.Mock)3 Mockito.when (org.mockito.Mockito.when)3 GuardedBy (io.opentelemetry.api.internal.GuardedBy)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 Map (java.util.Map)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2