use of io.opentelemetry.sdk.logs.data.LogData in project opentelemetry-java by open-telemetry.
the class OtlpHttpLogExporterTest method exportAndAssertResult.
private static ExportLogsServiceRequest exportAndAssertResult(OtlpHttpLogExporter otlpHttpLogExporter, boolean expectedResult) {
List<LogData> logs = Collections.singletonList(generateFakeLog());
CompletableResultCode resultCode = otlpHttpLogExporter.export(logs);
resultCode.join(10, TimeUnit.SECONDS);
assertThat(resultCode.isSuccess()).isEqualTo(expectedResult);
List<ResourceLogs> resourceLogs = Arrays.stream(ResourceLogsMarshaler.create(logs)).map(marshaler -> {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
marshaler.writeBinaryTo(bos);
return ResourceLogs.parseFrom(bos.toByteArray());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}).collect(Collectors.toList());
return ExportLogsServiceRequest.newBuilder().addAllResourceLogs(resourceLogs).build();
}
use of io.opentelemetry.sdk.logs.data.LogData in project opentelemetry-java by open-telemetry.
the class SystemOutLogExporter method export.
@Override
public CompletableResultCode export(Collection<LogData> logs) {
StringBuilder stringBuilder = new StringBuilder(60);
for (LogData log : logs) {
stringBuilder.setLength(0);
formatLog(stringBuilder, log);
System.out.println(stringBuilder);
}
return CompletableResultCode.ofSuccess();
}
use of io.opentelemetry.sdk.logs.data.LogData in project opentelemetry-java by open-telemetry.
the class SdkLogEmitterTest method logBuilder_maxAttributeLength.
@Test
void logBuilder_maxAttributeLength() {
int maxLength = 25;
AtomicReference<LogData> seenLog = new AtomicReference<>();
SdkLogEmitterProvider logEmitterProvider = SdkLogEmitterProvider.builder().addLogProcessor(seenLog::set).setLogLimits(() -> LogLimits.builder().setMaxAttributeValueLength(maxLength).build()).build();
LogBuilder logBuilder = logEmitterProvider.get("test").logBuilder();
String strVal = StringUtils.padLeft("", maxLength);
String tooLongStrVal = strVal + strVal;
logBuilder.setAttributes(Attributes.builder().put("string", tooLongStrVal).put("boolean", true).put("long", 1L).put("double", 1.0).put(stringArrayKey("stringArray"), Arrays.asList(strVal, tooLongStrVal)).put(booleanArrayKey("booleanArray"), Arrays.asList(true, false)).put(longArrayKey("longArray"), Arrays.asList(1L, 2L)).put(doubleArrayKey("doubleArray"), Arrays.asList(1.0, 2.0)).build()).emit();
Attributes attributes = seenLog.get().getAttributes();
assertThat(attributes).containsEntry("string", strVal).containsEntry("boolean", true).containsEntry("long", 1L).containsEntry("double", 1.0).containsEntry("stringArray", strVal, strVal).containsEntry("booleanArray", true, false).containsEntry("longArray", 1L, 2L).containsEntry("doubleArray", 1.0, 2.0);
}
use of io.opentelemetry.sdk.logs.data.LogData in project opentelemetry-java by open-telemetry.
the class InMemoryLogExporterTest method export_ReturnCode.
@Test
void export_ReturnCode() {
LogData logData = createLogData(DEBUG, "message 1");
assertThat(exporter.export(Collections.singletonList(logData)).isSuccess()).isTrue();
exporter.shutdown();
// After shutdown no more export.
assertThat(exporter.export(Collections.singletonList(logData)).isSuccess()).isFalse();
exporter.reset();
// Reset does not do anything if already shutdown.
assertThat(exporter.export(Collections.singletonList(logData)).isSuccess()).isFalse();
}
use of io.opentelemetry.sdk.logs.data.LogData 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));
}
Aggregations