/** If any annotation has an IP with skew associated, adjust accordingly. */ private static Span AdjustTimestamps(Span span, ClockSkew clockSkew) { Annotation[] annotations = null; var length = span.annotations.Count; for (int i = 0; i < length; i++) { var a = span.annotations[i]; if (a.endpoint == null) { continue; } if (clockSkew.endpoint.ipv4 == a.endpoint.ipv4) { if (annotations == null) { annotations = span.annotations.ToArray(); } annotations[i] = new Annotation(a.timestamp - clockSkew.skew, a.value, a.endpoint); } } if (annotations == null) { return(span); } // reset timestamp and duration as if there's skew, these will change. long first = annotations[0].timestamp; long last = annotations[length - 1].timestamp; long duration = last - first; return(new Span(span.traceId, span.name, span.id, span.parentId, first, duration, span.annotations, span.binaryAnnotations, span.debug)); }
/** * Recursively adjust the timestamps on the span tree. Root span is the reference point, all * children's timestamps gets adjusted based on that span's timestamps. */ private static void Adjust(SpanNode node, ClockSkew skewFromParent) { // adjust skew for the endpoint brought over from the parent span if (skewFromParent != null) { node.span = AdjustTimestamps(node.span, skewFromParent); } // Is there any skew in the current span? var skew = GetClockSkew(node.span); if (skew != null) { // the current span's skew may be a different endpoint than skewFromParent, adjust again. node.span = AdjustTimestamps(node.span, skew); // propagate skew to any children foreach (SpanNode child in node.children) { Adjust(child, skew); } } }
public TimeSpan GetClickSkew() { return(ClockSkew.ToTimeSpan(TimeSpan.FromSeconds(0))); }