Search in sources :

Example 1 with ResourceSpans

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();
}
Also used : RecordedRequest(com.linecorp.armeria.testing.junit5.server.mock.RecordedRequest) TraceFlags(io.opentelemetry.api.trace.TraceFlags) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) InetAddress(java.net.InetAddress) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) Duration(java.time.Duration) Level(org.slf4j.event.Level) GzipSource(okio.GzipSource) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) HttpResponse(com.linecorp.armeria.common.HttpResponse) MockWebServerExtension(com.linecorp.armeria.testing.junit5.server.mock.MockWebServerExtension) SpanContext(io.opentelemetry.api.trace.SpanContext) Status(com.google.rpc.Status) HttpMethod(com.linecorp.armeria.common.HttpMethod) SpanKind(io.opentelemetry.api.trace.SpanKind) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) OkHttpExporter(io.opentelemetry.exporter.internal.okhttp.OkHttpExporter) UncheckedIOException(java.io.UncheckedIOException) Test(org.junit.jupiter.api.Test) List(java.util.List) LogCapturer(io.github.netmikey.logunit.api.LogCapturer) HeldCertificate(okhttp3.tls.HeldCertificate) ExportTraceServiceRequest(io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest) SpanData(io.opentelemetry.sdk.trace.data.SpanData) Assertions.assertThatCode(org.assertj.core.api.Assertions.assertThatCode) ServerBuilder(com.linecorp.armeria.server.ServerBuilder) AggregatedHttpRequest(com.linecorp.armeria.common.AggregatedHttpRequest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StatusData(io.opentelemetry.sdk.trace.data.StatusData) MediaType(com.linecorp.armeria.common.MediaType) InstrumentationLibraryInfo(io.opentelemetry.sdk.common.InstrumentationLibraryInfo) TraceState(io.opentelemetry.api.trace.TraceState) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) RetryPolicy(io.opentelemetry.exporter.internal.retry.RetryPolicy) HttpStatus(com.linecorp.armeria.common.HttpStatus) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) ResourceSpansMarshaler(io.opentelemetry.exporter.internal.otlp.traces.ResourceSpansMarshaler) LoggingEvent(org.slf4j.event.LoggingEvent) Buffer(okio.Buffer) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) TimeUnit(java.util.concurrent.TimeUnit) ExportTraceServiceResponse(io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceResponse) RetryUtil(io.opentelemetry.exporter.internal.retry.RetryUtil) Message(com.google.protobuf.Message) Collections(java.util.Collections) CompletableResultCode(io.opentelemetry.sdk.common.CompletableResultCode) TestSpanData(io.opentelemetry.sdk.testing.trace.TestSpanData) SpanData(io.opentelemetry.sdk.trace.data.SpanData) TestSpanData(io.opentelemetry.sdk.testing.trace.TestSpanData) CompletableResultCode(io.opentelemetry.sdk.common.CompletableResultCode) UncheckedIOException(java.io.UncheckedIOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans)

Example 2 with ResourceSpans

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;
}
Also used : InstrumentationLibrarySpans(io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans) ArrayList(java.util.ArrayList) Resource(io.opentelemetry.proto.resource.v1.Resource) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) InstrumentationLibrary(io.opentelemetry.proto.common.v1.InstrumentationLibrary) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with ResourceSpans

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);
}
Also used : ExportTraceServiceRequest(io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest) Measurement(io.micrometer.core.instrument.Measurement) Channel(io.grpc.Channel) ByteString(com.google.protobuf.ByteString) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) Record(com.amazon.dataprepper.model.record.Record) StringJoiner(java.util.StringJoiner) Test(org.junit.Test)

Example 4 with ResourceSpans

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));
}
Also used : ExportTraceServiceRequest(io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest) Record(com.amazon.dataprepper.model.record.Record) ByteString(com.google.protobuf.ByteString) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) Test(org.junit.Test)

Example 5 with ResourceSpans

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);
}
Also used : ExportTraceServiceRequest(io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest) Measurement(io.micrometer.core.instrument.Measurement) Record(com.amazon.dataprepper.model.record.Record) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) StringJoiner(java.util.StringJoiner) Test(org.junit.Test)

Aggregations

ResourceSpans (io.opentelemetry.proto.trace.v1.ResourceSpans)22 ExportTraceServiceRequest (io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest)13 InstrumentationLibrarySpans (io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans)11 Span (io.opentelemetry.proto.trace.v1.Span)10 ByteString (com.google.protobuf.ByteString)9 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 Record (com.amazon.dataprepper.model.record.Record)8 Measurement (io.micrometer.core.instrument.Measurement)5 StringJoiner (java.util.StringJoiner)5 InstrumentationLibrary (io.opentelemetry.proto.common.v1.InstrumentationLibrary)4 HashMap (java.util.HashMap)4 List (java.util.List)4 PluginSetting (com.amazon.dataprepper.model.configuration.PluginSetting)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)3 Channel (io.grpc.Channel)3 SpanContext (io.opentelemetry.api.trace.SpanContext)3 TraceServiceGrpc (io.opentelemetry.proto.collector.trace.v1.TraceServiceGrpc)3 Resource (io.opentelemetry.proto.resource.v1.Resource)3 Map (java.util.Map)3