protected Long nullSafeLong(String lowerHexStr) { if (lowerHexStr == null) return null; return TraceAndSpanIdGenerator.unsignedLowerHexStringToLong(lowerHexStr); }
/** * A convenience static factory method that serves the same purpose as the * {@link TimestampedAnnotation#TimestampedAnnotation(long, String)} constructor. * * @param timestampEpochMicros The timestamp in epoch microseconds (not milliseconds). * @param value The value to associate with the given timestamp. * @return A new {@link TimestampedAnnotation} with the given timestamp and value. */ public static TimestampedAnnotation forEpochMicros(long timestampEpochMicros, String value) { return new TimestampedAnnotation(timestampEpochMicros, value); }
/** * @param primitiveLong The long value that should be converted to an unsigned long encoded in a hexadecimal string. * @return The given long value converted to an unsigned hex encoded string of length 16 (zeroes will be prepended as padding if necessary to * reach a string length of 16). You can convert back to a Java long primitive by passing the result into * {@link #unsignedLowerHexStringToLong(String)}. */ public static String longToUnsignedLowerHexString(long primitiveLong) { return ZipkinHexHelpers.toLowerHex(primitiveLong); }
@Override public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException { capturedSpan = Tracer.getInstance().getCurrentSpan(); captureSpanCopyAtTimeOfDoFilter = Span.newBuilder(capturedSpan).build(); } }
/** * @return A *copy* of the current thread's tracing information - retrieved by calling {@link * Tracer#getCurrentTracingStateCopy()}. Since this creates copies of the span stack and MDC info it can be * have a noticeable performance impact if used too many times (i.e. tens or hundreds of times per request for high * throughput services). NOTE: This is usually not needed unless you're doing asynchronous processing and need to * pass tracing state across thread boundaries. */ public static TracingState getCurrentThreadTracingState() { return Tracer.getInstance().getCurrentTracingStateCopy(); }
/** * @return this span's *current* status relative to {@link Tracer} on the current thread at the time this method is * called. This status is recalculated every time this method is called and is only relevant/correct until {@link * Tracer}'s state is modified (i.e. by starting a subspan, completing a span, using any of the asynchronous helper * methods to modify the span stack in any way, etc), so it should only be considered relevant for the moment the * call is made. * * <p>NOTE: Most app-level developers should not need to worry about this at all. */ public TracerManagedSpanStatus getCurrentTracerManagedSpanStatus() { return Tracer.getInstance().getCurrentManagedStatusForSpan(this); }
@Test public void fromKeyValueString_delegates_to_span_parser() { // given Span span = Span.newBuilder("foo", SpanPurpose.CLIENT) .withTag("blahtag", UUID.randomUUID().toString()) .build(); String keyValueStr = span.toKeyValueString(); // when Span result = span.fromKeyValueString(keyValueStr); // then verifySpanDeepEquals(result, span, true); }
@Test public void fromJSON_delegates_to_span_parser() { // given Span span = Span.newBuilder("foo", SpanPurpose.CLIENT) .withTag("blahtag", UUID.randomUUID().toString()) .build(); String json = span.toJSON(); // when Span result = span.fromJSON(json); // then verifySpanDeepEquals(result, span, true); }
private Span createFilledOutSpan(boolean completed) { Long durationNanos = (completed) ? durationNanosForFullyCompletedSpan : null; return new Span(traceId, parentSpanId, spanId, spanName, sampleableForFullyCompleteSpan, userId, spanPurposeForFullyCompletedSpan, startTimeEpochMicrosForFullyCompleteSpan, startTimeNanosForFullyCompleteSpan, durationNanos, tags, annotations ); }
/** * @return The JSON representation of this span. See {@link #toJSON()}. */ @Override public String toString() { return toJSON(); }
/** * Calls {@link Span#complete()} on the given span. */ public static void completeSpan(Span span) { span.complete(); } }
/** * @param hexString The lowercase hexadecimal string representing an unsigned 64-bit long that you want to convert to a Java long primitive. * @return The Java long primitive represented by the given lowercase hex string. If the string isn't lowercase hexadecimal encoded then a * {@link NumberFormatException} will be thrown. If the string is larger than 64-bits, any higher bits will be ignored. */ public static long unsignedLowerHexStringToLong(String hexString) { return ZipkinHexHelpers.lowerHexToUnsignedLong(hexString); }
/** * @param spanName The {@link Span#getSpanName()} to initialize the builder with. * @param spanPurpose The {@link SpanPurpose} to initialize the builder with. See the javadocs for {@link SpanPurpose} for full details on what each enum * option means. If you pass in null for this then {@link SpanPurpose#UNKNOWN} will be used. * @return A new span builder with nothing populated beyond the given span name. Based on the behavior of {@link Builder#build()}, if you were to build it * immediately you'd end up with an uncompleted root span for a new trace (same behavior as {@link #generateRootSpanForNewTrace(String, SpanPurpose)}. * You are free to adjust any values before building however, so you can setup the builder to represent any span you want. */ public static Builder newBuilder(String spanName, SpanPurpose spanPurpose) { return new Builder(spanName, spanPurpose); }
/** Inspired by {@code okio.Buffer.writeLong} */ static void writeHexLong(char[] data, int pos, long v) { writeHexByte(data, pos + 0, (byte) ((v >>> 56L) & 0xff)); writeHexByte(data, pos + 2, (byte) ((v >>> 48L) & 0xff)); writeHexByte(data, pos + 4, (byte) ((v >>> 40L) & 0xff)); writeHexByte(data, pos + 6, (byte) ((v >>> 32L) & 0xff)); writeHexByte(data, pos + 8, (byte) ((v >>> 24L) & 0xff)); writeHexByte(data, pos + 10, (byte) ((v >>> 16L) & 0xff)); writeHexByte(data, pos + 12, (byte) ((v >>> 8L) & 0xff)); writeHexByte(data, pos + 14, (byte) (v & 0xff)); }
protected Long nullSafeLong(String lowerHexStr, int index) { if (lowerHexStr == null) return null; return TraceAndSpanIdGenerator.unsignedLowerHexStringToLong(lowerHexStr, index); } }
private Span createFilledOutSpan( boolean completed, Map<String, String> tags, List<TimestampedAnnotation> annotations ) { Long durationNanos = (completed) ? durationNanosForFullyCompletedSpan : null; return new Span( traceId, parentSpanId, spanId, spanName, sampleableForFullyCompleteSpan, userId, spanPurposeForFullyCompletedSpan, startTimeEpochMicrosForFullyCompleteSpan, startTimeNanosForFullyCompleteSpan, durationNanos, tags, annotations ); }
/** * @param hexString The lowercase hexadecimal string representing an unsigned 64-bit long that you want to convert to a Java long primitive. * @param index index to read 16 hexadecimal characters from * @return The Java long primitive represented by the given lowercase hex string. If the string isn't lowercase hexadecimal encoded then a * {@link NumberFormatException} will be thrown. */ public static long unsignedLowerHexStringToLong(String hexString, int index) { return ZipkinHexHelpers.lowerHexToUnsignedLong(hexString, index); }
protected Long nullSafeLong(String lowerHexStr) { if (lowerHexStr == null) return null; return TraceAndSpanIdGenerator.unsignedLowerHexStringToLong(lowerHexStr); }
@Override public void call() throws Throwable { TraceAndSpanIdGenerator.unsignedLowerHexStringToLong(badHexString, 0); } });
@Override public void call() throws Throwable { TraceAndSpanIdGenerator.unsignedLowerHexStringToLong(badHexString); } });