use of io.opentelemetry.proto.trace.v1.ResourceSpans in project opentelemetry-java by open-telemetry.
the class OtlpHttpSpanExporterTest method exportAndAssertResult.
private static ExportTraceServiceRequest exportAndAssertResult(OtlpHttpSpanExporter otlpHttpSpanExporter, boolean expectedResult) {
List<SpanData> spans = Collections.singletonList(generateFakeSpan());
CompletableResultCode resultCode = otlpHttpSpanExporter.export(spans);
resultCode.join(10, TimeUnit.SECONDS);
assertThat(resultCode.isSuccess()).isEqualTo(expectedResult);
List<ResourceSpans> resourceSpans = Arrays.stream(ResourceSpansMarshaler.create(spans)).map(marshaler -> {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
marshaler.writeBinaryTo(bos);
return ResourceSpans.parseFrom(bos.toByteArray());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}).collect(Collectors.toList());
return ExportTraceServiceRequest.newBuilder().addAllResourceSpans(resourceSpans).build();
}
use of io.opentelemetry.proto.trace.v1.ResourceSpans 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.trace.v1.ResourceSpans in project data-prepper by opensearch-project.
the class PeerForwarderTest method testSingleRemoteIpForwardRequestError.
@Test
public void testSingleRemoteIpForwardRequestError() {
final List<String> testIps = generateTestIps(2);
final Channel channel = mock(Channel.class);
final String peerIp = testIps.get(1);
final String fullPeerIp = String.format("%s:21890", peerIp);
when(channel.authority()).thenReturn(fullPeerIp);
when(peerClientPool.getClient(peerIp)).thenReturn(client);
when(client.export(any(ExportTraceServiceRequest.class))).thenThrow(new RuntimeException());
when(client.getChannel()).thenReturn(channel);
MetricsTestUtil.initMetrics();
final PeerForwarder testPeerForwarder = generatePeerForwarder(testIps, 3);
final List<Record<ExportTraceServiceRequest>> exportedRecords = testPeerForwarder.doExecute(Collections.singletonList(new Record<>(REQUEST_4)));
final List<ResourceSpans> expectedLocalResourceSpans = Collections.singletonList(generateResourceSpans(SPAN_4, SPAN_5, SPAN_6));
Assert.assertEquals(1, exportedRecords.size());
final ExportTraceServiceRequest exportedRequest = exportedRecords.get(0).getData();
final List<ResourceSpans> forwardedResourceSpans = exportedRequest.getResourceSpansList();
assertTrue(forwardedResourceSpans.containsAll(expectedLocalResourceSpans));
assertTrue(expectedLocalResourceSpans.containsAll(forwardedResourceSpans));
// Verify metrics
final List<Measurement> forwardRequestErrorMeasurements = MetricsTestUtil.getMeasurementList(new StringJoiner(MetricNames.DELIMITER).add(TEST_PIPELINE_NAME).add("peer_forwarder").add(PeerForwarder.ERRORS).toString());
Assert.assertEquals(1, forwardRequestErrorMeasurements.size());
Assert.assertEquals(1.0, forwardRequestErrorMeasurements.get(0).getValue(), 0);
final List<Measurement> forwardRequestSuccessMeasurements = MetricsTestUtil.getMeasurementList(new StringJoiner(MetricNames.DELIMITER).add(TEST_PIPELINE_NAME).add("peer_forwarder").add(PeerForwarder.REQUESTS).toString());
Assert.assertEquals(1, forwardRequestSuccessMeasurements.size());
Assert.assertEquals(1.0, forwardRequestSuccessMeasurements.get(0).getValue(), 0);
final List<Measurement> forwardRequestLatencyMeasurements = MetricsTestUtil.getMeasurementList(new StringJoiner(MetricNames.DELIMITER).add(TEST_PIPELINE_NAME).add("peer_forwarder").add(PeerForwarder.LATENCY).toString());
Assert.assertEquals(3, forwardRequestLatencyMeasurements.size());
// COUNT
Assert.assertEquals(1.0, forwardRequestLatencyMeasurements.get(0).getValue(), 0);
// TOTAL_TIME
assertTrue(forwardRequestLatencyMeasurements.get(1).getValue() > 0.0);
// MAX
assertTrue(forwardRequestLatencyMeasurements.get(2).getValue() > 0.0);
}
use of io.opentelemetry.proto.trace.v1.ResourceSpans in project data-prepper by opensearch-project.
the class PeerForwarderTest method testSingleRemoteIpLocalRequestOnly.
@Test
public void testSingleRemoteIpLocalRequestOnly() throws Exception {
final List<String> testIps = generateTestIps(2);
final PeerForwarder testPeerForwarder = generatePeerForwarder(testIps, 3);
final List<Record<ExportTraceServiceRequest>> exportedRecords = testPeerForwarder.doExecute(Collections.singletonList(new Record<>(REQUEST_3)));
final List<ResourceSpans> expectedLocalResourceSpans = Collections.singletonList(generateResourceSpans(SPAN_1, SPAN_2, SPAN_3));
Assert.assertEquals(1, exportedRecords.size());
final ExportTraceServiceRequest localRequest = exportedRecords.get(0).getData();
final List<ResourceSpans> localResourceSpans = localRequest.getResourceSpansList();
assertTrue(localResourceSpans.containsAll(expectedLocalResourceSpans));
assertTrue(expectedLocalResourceSpans.containsAll(localResourceSpans));
}
use of io.opentelemetry.proto.trace.v1.ResourceSpans in project data-prepper by opensearch-project.
the class OTelTraceRawPrepperTest method testResourceSpansProcessingErrorMetrics.
@Test
public void testResourceSpansProcessingErrorMetrics() {
ExportTraceServiceRequest mockData = mock(ExportTraceServiceRequest.class);
Record record = new Record(mockData);
ResourceSpans mockResourceSpans = mock(ResourceSpans.class);
List<ResourceSpans> mockResourceSpansList = Collections.singletonList(mockResourceSpans);
when(mockData.getResourceSpansList()).thenReturn(mockResourceSpansList);
when(mockResourceSpans.getResource()).thenThrow(new RuntimeException());
oTelTraceRawPrepper.doExecute(Collections.singletonList(record));
final List<Measurement> resourceSpansErrorsMeasurement = MetricsTestUtil.getMeasurementList(new StringJoiner(MetricNames.DELIMITER).add("pipelineOTelTrace").add("OTelTrace").add(OTelTraceRawPrepper.RESOURCE_SPANS_PROCESSING_ERRORS).toString());
final List<Measurement> totalErrorsMeasurement = MetricsTestUtil.getMeasurementList(new StringJoiner(MetricNames.DELIMITER).add("pipelineOTelTrace").add("OTelTrace").add(OTelTraceRawPrepper.TOTAL_PROCESSING_ERRORS).toString());
Assert.assertEquals(1, resourceSpansErrorsMeasurement.size());
Assert.assertEquals(1.0, resourceSpansErrorsMeasurement.get(0).getValue(), 0);
Assert.assertEquals(1, totalErrorsMeasurement.size());
Assert.assertEquals(1.0, totalErrorsMeasurement.get(0).getValue(), 0);
}
Aggregations