B3TextMapCodec implements Codec<TextMap> { @Override public JaegerSpanContext extract(TextMap carrier) { Long traceIdLow = null; Long traceIdHigh = 0L; Long spanId = null; 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(), null ); if (baggage != null) { spanContext = spanContext.withBaggage(baggage); } return spanContext; } return null; } @Deprecated  B3TextMapCodec(); private  B3TextMapCodec(Builder builder); @Override void inject(JaegerSpanContext spanContext, TextMap carrier); @Override JaegerSpanContext extract(TextMap carrier);  }
@Test public void support128BitTraceIdExtraction() { String hex128Bits = "463ac35c9f6413ad48485a3953bb6124"; String lower64Bits = "48485a3953bb6124"; DelegatingTextMap textMap = new DelegatingTextMap(); textMap.put(B3TextMapCodec.TRACE_ID_NAME, hex128Bits); textMap.put(B3TextMapCodec.SPAN_ID_NAME, lower64Bits); textMap.put(B3TextMapCodec.PARENT_SPAN_ID_NAME, "0"); textMap.put(B3TextMapCodec.SAMPLED_NAME, "1"); textMap.put(B3TextMapCodec.FLAGS_NAME, "1"); textMap.put(B3TextMapCodec.BAGGAGE_PREFIX + "foo", "bar"); textMap.put("random-foo", "bar"); JaegerSpanContext context = b3Codec.extract(textMap); assertNotNull(HexCodec.lowerHexToUnsignedLong(lower64Bits)); assertEquals(HexCodec.lowerHexToUnsignedLong(hex128Bits).longValue(), context.getTraceIdLow()); assertEquals(HexCodec.higherHexToUnsignedLong(hex128Bits).longValue(), context.getTraceIdHigh()); assertEquals(HexCodec.lowerHexToUnsignedLong(lower64Bits).longValue(), context.getSpanId()); assertEquals(0, context.getParentId()); assertEquals(B3TextMapCodec.SAMPLED_FLAG | B3TextMapCodec.DEBUG_FLAG, context.getFlags()); assertEquals(1, ((Set<Entry<String, String>>)context.baggageItems()).size()); assertEquals("bar", context.getBaggageItem("foo")); }