use of io.opentracing.propagation.TextMapAdapter in project jaeger-client-java by jaegertracing.
the class TraceContextCodecTest method support128BitTraceIdExtraction.
@Test
public void support128BitTraceIdExtraction() {
String hex128Bits = "463ac35c9f6413ad48485a3953bb6124";
String parentSpan = "d1595c6ec91668af";
String tracecontext = String.format("00-%s-%s-01", hex128Bits, parentSpan);
TextMapAdapter textMap = new TextMapAdapter(new HashMap<>());
textMap.put(TRACE_PARENT, tracecontext);
JaegerSpanContext context = traceContextCodec.extract(textMap);
assertNotNull(HexCodec.lowerHexToUnsignedLong(parentSpan));
assertEquals(HexCodec.lowerHexToUnsignedLong(hex128Bits).longValue(), context.getTraceIdLow());
assertEquals(HexCodec.higherHexToUnsignedLong(hex128Bits).longValue(), context.getTraceIdHigh());
assertEquals(HexCodec.lowerHexToUnsignedLong(parentSpan).longValue(), context.getSpanId());
assertTrue(context.isSampled());
}
use of io.opentracing.propagation.TextMapAdapter in project jaeger-client-java by jaegertracing.
the class TraceContextCodecTest method testTraceStatePropagation.
@Test
public void testTraceStatePropagation() {
Map<String, String> extractCarrier = new HashMap<>();
TextMapAdapter textMap = new TextMapAdapter(extractCarrier);
textMap.put(TRACE_PARENT, EXAMPLE_TRACE_PARENT);
textMap.put(TRACE_STATE, "whatever");
JaegerSpanContext spanContext = traceContextCodec.extract(textMap);
Map<String, String> injectCarrier = new HashMap<>();
traceContextCodec.inject(spanContext, new TextMapAdapter(injectCarrier));
assertEquals(extractCarrier, injectCarrier);
}
use of io.opentracing.propagation.TextMapAdapter in project jaeger-client-java by jaegertracing.
the class TextMapCodecTest method testInjectDoNotEncodeSpanContext.
@Test
public void testInjectDoNotEncodeSpanContext() {
TextMapCodec codec = new TextMapCodec(true);
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));
String traceId = headers.get("uber-trace-id");
assertEquals("000000000000002a:0000000000000001:0:1", traceId);
}
use of io.opentracing.propagation.TextMapAdapter in project jaeger-client-java by jaegertracing.
the class TextMapCodecTest method testExtractSupportNonEncodedSpanContext.
@Test
public void testExtractSupportNonEncodedSpanContext() {
Map<String, String> headers = new HashMap<>();
headers.put("uber-trace-id", "2a:1:0:1");
TextMapCodec codec = new TextMapCodec(true);
JaegerSpanContext context = codec.extract(new TextMapAdapter(headers));
assertEquals(42, context.getTraceIdLow());
assertEquals(0L, context.getTraceIdHigh());
assertEquals(1L, context.getSpanId());
assertTrue(context.isSampled());
}
use of io.opentracing.propagation.TextMapAdapter in project jaeger-client-java by jaegertracing.
the class TextMapCodecTest method testAdhocBaggageWithoutTraceId.
/**
* Tests that the codec will return non-null SpanContext even if the only header
* present is "jaeger-baggage".
*/
@Test
public void testAdhocBaggageWithoutTraceId() {
Map<String, String> headers = new HashMap<>();
headers.put("jaeger-baggage", "k1=v1, k2 = v2, k3=v3=d3");
TextMapCodec codec = new TextMapCodec(false);
JaegerSpanContext context = codec.extract(new TextMapAdapter(headers));
assertEquals("v1", context.getBaggageItem("k1"));
assertEquals("v2", context.getBaggageItem("k2"));
assertNull(context.getBaggageItem("k3"));
}
Aggregations