Search in sources :

Example 1 with Span

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

the class JaegerExporterHandler method spanDataToJaegerThriftSpan.

private Span spanDataToJaegerThriftSpan(final SpanData spanData) {
    final long startTimeInMicros = timestampToMicros(spanData.getStartTimestamp());
    final long endTimeInMicros = timestampToMicros(spanData.getEndTimestamp());
    final SpanContext context = spanData.getContext();
    copyToBuffer(context.getTraceId());
    List<Tag> tags = attributesToTags(spanData.getAttributes().getAttributeMap(), spanKindToTag(spanData.getKind()));
    addStatusTags(tags, spanData.getStatus());
    return new io.jaegertracing.thriftjava.Span(traceIdLow(), traceIdHigh(), spanIdToLong(context.getSpanId()), spanIdToLong(spanData.getParentSpanId()), spanData.getName(), optionsToFlags(context.getTraceOptions()), startTimeInMicros, endTimeInMicros - startTimeInMicros).setReferences(linksToReferences(spanData.getLinks().getLinks())).setTags(tags).setLogs(timedEventsToLogs(spanData.getAnnotations().getEvents(), spanData.getMessageEvents().getEvents()));
}
Also used : SpanContext(io.opencensus.trace.SpanContext) Span(io.jaegertracing.thriftjava.Span) Tag(io.jaegertracing.thriftjava.Tag)

Example 2 with Span

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

the class ThriftSenderBaseTest method calculateBatchOverheadDifference.

private int calculateBatchOverheadDifference(int numberOfSpans) throws Exception {
    AutoExpandingBufferWriteTransport memoryTransport = new AutoExpandingBufferWriteTransport(new TConfiguration(), maxPacketSize, 2);
    Agent.Client memoryClient = new Agent.Client(new TCompactProtocol((memoryTransport)));
    Span span = new Span();
    span.setOperationName("raza");
    // 0, 0, 0, 0, "raza", 0, 0, 0);
    List<Span> spans = new ArrayList<>();
    for (int i = 0; i < numberOfSpans; i++) {
        spans.add(span);
    }
    memoryClient.emitBatch(new Batch(new io.jaegertracing.thriftjava.Process(SERVICE_NAME), spans));
    int emitBatchOverheadMultipleSpans = memoryTransport.getLength();
    memoryTransport.reset();
    for (int j = 0; j < numberOfSpans; j++) {
        span.write(new TCompactProtocol(memoryTransport));
    }
    int writeBatchOverheadMultipleSpans = memoryTransport.getLength();
    return emitBatchOverheadMultipleSpans - writeBatchOverheadMultipleSpans;
}
Also used : AutoExpandingBufferWriteTransport(org.apache.thrift.transport.AutoExpandingBufferWriteTransport) Agent(io.jaegertracing.agent.thrift.Agent) ArrayList(java.util.ArrayList) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol) Span(io.jaegertracing.thriftjava.Span) Batch(io.jaegertracing.thriftjava.Batch) TConfiguration(org.apache.thrift.TConfiguration)

Example 3 with Span

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

the class HttpSenderTest method generateSpans.

private List<Span> generateSpans() {
    ArrayList<Span> spans = new ArrayList<>();
    Span span = new Span();
    span.setOperationName("boomerang");
    spans.add(span);
    return spans;
}
Also used : ArrayList(java.util.ArrayList) Span(io.jaegertracing.thriftjava.Span)

Example 4 with Span

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

the class JaegerExporterHandlerTest method convertErrorSpanDataToJaegerThriftSpan.

@Test
public void convertErrorSpanDataToJaegerThriftSpan() throws SenderException {
    long startTime = 1519629870001L;
    long endTime = 1519630148002L;
    String statusMessage = "timeout";
    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(Collections.<String, AttributeValue>emptyMap(), 0), SpanData.TimedEvents.create(Collections.<TimedEvent<Annotation>>emptyList(), 0), SpanData.TimedEvents.create(Collections.<TimedEvent<MessageEvent>>emptyList(), 0), SpanData.Links.create(Collections.<Link>emptyList(), 0), 0, Status.DEADLINE_EXCEEDED.withDescription(statusMessage), 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.tags.size()).isEqualTo(3);
    assertThat(span.tags).containsExactly(new Tag(JaegerExporterHandler.SPAN_KIND, TagType.STRING).setVStr("server"), new Tag(JaegerExporterHandler.STATUS_CODE, TagType.LONG).setVLong(4), new Tag(JaegerExporterHandler.STATUS_MESSAGE, TagType.STRING).setVStr(statusMessage));
}
Also used : AttributeValue(io.opencensus.trace.AttributeValue) SpanData(io.opencensus.trace.export.SpanData) TimedEvent(io.opencensus.trace.export.SpanData.TimedEvent) Tag(io.jaegertracing.thriftjava.Tag) Span(io.jaegertracing.thriftjava.Span) Link(io.opencensus.trace.Link) Test(org.junit.Test)

Example 5 with Span

use of io.jaegertracing.thriftjava.Span 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

Span (io.jaegertracing.thriftjava.Span)5 Tag (io.jaegertracing.thriftjava.Tag)3 SpanData (io.opencensus.trace.export.SpanData)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Agent (io.jaegertracing.agent.thrift.Agent)1 Batch (io.jaegertracing.thriftjava.Batch)1 Log (io.jaegertracing.thriftjava.Log)1 SpanRef (io.jaegertracing.thriftjava.SpanRef)1 AttributeValue (io.opencensus.trace.AttributeValue)1 Link (io.opencensus.trace.Link)1 SpanContext (io.opencensus.trace.SpanContext)1 TimedEvent (io.opencensus.trace.export.SpanData.TimedEvent)1 TConfiguration (org.apache.thrift.TConfiguration)1 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)1 AutoExpandingBufferWriteTransport (org.apache.thrift.transport.AutoExpandingBufferWriteTransport)1