use of io.opentelemetry.sdk.logs.data.LogData in project opentelemetry-java-instrumentation by open-telemetry.
the class OpenTelemetryAppenderConfigTest method logStringMapMessageWithSpecialAttribute.
@Test
void logStringMapMessageWithSpecialAttribute() {
StringMapMessage message = new StringMapMessage();
message.put("key1", "val1");
message.put("message", "val2");
logger.info(message);
List<LogData> logDataList = logExporter.getFinishedLogItems();
assertThat(logDataList).hasSize(1);
LogData logData = logDataList.get(0);
assertThat(logData.getResource()).isEqualTo(resource);
assertThat(logData.getInstrumentationLibraryInfo()).isEqualTo(instrumentationLibraryInfo);
assertThat(logData.getBody().asString()).isEqualTo("val2");
assertThat(logData.getAttributes().size()).isEqualTo(1);
assertThat(logData.getAttributes().get(AttributeKey.stringKey("key1"))).isEqualTo("val1");
}
use of io.opentelemetry.sdk.logs.data.LogData in project opentelemetry-java-instrumentation by open-telemetry.
the class AgentTestingExporterAccess method getExportedLogs.
@SuppressWarnings("unchecked")
public static List<LogData> getExportedLogs() {
List<byte[]> exportRequests;
try {
exportRequests = (List<byte[]>) getLogExportRequests.invokeExact();
} catch (Throwable t) {
throw new AssertionError("Could not invoke getMetricExportRequests", t);
}
List<ResourceLogs> allResourceLogs = exportRequests.stream().map(serialized -> {
try {
return ExportLogsServiceRequest.parseFrom(serialized);
} catch (InvalidProtocolBufferException e) {
throw new AssertionError(e);
}
}).flatMap(request -> request.getResourceLogsList().stream()).collect(toList());
List<LogData> logs = new ArrayList<>();
for (ResourceLogs resourceLogs : allResourceLogs) {
Resource resource = resourceLogs.getResource();
for (InstrumentationLibraryLogs ilLogs : resourceLogs.getInstrumentationLibraryLogsList()) {
InstrumentationLibrary instrumentationLibrary = ilLogs.getInstrumentationLibrary();
for (LogRecord logRecord : ilLogs.getLogsList()) {
logs.add(createLogData(logRecord, io.opentelemetry.sdk.resources.Resource.create(fromProto(resource.getAttributesList())), InstrumentationLibraryInfo.create(instrumentationLibrary.getName(), instrumentationLibrary.getVersion())));
}
}
}
return logs;
}
use of io.opentelemetry.sdk.logs.data.LogData in project opentelemetry-java-instrumentation by open-telemetry.
the class OtlpInMemoryLogExporter method export.
@Override
public CompletableResultCode export(Collection<LogData> logs) {
for (LogData log : logs) {
logger.info("Exporting log {}", log);
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
LogsRequestMarshaler.create(logs).writeBinaryTo(bos);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
collectedRequests.add(bos.toByteArray());
return CompletableResultCode.ofSuccess();
}
use of io.opentelemetry.sdk.logs.data.LogData in project splunk-otel-java by signalfx.
the class StackToSpanLinkageProcessorTest method testProcessor.
@Test
void testProcessor() {
Instant time = Instant.now();
StackToSpanLinkage linkedSpan = new StackToSpanLinkage(time, "some stack", "event name", SpanLinkage.NONE);
LogDataCreator logCreator = mock(LogDataCreator.class);
BatchingLogsProcessor exportProcessor = mock(BatchingLogsProcessor.class);
LogDataBuilder builder = LogDataBuilder.create(Resource.getDefault(), InstrumentationLibraryInfo.create("test", "1.2.3"));
LogData log = builder.setBody("the.body").build();
when(logCreator.apply(linkedSpan)).thenReturn(log);
StackToSpanLinkageProcessor processor = new StackToSpanLinkageProcessor(logCreator, exportProcessor);
processor.accept(linkedSpan);
verify(exportProcessor).emit(log);
}
use of io.opentelemetry.sdk.logs.data.LogData in project splunk-otel-java by signalfx.
the class StackToSpanLinkageProcessor method accept.
@Override
public void accept(StackToSpanLinkage stackToSpanLinkage) {
LogData log = logDataCreator.apply(stackToSpanLinkage);
processor.emit(log);
}
Aggregations