/** Internal api for submitting an address. */ void submitAddress(String key, Endpoint endpoint) { Span span = currentSpan().get(); if (span == null) return; recorder().address(span, key, endpoint); }
/** * This adds an annotation that corresponds with {@link Span#getDuration()}, and sends the span * for collection. * * @return true if a span was sent for collection. */ boolean submitEndAnnotation(String finishAnnotation) { Span span = currentSpan().get(); if (span == null) return false; long timestamp = recorder().currentTimeMicroseconds(span); recorder().annotate(span, timestamp, finishAnnotation); recorder().finish(span, timestamp); return true; }
/** This adds an annotation that corresponds with {@link Span#getTimestamp()} */ void submitStartAnnotation(String startAnnotation) { Span span = currentSpan().get(); if (span == null) return; long timestamp = recorder().currentTimeMicroseconds(span); recorder().annotate(span, timestamp, startAnnotation); recorder().start(span, timestamp); }
/** * Associates an event that explains latency with the current system time. * * @param value A short tag indicating the event, like "finagle.retry" */ public void submitAnnotation(String value) { Span span = currentSpan().get(); if (span == null) return; recorder().annotate(span, recorder().currentTimeMicroseconds(span), value); }
/** * 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); }
/** * 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); }
void setStateCurrentTrace(Span span, String spanName) { checkNotBlank(spanName, "Null or blank span name"); recorder().name(span, spanName); currentSpan().setCurrentSpan(ServerSpan.create(span)); } /**
/** * Request a new local span, which starts now. * * @param component in-process component responsible for the operation * @param operation name of the operation that's begun * @return metadata about the new span or null if one wasn't started due to sampling policy. */ public SpanId startNewSpan(String component, String operation) { Span span = newSpan(); if (span == null) return null; return startSpan(component, operation, recorder().currentTimeMicroseconds(span), span); }
/** * Binary annotations are tags applied to a Span to give it context. For * example, a key "your_app.version" would let you lookup spans by version. * * @param key Name used to lookup spans, such as "your_app.version" * @param value String value, should not be <code>null</code>. */ public void submitBinaryAnnotation(String key, String value) { Span span = currentSpan().get(); if (span == null) return; recorder().tag(span, key, value); }
/** * Associates an event that explains latency with a timestamp. * * <p/> This is an alternative to {@link #submitAnnotation(String)}, when * you have a timestamp more precise or accurate than {@link System#currentTimeMillis()}. * * @param value A short tag indicating the event, like "finagle.retry" * @param timestamp microseconds from epoch */ public void submitAnnotation(String value, long timestamp) { Span span = currentSpan().get(); if (span == null) return; recorder().annotate(span, timestamp, value); }
/** * 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; }
@Override public void setClientAddress(Brave brave, Endpoint ca) { Span span = brave.serverSpanThreadBinder().get(); if (span == null) return; brave.serverTracer.recorder().address(span, "ca", ca); } };