use of com.uber.jaeger.SpanContext 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 com.uber.jaeger.SpanContext in project jaeger-client-java by jaegertracing.
the class JaegerThriftSpanConverter method convertSpan.
public static com.uber.jaeger.thriftjava.Span convertSpan(Span span) {
SpanContext context = span.context();
boolean oneChildOfParent = span.getReferences().size() == 1 && References.CHILD_OF.equals(span.getReferences().get(0).getType());
return new com.uber.jaeger.thriftjava.Span(context.getTraceId(), // TraceIdHigh is currently not supported
0, context.getSpanId(), oneChildOfParent ? context.getParentId() : 0, span.getOperationName(), context.getFlags(), span.getStart(), span.getDuration()).setReferences(oneChildOfParent ? Collections.<SpanRef>emptyList() : buildReferences(span.getReferences())).setTags(buildTags(span.getTags())).setLogs(buildLogs(span.getLogs()));
}
use of com.uber.jaeger.SpanContext in project jaeger-client-java by jaegertracing.
the class ThriftSpanConverter method convertSpan.
public static com.twitter.zipkin.thriftjava.Span convertSpan(Span span) {
Tracer tracer = span.getTracer();
Endpoint host = new Endpoint(tracer.getIpv4(), (short) 0, tracer.getServiceName());
SpanContext context = span.context();
return new com.twitter.zipkin.thriftjava.Span(context.getTraceId(), span.getOperationName(), context.getSpanId(), buildAnnotations(span, host), buildBinaryAnnotations(span, host)).setParent_id(context.getParentId()).setDebug(context.isDebug()).setTimestamp(span.getStart()).setDuration(span.getDuration());
}
use of com.uber.jaeger.SpanContext in project jaeger-client-java by jaegertracing.
the class ZipkinSenderTest method testFlushSendsSpan.
@Test
public void testFlushSendsSpan() throws Exception {
Span expectedSpan = (Span) tracer.buildSpan("raza").startManual();
assertEquals(0, sender.append(expectedSpan));
assertEquals(1, sender.flush());
List<List<zipkin.Span>> traces = zipkinRule.getTraces();
assertEquals(traces.size(), 1);
assertEquals(traces.get(0).size(), 1);
zipkin.Span actualSpan = traces.get(0).get(0);
SpanContext context = expectedSpan.context();
assertEquals(context.getTraceId(), actualSpan.traceId);
assertEquals(context.getSpanId(), actualSpan.id);
assertEquals(context.getParentId(), (long) actualSpan.parentId);
assertEquals(expectedSpan.getOperationName(), actualSpan.name);
for (BinaryAnnotation binaryAnnotation : actualSpan.binaryAnnotations) {
assertEquals(tracer.getServiceName(), binaryAnnotation.endpoint.serviceName);
}
for (Annotation annotation : actualSpan.annotations) {
assertEquals(tracer.getServiceName(), annotation.endpoint.serviceName);
}
}
use of com.uber.jaeger.SpanContext 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";
SpanContext ctx = setter.setBaggage(span, KEY, value);
Span child = (Span) tracer.buildSpan("some-operation").asChildOf(ctx).startManual();
ctx = setter.setBaggage(child, KEY, value);
assertBaggageLogs(child, KEY, value, false, true, false);
assertEquals(value, ctx.getBaggageItem(KEY));
assertEquals(2, metricsFactory.getCounter("jaeger:baggage_updates", "result=ok"));
}
Aggregations