use of io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans in project inspectit-ocelot by inspectIT.
the class OpenTelemetryProtoConverter method toSpanData.
/**
* @return Converts an {@link InstrumentationLibrarySpans} instance to a stream of individual {@link SpanData} instances.
*/
private Stream<SpanData> toSpanData(InstrumentationLibrarySpans librarySpans, Resource resource, Map<String, String> customSpanAttributes) {
InstrumentationLibrary library = librarySpans.getInstrumentationLibrary();
InstrumentationLibraryInfo libraryInfo = InstrumentationLibraryInfo.create(library.getName(), library.getVersion());
return librarySpans.getSpansList().stream().map(protoSpan -> OcelotSpanUtils.createSpanData(protoSpan, resource, libraryInfo, customSpanAttributes)).filter(Objects::nonNull);
}
use of io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans 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.InstrumentationLibrarySpans 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);
}
use of io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans 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());
}
use of io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans 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());
}
Aggregations