You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been playing around with what's needed for local tracing. Most notably, we need more precise timestamps than what System.currentTimeMillis gives. Here's an example
finalclassLocalTracer {
privatefinalClientTracerclientTracer;
privatefinalServerAndClientSpanStatestate;
privatefinalSpanCollectorspanCollector;
LocalTracer(ClientTracerclientTracer, ServerAndClientSpanStatestate, SpanCollectorspanCollector) {
this.clientTracer = clientTracer;
this.state = state;
this.spanCollector = spanCollector;
}
/** * Request a new local span, optionally providing the time it started. * * @param component component responsible for the operation * @param operation name of the operation that's begun * @param timestamp time the operation started, in epoch microseconds, or null if now. * @return metadata about the new span or null if one wasn't started due to sampling policy. * @see Constants#LOCAL_COMPONENT */SpanIdstartSpan(Stringcomponent, Stringoperation, @NullableLongtimestamp) {
SpanIdspanId = clientTracer.startNewSpan(operation);
if (spanId == null) returnnull; // Don't calculate time if we aren't going to trace.com.twitter.zipkin.gen.BinaryAnnotationlc = newcom.twitter.zipkin.gen.BinaryAnnotation();
lc.setKey(Constants.LOCAL_COMPONENT);
lc.setValue(component.getBytes(Util.UTF_8));
lc.setAnnotation_type(AnnotationType.STRING);
lc.setHost(state.getClientEndpoint());
Spanspan = state.getCurrentClientSpan();
synchronized (span) {
span.setTimestamp(timestamp == null ? System.currentTimeMillis() * 1000 : timestamp);
span.addToBinary_annotations(lc);
}
returnspanId;
}
/** Log an annotation with a relative timestamp more precise than system time. */voidsubmitAnnotation(Stringvalue, longtimestamp) {
Spanspan = state.getCurrentClientSpan();
if (span == null) return;
synchronized (span) {
span.addToAnnotations(newAnnotation(timestamp, value).setHost(state.getClientEndpoint()));
}
}
/** Completes the span, which took {@code duration} microseconds. */publicvoidfinishSpan(longduration) {
Spanspan = state.getCurrentClientSpan();
if (span == null) return;
synchronized (span) {
span.setDuration(duration);
spanCollector.collect(span);
}
state.setCurrentClientSpan(null);
state.setCurrentClientServiceName(null);
}
}
The text was updated successfully, but these errors were encountered:
A local span can represent bootstrap, codec, file i/o or other activity
that notably impacts performance.
Local spans always have a binary annotation "lc" which indicates the
component name. Usings zipkin's UI or Api, you can query by for spans
that use a component like this: `lc=spring-boot`
Here's an example of allocating precise duration for a local span:
```java
tracer.startSpan("codec", "encode");
try {
return codec.encode(input);
} finally {
tracer.finishSpan();
}
```
Fixes#111
See openzipkin/zipkin#821
I've been playing around with what's needed for local tracing. Most notably, we need more precise timestamps than what System.currentTimeMillis gives. Here's an example
The text was updated successfully, but these errors were encountered: