use of io.opentracing.propagation.TextMap 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.opentracing.propagation.TextMap in project brave by openzipkin.
the class BraveTracer method extract.
@Override
public <C> BraveSpanContext extract(Format<C> format, C carrier) {
if (format != Format.Builtin.HTTP_HEADERS) {
throw new UnsupportedOperationException(format.toString());
}
TraceContextOrSamplingFlags extracted = extractor.extract(new TextMapView(propagationKeys, (TextMap) carrier));
TraceContext context = extracted.context() != null ? tracer.joinSpan(extracted.context()).context() : tracer.nextSpan(extracted).context();
return new BraveSpanContext(context);
}
use of io.opentracing.propagation.TextMap in project incubator-skywalking by apache.
the class SkywalkingTracerInjectInterceptor method afterMethod.
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable {
Format format = (Format) allArguments[1];
if (Format.Builtin.TEXT_MAP.equals(format) || Format.Builtin.HTTP_HEADERS.equals(format)) {
TextMap carrier = (TextMap) allArguments[2];
ContextCarrier contextCarrier = new ContextCarrier();
ContextManager.inject(contextCarrier);
CarrierItem next = contextCarrier.items();
while (next.hasNext()) {
next = next.next();
carrier.put(next.getHeadKey(), next.getHeadValue());
}
} else {
// Don't support other format yet.
}
return null;
}
use of io.opentracing.propagation.TextMap in project jaeger-client-java by jaegertracing.
the class ThriftSpanConverterTest method testRpcChildSpanHasTheSameId.
@Test
public void testRpcChildSpanHasTheSameId() {
String expectedOperation = "parent";
Span client = (Span) tracer.buildSpan(expectedOperation).withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).startManual();
Map<String, String> map = new HashMap<>();
TextMap carrier = new TextMapInjectAdapter(map);
tracer.inject(client.context(), Format.Builtin.TEXT_MAP, carrier);
carrier = new TextMapExtractAdapter(map);
SpanContext ctx = (SpanContext) tracer.extract(Format.Builtin.TEXT_MAP, carrier);
assertEquals(client.context().getSpanId(), ctx.getSpanId());
Span server = (Span) tracer.buildSpan("child").withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER).asChildOf(ctx).startManual();
assertEquals("client and server must have the same span ID", client.context().getSpanId(), server.context().getSpanId());
}
use of io.opentracing.propagation.TextMap in project jaeger-client-java by jaegertracing.
the class PropagationTest method testDebugCorrelationId.
@Test
public void testDebugCorrelationId() {
Tracer tracer = new Tracer.Builder("test", new InMemoryReporter(), new ConstSampler(true)).build();
Map<String, String> headers = new HashMap<>();
headers.put(Constants.DEBUG_ID_HEADER_KEY, "Coraline");
TextMap carrier = new TextMapExtractAdapter(headers);
SpanContext spanContext = (SpanContext) tracer.extract(Format.Builtin.TEXT_MAP, carrier);
assertTrue(spanContext.isDebugIdContainerOnly());
assertEquals("Coraline", spanContext.getDebugId());
Span span = (Span) tracer.buildSpan("span").asChildOf(spanContext).start();
spanContext = (SpanContext) span.context();
assertTrue(spanContext.isSampled());
assertTrue(spanContext.isDebug());
assertEquals("Coraline", span.getTags().get(Constants.DEBUG_ID_HEADER_KEY));
}
Aggregations