/// <summary> /// Cast binary object Value to one of the following types : /// string, bool, short, int, long, byte[], double /// </summary> private void AddBinaryAnnotation(string annotationKey, object annotationValue, string serviceName = null, IPEndPoint endpoint = null) { var annotationType = GetAnnotationType(annotationValue); var bytes = EncodeValue(annotationValue, annotationType); _span.AddBinaryAnnotation(new BinaryAnnotation(annotationKey, bytes, annotationType, _record.Timestamp, serviceName, endpoint)); }
public void MinimumDurationShouldBeAMicrosecond() { var spanState = new SpanState(1, null, 2, isSampled: null, isDebug: false); var span = new Span(spanState, TimeUtils.UtcNow); var annotationTime = span.SpanCreated; span.AddBinaryAnnotation(new BinaryAnnotation(zipkinCoreConstants.LOCAL_COMPONENT, Encoding.UTF8.GetBytes("lc1"), AnnotationType.STRING, annotationTime, SerializerUtils.DefaultServiceName, SerializerUtils.DefaultEndPoint)); span.SetAsComplete(annotationTime.AddTicks(1)); Assert.NotNull(span.Duration); Assert.AreEqual(0.001, span.Duration.Value.TotalMilliseconds); }
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); }