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