Search in sources :

Example 1 with SpanRef

use of io.jaegertracing.thriftjava.SpanRef in project instrumentation-java by census-instrumentation.

the class JaegerExporterHandler method linksToReferences.

private List<SpanRef> linksToReferences(final List<Link> links) {
    final List<SpanRef> spanRefs = Lists.newArrayListWithExpectedSize(links.size());
    for (final Link link : links) {
        copyToBuffer(link.getTraceId());
        spanRefs.add(new SpanRef(linkTypeToRefType(link.getType()), traceIdLow(), traceIdHigh(), spanIdToLong(link.getSpanId())));
    }
    return spanRefs;
}
Also used : SpanRef(io.jaegertracing.thriftjava.SpanRef) Link(io.opencensus.trace.Link)

Example 2 with SpanRef

use of io.jaegertracing.thriftjava.SpanRef in project jaeger-client-java by jaegertracing.

the class JaegerThriftSpanConverter method convertSpan.

public static io.jaegertracing.thriftjava.Span convertSpan(JaegerSpan jaegerSpan) {
    JaegerSpanContext context = jaegerSpan.context();
    boolean oneChildOfParent = jaegerSpan.getReferences().size() == 1 && References.CHILD_OF.equals(jaegerSpan.getReferences().get(0).getType());
    List<SpanRef> references = oneChildOfParent ? Collections.<SpanRef>emptyList() : buildReferences(jaegerSpan.getReferences());
    return new io.jaegertracing.thriftjava.Span(context.getTraceIdLow(), context.getTraceIdHigh(), context.getSpanId(), oneChildOfParent ? context.getParentId() : 0, jaegerSpan.getOperationName(), context.getFlags(), jaegerSpan.getStart(), jaegerSpan.getDuration()).setReferences(references).setTags(buildTags(jaegerSpan.getTags())).setLogs(buildLogs(jaegerSpan.getLogs()));
}
Also used : SpanRef(io.jaegertracing.thriftjava.SpanRef) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext)

Example 3 with SpanRef

use of io.jaegertracing.thriftjava.SpanRef in project jaeger-client-java by jaegertracing.

the class JaegerThriftSpanConverter method buildReferences.

static List<SpanRef> buildReferences(List<Reference> references) {
    List<SpanRef> thriftReferences = new ArrayList<SpanRef>(references.size());
    for (Reference reference : references) {
        SpanRefType thriftRefType = References.CHILD_OF.equals(reference.getType()) ? SpanRefType.CHILD_OF : SpanRefType.FOLLOWS_FROM;
        thriftReferences.add(new SpanRef(thriftRefType, reference.getSpanContext().getTraceIdLow(), reference.getSpanContext().getTraceIdHigh(), reference.getSpanContext().getSpanId()));
    }
    return thriftReferences;
}
Also used : Reference(io.jaegertracing.internal.Reference) SpanRef(io.jaegertracing.thriftjava.SpanRef) SpanRefType(io.jaegertracing.thriftjava.SpanRefType) ArrayList(java.util.ArrayList)

Example 4 with SpanRef

use of io.jaegertracing.thriftjava.SpanRef in project instrumentation-java by census-instrumentation.

the class JaegerExporterHandlerTest method exportShouldConvertFromSpanDataToJaegerThriftSpan.

@Test
public void exportShouldConvertFromSpanDataToJaegerThriftSpan() throws SenderException {
    final long startTime = 1519629870001L;
    final long endTime = 1519630148002L;
    final SpanData spanData = SpanData.create(sampleSpanContext(), SpanId.fromBytes(new byte[] { (byte) 0x7F, FF, FF, FF, FF, FF, FF, FF }), true, "test", Kind.SERVER, Timestamp.fromMillis(startTime), SpanData.Attributes.create(sampleAttributes(), 0), SpanData.TimedEvents.create(singletonList(sampleAnnotation()), 0), SpanData.TimedEvents.create(singletonList(sampleMessageEvent()), 0), SpanData.Links.create(sampleLinks(), 0), 0, Status.OK, Timestamp.fromMillis(endTime));
    handler.export(singletonList(spanData));
    verify(mockSender).send(eq(process), captor.capture());
    List<Span> spans = captor.getValue();
    assertThat(spans.size()).isEqualTo(1);
    Span span = spans.get(0);
    assertThat(span.operationName).isEqualTo("test");
    assertThat(span.spanId).isEqualTo(256L);
    assertThat(span.traceIdHigh).isEqualTo(-72057594037927936L);
    assertThat(span.traceIdLow).isEqualTo(1L);
    assertThat(span.parentSpanId).isEqualTo(Long.MAX_VALUE);
    assertThat(span.flags).isEqualTo(1);
    assertThat(span.startTime).isEqualTo(MILLISECONDS.toMicros(startTime));
    assertThat(span.duration).isEqualTo(MILLISECONDS.toMicros(endTime - startTime));
    assertThat(span.tags.size()).isEqualTo(5);
    assertThat(span.tags).containsExactly(new Tag("BOOL", TagType.BOOL).setVBool(false), new Tag("LONG", TagType.LONG).setVLong(Long.MAX_VALUE), new Tag(JaegerExporterHandler.SPAN_KIND, TagType.STRING).setVStr("server"), new Tag("STRING", TagType.STRING).setVStr("Judge of a man by his questions rather than by his answers. -- Voltaire"), new Tag(JaegerExporterHandler.STATUS_CODE, TagType.LONG).setVLong(0));
    assertThat(span.logs.size()).isEqualTo(2);
    Log log = span.logs.get(0);
    assertThat(log.timestamp).isEqualTo(1519629872987654L);
    assertThat(log.fields.size()).isEqualTo(4);
    assertThat(log.fields).containsExactly(new Tag("message", TagType.STRING).setVStr("annotation #1"), new Tag("bool", TagType.BOOL).setVBool(true), new Tag("long", TagType.LONG).setVLong(1337L), new Tag("string", TagType.STRING).setVStr("Kind words do not cost much. Yet they accomplish much. -- Pascal"));
    log = span.logs.get(1);
    assertThat(log.timestamp).isEqualTo(1519629871123456L);
    assertThat(log.fields.size()).isEqualTo(4);
    assertThat(log.fields).containsExactly(new Tag("message", TagType.STRING).setVStr("sent message"), new Tag("id", TagType.LONG).setVLong(42L), new Tag("compressed_size", TagType.LONG).setVLong(69), new Tag("uncompressed_size", TagType.LONG).setVLong(96));
    assertThat(span.references.size()).isEqualTo(1);
    SpanRef reference = span.references.get(0);
    assertThat(reference.traceIdHigh).isEqualTo(-1L);
    assertThat(reference.traceIdLow).isEqualTo(-256L);
    assertThat(reference.spanId).isEqualTo(512L);
    assertThat(reference.refType).isEqualTo(SpanRefType.CHILD_OF);
}
Also used : SpanData(io.opencensus.trace.export.SpanData) Log(io.jaegertracing.thriftjava.Log) SpanRef(io.jaegertracing.thriftjava.SpanRef) Tag(io.jaegertracing.thriftjava.Tag) Span(io.jaegertracing.thriftjava.Span) Test(org.junit.Test)

Aggregations

SpanRef (io.jaegertracing.thriftjava.SpanRef)4 JaegerSpanContext (io.jaegertracing.internal.JaegerSpanContext)1 Reference (io.jaegertracing.internal.Reference)1 Log (io.jaegertracing.thriftjava.Log)1 Span (io.jaegertracing.thriftjava.Span)1 SpanRefType (io.jaegertracing.thriftjava.SpanRefType)1 Tag (io.jaegertracing.thriftjava.Tag)1 Link (io.opencensus.trace.Link)1 SpanData (io.opencensus.trace.export.SpanData)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1