Search in sources :

Example 11 with ResourceSpans

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

the class OpenTelemetryAcceptanceTest method traceReporting.

@Test
public void traceReporting() {
    WaitUtils.waitFor(30, () -> {
        // call the json RPC endpoint to generate a trace.
        net.netVersion().verify(metricsNode);
        List<ResourceSpans> spans = fakeTracesCollector.getReceivedSpans();
        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()).isTrue();
    });
}
Also used : ByteString(com.google.protobuf.ByteString) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) Span(io.opentelemetry.proto.trace.v1.Span) Test(org.junit.Test)

Example 12 with ResourceSpans

use of io.opentelemetry.proto.trace.v1.ResourceSpans in project inspectit-ocelot by inspectIT.

the class OpenTelemetryProtoConverter method convert.

/**
 * Converts open-telemetry proto data to the open-telemetry SDK span data.
 *
 * @param data data to convert
 *
 * @return Non-null collection of {@link SpanData}
 */
public Collection<SpanData> convert(ExportTraceServiceRequest data) {
    List<SpanData> result = new ArrayList<>();
    for (ResourceSpans resourceSpans : data.getResourceSpansList()) {
        // create general span resources, e.g. sdk-version, service-name, ...
        Attributes attributes = OcelotSpanUtils.toAttributes(resourceSpans.getResource().getAttributesList());
        final Resource resource = Resource.create(attributes);
        Map<String, String> customSpanAttributes = getCustomSpanAttributes();
        resourceSpans.getInstrumentationLibrarySpansList().stream().flatMap(librarySpans -> toSpanData(librarySpans, resource, customSpanAttributes)).forEach(result::add);
    }
    return result;
}
Also used : java.util(java.util) RequestUtils(rocks.inspectit.oce.eum.server.utils.RequestUtils) ImmutableMap(com.google.common.collect.ImmutableMap) Resource(io.opentelemetry.sdk.resources.Resource) Attributes(io.opentelemetry.api.common.Attributes) InstrumentationLibrarySpans(io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans) Autowired(org.springframework.beans.factory.annotation.Autowired) Supplier(java.util.function.Supplier) InstrumentationLibraryInfo(io.opentelemetry.sdk.common.InstrumentationLibraryInfo) EumServerConfiguration(rocks.inspectit.oce.eum.server.configuration.model.EumServerConfiguration) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) HttpServletRequest(javax.servlet.http.HttpServletRequest) Stream(java.util.stream.Stream) InstrumentationLibrary(io.opentelemetry.proto.common.v1.InstrumentationLibrary) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) OcelotSpanUtils(io.opentelemetry.sdk.trace.OcelotSpanUtils) ExportTraceServiceRequest(io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest) SpanData(io.opentelemetry.sdk.trace.data.SpanData) VisibleForTesting(com.google.common.annotations.VisibleForTesting) SpanData(io.opentelemetry.sdk.trace.data.SpanData) Attributes(io.opentelemetry.api.common.Attributes) Resource(io.opentelemetry.sdk.resources.Resource) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans)

Example 13 with ResourceSpans

use of io.opentelemetry.proto.trace.v1.ResourceSpans in project opentelemetry-java by open-telemetry.

the class TraceRequestMarshalerTest method toProtoResourceSpans.

@Test
void toProtoResourceSpans() {
    ResourceSpansMarshaler[] resourceSpansMarshalers = ResourceSpansMarshaler.create(Collections.singleton(TestSpanData.builder().setHasEnded(true).setSpanContext(SPAN_CONTEXT).setParentSpanContext(SpanContext.getInvalid()).setName("GET /api/endpoint").setKind(SpanKind.SERVER).setStartEpochNanos(12345).setEndEpochNanos(12349).setStatus(StatusData.unset()).setInstrumentationLibraryInfo(InstrumentationLibraryInfo.create("testLib", "1.0", "http://url")).setResource(Resource.builder().put("one", 1).setSchemaUrl("http://url").build()).build()));
    assertThat(resourceSpansMarshalers).hasSize(1);
    ResourceSpans onlyResourceSpans = parse(ResourceSpans.getDefaultInstance(), resourceSpansMarshalers[0]);
    assertThat(onlyResourceSpans.getSchemaUrl()).isEqualTo("http://url");
    assertThat(onlyResourceSpans.getInstrumentationLibrarySpansCount()).isEqualTo(1);
    InstrumentationLibrarySpans instrumentationLibrarySpans = onlyResourceSpans.getInstrumentationLibrarySpans(0);
    assertThat(instrumentationLibrarySpans.getSchemaUrl()).isEqualTo("http://url");
    assertThat(instrumentationLibrarySpans.getInstrumentationLibrary()).isEqualTo(InstrumentationLibrary.newBuilder().setName("testLib").setVersion("1.0").build());
}
Also used : InstrumentationLibrarySpans(io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) Test(org.junit.jupiter.api.Test)

Example 14 with ResourceSpans

use of io.opentelemetry.proto.trace.v1.ResourceSpans in project opentelemetry-java by open-telemetry.

the class TraceRequestMarshalerTest method parse.

@SuppressWarnings("unchecked")
private static <T extends Message> T parse(T prototype, Marshaler marshaler) {
    byte[] serialized = toByteArray(marshaler);
    T result;
    try {
        result = (T) prototype.newBuilderForType().mergeFrom(serialized).build();
    } catch (InvalidProtocolBufferException e) {
        throw new UncheckedIOException(e);
    }
    // Our marshaler should produce the exact same length of serialized output (for example, field
    // default values are not outputted), so we check that here. The output itself may have slightly
    // different ordering, mostly due to the way we don't output oneof values in field order all the
    // tieme. If the lengths are equal and the resulting protos are equal, the marshaling is
    // guaranteed to be valid.
    assertThat(result.getSerializedSize()).isEqualTo(serialized.length);
    // We don't compare JSON strings due to some differences (particularly serializing enums as
    // numbers instead of names). This may improve in the future but what matters is what we produce
    // can be parsed.
    String json = toJson(marshaler);
    Message.Builder builder = prototype.newBuilderForType();
    try {
        JsonFormat.parser().merge(json, builder);
    } catch (InvalidProtocolBufferException e) {
        throw new UncheckedIOException(e);
    }
    // libraries currently support customizing on the parse side.
    if (result instanceof Span) {
        fixSpanJsonIds((Span.Builder) builder);
    }
    // libraries currently support customizing on the parse side.
    if (result instanceof Span.Link) {
        fixLinkJsonIds((Span.Link.Builder) builder);
    }
    if (result instanceof ResourceSpans) {
        ResourceSpans.Builder fixed = (ResourceSpans.Builder) builder;
        for (InstrumentationLibrarySpans.Builder ils : fixed.getInstrumentationLibrarySpansBuilderList()) {
            for (Span.Builder span : ils.getSpansBuilderList()) {
                fixSpanJsonIds(span);
            }
        }
    }
    assertThat(builder.build()).isEqualTo(result);
    return result;
}
Also used : Message(com.google.protobuf.Message) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) UncheckedIOException(java.io.UncheckedIOException) ByteString(com.google.protobuf.ByteString) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) Span(io.opentelemetry.proto.trace.v1.Span) STATUS_CODE_UNSET(io.opentelemetry.proto.trace.v1.Status.StatusCode.STATUS_CODE_UNSET) InstrumentationLibrarySpans(io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans)

Example 15 with ResourceSpans

use of io.opentelemetry.proto.trace.v1.ResourceSpans in project opentelemetry-java by open-telemetry.

the class OtlpExporterIntegrationTest method testTraceExport.

private static void testTraceExport(SpanExporter spanExporter) {
    SdkTracerProvider tracerProvider = SdkTracerProvider.builder().addSpanProcessor(SimpleSpanProcessor.create(spanExporter)).setResource(RESOURCE).build();
    SpanContext linkContext = SpanContext.create(IdGenerator.random().generateTraceId(), IdGenerator.random().generateSpanId(), TraceFlags.getDefault(), TraceState.getDefault());
    Span span = tracerProvider.get(OtlpExporterIntegrationTest.class.getName()).spanBuilder("my span name").addLink(linkContext).startSpan();
    span.setAttribute("key", "value");
    span.addEvent("event");
    span.end();
    await().atMost(Duration.ofSeconds(30)).untilAsserted(() -> assertThat(grpcServer.traceRequests).hasSize(1));
    ExportTraceServiceRequest request = grpcServer.traceRequests.get(0);
    assertThat(request.getResourceSpansCount()).isEqualTo(1);
    ResourceSpans resourceSpans = request.getResourceSpans(0);
    assertThat(resourceSpans.getResource().getAttributesList()).contains(KeyValue.newBuilder().setKey(ResourceAttributes.SERVICE_NAME.getKey()).setValue(AnyValue.newBuilder().setStringValue("integration test").build()).build());
    assertThat(resourceSpans.getInstrumentationLibrarySpansCount()).isEqualTo(1);
    InstrumentationLibrarySpans ilSpans = resourceSpans.getInstrumentationLibrarySpans(0);
    assertThat(ilSpans.getInstrumentationLibrary().getName()).isEqualTo(OtlpExporterIntegrationTest.class.getName());
    assertThat(ilSpans.getSpansCount()).isEqualTo(1);
    io.opentelemetry.proto.trace.v1.Span protoSpan = ilSpans.getSpans(0);
    assertThat(protoSpan.getTraceId().toByteArray()).isEqualTo(span.getSpanContext().getTraceIdBytes());
    assertThat(protoSpan.getSpanId().toByteArray()).isEqualTo(span.getSpanContext().getSpanIdBytes());
    assertThat(protoSpan.getName()).isEqualTo("my span name");
    assertThat(protoSpan.getAttributesList()).isEqualTo(Collections.singletonList(KeyValue.newBuilder().setKey("key").setValue(AnyValue.newBuilder().setStringValue("value").build()).build()));
    assertThat(protoSpan.getEventsCount()).isEqualTo(1);
    assertThat(protoSpan.getEvents(0).getName()).isEqualTo("event");
    assertThat(protoSpan.getLinksCount()).isEqualTo(1);
    Link link = protoSpan.getLinks(0);
    assertThat(link.getTraceId().toByteArray()).isEqualTo(linkContext.getTraceIdBytes());
    assertThat(link.getSpanId().toByteArray()).isEqualTo(linkContext.getSpanIdBytes());
}
Also used : ExportTraceServiceRequest(io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest) SpanContext(io.opentelemetry.api.trace.SpanContext) InstrumentationLibrarySpans(io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans) SdkTracerProvider(io.opentelemetry.sdk.trace.SdkTracerProvider) ResourceSpans(io.opentelemetry.proto.trace.v1.ResourceSpans) Span(io.opentelemetry.api.trace.Span) Link(io.opentelemetry.proto.trace.v1.Span.Link)

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