Search in sources :

Example 1 with Kind

use of io.opencensus.trace.Span.Kind 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 2 with Kind

use of io.opencensus.trace.Span.Kind in project instrumentation-java by census-instrumentation.

the class HttpClientHandlerTest method handleStartShouldSetKindToClient.

@Test
public void handleStartShouldSetKindToClient() {
    handler.handleStart(parentSpan, carrier, request);
    verify(spanBuilder).setSpanKind(kindArgumentCaptor.capture());
    Kind kind = kindArgumentCaptor.getValue();
    assertThat(kind).isEqualTo(Kind.CLIENT);
}
Also used : Kind(io.opencensus.trace.Span.Kind) Test(org.junit.Test)

Example 3 with Kind

use of io.opencensus.trace.Span.Kind in project instrumentation-java by census-instrumentation.

the class HttpServerHandlerTest method handleStartShouldSetKindToServer.

@Test
public void handleStartShouldSetKindToServer() throws SpanContextParseException {
    handler.handleStart(carrier, request);
    verify(spanBuilderWithRemoteParent).setSpanKind(kindArgumentCaptor.capture());
    Kind kind = kindArgumentCaptor.getValue();
    assertThat(kind).isEqualTo(Kind.SERVER);
}
Also used : Kind(io.opencensus.trace.Span.Kind) Test(org.junit.Test)

Aggregations

Kind (io.opencensus.trace.Span.Kind)3 Test (org.junit.Test)2 Timestamp (io.opencensus.common.Timestamp)1 Span (io.opencensus.proto.trace.v1.Span)1 SpanKind (io.opencensus.proto.trace.v1.Span.SpanKind)1 SpanContext (io.opencensus.trace.SpanContext)1 SpanId (io.opencensus.trace.SpanId)1 TraceId (io.opencensus.trace.TraceId)1