use of io.opentelemetry.proto.logs.v1.LogRecord 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;
}
Aggregations