Ejemplo n.º 1
0
        public void ToSpanData_ActiveSpan()
        {
            ISpan span =
                Span.StartSpan(
                    spanContext,
                    recordSpanOptions,
                    SPAN_NAME,
                    parentSpanId,
                    true,
                    TraceParams.DEFAULT,
                    startEndHandler,
                    timestampConverter,
                    testClock);

            span.PutAttribute(
                "MySingleStringAttributeKey",
                AttributeValue.StringAttributeValue("MySingleStringAttributeValue"));
            span.PutAttributes(attributes);
            testClock.AdvanceTime(Duration.Create(0, 100));
            span.AddAnnotation(Annotation.FromDescription(ANNOTATION_DESCRIPTION));
            testClock.AdvanceTime(Duration.Create(0, 100));
            span.AddAnnotation(ANNOTATION_DESCRIPTION, attributes);
            testClock.AdvanceTime(Duration.Create(0, 100));
            IMessageEvent networkEvent =
                MessageEvent.Builder(MessageEventType.RECEIVED, 1).SetUncompressedMessageSize(3).Build();

            span.AddMessageEvent(networkEvent);
            testClock.AdvanceTime(Duration.Create(0, 100));
            ILink link = Link.FromSpanContext(spanContext, LinkType.CHILD_LINKED_SPAN);

            span.AddLink(link);
            ISpanData spanData = ((Span)span).ToSpanData();

            Assert.Equal(spanContext, spanData.Context);
            Assert.Equal(SPAN_NAME, spanData.Name);
            Assert.Equal(parentSpanId, spanData.ParentSpanId);
            Assert.True(spanData.HasRemoteParent);
            Assert.Equal(0, spanData.Attributes.DroppedAttributesCount);
            Assert.Equal(expectedAttributes, spanData.Attributes.AttributeMap);
            Assert.Equal(0, spanData.Annotations.DroppedEventsCount);
            Assert.Equal(2, spanData.Annotations.Events.Count);
            Assert.Equal(timestamp.AddNanos(100), spanData.Annotations.Events[0].Timestamp);
            Assert.Equal(Annotation.FromDescription(ANNOTATION_DESCRIPTION), spanData.Annotations.Events[0].Event);
            Assert.Equal(timestamp.AddNanos(200), spanData.Annotations.Events[1].Timestamp);
            Assert.Equal(Annotation.FromDescriptionAndAttributes(ANNOTATION_DESCRIPTION, attributes), spanData.Annotations.Events[1].Event);
            Assert.Equal(0, spanData.MessageEvents.DroppedEventsCount);
            Assert.Equal(1, spanData.MessageEvents.Events.Count);
            Assert.Equal(timestamp.AddNanos(300), spanData.MessageEvents.Events[0].Timestamp);
            Assert.Equal(networkEvent, spanData.MessageEvents.Events[0].Event);
            Assert.Equal(0, spanData.Links.DroppedLinksCount);
            Assert.Equal(1, spanData.Links.Links.Count);
            Assert.Equal(link, spanData.Links.Links[0]);
            Assert.Equal(timestamp, spanData.StartTimestamp);
            Assert.Null(spanData.Status);
            Assert.Null(spanData.EndTimestamp);

            var startEndMock = Mock.Get <IStartEndHandler>(startEndHandler);
            var spanBase     = span as SpanBase;

            startEndMock.Verify(s => s.OnStart(spanBase), Times.Once);
        }