Search in sources :

Example 26 with JaegerSpanContext

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

the class TextMapCodecTest method testContextAsStringFormatsPositiveFields.

@Test
public void testContextAsStringFormatsPositiveFields() {
    long traceIdLow = -10L;
    long spanId = -10L;
    long parentId = -10L;
    byte flags = (byte) 129;
    JaegerSpanContext context = new JaegerSpanContext(0L, traceIdLow, spanId, parentId, flags);
    assertEquals("fffffffffffffff6:fffffffffffffff6:fffffffffffffff6:81", TextMapCodec.contextAsString(context));
    JaegerSpanContext contextFromStr = TextMapCodec.contextFromString(context.toString());
    assertEquals(traceIdLow, contextFromStr.getTraceIdLow());
    assertEquals(0L, contextFromStr.getTraceIdHigh());
    assertEquals(spanId, contextFromStr.getSpanId());
    assertEquals(parentId, contextFromStr.getParentId());
    assertEquals(flags, contextFromStr.getFlags());
}
Also used : JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Example 27 with JaegerSpanContext

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

the class TextMapCodecTest method testAdhocBaggageWithTraceId.

/**
 * Tests that the codec will include baggage from header "jaeger-baggage".
 */
@Test
public void testAdhocBaggageWithTraceId() {
    TextMapCodec codec = new TextMapCodec(false);
    Map<String, String> headers = new HashMap<>();
    long traceIdLow = 42;
    long spanId = 1;
    long parentId = 0;
    codec.inject(new JaegerSpanContext(0L, traceIdLow, spanId, parentId, (byte) 1), new TextMapAdapter(headers));
    headers.put("jaeger-baggage", "k1=v1, k2 = v2");
    JaegerSpanContext context = codec.extract(new TextMapAdapter(headers));
    assertEquals("must have trace ID", 42, context.getTraceIdLow());
    assertEquals("must have trace ID", 0L, context.getTraceIdHigh());
    assertEquals("must have bagggae", "v1", context.getBaggageItem("k1"));
    assertEquals("must have bagggae", "v2", context.getBaggageItem("k2"));
}
Also used : HashMap(java.util.HashMap) TextMapAdapter(io.opentracing.propagation.TextMapAdapter) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Example 28 with JaegerSpanContext

use of io.jaegertracing.internal.JaegerSpanContext 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 29 with JaegerSpanContext

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

the class ZipkinSenderTest method testAppend128BitTraceId.

@Test
public void testAppend128BitTraceId() throws Exception {
    JaegerSpan expectedSpan = tracer128.buildSpan("raza").start();
    sender.append(expectedSpan);
    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();
    assertNotEquals(context.getTraceIdHigh(), 0L);
    assertTrue(actualSpan.traceId().length() > 16);
    assertEquals(context.getTraceIdLow(), HexCodec.lowerHexToUnsignedLong(actualSpan.traceId()));
    assertEquals(context.getTraceIdHigh(), HexCodec.lowerHexToUnsignedLong(actualSpan.traceId().substring(0, 16)));
}
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 30 with JaegerSpanContext

use of io.jaegertracing.internal.JaegerSpanContext 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)

Aggregations

JaegerSpanContext (io.jaegertracing.internal.JaegerSpanContext)68 Test (org.junit.Test)59 HashMap (java.util.HashMap)20 TextMapAdapter (io.opentracing.propagation.TextMapAdapter)19 JaegerSpan (io.jaegertracing.internal.JaegerSpan)10 JaegerTracer (io.jaegertracing.internal.JaegerTracer)8 Response (javax.ws.rs.core.Response)7 TextMap (io.opentracing.propagation.TextMap)6 CodecConfiguration (io.jaegertracing.Configuration.CodecConfiguration)4 ReporterConfiguration (io.jaegertracing.Configuration.ReporterConfiguration)4 SamplerConfiguration (io.jaegertracing.Configuration.SamplerConfiguration)4 SenderConfiguration (io.jaegertracing.Configuration.SenderConfiguration)4 List (java.util.List)3 ObservedSpan (io.jaegertracing.crossdock.api.ObservedSpan)2 TestBinaryCarrier (io.jaegertracing.internal.propagation.TestBinaryCarrier)2 InMemoryReporter (io.jaegertracing.internal.reporters.InMemoryReporter)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1 Endpoint (com.twitter.zipkin.thriftjava.Endpoint)1