/** * Completes the span, assigning the most precise duration possible. */ public void finishSpan() { Span span = currentSpan().get(); if (span == null) return; recorder().finish(span, recorder().currentTimeMicroseconds(span)); currentSpan().setCurrentSpan(null); }
/** * Request the span that should be considered the new span's parent. * * If {@link #allowNestedLocalSpans()} is enabled, the new span's parent * will be the current local span (if one exists). * * If nested local spans is not enabled or there is no current local span, * the new span's parent will be the current server span (if one exists). * * @return span that should be the new span's parent, or null if one does not exist. */ @Nullable SpanId maybeParent() { Span parentSpan = null; if (allowNestedLocalSpans()) { parentSpan = currentSpan().get(); } if (parentSpan == null) { Span currentServerSpan = currentServerSpan().get(); if (currentServerSpan != null) { parentSpan = currentServerSpan; } } if (parentSpan == null) return null; return Brave.context(parentSpan); }
/** * Completes the span, which took {@code duration} microseconds. */ public void finishSpan(long duration) { Span span = currentSpan().get(); if (span == null) return; final Long timestamp; synchronized (span) { timestamp = span.getTimestamp(); } if (timestamp == null) { recorder().flush(span); } else { recorder().finish(span, timestamp + duration); } currentSpan().setCurrentSpan(null); }