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();
}
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);
}
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);
}
Aggregations