use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.
the class B3TextMapCodec method extract.
@Override
public JaegerSpanContext extract(TextMap carrier) {
Long traceIdLow = null;
// It's enough to check for a null low trace id
Long traceIdHigh = 0L;
Long spanId = null;
// Conventionally, parent id == 0 means the root span
Long parentId = 0L;
byte flags = 0;
Map<String, String> baggage = null;
for (Map.Entry<String, String> entry : carrier) {
if (entry.getKey().equalsIgnoreCase(SAMPLED_NAME)) {
String value = entry.getValue();
if ("1".equals(value) || "true".equalsIgnoreCase(value)) {
flags |= SAMPLED_FLAG;
}
} else if (entry.getKey().equalsIgnoreCase(TRACE_ID_NAME)) {
traceIdLow = HexCodec.lowerHexToUnsignedLong(entry.getValue());
traceIdHigh = HexCodec.higherHexToUnsignedLong(entry.getValue());
} else if (entry.getKey().equalsIgnoreCase(PARENT_SPAN_ID_NAME)) {
parentId = HexCodec.lowerHexToUnsignedLong(entry.getValue());
} else if (entry.getKey().equalsIgnoreCase(SPAN_ID_NAME)) {
spanId = HexCodec.lowerHexToUnsignedLong(entry.getValue());
} else if (entry.getKey().equalsIgnoreCase(FLAGS_NAME)) {
if (entry.getValue().equals("1")) {
flags |= DEBUG_FLAG;
}
} else if (entry.getKey().startsWith(baggagePrefix)) {
if (baggage == null) {
baggage = new HashMap<String, String>();
}
baggage.put(keys.unprefixedKey(entry.getKey(), baggagePrefix), entry.getValue());
}
}
if (null != traceIdLow && null != parentId && null != spanId) {
JaegerSpanContext spanContext = objectFactory.createSpanContext(traceIdHigh, traceIdLow, spanId, parentId, flags, Collections.<String, String>emptyMap(), // debugId
null);
if (baggage != null) {
spanContext = spanContext.withBaggage(baggage);
}
return spanContext;
}
return null;
}
use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.
the class JaegerTracerResiliencyTest method shouldFallbackWhenInjectingWithFaultyCodec.
@Test
public void shouldFallbackWhenInjectingWithFaultyCodec() {
JaegerSpanContext context = tracer.buildSpan("test-span").start().context();
tracer.inject(context, Builtin.TEXT_MAP, new NoopTextMap());
}
use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.
the class JaegerTracerResiliencyTest method shouldFallbackWhenExtractingWithFaultyCodec.
@Test
public void shouldFallbackWhenExtractingWithFaultyCodec() {
JaegerSpanContext span = tracer.extract(Builtin.TEXT_MAP, new NoopTextMap());
assertNull(span);
}
use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.
the class BaggageSetterTest method testOverrideBaggage.
@Test
public void testOverrideBaggage() {
when(mgr.getRestriction(SERVICE, KEY)).thenReturn(Restriction.of(true, 5));
final String value = "value";
JaegerSpanContext ctx = setter.setBaggage(jaegerSpan, KEY, value);
JaegerSpan child = tracer.buildSpan("some-operation").asChildOf(ctx).start();
ctx = setter.setBaggage(child, KEY, value);
assertBaggageLogs(child, KEY, value, false, true, false);
assertEquals(value, ctx.getBaggageItem(KEY));
assertEquals(2, metricsFactory.getCounter("jaeger_tracer_baggage_updates", "result=ok"));
}
use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.
the class BaggageSetterTest method testUnsampledSpan.
@Test
public void testUnsampledSpan() {
tracer = new JaegerTracer.Builder(SERVICE).withReporter(reporter).withSampler(new ConstSampler(false)).withMetrics(metrics).build();
jaegerSpan = tracer.buildSpan("some-operation").start();
when(mgr.getRestriction(SERVICE, KEY)).thenReturn(Restriction.of(true, 5));
final String value = "value";
JaegerSpanContext ctx = setter.setBaggage(jaegerSpan, KEY, value);
assertEquals(value, ctx.getBaggageItem(KEY));
// No logs should be written if the span is not sampled
assertNull(jaegerSpan.getLogs());
}
Aggregations