use of io.opentelemetry.proto.resource.v1.Resource in project instrumentation-java by census-instrumentation.
the class OcAgentNodeUtilsTest method toResourceProto_Null.
@Test
public void toResourceProto_Null() {
Resource resourceProto = OcAgentNodeUtils.toResourceProto(null);
assertThat(resourceProto).isNull();
}
use of io.opentelemetry.proto.resource.v1.Resource in project wavefront-proxy by wavefrontHQ.
the class OtlpProtobufUtils method fromOtlpRequest.
// TODO: consider transforming a single span and returning it for immedidate reporting in
// wfSender. This could be more efficient, and also more reliable in the event the loops
// below throw an error and we don't report any of the list.
@VisibleForTesting
static List<WavefrontSpanAndLogs> fromOtlpRequest(ExportTraceServiceRequest request, @Nullable ReportableEntityPreprocessor preprocessor, String defaultSource) {
List<WavefrontSpanAndLogs> wfSpansAndLogs = new ArrayList<>();
for (ResourceSpans rSpans : request.getResourceSpansList()) {
Resource resource = rSpans.getResource();
OTLP_DATA_LOGGER.finest(() -> "Inbound OTLP Resource: " + resource);
for (InstrumentationLibrarySpans ilSpans : rSpans.getInstrumentationLibrarySpansList()) {
InstrumentationLibrary iLibrary = ilSpans.getInstrumentationLibrary();
OTLP_DATA_LOGGER.finest(() -> "Inbound OTLP Instrumentation Library: " + iLibrary);
for (io.opentelemetry.proto.trace.v1.Span otlpSpan : ilSpans.getSpansList()) {
OTLP_DATA_LOGGER.finest(() -> "Inbound OTLP Span: " + otlpSpan);
wfSpansAndLogs.add(transformAll(otlpSpan, resource.getAttributesList(), iLibrary, preprocessor, defaultSource));
}
}
}
return wfSpansAndLogs;
}
use of io.opentelemetry.proto.resource.v1.Resource 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.proto.resource.v1.Resource in project opentelemetry-java-instrumentation by open-telemetry.
the class AgentTestingExporterAccess method getExportedMetrics.
@SuppressWarnings("unchecked")
public static List<MetricData> getExportedMetrics() {
List<byte[]> exportRequests;
try {
exportRequests = (List<byte[]>) getMetricExportRequests.invokeExact();
} catch (Throwable t) {
throw new AssertionError("Could not invoke getMetricExportRequests", t);
}
List<ResourceMetrics> allResourceMetrics = exportRequests.stream().map(serialized -> {
try {
return ExportMetricsServiceRequest.parseFrom(serialized);
} catch (InvalidProtocolBufferException e) {
throw new AssertionError(e);
}
}).flatMap(request -> request.getResourceMetricsList().stream()).collect(toList());
List<MetricData> metrics = new ArrayList<>();
for (ResourceMetrics resourceMetrics : allResourceMetrics) {
Resource resource = resourceMetrics.getResource();
for (InstrumentationLibraryMetrics ilMetrics : resourceMetrics.getInstrumentationLibraryMetricsList()) {
InstrumentationLibrary instrumentationLibrary = ilMetrics.getInstrumentationLibrary();
for (Metric metric : ilMetrics.getMetricsList()) {
metrics.add(createMetricData(metric, io.opentelemetry.sdk.resources.Resource.create(fromProto(resource.getAttributesList())), InstrumentationLibraryInfo.create(instrumentationLibrary.getName(), instrumentationLibrary.getVersion())));
}
}
}
return metrics;
}
use of io.opentelemetry.proto.resource.v1.Resource in project opentelemetry-java-instrumentation by open-telemetry.
the class AgentTestingExporterAccess method getExportedSpans.
@SuppressWarnings("unchecked")
public static List<SpanData> getExportedSpans() {
List<byte[]> exportRequests;
try {
exportRequests = (List<byte[]>) getSpanExportRequests.invokeExact();
} catch (Throwable t) {
throw new AssertionError("Could not invoke getSpanExportRequests", t);
}
List<ResourceSpans> allResourceSpans = exportRequests.stream().map(serialized -> {
try {
return ExportTraceServiceRequest.parseFrom(serialized);
} catch (InvalidProtocolBufferException e) {
throw new AssertionError(e);
}
}).flatMap(request -> request.getResourceSpansList().stream()).collect(toList());
List<SpanData> spans = new ArrayList<>();
for (ResourceSpans resourceSpans : allResourceSpans) {
Resource resource = resourceSpans.getResource();
for (InstrumentationLibrarySpans ilSpans : resourceSpans.getInstrumentationLibrarySpansList()) {
InstrumentationLibrary instrumentationLibrary = ilSpans.getInstrumentationLibrary();
for (Span span : ilSpans.getSpansList()) {
String traceId = bytesToHex(span.getTraceId().toByteArray());
spans.add(TestSpanData.builder().setSpanContext(SpanContext.create(traceId, bytesToHex(span.getSpanId().toByteArray()), TraceFlags.getDefault(), extractTraceState(span.getTraceState()))).setParentSpanContext(SpanContext.create(traceId, bytesToHex(span.getParentSpanId().toByteArray()), TraceFlags.getDefault(), TraceState.getDefault())).setResource(io.opentelemetry.sdk.resources.Resource.create(fromProto(resource.getAttributesList()))).setInstrumentationLibraryInfo(InstrumentationLibraryInfo.create(instrumentationLibrary.getName(), instrumentationLibrary.getVersion())).setName(span.getName()).setStartEpochNanos(span.getStartTimeUnixNano()).setEndEpochNanos(span.getEndTimeUnixNano()).setAttributes(fromProto(span.getAttributesList())).setEvents(span.getEventsList().stream().map(event -> EventData.create(event.getTimeUnixNano(), event.getName(), fromProto(event.getAttributesList()), event.getDroppedAttributesCount() + event.getAttributesCount())).collect(toList())).setStatus(fromProto(span.getStatus())).setKind(fromProto(span.getKind())).setLinks(span.getLinksList().stream().map(link -> LinkData.create(SpanContext.create(bytesToHex(link.getTraceId().toByteArray()), bytesToHex(link.getSpanId().toByteArray()), TraceFlags.getDefault(), extractTraceState(link.getTraceState())), fromProto(link.getAttributesList()), link.getDroppedAttributesCount() + link.getAttributesCount())).collect(toList())).setHasEnded(true).setTotalRecordedEvents(span.getEventsCount() + span.getDroppedEventsCount()).setTotalRecordedLinks(span.getLinksCount() + span.getDroppedLinksCount()).setTotalAttributeCount(span.getAttributesCount() + span.getDroppedAttributesCount()).build());
}
}
}
return spans;
}
Aggregations