Created
September 21, 2016 01:21
-
-
Save codefromthecrypt/a7e772c6eaecc9e3c5a316429f319986 to your computer and use it in GitHub Desktop.
guess timestamp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Instrumentation should set {@link Span#timestamp} when recording a span so that guess-work | |
* isn't needed. Since a lot of instrumentation don't, we have to make some guesses. | |
* | |
* <pre><ul> | |
* <li>If there is a {@link Constants#CLIENT_SEND}, use that</li> | |
* <li>Fall back to {@link Constants#SERVER_RECV}, if a root span</li> | |
* <li>Otherwise, return null</li> | |
* </ul></pre> | |
*/ | |
public static Long guessTimestamp(Span span) { | |
if (span.timestamp != null || span.annotations.isEmpty()) return span.timestamp; | |
boolean isRoot = span.parentId == null; | |
Long rootServerRecv = null; | |
for (int i = 0, length = span.annotations.size(); i < length; i++) { | |
Annotation annotation = span.annotations.get(i); | |
if (annotation.value.equals(Constants.CLIENT_SEND)) { | |
return annotation.timestamp; | |
} else if (annotation.value.equals(Constants.SERVER_RECV) && isRoot) { | |
rootServerRecv = annotation.timestamp; | |
} | |
} | |
return rootServerRecv; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment