@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof LocalTracer) { LocalTracer that = (LocalTracer) o; return (this.recorder.equals(that.recorder())) && (this.currentServerSpan.equals(that.currentServerSpan())) && (this.currentSpan.equals(that.currentSpan())) && (this.allowNestedLocalSpans == that.allowNestedLocalSpans()) && (this.spanFactory.equals(that.spanFactory())); } return false; }
/** * 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); }
Span newSpan() { // When a trace context is extracted from an incoming request, it may have only the // sampled header (no ids). If the header says unsampled, we must honor that. Since // we currently don't synthesize a fake span when a trace is unsampled, we have to // check sampled state explicitly. Boolean sample = currentServerSpan().sampled(); if (Boolean.FALSE.equals(sample)) { currentSpan().setCurrentSpan(null); return null; } Span span = spanFactory().nextSpan(maybeParent()); SpanId context = Brave.context(span); if (Boolean.FALSE.equals(context.sampled())) { currentSpan().setCurrentSpan(null); return null; } return span; }
/** * 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); }
SpanId startSpan(String component, String operation, long timestamp, Span span) { recorder().start(span, timestamp); recorder().name(span, operation); recorder().tag(span, "lc", component); currentSpan().setCurrentSpan(span); return Brave.context(span); }
/** * 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); }