/// <inheritdoc/>
 public abstract void RecordSpanData(ISpanData span);
Esempio n. 2
0
        public void DroppingAndAddingAttributes()
        {
            int         maxNumberOfAttributes = 8;
            TraceParams traceParams           =
                TraceParams.DEFAULT.ToBuilder().SetMaxNumberOfAttributes(maxNumberOfAttributes).Build();
            ISpan span =
                Span.StartSpan(
                    spanContext,
                    recordSpanOptions,
                    SPAN_NAME,
                    parentSpanId,
                    false,
                    traceParams,
                    startEndHandler,
                    timestampConverter,
                    testClock);

            for (int i = 0; i < 2 * maxNumberOfAttributes; i++)
            {
                IDictionary <string, IAttributeValue> attributes = new Dictionary <string, IAttributeValue>
                {
                    { "MyStringAttributeKey" + i, AttributeValue.LongAttributeValue(i) }
                };
                span.PutAttributes(attributes);
            }

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

            Assert.Equal(maxNumberOfAttributes, spanData.Attributes.DroppedAttributesCount);
            Assert.Equal(maxNumberOfAttributes, spanData.Attributes.AttributeMap.Count);
            for (int i = 0; i < maxNumberOfAttributes; i++)
            {
                Assert.Equal(
                    AttributeValue.LongAttributeValue(i + maxNumberOfAttributes),
                    spanData.Attributes.AttributeMap["MyStringAttributeKey" + (i + maxNumberOfAttributes)]);
            }

            for (int i = 0; i < maxNumberOfAttributes / 2; i++)
            {
                IDictionary <string, IAttributeValue> attributes = new Dictionary <string, IAttributeValue>
                {
                    { "MyStringAttributeKey" + i, AttributeValue.LongAttributeValue(i) }
                };
                span.PutAttributes(attributes);
            }

            spanData = ((Span)span).ToSpanData();
            Assert.Equal(maxNumberOfAttributes * 3 / 2, spanData.Attributes.DroppedAttributesCount);
            Assert.Equal(maxNumberOfAttributes, spanData.Attributes.AttributeMap.Count);

            // Test that we still have in the attributes map the latest maxNumberOfAttributes / 2 entries.
            for (int i = 0; i < maxNumberOfAttributes / 2; i++)
            {
                Assert.Equal(
                    AttributeValue.LongAttributeValue(i + (maxNumberOfAttributes * 3 / 2)),
                    spanData.Attributes.AttributeMap["MyStringAttributeKey" + (i + (maxNumberOfAttributes * 3 / 2))]);
            }

            // Test that we have the newest re-added initial entries.
            for (int i = 0; i < maxNumberOfAttributes / 2; i++)
            {
                Assert.Equal(AttributeValue.LongAttributeValue(i), spanData.Attributes.AttributeMap["MyStringAttributeKey" + i]);
            }
        }
 /// <inheritdoc/>
 public override void RecordSpanData(ISpanData span)
 {
 }
Esempio n. 4
0
        public void GoSpanData_EndedSpan()
        {
            ISpan span =
                Span.StartSpan(
                    spanContext,
                    recordSpanOptions,
                    SPAN_NAME,
                    parentSpanId,
                    false,
                    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);
            ILink link = Link.FromSpanContext(spanContext, LinkType.CHILD_LINKED_SPAN);

            span.AddLink(link);
            testClock.AdvanceTime(Duration.Create(0, 100));
            span.End(EndSpanOptions.Builder().SetStatus(Status.CANCELLED).Build());

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

            Assert.Equal(spanContext, spanData.Context);
            Assert.Equal(SPAN_NAME, spanData.Name);
            Assert.Equal(parentSpanId, spanData.ParentSpanId);
            Assert.False(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.Equal(Status.CANCELLED, spanData.Status);
            Assert.Equal(timestamp.AddNanos(400), spanData.EndTimestamp);

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

            startEndMock.Verify(s => s.OnStart(spanBase), Times.Once);
            startEndMock.Verify(s => s.OnEnd(spanBase), Times.Once);
        }
        /// <inheritdoc/>
        public override Task ExportAsync(ISpanData export, CancellationToken token)
        {
            this.worker.ExportAsync(export, token);

            return(Task.CompletedTask);
        }
Esempio n. 6
0
 public Task ExportAsync(ISpanData export, CancellationToken token)
 {
     return(Task.CompletedTask);
 }
Esempio n. 7
0
 public void RecordSpanData(ISpanData span)
 {
     throw new NotImplementedException();
 }
Esempio n. 8
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.ChildLinkedSpan);

            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.ToList()[0].Timestamp);
            Assert.Equal(Annotation.FromDescription(ANNOTATION_DESCRIPTION), spanData.Annotations.Events.ToList()[0].Event);
            Assert.Equal(timestamp.AddNanos(200), spanData.Annotations.Events.ToList()[1].Timestamp);
            Assert.Equal(Annotation.FromDescriptionAndAttributes(ANNOTATION_DESCRIPTION, attributes), spanData.Annotations.Events.ToList()[1].Event);
            Assert.Equal(0, spanData.MessageEvents.DroppedEventsCount);
            Assert.Single(spanData.MessageEvents.Events);
            Assert.Equal(timestamp.AddNanos(300), spanData.MessageEvents.Events.First().Timestamp);
            Assert.Equal(networkEvent, spanData.MessageEvents.Events.First().Event);
            Assert.Equal(0, spanData.Links.DroppedLinksCount);
            Assert.Single(spanData.Links.Links);
            Assert.Equal(link, spanData.Links.Links.First());
            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);
        }