Search in sources :

Example 6 with LogData

use of io.opentelemetry.sdk.logs.data.LogData 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 7 with LogData

use of io.opentelemetry.sdk.logs.data.LogData 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)

Example 8 with LogData

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

the class BatchLogProcessorTest method emitMoreLogsThanBufferSize.

@Test
void emitMoreLogsThanBufferSize() {
    CompletableLogExporter logExporter = new CompletableLogExporter();
    SdkLogEmitterProvider sdkLogEmitterProvider = SdkLogEmitterProvider.builder().addLogProcessor(BatchLogProcessor.builder(logExporter).setMaxQueueSize(6).setMaxExportBatchSize(2).setScheduleDelay(MAX_SCHEDULE_DELAY_MILLIS, TimeUnit.MILLISECONDS).build()).build();
    emitLog(sdkLogEmitterProvider, LOG_MESSAGE_1);
    emitLog(sdkLogEmitterProvider, LOG_MESSAGE_1);
    emitLog(sdkLogEmitterProvider, LOG_MESSAGE_1);
    emitLog(sdkLogEmitterProvider, LOG_MESSAGE_1);
    emitLog(sdkLogEmitterProvider, LOG_MESSAGE_1);
    emitLog(sdkLogEmitterProvider, LOG_MESSAGE_1);
    logExporter.succeed();
    await().untilAsserted(() -> assertThat(logExporter.getExported()).hasSize(6).allSatisfy(logData -> assertThat(logData).hasBody(LOG_MESSAGE_1)));
}
Also used : Strictness(org.mockito.quality.Strictness) LogAssertions.assertThat(io.opentelemetry.sdk.testing.assertj.LogAssertions.assertThat) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) AssertionsForClassTypes.assertThatCode(org.assertj.core.api.AssertionsForClassTypes.assertThatCode) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Mock(org.mockito.Mock) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayList(java.util.ArrayList) Mockito.doThrow(org.mockito.Mockito.doThrow) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) LogData(io.opentelemetry.sdk.logs.data.LogData) Nullable(javax.annotation.Nullable) Awaitility.await(org.awaitility.Awaitility.await) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) GuardedBy(io.opentelemetry.api.internal.GuardedBy) SdkLogEmitterProvider(io.opentelemetry.sdk.logs.SdkLogEmitterProvider) Collection(java.util.Collection) LogAssertions(io.opentelemetry.sdk.testing.assertj.LogAssertions) Mockito.when(org.mockito.Mockito.when) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) SuppressLogger(io.opentelemetry.internal.testing.slf4j.SuppressLogger) Mockito.reset(org.mockito.Mockito.reset) Timeout(org.junit.jupiter.api.Timeout) CompletableResultCode(io.opentelemetry.sdk.common.CompletableResultCode) SdkLogEmitterProvider(io.opentelemetry.sdk.logs.SdkLogEmitterProvider) Test(org.junit.jupiter.api.Test)

Example 9 with LogData

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

the class SimpleLogProcessor method emit.

@Override
public void emit(LogData logData) {
    try {
        List<LogData> logs = Collections.singletonList(logData);
        CompletableResultCode result = logExporter.export(logs);
        pendingExports.add(result);
        result.whenComplete(() -> {
            pendingExports.remove(result);
            if (!result.isSuccess()) {
                logger.log(Level.FINE, "Exporter failed");
            }
        });
    } catch (RuntimeException e) {
        logger.log(Level.WARNING, "Exporter threw an Exception", e);
    }
}
Also used : LogData(io.opentelemetry.sdk.logs.data.LogData) CompletableResultCode(io.opentelemetry.sdk.common.CompletableResultCode)

Example 10 with LogData

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

the class SimpleLogProcessorTest method shutdown.

@Test
void shutdown() {
    CompletableResultCode export1 = new CompletableResultCode();
    CompletableResultCode export2 = new CompletableResultCode();
    when(logExporter.export(any())).thenReturn(export1, export2);
    LogData logData = TestUtil.createLogData(DEBUG, "Log message");
    logProcessor.emit(logData);
    logProcessor.emit(logData);
    verify(logExporter, times(2)).export(Collections.singletonList(logData));
    CompletableResultCode shutdown = logProcessor.shutdown();
    assertThat(shutdown.isDone()).isFalse();
    export1.succeed();
    assertThat(shutdown.isDone()).isFalse();
    verify(logExporter, never()).shutdown();
    export2.succeed();
    assertThat(shutdown.isDone()).isTrue();
    assertThat(shutdown.isSuccess()).isTrue();
    verify(logExporter).shutdown();
}
Also used : LogData(io.opentelemetry.sdk.logs.data.LogData) CompletableResultCode(io.opentelemetry.sdk.common.CompletableResultCode) Test(org.junit.jupiter.api.Test)

Aggregations

LogData (io.opentelemetry.sdk.logs.data.LogData)40 Test (org.junit.jupiter.api.Test)34 Instant (java.time.Instant)8 SdkLogEmitterProvider (io.opentelemetry.sdk.logs.SdkLogEmitterProvider)7 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 Attributes (io.opentelemetry.api.common.Attributes)5 SpanContext (io.opentelemetry.api.trace.SpanContext)4 SuppressLogger (io.opentelemetry.internal.testing.slf4j.SuppressLogger)4 Clock (io.opentelemetry.sdk.common.Clock)4 CompletableResultCode (io.opentelemetry.sdk.common.CompletableResultCode)4 Resource (io.opentelemetry.sdk.resources.Resource)4 TimeUnit (java.util.concurrent.TimeUnit)4 SpanLinkage (com.splunk.opentelemetry.profiler.context.SpanLinkage)3 EventPeriods (com.splunk.opentelemetry.profiler.events.EventPeriods)3 TraceFlags (io.opentelemetry.api.trace.TraceFlags)3 TraceState (io.opentelemetry.api.trace.TraceState)3 LogDataBuilder (io.opentelemetry.sdk.logs.data.LogDataBuilder)3 Mockito.when (org.mockito.Mockito.when)3 CONFIG_KEY_MEMORY_SAMPLER_INTERVAL (com.splunk.opentelemetry.profiler.Configuration.CONFIG_KEY_MEMORY_SAMPLER_INTERVAL)2 CONFIG_KEY_TLAB_ENABLED (com.splunk.opentelemetry.profiler.Configuration.CONFIG_KEY_TLAB_ENABLED)2