Search in sources :

Example 6 with JaegerSpan

use of io.jaegertracing.internal.JaegerSpan in project jaeger-client-java by jaegertracing.

the class TraceContextCodecTest method testDebugIdWithoutTraceHeader.

@Test
public void testDebugIdWithoutTraceHeader() {
    Map<String, String> extractCarrier = new HashMap<>();
    TextMapAdapter textMap = new TextMapAdapter(extractCarrier);
    textMap.put(Constants.DEBUG_ID_HEADER_KEY, EXAMPLE_DEBUG_ID);
    JaegerSpanContext spanContext = traceContextCodec.extract(textMap);
    JaegerTracer tracer = new JaegerTracer.Builder("service").withReporter(new InMemoryReporter()).build();
    JaegerSpan child = tracer.buildSpan("span").asChildOf(spanContext).start();
    assertTrue(child.context().isDebug());
    child.finish();
    tracer.close();
}
Also used : InMemoryReporter(io.jaegertracing.internal.reporters.InMemoryReporter) HashMap(java.util.HashMap) JaegerSpan(io.jaegertracing.internal.JaegerSpan) TextMapAdapter(io.opentracing.propagation.TextMapAdapter) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) JaegerTracer(io.jaegertracing.internal.JaegerTracer) Test(org.junit.Test)

Example 7 with JaegerSpan

use of io.jaegertracing.internal.JaegerSpan in project jaeger-client-java by jaegertracing.

the class TraceBehavior method observeSpan.

private ObservedSpan observeSpan() {
    JaegerSpan span = (JaegerSpan) tracer.activeSpan();
    if (tracer.activeSpan() == null) {
        log.error("No span found");
        return new ObservedSpan("no span found", false, "no span found");
    }
    JaegerSpanContext context = span.context();
    String traceId = context.getTraceId();
    boolean sampled = context.isSampled();
    String baggage = span.getBaggageItem(Constants.BAGGAGE_KEY);
    return new ObservedSpan(traceId, sampled, baggage);
}
Also used : ObservedSpan(io.jaegertracing.crossdock.api.ObservedSpan) JaegerSpan(io.jaegertracing.internal.JaegerSpan) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext)

Example 8 with JaegerSpan

use of io.jaegertracing.internal.JaegerSpan in project jaeger-client-java by jaegertracing.

the class ZipkinV2ReporterTest method testConvertsAndSendsSpan.

@Test
public void testConvertsAndSendsSpan() {
    JaegerSpan span = tracer.buildSpan("raza").start();
    span.finish();
    reporter.report(span);
    zipkinReporter.flush();
    List<List<zipkin2.Span>> spans = zipkinRule.getTraces();
    assertEquals(spans.get(0).get(0).name(), "raza");
}
Also used : JaegerSpan(io.jaegertracing.internal.JaegerSpan) List(java.util.List) Test(org.junit.Test)

Example 9 with JaegerSpan

use of io.jaegertracing.internal.JaegerSpan in project jaeger-client-java by jaegertracing.

the class ZipkinSenderTest method testFlushSendsSpan.

@Test
public void testFlushSendsSpan() throws Exception {
    JaegerSpan expectedSpan = tracer.buildSpan("raza").start();
    assertEquals(0, sender.append(expectedSpan));
    assertEquals(1, sender.flush());
    List<List<zipkin2.Span>> traces = zipkinRule.getTraces();
    assertEquals(traces.size(), 1);
    assertEquals(traces.get(0).size(), 1);
    zipkin2.Span actualSpan = traces.get(0).get(0);
    JaegerSpanContext context = expectedSpan.context();
    assertEquals(context.getTraceIdLow(), HexCodec.lowerHexToUnsignedLong(actualSpan.traceId()));
    assertEquals(context.getTraceIdHigh(), 0L);
    assertEquals(context.getSpanId(), HexCodec.lowerHexToUnsignedLong(actualSpan.id()));
    assertEquals(context.getParentId(), 0L);
    assertNull(actualSpan.parentId());
    assertEquals(expectedSpan.getOperationName(), actualSpan.name());
    assertEquals(tracer.getServiceName(), actualSpan.localServiceName());
}
Also used : JaegerSpan(io.jaegertracing.internal.JaegerSpan) ArrayList(java.util.ArrayList) List(java.util.List) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Example 10 with JaegerSpan

use of io.jaegertracing.internal.JaegerSpan in project jaeger-client-java by jaegertracing.

the class ZipkinSenderTest method testAppend.

@Test
public void testAppend() throws Exception {
    JaegerSpan jaegerSpan = tracer.buildSpan("raza").start();
    com.twitter.zipkin.thriftjava.Span span = ThriftSpanConverter.convertSpan(jaegerSpan);
    int expectedNumSpans = 11;
    List<byte[]> spansToSend = new ArrayList<>(expectedNumSpans);
    for (int i = 0; i < expectedNumSpans; i++) {
        spansToSend.add(new ThriftSpanEncoder().encode(ZipkinSender.backFillHostOnAnnotations(span)));
    }
    // create a sender that's a multiple of the span size (accounting for span overhead)
    // this allows us to test the boundary conditions of writing spans.
    int messageMaxBytes = sender.delegate.messageSizeInBytes(spansToSend);
    sender.close();
    sender = newSender(messageMaxBytes);
    // add enough spans to be under buffer limit
    for (int i = 0; i < expectedNumSpans - 1; i++) {
        assertEquals(0, sender.append(jaegerSpan));
    }
    // add a span that overflows the limit to hit the last branch
    int result = sender.append(jaegerSpan);
    assertEquals(expectedNumSpans, result);
}
Also used : JaegerSpan(io.jaegertracing.internal.JaegerSpan) ArrayList(java.util.ArrayList) ThriftSpanEncoder(io.jaegertracing.zipkin.internal.ThriftSpanEncoder) Test(org.junit.Test)

Aggregations

JaegerSpan (io.jaegertracing.internal.JaegerSpan)51 Test (org.junit.Test)47 JaegerSpanContext (io.jaegertracing.internal.JaegerSpanContext)10 HashMap (java.util.HashMap)8 JaegerTracer (io.jaegertracing.internal.JaegerTracer)7 InMemoryReporter (io.jaegertracing.internal.reporters.InMemoryReporter)7 ConstSampler (io.jaegertracing.internal.samplers.ConstSampler)6 ArrayList (java.util.ArrayList)6 TreeMap (java.util.TreeMap)5 BinaryAnnotation (com.twitter.zipkin.thriftjava.BinaryAnnotation)4 SenderException (io.jaegertracing.internal.exceptions.SenderException)4 TextMap (io.opentracing.propagation.TextMap)4 TextMapAdapter (io.opentracing.propagation.TextMapAdapter)4 List (java.util.List)4 Annotation (com.twitter.zipkin.thriftjava.Annotation)3 Process (io.jaegertracing.thriftjava.Process)3 Map (java.util.Map)3 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)2 Builder (io.jaegertracing.internal.reporters.RemoteReporter.Builder)2 InMemorySender (io.jaegertracing.internal.senders.InMemorySender)2