use of io.opentracing.propagation.TextMap in project jaeger-client-java by jaegertracing.
the class B3TextMapCodecTest method testExtract_childSpan.
@Test
public void testExtract_childSpan() throws Exception {
SpanId spanId = SpanId.builder().spanId(2L).traceId(1L).parentId(1L).build();
TextMap textMap = makeRequestWithSpanId(spanId);
SpanContext context = b3Codec.extract(textMap);
assertEquals(1, context.getTraceId());
assertEquals(1, context.getParentId());
assertEquals(2, context.getSpanId());
// sampled
assertEquals(1, context.getFlags());
}
use of io.opentracing.propagation.TextMap in project jaeger-client-java by jaegertracing.
the class B3TextMapCodecTest method testExtract_rootSpan.
@Test
public void testExtract_rootSpan() throws Exception {
SpanId spanId = SpanId.builder().spanId(1L).traceId(1L).parentId(null).build();
TextMap textMap = makeRequestWithSpanId(spanId);
SpanContext context = b3Codec.extract(textMap);
assertEquals(1, context.getTraceId());
// parentID==0 means root span
assertEquals(0, context.getParentId());
assertEquals(1, context.getSpanId());
// sampled
assertEquals(1, context.getFlags());
}
use of io.opentracing.propagation.TextMap in project jaeger-client-java by jaegertracing.
the class TextMapCodec method extract.
@Override
public SpanContext extract(TextMap carrier) {
SpanContext context = null;
Map<String, String> baggage = null;
String debugId = null;
for (Map.Entry<String, String> entry : carrier) {
// TODO there should be no lower-case here
String key = entry.getKey().toLowerCase(Locale.ROOT);
if (key.equals(contextKey)) {
context = SpanContext.contextFromString(decodedValue(entry.getValue()));
} else if (key.equals(Constants.DEBUG_ID_HEADER_KEY)) {
debugId = decodedValue(entry.getValue());
} else if (key.startsWith(baggagePrefix)) {
if (baggage == null) {
baggage = new HashMap<String, String>();
}
baggage.put(keys.unprefixedKey(key, baggagePrefix), decodedValue(entry.getValue()));
}
}
if (context == null) {
if (debugId != null) {
return SpanContext.withDebugId(debugId);
}
return null;
}
if (baggage == null) {
return context;
}
return context.withBaggage(baggage);
}
use of io.opentracing.propagation.TextMap in project jaeger-client-java by jaegertracing.
the class TracerTest method testRegisterInjector.
@Test
public void testRegisterInjector() {
@SuppressWarnings("unchecked") Injector<TextMap> injector = mock(Injector.class);
Tracer tracer = new Tracer.Builder("TracerTestService", new InMemoryReporter(), new ConstSampler(true)).withMetrics(new Metrics(new InMemoryMetricsFactory())).registerInjector(Format.Builtin.TEXT_MAP, injector).build();
Span span = (Span) tracer.buildSpan("leela").start();
TextMap carrier = mock(TextMap.class);
tracer.inject(span.context(), Format.Builtin.TEXT_MAP, carrier);
verify(injector).inject(any(SpanContext.class), any(TextMap.class));
}
use of io.opentracing.propagation.TextMap in project jaeger-client-java by jaegertracing.
the class B3TextMapCodecResiliencyTest method shouldFallbackWhenMaliciousInput.
@Test
@UseDataProvider("maliciousInputs")
public void shouldFallbackWhenMaliciousInput(String headerName, String maliciousInput) {
TextMap maliciousCarrier = validHeaders();
maliciousCarrier.put(headerName, maliciousInput);
// when
SpanContext extract = sut.extract(maliciousCarrier);
// then
assertNull(extract);
}
Aggregations