@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof ClientTracer) { ClientTracer that = (ClientTracer) o; return (this.recorder.equals(that.recorder())) && (this.currentLocalSpan.equals(that.currentLocalSpan())) && (this.currentServerSpan.equals(that.currentServerSpan())) && (this.currentSpan.equals(that.currentSpan())) && (this.spanFactory.equals(that.spanFactory())); } return false; }
/** * Start a new span for a new client request that will be bound to current thread. The ClientTracer can decide to return * <code>null</code> in case this request should not be traced (eg sampling). * * @param requestName Request name. Should be lowercase. Null or empty will defer to the server's name of the operation. * @return Span id for new request or <code>null</code> in case we should not trace this new client request. */ public SpanId startNewSpan(@Nullable String requestName) { // 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 newSpan = spanFactory().nextSpan(maybeParent()); SpanId nextContext = Brave.context(newSpan); if (Boolean.FALSE.equals(nextContext.sampled())) { currentSpan().setCurrentSpan(null); return null; } recorder().name(newSpan, requestName); currentSpan().setCurrentSpan(newSpan); return nextContext; }