Search in sources :

Example 36 with Span

use of io.opentelemetry.proto.trace.v1.Span in project instrumentation-java by census-instrumentation.

the class TraceProtoUtils method toSpanProto.

/**
 * Converts {@link SpanData} to {@link Span} proto.
 *
 * @param spanData the {@code SpanData}.
 * @return proto representation of {@code Span}.
 */
static Span toSpanProto(SpanData spanData) {
    SpanContext spanContext = spanData.getContext();
    TraceId traceId = spanContext.getTraceId();
    SpanId spanId = spanContext.getSpanId();
    Span.Builder spanBuilder = Span.newBuilder().setTraceId(toByteString(traceId.getBytes())).setSpanId(toByteString(spanId.getBytes())).setTracestate(toTracestateProto(spanContext.getTracestate())).setName(toTruncatableStringProto(spanData.getName())).setStartTime(toTimestampProto(spanData.getStartTimestamp())).setAttributes(toAttributesProto(spanData.getAttributes())).setTimeEvents(toTimeEventsProto(spanData.getAnnotations(), spanData.getMessageEvents())).setLinks(toLinksProto(spanData.getLinks()));
    Kind kind = spanData.getKind();
    if (kind != null) {
        spanBuilder.setKind(toSpanKindProto(kind));
    }
    io.opencensus.trace.Status status = spanData.getStatus();
    if (status != null) {
        spanBuilder.setStatus(toStatusProto(status));
    }
    Timestamp end = spanData.getEndTimestamp();
    if (end != null) {
        spanBuilder.setEndTime(toTimestampProto(end));
    }
    Integer childSpanCount = spanData.getChildSpanCount();
    if (childSpanCount != null) {
        spanBuilder.setChildSpanCount(UInt32Value.newBuilder().setValue(childSpanCount).build());
    }
    Boolean hasRemoteParent = spanData.getHasRemoteParent();
    if (hasRemoteParent != null) {
        spanBuilder.setSameProcessAsParentSpan(BoolValue.of(!hasRemoteParent));
    }
    SpanId parentSpanId = spanData.getParentSpanId();
    if (parentSpanId != null && parentSpanId.isValid()) {
        spanBuilder.setParentSpanId(toByteString(parentSpanId.getBytes()));
    }
    return spanBuilder.build();
}
Also used : SpanContext(io.opencensus.trace.SpanContext) SpanKind(io.opencensus.proto.trace.v1.Span.SpanKind) Kind(io.opencensus.trace.Span.Kind) TraceId(io.opencensus.trace.TraceId) Span(io.opencensus.proto.trace.v1.Span) Timestamp(io.opencensus.common.Timestamp) SpanId(io.opencensus.trace.SpanId)

Example 37 with Span

use of io.opentelemetry.proto.trace.v1.Span in project zipkin by openzipkin.

the class ZipkinRuleTest method getTraces_whenMissingTimestamps.

/**
 * The rule is here to help debugging. Even partial spans should be returned
 */
@Test
public void getTraces_whenMissingTimestamps() throws IOException {
    Span span = Span.newBuilder().traceId("1").id("1").name("foo").build();
    // write the span to the zipkin using http
    assertThat(postSpansV1(asList(span)).code()).isEqualTo(202);
    // read the traces directly
    assertThat(zipkin.getTraces()).containsOnly(asList(span));
}
Also used : Span(zipkin2.Span) Test(org.junit.Test)

Example 38 with Span

use of io.opentelemetry.proto.trace.v1.Span in project zipkin by openzipkin.

the class CassandraSpanConsumerTest method traceByServiceSpan_indexesLocalServiceNameAndEmptySpanName.

/**
 * To allow lookups w/o a span name, we index "". "" is used instead of null to avoid creating
 * tombstones.
 */
@Test
public void traceByServiceSpan_indexesLocalServiceNameAndEmptySpanName() {
    Span span = spanWithoutAnnotationsOrTags;
    AggregateCall<?, Void> call = (AggregateCall<?, Void>) consumer.accept(singletonList(span));
    assertThat(call.delegate()).filteredOn(c -> c instanceof InsertTraceByServiceSpan).extracting("input.service", "input.span").containsExactly(tuple(FRONTEND.serviceName(), span.name()), tuple(FRONTEND.serviceName(), ""));
}
Also used : AggregateCall(zipkin2.internal.AggregateCall) Span(zipkin2.Span) Test(org.junit.Test)

Example 39 with Span

use of io.opentelemetry.proto.trace.v1.Span in project zipkin by openzipkin.

the class CassandraSpanConsumerTest method strictTraceIdFalse_setsTraceIdHigh.

@Test
public void strictTraceIdFalse_setsTraceIdHigh() {
    consumer = spanConsumer(CassandraStorage.newBuilder().strictTraceId(false));
    Span span = spanWithoutAnnotationsOrTags.toBuilder().traceId("77fcac3d4c5be8d2a037812820c65f28").build();
    AggregateCall<?, Void> call = (AggregateCall<?, Void>) consumer.accept(singletonList(span));
    assertThat(call.delegate()).filteredOn(c -> c instanceof InsertSpan).extracting("input.trace_id_high", "input.trace_id").containsExactly(tuple("77fcac3d4c5be8d2", "a037812820c65f28"));
}
Also used : AggregateCall(zipkin2.internal.AggregateCall) Span(zipkin2.Span) Test(org.junit.Test)

Example 40 with Span

use of io.opentelemetry.proto.trace.v1.Span in project zipkin by openzipkin.

the class CassandraSpanConsumerTest method serviceSpanKeys_emptyWhenNoEndpoints.

@Test
public void serviceSpanKeys_emptyWhenNoEndpoints() {
    Span span = spanWithoutAnnotationsOrTags.toBuilder().localEndpoint(null).build();
    assertThat(consumer.accept(singletonList(span))).isInstanceOf(ResultSetFutureCall.class);
}
Also used : Span(zipkin2.Span) Test(org.junit.Test)

Aggregations

Span (zipkin2.Span)335 Test (org.junit.Test)237 Test (org.junit.jupiter.api.Test)84 ArrayList (java.util.ArrayList)47 Endpoint (zipkin2.Endpoint)43 TestObjects.newClientSpan (zipkin2.TestObjects.newClientSpan)41 Span (io.opentelemetry.proto.trace.v1.Span)35 List (java.util.List)23 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)20 V1Span (zipkin2.v1.V1Span)17 Span (com.google.devtools.cloudtrace.v2.Span)16 Map (java.util.Map)14 AggregateCall (zipkin2.internal.AggregateCall)13 ResourceSpans (io.opentelemetry.proto.trace.v1.ResourceSpans)11 Arrays.asList (java.util.Arrays.asList)11 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)11 Annotation (wavefront.report.Annotation)11 Trace (com.google.devtools.cloudtrace.v1.Trace)10 TraceSpan (com.google.devtools.cloudtrace.v1.TraceSpan)10 AttributeValue (com.google.devtools.cloudtrace.v2.AttributeValue)10