Пример #1
0
        private static void AddClientSendReceiveAnnotations(Span span, DateTime startTime, TimeSpan timeOffset)
        {
            var endtime = startTime + timeOffset;

            span.AddAnnotation(new ZipkinAnnotation(startTime, zipkinCoreConstants.CLIENT_SEND));
            span.AddAnnotation(new ZipkinAnnotation(endtime, zipkinCoreConstants.CLIENT_RECV));
            span.SetAsComplete(endtime);
        }
Пример #2
0
        private static TimeSpan?GetSpanDuration(TimeSpan offset, params string[] annotations)
        {
            var spanState      = new SpanState(1, null, 2, isSampled: null, isDebug: false);
            var span           = new Span(spanState, TimeUtils.UtcNow);
            var annotationTime = span.SpanCreated;

            Array.ForEach(annotations, a =>
                          span.AddAnnotation(new ZipkinAnnotation(annotationTime, a)));

            span.SetAsComplete(annotationTime.Add(offset));

            return(span.Duration);
        }
Пример #3
0
        public void SpanCorrectlyConvertedToThrift(long?parentSpanId)
        {
            var          hostIp      = IPAddress.Loopback;
            const int    hostPort    = 1234;
            const string serviceName = "myCriteoService";
            const string methodName  = "GET";

            var spanState = new SpanState(2, 1, parentSpanId, 2, SpanFlags.None);
            var timestamp = TimeUtils.UtcNow;
            var span      = new Span(spanState, timestamp)
            {
                Endpoint = new IPEndPoint(hostIp, hostPort), ServiceName = serviceName, Name = methodName
            };

            var zipkinAnnDateTime = TimeUtils.UtcNow;
            var timeOffset        = TimeSpan.FromMilliseconds(500);

            AddClientSendReceiveAnnotations(span, zipkinAnnDateTime, timeOffset);
            span.AddAnnotation(new ZipkinAnnotation(zipkinAnnDateTime, SomeRandomAnnotation));

            const string         binAnnKey  = "http.uri";
            var                  binAnnVal  = new byte[] { 0x00 };
            const AnnotationType binAnnType = AnnotationType.STRING;

            span.AddBinaryAnnotation(new BinaryAnnotation(binAnnKey, binAnnVal, binAnnType, TimeUtils.UtcNow, null, null));

            var thriftSpan = ThriftSpanSerializer.ConvertToThrift(span);

            var expectedHost = new Endpoint()
            {
                Ipv4         = SerializerUtils.IpToInt(hostIp),
                Port         = hostPort,
                Service_name = serviceName
            };

            Assert.AreEqual(spanState.TraceIdHigh, thriftSpan.Trace_id_high);
            Assert.AreEqual(spanState.TraceId, thriftSpan.Trace_id);
            Assert.AreEqual(spanState.SpanId, thriftSpan.Id);
            Assert.True(thriftSpan.Timestamp.HasValue);

            if (span.IsRoot)
            {
                Assert.IsNull(thriftSpan.Parent_id); // root span has no parent
            }
            else
            {
                Assert.AreEqual(parentSpanId, thriftSpan.Parent_id);
            }

            Assert.AreEqual(false, thriftSpan.Debug);
            Assert.AreEqual(methodName, thriftSpan.Name);

            Assert.AreEqual(3, thriftSpan.Annotations.Count);

            thriftSpan.Annotations.ForEach(ann =>
            {
                Assert.AreEqual(expectedHost, ann.Host);
            });

            Assert.AreEqual(thriftSpan.Annotations.FirstOrDefault(a => a.Value.Equals(zipkinCoreConstants.CLIENT_SEND)).Timestamp, zipkinAnnDateTime.ToUnixTimestamp());
            Assert.AreEqual(thriftSpan.Annotations.FirstOrDefault(a => a.Value.Equals(zipkinCoreConstants.CLIENT_RECV)).Timestamp, (zipkinAnnDateTime + timeOffset).ToUnixTimestamp());
            Assert.AreEqual(thriftSpan.Annotations.FirstOrDefault(a => a.Value.Equals(SomeRandomAnnotation)).Timestamp, zipkinAnnDateTime.ToUnixTimestamp());

            Assert.AreEqual(1, thriftSpan.Binary_annotations.Count);

            thriftSpan.Binary_annotations.ForEach(ann =>
            {
                Assert.AreEqual(expectedHost, ann.Host);
                Assert.AreEqual(binAnnKey, ann.Key);
                Assert.AreEqual(binAnnVal, ann.Value);
                Assert.AreEqual(binAnnType, ann.Annotation_type);
            });

            Assert.AreEqual(thriftSpan.Duration, timeOffset.TotalMilliseconds * 1000);
        }
Пример #4
0
 private void AddTimestampedAnnotation(string value)
 {
     _span.AddAnnotation(new ZipkinAnnotation(_record.Timestamp, value));
 }