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