diff options
Diffstat (limited to 'core')
3 files changed, 16 insertions, 15 deletions
diff --git a/core/src/main/java/com/google/instrumentation/trace/SpanBuilder.java b/core/src/main/java/com/google/instrumentation/trace/SpanBuilder.java index 07fcde75..0c234cea 100644 --- a/core/src/main/java/com/google/instrumentation/trace/SpanBuilder.java +++ b/core/src/main/java/com/google/instrumentation/trace/SpanBuilder.java @@ -29,12 +29,15 @@ import javax.annotation.Nullable; * <pre>{@code * class MyClass { * private static final Tracer tracer = Tracer.getTracer(); - * void doWork(Span parent) { - * // Create a Span as a child of the given parent. - * Span span = tracer.spanBuilder(parent, "MyChildSpan").startSpan(); + * void DoWork() { + * Span span = tracer.spanBuilder(null, "MyRootSpan").startSpan(); * span.addAnnotation("my annotation"); - * doSomeWork(span); // Manually propagate the new span down the stack. - * span.end(); // Manually end the span. + * try { + * doSomeWork(span); // Manually propagate the new span down the stack. + * } finally { + * // To make sure we end the span even in case of an exception. + * span.end(); // Manually end the span. + * } * } * } * }</pre> diff --git a/core/src/main/java/com/google/instrumentation/trace/SpanId.java b/core/src/main/java/com/google/instrumentation/trace/SpanId.java index 9732a4c8..70ed6a14 100644 --- a/core/src/main/java/com/google/instrumentation/trace/SpanId.java +++ b/core/src/main/java/com/google/instrumentation/trace/SpanId.java @@ -23,7 +23,7 @@ import java.util.Random; import javax.annotation.concurrent.Immutable; /** - * A class that represents a span identifier. A valid span identifier is a 8-bytes array with + * A class that represents a span identifier. A valid span identifier is an 8-byte array with * at least one non-zero byte. */ @Immutable @@ -80,7 +80,7 @@ public final class SpanId implements Comparable<SpanId> { /** - * Returns whether the span identifier is valid. A valid span identifier is a 8-bytes array with + * Returns whether the span identifier is valid. A valid span identifier is an 8-byte array with * at least one non-zero byte. * * @return {@code true} if the span identifier is valid. @@ -120,10 +120,9 @@ public final class SpanId implements Comparable<SpanId> { @Override public int compareTo(SpanId that) { for (int i = 0; i < SPAN_ID_SIZE; i++) { - if (bytes[i] == that.bytes[i]) { - continue; + if (bytes[i] != that.bytes[i]) { + return bytes[i] < that.bytes[i] ? -1 : 1; } - return bytes[i] < that.bytes[i] ? -1 : 1; } return 0; } diff --git a/core/src/main/java/com/google/instrumentation/trace/TraceId.java b/core/src/main/java/com/google/instrumentation/trace/TraceId.java index b33a7ace..20d2e108 100644 --- a/core/src/main/java/com/google/instrumentation/trace/TraceId.java +++ b/core/src/main/java/com/google/instrumentation/trace/TraceId.java @@ -23,7 +23,7 @@ import java.util.Random; import javax.annotation.concurrent.Immutable; /** - * A class that represents a trace identifier. A valid trace identifier is a 16-bytes array with + * A class that represents a trace identifier. A valid trace identifier is a 16-byte array with * at least one non-zero byte. */ @Immutable @@ -79,7 +79,7 @@ public final class TraceId implements Comparable<TraceId> { } /** - * Returns whether the {@code TraceId} is valid. A valid trace identifier is a 16-bytes array with + * Returns whether the {@code TraceId} is valid. A valid trace identifier is a 16-byte array with * at least one non-zero byte. * * @return {@code true} if the {@code TraceId} is valid. @@ -119,10 +119,9 @@ public final class TraceId implements Comparable<TraceId> { @Override public int compareTo(TraceId that) { for (int i = 0; i < TRACE_ID_SIZE; i++) { - if (bytes[i] == that.bytes[i]) { - continue; + if (bytes[i] != that.bytes[i]) { + return bytes[i] < that.bytes[i] ? -1 : 1; } - return bytes[i] < that.bytes[i] ? -1 : 1; } return 0; } |
