/** * Encode context into a string. * @param context Span context to encode. * @return Encoded string representing span context. */ public static String contextAsString(JaegerSpanContext context) { int intFlag = context.getFlags() & 0xFF; return new StringBuilder() .append(context.getTraceId()).append(":") .append(Long.toHexString(context.getSpanId())).append(":") .append(Long.toHexString(context.getParentId())).append(":") .append(Integer.toHexString(intFlag)) .toString(); }
private JaegerSpan setTagAsObject(String key, Object value) { if (key.equals(Tags.SAMPLING_PRIORITY.getKey()) && (value instanceof Number)) { int priority = ((Number) value).intValue(); byte newFlags; if (priority > 0) { newFlags = (byte) (context.getFlags() | JaegerSpanContext.flagSampled | JaegerSpanContext.flagDebug); } else { newFlags = (byte) (context.getFlags() & (~JaegerSpanContext.flagSampled)); } context = context.withFlags(newFlags); } if (context.isSampled()) { tags.put(key, value); } return this; }
context == null ? 0L : context.getSpanId(), context == null ? 0L : context.getParentId(), context == null ? (byte)0 : context.getFlags(), baggage, debugId);
public static io.jaegertracing.thriftjava.Span convertSpan(JaegerSpan jaegerSpan) { JaegerSpanContext context = jaegerSpan.context(); boolean oneChildOfParent = jaegerSpan.getReferences().size() == 1 && References.CHILD_OF.equals(jaegerSpan.getReferences().get(0).getType()); List<SpanRef> references = oneChildOfParent ? Collections.<SpanRef>emptyList() : buildReferences(jaegerSpan.getReferences()); return new io.jaegertracing.thriftjava.Span( context.getTraceIdLow(), context.getTraceIdHigh(), context.getSpanId(), oneChildOfParent ? context.getParentId() : 0, jaegerSpan.getOperationName(), context.getFlags(), jaegerSpan.getStart(), jaegerSpan.getDuration() ) .setReferences(references) .setTags(buildTags(jaegerSpan.getTags())) .setLogs(buildLogs(jaegerSpan.getLogs())); }
private JaegerSpanContext createChildContext() { JaegerSpanContext preferredReference = preferredReference(); if (isRpcServer()) { if (isSampled()) { metrics.tracesJoinedSampled.inc(1); } else { metrics.tracesJoinedNotSampled.inc(1); } // Zipkin server compatibility if (zipkinSharedRpcSpan) { return preferredReference; } } return getObjectFactory().createSpanContext( preferredReference.getTraceIdHigh(), preferredReference.getTraceIdLow(), Utils.uniqueId(), preferredReference.getSpanId(), // should we do OR across passed references? preferredReference.getFlags(), getBaggage(), null); }