Search in sources :

Example 6 with ResourceSpans

use of io.opentelemetry.proto.trace.v1.ResourceSpans in project data-prepper by opensearch-project.

the class OTelTraceRawPrepper method doExecute.

/**
 * execute the prepper logic which could potentially modify the incoming record. The level to which the record has
 * been modified depends on the implementation
 *
 * @param records Input records that will be modified/processed
 * @return Record  modified output records
 */
@Override
public Collection<Record<String>> doExecute(Collection<Record<ExportTraceServiceRequest>> records) {
    final List<RawSpan> rawSpans = new LinkedList<>();
    for (Record<ExportTraceServiceRequest> ets : records) {
        for (ResourceSpans rs : ets.getData().getResourceSpansList()) {
            try {
                final String serviceName = OTelProtoHelper.getServiceName(rs.getResource()).orElse(null);
                final Map<String, Object> resourceAttributes = OTelProtoHelper.getResourceAttributes(rs.getResource());
                for (InstrumentationLibrarySpans is : rs.getInstrumentationLibrarySpansList()) {
                    for (Span sp : is.getSpansList()) {
                        final RawSpan rawSpan = new RawSpanBuilder().setFromSpan(sp, is.getInstrumentationLibrary(), serviceName, resourceAttributes).build();
                        processRawSpan(rawSpan, rawSpans);
                    }
                }
            } catch (Exception ex) {
                LOG.error("Unable to process invalid ResourceSpan {} :", rs, ex);
                resourceSpanErrorsCounter.increment();
                totalProcessingErrorsCounter.increment();
            }
        }
    }
    rawSpans.addAll(getTracesToFlushByGarbageCollection());
    return convertRawSpansToJsonRecords(rawSpans);
}
Also used : ExportTraceServiceRequest(io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest) RawSpan(com.amazon.dataprepper.plugins.prepper.oteltrace.model.RawSpan) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) RawSpan(com.amazon.dataprepper.plugins.prepper.oteltrace.model.RawSpan) Span(io.opentelemetry.proto.trace.v1.Span) LinkedList(java.util.LinkedList) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) InstrumentationLibrarySpans(io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans) RawSpanBuilder(com.amazon.dataprepper.plugins.prepper.oteltrace.model.RawSpanBuilder)

Example 7 with ResourceSpans

use of io.opentelemetry.proto.trace.v1.ResourceSpans in project data-prepper by opensearch-project.

the class ServiceMapStatefulPrepperTest method testTraceGroups.

@Test
public void testTraceGroups() throws Exception {
    final Clock clock = Mockito.mock(Clock.class);
    Mockito.when(clock.millis()).thenReturn(1L);
    Mockito.when(clock.instant()).thenReturn(Instant.now());
    ExecutorService threadpool = Executors.newCachedThreadPool();
    final File path = new File(ServiceMapPrepperConfig.DEFAULT_DB_PATH);
    final ServiceMapStatefulPrepper serviceMapStateful1 = new ServiceMapStatefulPrepper(100, path, clock, 2, PLUGIN_SETTING);
    final ServiceMapStatefulPrepper serviceMapStateful2 = new ServiceMapStatefulPrepper(100, path, clock, 2, PLUGIN_SETTING);
    final byte[] rootSpanId1 = ServiceMapTestUtils.getRandomBytes(8);
    final byte[] rootSpanId2 = ServiceMapTestUtils.getRandomBytes(8);
    final byte[] traceId1 = ServiceMapTestUtils.getRandomBytes(16);
    final byte[] traceId2 = ServiceMapTestUtils.getRandomBytes(16);
    final String traceGroup1 = "reset_password";
    final String traceGroup2 = "checkout";
    final ResourceSpans frontendSpans1 = ServiceMapTestUtils.getResourceSpans(FRONTEND_SERVICE, traceGroup1, rootSpanId1, null, traceId1, Span.SpanKind.SPAN_KIND_CLIENT);
    final ResourceSpans authenticationSpansServer = ServiceMapTestUtils.getResourceSpans(AUTHENTICATION_SERVICE, "reset", ServiceMapTestUtils.getRandomBytes(8), ServiceMapTestUtils.getSpanId(frontendSpans1), traceId1, Span.SpanKind.SPAN_KIND_SERVER);
    final ResourceSpans authenticationSpansClient = ServiceMapTestUtils.getResourceSpans(AUTHENTICATION_SERVICE, "reset", ServiceMapTestUtils.getRandomBytes(8), ServiceMapTestUtils.getSpanId(authenticationSpansServer), traceId1, Span.SpanKind.SPAN_KIND_CLIENT);
    final ResourceSpans passwordDbSpans = ServiceMapTestUtils.getResourceSpans(PASSWORD_DATABASE, "update", ServiceMapTestUtils.getRandomBytes(8), ServiceMapTestUtils.getSpanId(authenticationSpansClient), traceId1, Span.SpanKind.SPAN_KIND_SERVER);
    final ResourceSpans frontendSpans2 = ServiceMapTestUtils.getResourceSpans(FRONTEND_SERVICE, traceGroup2, rootSpanId2, null, traceId2, Span.SpanKind.SPAN_KIND_CLIENT);
    final ResourceSpans checkoutSpansServer = ServiceMapTestUtils.getResourceSpans(CHECKOUT_SERVICE, "checkout", ServiceMapTestUtils.getRandomBytes(8), rootSpanId2, traceId2, Span.SpanKind.SPAN_KIND_SERVER);
    final ResourceSpans checkoutSpansClient = ServiceMapTestUtils.getResourceSpans(CHECKOUT_SERVICE, "checkout", ServiceMapTestUtils.getRandomBytes(8), ServiceMapTestUtils.getSpanId(checkoutSpansServer), traceId2, Span.SpanKind.SPAN_KIND_CLIENT);
    final ResourceSpans cartSpans = ServiceMapTestUtils.getResourceSpans(CART_SERVICE, "get_items", ServiceMapTestUtils.getRandomBytes(8), ServiceMapTestUtils.getSpanId(checkoutSpansClient), traceId2, Span.SpanKind.SPAN_KIND_SERVER);
    final ResourceSpans paymentSpans = ServiceMapTestUtils.getResourceSpans(PAYMENT_SERVICE, "charge", ServiceMapTestUtils.getRandomBytes(8), ServiceMapTestUtils.getSpanId(checkoutSpansClient), traceId2, Span.SpanKind.SPAN_KIND_SERVER);
    // Expected relationships
    final ServiceMapRelationship frontendAuth = ServiceMapRelationship.newDestinationRelationship(FRONTEND_SERVICE, Span.SpanKind.SPAN_KIND_CLIENT.name(), AUTHENTICATION_SERVICE, "reset", traceGroup1);
    final ServiceMapRelationship authPassword = ServiceMapRelationship.newDestinationRelationship(AUTHENTICATION_SERVICE, Span.SpanKind.SPAN_KIND_CLIENT.name(), PASSWORD_DATABASE, "update", traceGroup1);
    final ServiceMapRelationship frontendCheckout = ServiceMapRelationship.newDestinationRelationship(FRONTEND_SERVICE, Span.SpanKind.SPAN_KIND_CLIENT.name(), CHECKOUT_SERVICE, "checkout", traceGroup2);
    final ServiceMapRelationship checkoutCart = ServiceMapRelationship.newDestinationRelationship(CHECKOUT_SERVICE, Span.SpanKind.SPAN_KIND_CLIENT.name(), CART_SERVICE, "get_items", traceGroup2);
    final ServiceMapRelationship checkoutPayment = ServiceMapRelationship.newDestinationRelationship(CHECKOUT_SERVICE, Span.SpanKind.SPAN_KIND_CLIENT.name(), PAYMENT_SERVICE, "charge", traceGroup2);
    final ServiceMapRelationship checkoutTarget = ServiceMapRelationship.newTargetRelationship(CHECKOUT_SERVICE, Span.SpanKind.SPAN_KIND_SERVER.name(), CHECKOUT_SERVICE, "checkout", traceGroup2);
    final ServiceMapRelationship authTarget = ServiceMapRelationship.newTargetRelationship(AUTHENTICATION_SERVICE, Span.SpanKind.SPAN_KIND_SERVER.name(), AUTHENTICATION_SERVICE, "reset", traceGroup1);
    final ServiceMapRelationship passwordTarget = ServiceMapRelationship.newTargetRelationship(PASSWORD_DATABASE, Span.SpanKind.SPAN_KIND_SERVER.name(), PASSWORD_DATABASE, "update", traceGroup1);
    final ServiceMapRelationship paymentTarget = ServiceMapRelationship.newTargetRelationship(PAYMENT_SERVICE, Span.SpanKind.SPAN_KIND_SERVER.name(), PAYMENT_SERVICE, "charge", traceGroup2);
    final ServiceMapRelationship cartTarget = ServiceMapRelationship.newTargetRelationship(CART_SERVICE, Span.SpanKind.SPAN_KIND_SERVER.name(), CART_SERVICE, "get_items", traceGroup2);
    final Set<ServiceMapRelationship> relationshipsFound = new HashSet<>();
    // First batch
    Mockito.when(clock.millis()).thenReturn(110L);
    Future<Set<ServiceMapRelationship>> r1 = ServiceMapTestUtils.startExecuteAsync(threadpool, serviceMapStateful1, Collections.singletonList(new Record<>(ServiceMapTestUtils.getExportTraceServiceRequest(frontendSpans1, checkoutSpansServer))));
    Future<Set<ServiceMapRelationship>> r2 = ServiceMapTestUtils.startExecuteAsync(threadpool, serviceMapStateful2, Collections.singletonList(new Record<>(ServiceMapTestUtils.getExportTraceServiceRequest(frontendSpans2, checkoutSpansClient))));
    relationshipsFound.addAll(r1.get());
    relationshipsFound.addAll(r2.get());
    // Shouldn't find any relationships
    Assert.assertEquals(0, relationshipsFound.size());
    // Second batch
    Mockito.when(clock.millis()).thenReturn(220L);
    Future<Set<ServiceMapRelationship>> r3 = ServiceMapTestUtils.startExecuteAsync(threadpool, serviceMapStateful1, Arrays.asList(new Record<>(ServiceMapTestUtils.getExportTraceServiceRequest(authenticationSpansServer, authenticationSpansClient)), new Record<>(ServiceMapTestUtils.getExportTraceServiceRequest(cartSpans))));
    Future<Set<ServiceMapRelationship>> r4 = ServiceMapTestUtils.startExecuteAsync(threadpool, serviceMapStateful2, Collections.singletonList(new Record<>(ServiceMapTestUtils.getExportTraceServiceRequest(passwordDbSpans, paymentSpans))));
    relationshipsFound.addAll(r3.get());
    relationshipsFound.addAll(r4.get());
    // Should find the frontend->checkout relationship indicated in the first batch
    Assert.assertEquals(2, relationshipsFound.size());
    assertTrue(relationshipsFound.containsAll(Arrays.asList(frontendCheckout, checkoutTarget)));
    // Third batch
    Mockito.when(clock.millis()).thenReturn(340L);
    Future<Set<ServiceMapRelationship>> r5 = ServiceMapTestUtils.startExecuteAsync(threadpool, serviceMapStateful1, Arrays.asList());
    Future<Set<ServiceMapRelationship>> r6 = ServiceMapTestUtils.startExecuteAsync(threadpool, serviceMapStateful2, Arrays.asList());
    relationshipsFound.addAll(r5.get());
    relationshipsFound.addAll(r6.get());
    // Should find the rest of the relationships
    Assert.assertEquals(10, relationshipsFound.size());
    assertTrue(relationshipsFound.containsAll(Arrays.asList(frontendAuth, authTarget, authPassword, passwordTarget, checkoutCart, cartTarget, checkoutPayment, paymentTarget)));
    // Extra validation
    final List<ServiceMapSourceDest> expectedSourceDests = Arrays.asList(new ServiceMapSourceDest(FRONTEND_SERVICE, AUTHENTICATION_SERVICE), new ServiceMapSourceDest(AUTHENTICATION_SERVICE, PASSWORD_DATABASE), new ServiceMapSourceDest(FRONTEND_SERVICE, CHECKOUT_SERVICE), new ServiceMapSourceDest(CHECKOUT_SERVICE, CART_SERVICE), new ServiceMapSourceDest(CHECKOUT_SERVICE, PAYMENT_SERVICE));
    assertTrue(evaluateEdges(relationshipsFound).containsAll(expectedSourceDests));
    // Verify gauges
    final List<Measurement> spansDbSizeMeasurement = MetricsTestUtil.getMeasurementList(new StringJoiner(MetricNames.DELIMITER).add("testPipelineName").add("testServiceMapPrepper").add(ServiceMapStatefulPrepper.SPANS_DB_SIZE).toString());
    Assert.assertEquals(1, spansDbSizeMeasurement.size());
    final List<Measurement> traceGroupDbSizeMeasurement = MetricsTestUtil.getMeasurementList(new StringJoiner(MetricNames.DELIMITER).add("testPipelineName").add("testServiceMapPrepper").add(ServiceMapStatefulPrepper.TRACE_GROUP_DB_SIZE).toString());
    Assert.assertEquals(1, traceGroupDbSizeMeasurement.size());
    // Make sure that future relationships that are equivalent are caught by cache
    final byte[] rootSpanId3 = ServiceMapTestUtils.getRandomBytes(8);
    final byte[] traceId3 = ServiceMapTestUtils.getRandomBytes(16);
    final ResourceSpans frontendSpans3 = ServiceMapTestUtils.getResourceSpans(FRONTEND_SERVICE, traceGroup1, rootSpanId3, rootSpanId3, traceId3, Span.SpanKind.SPAN_KIND_CLIENT);
    final ResourceSpans authenticationSpansServer2 = ServiceMapTestUtils.getResourceSpans(AUTHENTICATION_SERVICE, "reset", ServiceMapTestUtils.getRandomBytes(8), ServiceMapTestUtils.getSpanId(frontendSpans3), traceId3, Span.SpanKind.SPAN_KIND_SERVER);
    when(clock.millis()).thenReturn(450L);
    Future<Set<ServiceMapRelationship>> r7 = ServiceMapTestUtils.startExecuteAsync(threadpool, serviceMapStateful1, Collections.singletonList(new Record<>(ServiceMapTestUtils.getExportTraceServiceRequest(frontendSpans3))));
    Future<Set<ServiceMapRelationship>> r8 = ServiceMapTestUtils.startExecuteAsync(threadpool, serviceMapStateful2, Collections.singletonList(new Record<>(ServiceMapTestUtils.getExportTraceServiceRequest(authenticationSpansServer2))));
    assertTrue(r7.get().isEmpty());
    assertTrue(r8.get().isEmpty());
    when(clock.millis()).thenReturn(560L);
    Future<Set<ServiceMapRelationship>> r9 = ServiceMapTestUtils.startExecuteAsync(threadpool, serviceMapStateful1, Arrays.asList());
    Future<Set<ServiceMapRelationship>> r10 = ServiceMapTestUtils.startExecuteAsync(threadpool, serviceMapStateful2, Arrays.asList());
    assertTrue(r9.get().isEmpty());
    assertTrue(r10.get().isEmpty());
    serviceMapStateful1.shutdown();
}
Also used : Measurement(io.micrometer.core.instrument.Measurement) HashSet(java.util.HashSet) Set(java.util.Set) Clock(java.time.Clock) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) ExecutorService(java.util.concurrent.ExecutorService) Record(com.amazon.dataprepper.model.record.Record) File(java.io.File) StringJoiner(java.util.StringJoiner) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with ResourceSpans

use of io.opentelemetry.proto.trace.v1.ResourceSpans in project data-prepper by opensearch-project.

the class ServiceMapStatefulPrepperTest method testPrepareForShutdown.

@Test
public void testPrepareForShutdown() throws Exception {
    final File path = new File(ServiceMapPrepperConfig.DEFAULT_DB_PATH);
    final ServiceMapStatefulPrepper serviceMapStateful = new ServiceMapStatefulPrepper(100, path, Clock.systemUTC(), 1, PLUGIN_SETTING);
    final byte[] rootSpanId1 = ServiceMapTestUtils.getRandomBytes(8);
    final byte[] traceId1 = ServiceMapTestUtils.getRandomBytes(16);
    final String traceGroup1 = "reset_password";
    final ResourceSpans frontendSpans1 = ServiceMapTestUtils.getResourceSpans(FRONTEND_SERVICE, traceGroup1, rootSpanId1, null, traceId1, Span.SpanKind.SPAN_KIND_CLIENT);
    final ResourceSpans authenticationSpansServer = ServiceMapTestUtils.getResourceSpans(AUTHENTICATION_SERVICE, "reset", ServiceMapTestUtils.getRandomBytes(8), ServiceMapTestUtils.getSpanId(frontendSpans1), traceId1, Span.SpanKind.SPAN_KIND_SERVER);
    serviceMapStateful.execute(Collections.singletonList(new Record<>(ServiceMapTestUtils.getExportTraceServiceRequest(frontendSpans1, authenticationSpansServer))));
    assertFalse(serviceMapStateful.isReadyForShutdown());
    serviceMapStateful.prepareForShutdown();
    serviceMapStateful.execute(Collections.emptyList());
    assertTrue(serviceMapStateful.isReadyForShutdown());
    serviceMapStateful.shutdown();
}
Also used : Record(com.amazon.dataprepper.model.record.Record) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) File(java.io.File) Test(org.junit.Test)

Example 9 with ResourceSpans

use of io.opentelemetry.proto.trace.v1.ResourceSpans in project data-prepper by opensearch-project.

the class EndToEndRawSpanTest method getResourceSpansBatch.

private List<ResourceSpans> getResourceSpansBatch(final List<EndToEndTestSpan> testSpanList) {
    final ArrayList<ResourceSpans> spansList = new ArrayList<>();
    for (final EndToEndTestSpan testSpan : testSpanList) {
        final String traceId = testSpan.traceId;
        final String parentId = testSpan.parentId;
        final String spanId = testSpan.spanId;
        final String serviceName = testSpan.serviceName;
        final String spanName = testSpan.name;
        final Span.SpanKind spanKind = testSpan.spanKind;
        final String endTime = testSpan.endTime;
        final Long durationInNanos = testSpan.durationInNanos;
        final Integer statusCode = testSpan.statusCode;
        final ResourceSpans rs = getResourceSpans(serviceName, spanName, spanId.getBytes(), parentId != null ? parentId.getBytes() : null, traceId.getBytes(), spanKind, endTime, durationInNanos, statusCode);
        spansList.add(rs);
    }
    return spansList;
}
Also used : ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) Span(io.opentelemetry.proto.trace.v1.Span)

Example 10 with ResourceSpans

use of io.opentelemetry.proto.trace.v1.ResourceSpans in project besu by hyperledger.

the class OpenTelemetryAcceptanceTest method traceReportingWithTraceId.

@Test
public void traceReportingWithTraceId() {
    Duration timeout = Duration.ofSeconds(1);
    OkHttpClient okClient = new OkHttpClient.Builder().connectTimeout(timeout).readTimeout(timeout).writeTimeout(timeout).build();
    WaitUtils.waitFor(30, () -> {
        // call the json RPC endpoint to generate a trace - with trace metadata of our own
        Configuration config = new Configuration("okhttp").withSampler(Configuration.SamplerConfiguration.fromEnv().withType("const").withParam(1));
        Tracer tracer = config.getTracer();
        Call.Factory client = new TracingCallFactory(okClient, tracer);
        Request request = new Request.Builder().url("http://localhost:" + metricsNode.getJsonRpcPort().get()).post(RequestBody.create("{\"jsonrpc\":\"2.0\",\"method\":\"net_version\",\"params\":[],\"id\":255}", MediaType.get("application/json"))).build();
        Response response = client.newCall(request).execute();
        assertThat(response.code()).isEqualTo(200);
        response.close();
        List<ResourceSpans> spans = new ArrayList<>(fakeTracesCollector.getReceivedSpans());
        fakeTracesCollector.getReceivedSpans().clear();
        assertThat(spans.isEmpty()).isFalse();
        Span internalSpan = spans.get(0).getInstrumentationLibrarySpans(0).getSpans(0);
        assertThat(internalSpan.getKind()).isEqualTo(Span.SpanKind.SPAN_KIND_INTERNAL);
        ByteString parent = internalSpan.getParentSpanId();
        assertThat(parent.isEmpty()).isFalse();
        Span serverSpan = spans.get(0).getInstrumentationLibrarySpans(0).getSpans(1);
        assertThat(serverSpan.getKind()).isEqualTo(Span.SpanKind.SPAN_KIND_SERVER);
        ByteString rootSpanId = serverSpan.getParentSpanId();
        assertThat(rootSpanId.isEmpty()).isFalse();
    });
}
Also used : Call(okhttp3.Call) OkHttpClient(okhttp3.OkHttpClient) MetricsConfiguration(org.hyperledger.besu.metrics.prometheus.MetricsConfiguration) Configuration(io.jaegertracing.Configuration) Tracer(io.opentracing.Tracer) ByteString(com.google.protobuf.ByteString) NettyServerBuilder(io.grpc.netty.NettyServerBuilder) BesuNodeConfigurationBuilder(org.hyperledger.besu.tests.acceptance.dsl.node.configuration.BesuNodeConfigurationBuilder) Request(okhttp3.Request) ExportMetricsServiceRequest(io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceRequest) ExportTraceServiceRequest(io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest) ArrayList(java.util.ArrayList) Duration(java.time.Duration) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) Span(io.opentelemetry.proto.trace.v1.Span) Response(okhttp3.Response) ExportTraceServiceResponse(io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceResponse) ExportMetricsServiceResponse(io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceResponse) TracingCallFactory(io.opentracing.contrib.okhttp3.TracingCallFactory) 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