示例#1
0
        internal override ISpanData ToSpanData()
        {
            if (!Options.HasFlag(SpanOptions.RECORD_EVENTS))
            {
                throw new InvalidOperationException("Getting SpanData for a Span without RECORD_EVENTS option.");
            }

            Attributes attributesSpanData = attributes == null?Attributes.Create(new Dictionary <string, IAttributeValue>(), 0)
                                                : Attributes.Create(attributes, attributes.NumberOfDroppedAttributes);

            ITimedEvents <IAnnotation>   annotationsSpanData   = CreateTimedEvents(InitializedAnnotations, timestampConverter);
            ITimedEvents <IMessageEvent> messageEventsSpanData = CreateTimedEvents(InitializedMessageEvents, timestampConverter);
            LinkList linksSpanData = links == null?LinkList.Create(new List <ILink>(), 0) : LinkList.Create(links.Events.ToList(), links.NumberOfDroppedEvents);

            return(SpanData.Create(
                       Context,
                       parentSpanId,
                       hasRemoteParent,
                       name,
                       timestampConverter.ConvertNanoTime(startNanoTime),
                       attributesSpanData,
                       annotationsSpanData,
                       messageEventsSpanData,
                       linksSpanData,
                       null, // Not supported yet.
                       hasBeenEnded ? StatusWithDefault : null,
                       hasBeenEnded ? timestampConverter.ConvertNanoTime(endNanoTime) : null));
        }
示例#2
0
        public void GenerateSpan()
        {
            ZipkinEndpoint localEndpoint = new ZipkinEndpoint()
            {
                ServiceName = "tweetiebird"
            };

            var traceId  = "d239036e7d5cec116b562147388b35bf";
            var spanId   = "9cc1e3049173be09";
            var parentId = "8b03ab423da481c5";

            Dictionary <string, IAttributeValue> attributes    = new Dictionary <string, IAttributeValue>();
            IList <ITimedEvent <IAnnotation> >   annotations   = new List <ITimedEvent <IAnnotation> >();
            List <ITimedEvent <IMessageEvent> >  networkEvents = new List <ITimedEvent <IMessageEvent> >()
            {
                TimedEvent <IMessageEvent> .Create(Timestamp.Create(EPOCH_SECONDS + 1505855799, 433901068), new MessageEventBuilder(MessageEventType.RECEIVED, 0, 0, 0).SetCompressedMessageSize(7).Build()),
                TimedEvent <IMessageEvent> .Create(Timestamp.Create(EPOCH_SECONDS + 1505855799, 459486280), new MessageEventBuilder(MessageEventType.SENT, 0, 0, 0).SetCompressedMessageSize(13).Build())
            };

            ISpanData data = SpanData.Create(
                SpanContext.Create(
                    TraceId.FromBytes(Arrays.StringToByteArray(traceId)),
                    SpanId.FromBytes(Arrays.StringToByteArray(spanId)),
                    TraceOptions.FromBytes(new byte[] { 1 })),
                SpanId.FromBytes(Arrays.StringToByteArray(parentId)),
                true,                               /* hasRemoteParent */
                "Recv.helloworld.Greeter.SayHello", /* name */
                Timestamp.Create(EPOCH_SECONDS + 1505855794, 194009601) /* startTimestamp */,
                Attributes.Create(attributes, 0 /* droppedAttributesCount */),
                TimedEvents <IAnnotation> .Create(annotations, 0 /* droppedEventsCount */),
                TimedEvents <IMessageEvent> .Create(networkEvents, 0 /* droppedEventsCount */),
                LinkList.Create(new List <ILink>(), 0 /* droppedLinksCount */),
                null, /* childSpanCount */
                Status.OK,
                Timestamp.Create(EPOCH_SECONDS + 1505855799, 465726528) /* endTimestamp */);

            var handler = new TraceExporterHandler(new TraceExporterOptions()
            {
                UseShortTraceIds = false
            });
            var result = handler.GenerateSpan(data, localEndpoint);

            var zspan = ZipkinSpan.NewBuilder()
                        .TraceId(traceId)
                        .ParentId(parentId)
                        .Id(spanId)
                        .Kind(ZipkinSpanKind.SERVER)
                        .Name(data.Name)
                        .Timestamp(1505855794000000L + (194009601L / 1000))
                        .Duration(
                (1505855799000000L + (465726528L / 1000))
                - (1505855794000000L + (194009601L / 1000)))
                        .LocalEndpoint(localEndpoint)
                        .AddAnnotation(1505855799000000L + (433901068L / 1000), "RECEIVED")
                        .AddAnnotation(1505855799000000L + (459486280L / 1000), "SENT")
                        .PutTag("census.status_code", "OK")
                        .Build();

            Assert.Equal(zspan, result);
        }
示例#3
0
        public void SpanData_ToString()
        {
            string spanDataString =
                SpanData.Create(
                    spanContext,
                    parentSpanId,
                    false,
                    SPAN_NAME,
                    StartTimestamp,
                    attributes,
                    annotations,
                    messageEvents,
                    links,
                    CHILD_SPAN_COUNT,
                    Status,
                    EndTimestamp)
                .ToString();

            Assert.Contains(spanContext.ToString(), spanDataString);
            Assert.Contains(parentSpanId.ToString(), spanDataString);
            Assert.Contains(SPAN_NAME, spanDataString);
            Assert.Contains(StartTimestamp.ToString(), spanDataString);
            Assert.Contains(attributes.ToString(), spanDataString);
            Assert.Contains(annotations.ToString(), spanDataString);
            Assert.Contains(messageEvents.ToString(), spanDataString);
            Assert.Contains(links.ToString(), spanDataString);
            Assert.Contains(Status.ToString(), spanDataString);
            Assert.Contains(EndTimestamp.ToString(), spanDataString);
        }
示例#4
0
        public void SpanData_AllValues()
        {
            ISpanData spanData =
                SpanData.Create(
                    spanContext,
                    parentSpanId,
                    true,
                    SPAN_NAME,
                    startTimestamp,
                    attributes,
                    events,
                    links,
                    CHILD_SPAN_COUNT,
                    status,
                    kind,
                    endTimestamp);

            Assert.Equal(spanContext, spanData.Context);
            Assert.Equal(parentSpanId, spanData.ParentSpanId);
            Assert.True(spanData.HasRemoteParent);
            Assert.Equal(SPAN_NAME, spanData.Name);
            Assert.Equal(startTimestamp, spanData.StartTimestamp);
            Assert.Equal(attributes, spanData.Attributes);
            Assert.Equal(events, spanData.Events);
            Assert.Equal(links, spanData.Links);
            Assert.Equal(CHILD_SPAN_COUNT, spanData.ChildSpanCount);
            Assert.Equal(status, spanData.Status);
            Assert.Equal(endTimestamp, spanData.EndTimestamp);
        }
示例#5
0
        public void SpanData_ToString()
        {
            string spanDataString =
                SpanData.Create(
                    spanContext,
                    parentSpanId,
                    false,
                    SPAN_NAME,
                    startTimestamp,
                    attributes,
                    events,
                    links,
                    CHILD_SPAN_COUNT,
                    status,
                    kind,
                    endTimestamp)
                .ToString();

            Assert.Contains(spanContext.ToString(), spanDataString);
            Assert.Contains(parentSpanId.ToString(), spanDataString);
            Assert.Contains(SPAN_NAME, spanDataString);
            Assert.Contains(startTimestamp.ToString(), spanDataString);
            Assert.Contains(attributes.ToString(), spanDataString);
            Assert.Contains(events.ToString(), spanDataString);
            Assert.Contains(links.ToString(), spanDataString);
            Assert.Contains(status.ToString(), spanDataString);
            Assert.Contains(endTimestamp.ToString(), spanDataString);
        }
示例#6
0
        public void SpanData_RootActiveSpan()
        {
            var spanData =
                SpanData.Create(
                    spanContext,
                    null,
                    resource,
                    SPAN_NAME,
                    startTimestamp,
                    attributes,
                    events,
                    links,
                    null,
                    null,
                    SPAN_KIND,
                    null);

            Assert.Equal(spanContext, spanData.Context);
            Assert.Null(spanData.ParentSpanId);
            Assert.Equal(resource, spanData.Resource);
            Assert.Equal(SPAN_NAME, spanData.Name);
            Assert.Equal(startTimestamp, spanData.StartTimestamp);
            Assert.Equal(attributes, spanData.Attributes);
            Assert.Equal(events, spanData.Events);
            Assert.Equal(links, spanData.Links);
            Assert.Null(spanData.ChildSpanCount);
            Assert.Null(spanData.Status);
            Assert.Null(spanData.EndTimestamp);
        }
示例#7
0
        public void SpanData_AllDataEmpty()
        {
            ISpanData spanData =
                SpanData.Create(
                    spanContext,
                    parentSpanId,
                    false,
                    SPAN_NAME,
                    startTimestamp,
                    Attributes.Create(new Dictionary <string, IAttributeValue>(), 0),
                    TimedEvents <IEvent> .Create(new List <ITimedEvent <IEvent> >(), 0),
                    LinkList.Create(new List <ILink>(), 0),
                    0,
                    status,
                    kind,
                    endTimestamp);

            Assert.Equal(spanContext, spanData.Context);
            Assert.Equal(parentSpanId, spanData.ParentSpanId);
            Assert.False(spanData.HasRemoteParent);
            Assert.Equal(SPAN_NAME, spanData.Name);
            Assert.Equal(startTimestamp, spanData.StartTimestamp);
            Assert.Empty(spanData.Attributes.AttributeMap);
            Assert.Empty(spanData.Events.Events);
            Assert.Empty(spanData.Links.Links);
            Assert.Equal(0, spanData.ChildSpanCount);
            Assert.Equal(status, spanData.Status);
            Assert.Equal(endTimestamp, spanData.EndTimestamp);
        }
示例#8
0
        // public virtual void AddMessageEvent(MessageEventBase messageEvent)
        // {
        // Default implementation by invoking addNetworkEvent() so that any existing derived classes,
        // including implementation and the mocked ones, do not need to override this method explicitly.
        // addNetworkEvent(BaseMessageEventUtil.asNetworkEvent(messageEvent));
        // }

        public override ISpanData ToSpanData()
        {
            if (!this.Options.HasFlag(SpanOptions.RecordEvents))
            {
                throw new InvalidOperationException("Getting SpanData for a Span without RECORD_EVENTS option.");
            }

            Attributes attributesSpanData = this.attributes == null?Attributes.Create(new Dictionary <string, IAttributeValue>(), 0)
                                                : Attributes.Create(this.attributes, this.attributes.NumberOfDroppedAttributes);

            ITimedEvents <IAnnotation>   annotationsSpanData   = CreateTimedEvents(this.InitializedAnnotations, this.timestampConverter);
            ITimedEvents <IMessageEvent> messageEventsSpanData = CreateTimedEvents(this.InitializedMessageEvents, this.timestampConverter);
            LinkList linksSpanData = this.links == null?LinkList.Create(new List <ILink>(), 0) : LinkList.Create(this.links.Events.ToList(), this.links.NumberOfDroppedEvents);

            return(SpanData.Create(
                       this.Context,
                       this.parentSpanId,
                       this.hasRemoteParent,
                       this.Name,
                       this.timestampConverter.ConvertNanoTime(this.startNanoTime),
                       attributesSpanData,
                       annotationsSpanData,
                       messageEventsSpanData,
                       linksSpanData,
                       null, // Not supported yet.
                       this.hasBeenEnded ? this.StatusWithDefault : null,
                       this.Kind.HasValue ? this.Kind.Value : SpanKind.Client,
                       this.hasBeenEnded ? this.timestampConverter.ConvertNanoTime(this.endNanoTime) : null));
        }
示例#9
0
        public void NoopTracer_RecordData()
        {
            Assert.Throws <ArgumentNullException>(() => NoopTracer.Instance.RecordSpanData(null));

            // does not throw
            NoopTracer.Instance.RecordSpanData(SpanData.Create(SpanContext.Blank, null, Resource.Empty, "foo", Timestamp.Zero, null, null, null, null, Status.Ok, SpanKind.Internal, Timestamp.Zero));
        }
示例#10
0
        public void SpanData_AllValues()
        {
            var spanData =
                SpanData.Create(
                    spanContext,
                    parentSpanId,
                    resource,
                    SPAN_NAME,
                    startTimestamp,
                    attributes,
                    events,
                    links,
                    CHILD_SPAN_COUNT,
                    status,
                    SPAN_KIND,
                    endTimestamp);

            Assert.Equal(spanContext, spanData.Context);
            Assert.Equal(parentSpanId, spanData.ParentSpanId);
            Assert.Equal(resource, spanData.Resource);
            Assert.Equal(SPAN_NAME, spanData.Name);
            Assert.Equal(startTimestamp, spanData.StartTimestamp);
            Assert.Equal(attributes, spanData.Attributes);
            Assert.Equal(events, spanData.Events);
            Assert.Equal(links, spanData.Links);
            Assert.Equal(CHILD_SPAN_COUNT, spanData.ChildSpanCount);
            Assert.Equal(status, spanData.Status);
            Assert.Equal(endTimestamp, spanData.EndTimestamp);
        }
示例#11
0
        public void SpanData_RootActiveSpan()
        {
            ISpanData spanData =
                SpanData.Create(
                    spanContext,
                    null,
                    null,
                    SPAN_NAME,
                    startTimestamp,
                    attributes,
                    events,
                    links,
                    null,
                    null,
                    kind,
                    null);

            Assert.Equal(spanContext, spanData.Context);
            Assert.Null(spanData.ParentSpanId);
            Assert.Null(spanData.HasRemoteParent);
            Assert.Equal(SPAN_NAME, spanData.Name);
            Assert.Equal(startTimestamp, spanData.StartTimestamp);
            Assert.Equal(attributes, spanData.Attributes);
            Assert.Equal(events, spanData.Events);
            Assert.Equal(links, spanData.Links);
            Assert.Null(spanData.ChildSpanCount);
            Assert.Null(spanData.Status);
            Assert.Null(spanData.EndTimestamp);
        }
        public void SpanDataEquals()
        {
            ISpanData allSpanData1 =
                SpanData.Create(
                    spanContext,
                    parentSpanId,
                    false,
                    SPAN_NAME,
                    startTimestamp,
                    attributes,
                    annotations,
                    messageEvents,
                    links,
                    CHILD_SPAN_COUNT,
                    status,
                    kind,
                    endTimestamp);
            ISpanData allSpanData2 =
                SpanData.Create(
                    spanContext,
                    parentSpanId,
                    false,
                    SPAN_NAME,
                    startTimestamp,
                    attributes,
                    annotations,
                    messageEvents,
                    links,
                    CHILD_SPAN_COUNT,
                    status,
                    kind,
                    endTimestamp);
            ISpanData emptySpanData =
                SpanData.Create(
                    spanContext,
                    parentSpanId,
                    false,
                    SPAN_NAME,
                    startTimestamp,
                    Attributes.Create(new Dictionary <string, IAttributeValue>(), 0),
                    TimedEvents <IAnnotation> .Create(new List <ITimedEvent <IAnnotation> >(), 0),
                    TimedEvents <IMessageEvent> .Create(new List <ITimedEvent <IMessageEvent> >(), 0),
                    LinkList.Create(new List <ILink>(), 0),
                    0,
                    status,
                    kind,
                    endTimestamp);

            Assert.Equal(allSpanData1, allSpanData2);
            Assert.NotEqual(emptySpanData, allSpanData1);
            Assert.NotEqual(emptySpanData, allSpanData2);
        }
示例#13
0
        public void SpanDataEquals()
        {
            var allSpanData1 =
                SpanData.Create(
                    spanContext,
                    parentSpanId,
                    resource,
                    SPAN_NAME,
                    startTimestamp,
                    attributes,
                    events,
                    links,
                    CHILD_SPAN_COUNT,
                    status,
                    SPAN_KIND,
                    endTimestamp);
            var allSpanData2 =
                SpanData.Create(
                    spanContext,
                    parentSpanId,
                    resource,
                    SPAN_NAME,
                    startTimestamp,
                    attributes,
                    events,
                    links,
                    CHILD_SPAN_COUNT,
                    status,
                    SPAN_KIND,
                    endTimestamp);
            var emptySpanData =
                SpanData.Create(
                    spanContext,
                    parentSpanId,
                    resource,
                    SPAN_NAME,
                    startTimestamp,
                    Attributes.Create(new Dictionary <string, IAttributeValue>(), 0),
                    TimedEvents <IEvent> .Create(new List <ITimedEvent <IEvent> >(), 0),
                    LinkList.Create(new List <ILink>(), 0),
                    0,
                    status,
                    SPAN_KIND,
                    endTimestamp);

            Assert.Equal(allSpanData1, allSpanData2);
            Assert.NotEqual(emptySpanData, allSpanData1);
            Assert.NotEqual(emptySpanData, allSpanData2);
        }
        internal static ISpanData ProfiledCommandToSpanData(ISpanContext context, string name, ISpanId parentSpanId, IProfiledCommand command)
        {
            var hasRemoteParent = false;

            // use https://github.com/opentracing/specification/blob/master/semantic_conventions.md for now

            // Timing example:
            // command.CommandCreated; //2019-01-10 22:18:28Z

            // command.CreationToEnqueued;      // 00:00:32.4571995
            // command.EnqueuedToSending;       // 00:00:00.0352838
            // command.SentToResponse;          // 00:00:00.0060586
            // command.ResponseToCompletion;    // 00:00:00.0002601

            // Total:
            // command.ElapsedTime;             // 00:00:32.4988020

            // TODO: make timestamp with the better precision
            Timestamp startTimestamp = Timestamp.FromMillis(new DateTimeOffset(command.CommandCreated).ToUnixTimeMilliseconds());

            var timestamp = new DateTimeOffset(command.CommandCreated).Add(command.CreationToEnqueued);
            var events    = TimedEvents <IEvent> .Create(
                new List <ITimedEvent <IEvent> >()
            {
                TimedEvent <IEvent> .Create(Timestamp.FromMillis(timestamp.ToUnixTimeMilliseconds()), Event.Create("Enqueued")),
                TimedEvent <IEvent> .Create(Timestamp.FromMillis((timestamp = timestamp.Add(command.EnqueuedToSending)).ToUnixTimeMilliseconds()), Event.Create("Sent")),
                TimedEvent <IEvent> .Create(Timestamp.FromMillis((timestamp = timestamp.Add(command.SentToResponse)).ToUnixTimeMilliseconds()), Event.Create("ResponseRecieved")),
            },
                droppedEventsCount : 0);

            Timestamp endTimestamp = Timestamp.FromMillis(new DateTimeOffset(command.CommandCreated.Add(command.ElapsedTime)).ToUnixTimeMilliseconds());

            // TODO: deal with the re-transmission
            // command.RetransmissionOf;
            // command.RetransmissionReason;

            var attributesMap = new Dictionary <string, IAttributeValue>()
            {
                // TODO: pre-allocate constant attribute and reuse
                { "db.type", AttributeValue.StringAttributeValue("redis") },

                // Example: "redis.flags": None, DemandMaster
                { "redis.flags", AttributeValue.StringAttributeValue(command.Flags.ToString()) },
            };

            if (command.Command != null)
            {
                // Example: "db.statement": SET;
                attributesMap.Add("db.statement", AttributeValue.StringAttributeValue(command.Command));
            }

            if (command.EndPoint != null)
            {
                // Example: "db.instance": Unspecified/localhost:6379[0]
                attributesMap.Add("db.instance", AttributeValue.StringAttributeValue(command.EndPoint.ToString() + "[" + command.Db + "]"));
            }

            var attributes = Attributes.Create(attributesMap, 0);

            ILinks links          = null;
            int?   childSpanCount = 0;

            // TODO: this is strange that IProfiledCommand doesn't give the result
            Status   status = Status.Ok;
            SpanKind kind   = SpanKind.Client;

            return(SpanData.Create(context, parentSpanId, hasRemoteParent, name, startTimestamp, attributes, events, links, childSpanCount, status, kind, endTimestamp));
        }
示例#15
0
        public void JaegerSpanConverterTest_ConvertSpanToJaegerSpan_NoAttributes()
        {
            var startTimestamp = DateTime.Now;
            var endTimestamp   = startTimestamp.AddSeconds(60);
            var eventTimestamp = DateTime.Now;

            var traceId      = ActivityTraceId.CreateRandom();
            var traceIdAsInt = new Int128(traceId);
            var spanId       = ActivitySpanId.CreateRandom();
            var spanIdAsInt  = new Int128(spanId);
            var parentSpanId = ActivitySpanId.CreateRandom();
            var events       = TimedEvents <IEvent> .Create(new List <ITimedEvent <IEvent> >
            {
                TimedEvent <IEvent> .Create(
                    eventTimestamp,
                    Event.Create(
                        "Event1",
                        new Dictionary <string, object>
                {
                    { "key", "value" },
                }
                        )
                    ),
                TimedEvent <IEvent> .Create(
                    eventTimestamp,
                    Event.Create(
                        "Event2",
                        new Dictionary <string, object>
                {
                    { "key", "value" },
                }
                        )
                    ),
            }, 0);

            var linkedSpanId = ActivitySpanId.CreateRandom();

            var link = Link.FromSpanContext(SpanContext.Create(
                                                traceId,
                                                linkedSpanId,
                                                ActivityTraceFlags.Recorded,
                                                Tracestate.Empty));

            var linkTraceIdAsInt = new Int128(link.Context.TraceId);
            var linkSpanIdAsInt  = new Int128(link.Context.SpanId);

            var links = LinkList.Create(new List <ILink> {
                link
            }, 0);

            var spanData = SpanData.Create(
                SpanContext.Create(
                    traceId,
                    spanId,
                    ActivityTraceFlags.Recorded,
                    Tracestate.Empty
                    ),
                parentSpanId,
                Resource.Empty,
                "Name",
                startTimestamp,
                null,
                events,
                links,
                null,
                Status.Ok,
                SpanKind.Client,
                endTimestamp
                );

            var jaegerSpan = spanData.ToJaegerSpan();

            Assert.Equal("Name", jaegerSpan.OperationName);
            Assert.Equal(2, jaegerSpan.Logs.Count());

            Assert.Equal(traceIdAsInt.High, jaegerSpan.TraceIdHigh);
            Assert.Equal(traceIdAsInt.Low, jaegerSpan.TraceIdLow);
            Assert.Equal(spanIdAsInt.Low, jaegerSpan.SpanId);
            Assert.Equal(new Int128(parentSpanId).Low, jaegerSpan.ParentSpanId);

            Assert.Equal(links.Links.Count(), jaegerSpan.References.Count());
            var references = jaegerSpan.References.ToArray();
            var jaegerRef  = references[0];

            Assert.Equal(linkTraceIdAsInt.High, jaegerRef.TraceIdHigh);
            Assert.Equal(linkTraceIdAsInt.Low, jaegerRef.TraceIdLow);
            Assert.Equal(linkSpanIdAsInt.Low, jaegerRef.SpanId);

            Assert.Equal(0x1, jaegerSpan.Flags);

            Assert.Equal(startTimestamp.ToEpochMicroseconds(), jaegerSpan.StartTime);
            Assert.Equal(endTimestamp.ToEpochMicroseconds() - startTimestamp.ToEpochMicroseconds(), jaegerSpan.Duration);

            Assert.Empty(jaegerSpan.JaegerTags);

            var logs      = jaegerSpan.Logs.ToArray();
            var jaegerLog = logs[0];

            Assert.Equal(events.Events.First().Timestamp.ToEpochMicroseconds(), jaegerLog.Timestamp);
            Assert.Equal(jaegerLog.Fields.Count(), 2);
            var eventFields = jaegerLog.Fields.ToArray();
            var eventField  = eventFields[0];

            Assert.Equal("key", eventField.Key);
            Assert.Equal("value", eventField.VStr);
            eventField = eventFields[1];
            Assert.Equal("description", eventField.Key);
            Assert.Equal("Event1", eventField.VStr);

            jaegerLog = logs[1];
            Assert.Equal(events.Events.First().Timestamp.ToEpochMicroseconds(), jaegerLog.Timestamp);
            Assert.Equal(jaegerLog.Fields.Count(), 2);
            eventFields = jaegerLog.Fields.ToArray();
            eventField  = eventFields[0];
            Assert.Equal("key", eventField.Key);
            Assert.Equal("value", eventField.VStr);
            eventField = eventFields[1];
            Assert.Equal("description", eventField.Key);
            Assert.Equal("Event2", eventField.VStr);
        }
示例#16
0
        public void AllPropertiesShouldTranslate()
        {
            var startTs = DateTime.Now;
            var endTs   = startTs.AddSeconds(60);
            var evtTs   = DateTime.Now;

            var traceId  = ActivityTraceId.CreateRandom();
            var spanId   = ActivitySpanId.CreateRandom();
            var parentId = ActivitySpanId.CreateRandom();

            var traceIdInt  = traceId.ToLSTraceId();
            var spanIdInt   = spanId.ToLSSpanId();
            var parentIdInt = parentId.ToLSSpanId();

            var attrs = Attributes.Create(new Dictionary <string, object>
            {
                { "stringKey", "foo" }, { "longKey", 1L }, { "doubleKey", 1D }, { "boolKey", true },
            }, 0);
            var evts = TimedEvents <IEvent> .Create(new List <ITimedEvent <IEvent> >
            {
                TimedEvent <IEvent> .Create(
                    evtTs,
                    Event.Create(
                        "evt1",
                        new Dictionary <string, object>
                {
                    { "key", "value" },
                }
                        )
                    ),
                TimedEvent <IEvent> .Create(
                    evtTs,
                    Event.Create(
                        "evt2",
                        new Dictionary <string, object>
                {
                    { "key", "value" },
                }
                        )
                    ),
            }, 0);

            var linkedSpanId = ActivitySpanId.CreateRandom();
            var link         = Link.FromSpanContext(SpanContext.Create(
                                                        traceId, linkedSpanId, ActivityTraceFlags.Recorded, Tracestate.Empty));
            var links = LinkList.Create(new List <ILink> {
                link
            }, 0);
            var spanData = SpanData.Create(
                SpanContext.Create(
                    traceId, spanId, ActivityTraceFlags.Recorded, Tracestate.Empty
                    ),
                parentId,
                Resource.Empty,
                "Test",
                startTs,
                attrs,
                evts,
                links,
                null,
                Status.Ok,
                SpanKind.Client,
                endTs
                );

            var lsSpan = spanData.ToLightStepSpan();

            Assert.Equal("Test", lsSpan.OperationName);
            Assert.Equal(2, lsSpan.Logs.Count);
            Assert.Equal(4, lsSpan.Tags.Count);

            Assert.Equal(traceIdInt, lsSpan.SpanContext.TraceId);
            Assert.Equal(spanIdInt, lsSpan.SpanContext.SpanId);
            Assert.Equal(parentIdInt, lsSpan.References[0].SpanContext.SpanId);
        }
        internal static SpanData ProfiledCommandToSpanData(SpanContext context, string name, ActivitySpanId parentSpanId, IProfiledCommand command)
        {
            // use https://github.com/opentracing/specification/blob/master/semantic_conventions.md for now

            // Timing example:
            // command.CommandCreated; //2019-01-10 22:18:28Z

            // command.CreationToEnqueued;      // 00:00:32.4571995
            // command.EnqueuedToSending;       // 00:00:00.0352838
            // command.SentToResponse;          // 00:00:00.0060586
            // command.ResponseToCompletion;    // 00:00:00.0002601

            // Total:
            // command.ElapsedTime;             // 00:00:32.4988020

            // TODO: make timestamp with the better precision
            var startTimestamp = command.CommandCreated;

            var enqueued = command.CommandCreated.Add(command.CreationToEnqueued);
            var send     = enqueued.Add(command.EnqueuedToSending);
            var response = send.Add(command.SentToResponse);
            var events   = TimedEvents <IEvent> .Create(
                new List <ITimedEvent <IEvent> >()
            {
                TimedEvent <IEvent> .Create(enqueued, Event.Create("Enqueued")),
                TimedEvent <IEvent> .Create(send, Event.Create("Sent")),
                TimedEvent <IEvent> .Create(response, Event.Create("ResponseReceived")),
            },
                droppedEventsCount : 0);

            var endTimestamp = command.CommandCreated.Add(command.ElapsedTime);

            // TODO: deal with the re-transmission
            // command.RetransmissionOf;
            // command.RetransmissionReason;

            // TODO: determine what to do with Resource in this context
            var resource = Resource.Empty;

            var attributesMap = new Dictionary <string, object>()
            {
                // TODO: pre-allocate constant attribute and reuse
                { "db.type", "redis" },

                // Example: "redis.flags": None, DemandMaster
                { "redis.flags", command.Flags.ToString() },
            };

            if (command.Command != null)
            {
                // Example: "db.statement": SET;
                attributesMap.Add("db.statement", command.Command);
            }

            if (command.EndPoint != null)
            {
                // Example: "db.instance": Unspecified/localhost:6379[0]
                attributesMap.Add("db.instance", command.EndPoint.ToString() + "[" + command.Db + "]");
            }

            var attributes = Attributes.Create(attributesMap, 0);

            ILinks links          = null;
            int?   childSpanCount = 0;

            // TODO: this is strange that IProfiledCommand doesn't give the result
            var status = Status.Ok;
            var kind   = SpanKind.Client;

            return(SpanData.Create(context, parentSpanId, resource, name, startTimestamp, attributes, events, links, childSpanCount, status, kind, endTimestamp));
        }
示例#18
0
        public void JaegerSpanConverterTest_ConvertSpanToJaegerSpan_NoLinks()
        {
            var startTimestamp = DateTime.Now;
            var endTimestamp   = startTimestamp.AddSeconds(60);
            var eventTimestamp = DateTime.Now;

            var traceId      = ActivityTraceId.CreateRandom();
            var traceIdAsInt = new Int128(traceId);
            var spanId       = ActivitySpanId.CreateRandom();
            var spanIdAsInt  = new Int128(spanId);
            var parentSpanId = ActivitySpanId.CreateRandom();
            var attributes   = Attributes.Create(new Dictionary <string, object> {
                { "stringKey", "value" },
                { "longKey", 1L },
                { "longKey2", 1 },
                { "doubleKey", 1D },
                { "doubleKey2", 1F },
                { "boolKey", true },
            }, 0);
            var events = TimedEvents <IEvent> .Create(new List <ITimedEvent <IEvent> >
            {
                TimedEvent <IEvent> .Create(
                    eventTimestamp,
                    Event.Create(
                        "Event1",
                        new Dictionary <string, object>
                {
                    { "key", "value" },
                }
                        )
                    ),
                TimedEvent <IEvent> .Create(
                    eventTimestamp,
                    Event.Create(
                        "Event2",
                        new Dictionary <string, object>
                {
                    { "key", "value" },
                }
                        )
                    ),
            }, 0);

            var spanData = SpanData.Create(
                SpanContext.Create(
                    traceId,
                    spanId,
                    ActivityTraceFlags.Recorded,
                    Tracestate.Empty
                    ),
                parentSpanId,
                Resource.Empty,
                "Name",
                startTimestamp,
                attributes,
                events,
                null,
                null,
                Status.Ok,
                SpanKind.Client,
                endTimestamp
                );

            var jaegerSpan = spanData.ToJaegerSpan();

            Assert.Equal("Name", jaegerSpan.OperationName);
            Assert.Equal(2, jaegerSpan.Logs.Count());

            Assert.Equal(traceIdAsInt.High, jaegerSpan.TraceIdHigh);
            Assert.Equal(traceIdAsInt.Low, jaegerSpan.TraceIdLow);
            Assert.Equal(spanIdAsInt.Low, jaegerSpan.SpanId);
            Assert.Equal(new Int128(parentSpanId).Low, jaegerSpan.ParentSpanId);

            Assert.Empty(jaegerSpan.References);

            Assert.Equal(0x1, jaegerSpan.Flags);

            Assert.Equal(startTimestamp.ToEpochMicroseconds(), jaegerSpan.StartTime);
            Assert.Equal(endTimestamp.ToEpochMicroseconds() - startTimestamp.ToEpochMicroseconds(), jaegerSpan.Duration);

            var tags = jaegerSpan.JaegerTags.ToArray();
            var tag  = tags[0];

            Assert.Equal(JaegerTagType.STRING, tag.VType);
            Assert.Equal("stringKey", tag.Key);
            Assert.Equal("value", tag.VStr);
            tag = tags[1];
            Assert.Equal(JaegerTagType.LONG, tag.VType);
            Assert.Equal("longKey", tag.Key);
            Assert.Equal(1, tag.VLong);
            tag = tags[2];
            Assert.Equal(JaegerTagType.LONG, tag.VType);
            Assert.Equal("longKey2", tag.Key);
            Assert.Equal(1, tag.VLong);
            tag = tags[3];
            Assert.Equal(JaegerTagType.DOUBLE, tag.VType);
            Assert.Equal("doubleKey", tag.Key);
            Assert.Equal(1, tag.VDouble);
            tag = tags[4];
            Assert.Equal(JaegerTagType.DOUBLE, tag.VType);
            Assert.Equal("doubleKey2", tag.Key);
            Assert.Equal(1, tag.VDouble);
            tag = tags[5];
            Assert.Equal(JaegerTagType.BOOL, tag.VType);
            Assert.Equal("boolKey", tag.Key);
            Assert.Equal(true, tag.VBool);

            var logs      = jaegerSpan.Logs.ToArray();
            var jaegerLog = logs[0];

            Assert.Equal(events.Events.First().Timestamp.ToEpochMicroseconds(), jaegerLog.Timestamp);
            Assert.Equal(2, jaegerLog.Fields.Count());
            var eventFields = jaegerLog.Fields.ToArray();
            var eventField  = eventFields[0];

            Assert.Equal("key", eventField.Key);
            Assert.Equal("value", eventField.VStr);
            eventField = eventFields[1];
            Assert.Equal("description", eventField.Key);
            Assert.Equal("Event1", eventField.VStr);

            jaegerLog = logs[1];
            Assert.Equal(events.Events.First().Timestamp.ToEpochMicroseconds(), jaegerLog.Timestamp);
            Assert.Equal(jaegerLog.Fields.Count(), 2);
            eventFields = jaegerLog.Fields.ToArray();
            eventField  = eventFields[0];
            Assert.Equal("key", eventField.Key);
            Assert.Equal("value", eventField.VStr);
            eventField = eventFields[1];
            Assert.Equal("description", eventField.Key);
            Assert.Equal("Event2", eventField.VStr);
        }
示例#19
0
        public void JaegerSpanConverterTest_ConvertSpanToJaegerSpan_NoEvents()
        {
            var startTimestamp = DateTime.Now;
            var endTimestamp   = startTimestamp.AddSeconds(60);
            var eventTimestamp = DateTime.Now;

            var traceId      = ActivityTraceId.CreateRandom();
            var traceIdAsInt = new Int128(traceId);
            var spanId       = ActivitySpanId.CreateRandom();
            var spanIdAsInt  = new Int128(spanId);
            var parentSpanId = ActivitySpanId.CreateRandom();
            var attributes   = Attributes.Create(new Dictionary <string, object> {
                { "stringKey", "value" },
                { "longKey", 1L },
                { "longKey2", 1 },
                { "doubleKey", 1D },
                { "doubleKey2", 1F },
                { "boolKey", true },
            }, 0);

            var linkedSpanId = ActivitySpanId.CreateRandom();

            var link = Link.FromSpanContext(SpanContext.Create(
                                                traceId,
                                                linkedSpanId,
                                                ActivityTraceFlags.Recorded,
                                                Tracestate.Empty));

            var linkTraceIdAsInt = new Int128(link.Context.TraceId);
            var linkSpanIdAsInt  = new Int128(link.Context.SpanId);

            var links = LinkList.Create(new List <ILink> {
                link
            }, 0);

            var spanData = SpanData.Create(
                SpanContext.Create(
                    traceId,
                    spanId,
                    ActivityTraceFlags.Recorded,
                    Tracestate.Empty
                    ),
                parentSpanId,
                Resource.Empty,
                "Name",
                startTimestamp,
                attributes,
                null,
                links,
                null,
                Status.Ok,
                SpanKind.Client,
                endTimestamp
                );

            var jaegerSpan = spanData.ToJaegerSpan();

            Assert.Equal("Name", jaegerSpan.OperationName);
            Assert.Empty(jaegerSpan.Logs);

            Assert.Equal(traceIdAsInt.High, jaegerSpan.TraceIdHigh);
            Assert.Equal(traceIdAsInt.Low, jaegerSpan.TraceIdLow);
            Assert.Equal(spanIdAsInt.Low, jaegerSpan.SpanId);
            Assert.Equal(new Int128(parentSpanId).Low, jaegerSpan.ParentSpanId);

            Assert.Equal(links.Links.Count(), jaegerSpan.References.Count());
            var references = jaegerSpan.References.ToArray();
            var jaegerRef  = references[0];

            Assert.Equal(linkTraceIdAsInt.High, jaegerRef.TraceIdHigh);
            Assert.Equal(linkTraceIdAsInt.Low, jaegerRef.TraceIdLow);
            Assert.Equal(linkSpanIdAsInt.Low, jaegerRef.SpanId);

            Assert.Equal(0x1, jaegerSpan.Flags);

            Assert.Equal(startTimestamp.ToEpochMicroseconds(), jaegerSpan.StartTime);
            Assert.Equal(endTimestamp.ToEpochMicroseconds() - startTimestamp.ToEpochMicroseconds(), jaegerSpan.Duration);

            var tags = jaegerSpan.JaegerTags.ToArray();
            var tag  = tags[0];

            Assert.Equal(JaegerTagType.STRING, tag.VType);
            Assert.Equal("stringKey", tag.Key);
            Assert.Equal("value", tag.VStr);
            tag = tags[1];
            Assert.Equal(JaegerTagType.LONG, tag.VType);
            Assert.Equal("longKey", tag.Key);
            Assert.Equal(1, tag.VLong);
            tag = tags[2];
            Assert.Equal(JaegerTagType.LONG, tag.VType);
            Assert.Equal("longKey2", tag.Key);
            Assert.Equal(1, tag.VLong);
            tag = tags[3];
            Assert.Equal(JaegerTagType.DOUBLE, tag.VType);
            Assert.Equal("doubleKey", tag.Key);
            Assert.Equal(1, tag.VDouble);
            tag = tags[4];
            Assert.Equal(JaegerTagType.DOUBLE, tag.VType);
            Assert.Equal("doubleKey2", tag.Key);
            Assert.Equal(1, tag.VDouble);
            tag = tags[5];
            Assert.Equal(JaegerTagType.BOOL, tag.VType);
            Assert.Equal("boolKey", tag.Key);
            Assert.Equal(true, tag.VBool);
        }
 public void SpanData_RootActiveSpan()
 {
     var spanData =
         SpanData.Create(
             spanContext,
示例#21
0
        private SpanData CreateTestSpan()
        {
            var startTimestamp = new DateTime(2019, 1, 1);
            var endTimestamp   = startTimestamp.AddSeconds(60);
            var eventTimestamp = new DateTime(2019, 1, 1);

            var traceId      = ActivityTraceId.CreateFromString("e8ea7e9ac72de94e91fabc613f9686b2".AsSpan());
            var traceIdAsInt = new Int128(traceId);
            var spanId       = ActivitySpanId.CreateFromString("6a69db47429ea340".AsSpan());
            var spanIdAsInt  = new Int128(spanId);
            var parentSpanId = ActivitySpanId.CreateFromBytes(new byte [] { 12, 23, 34, 45, 56, 67, 78, 89 });
            var attributes   = Attributes.Create(new Dictionary <string, object> {
                { "stringKey", "value" },
                { "longKey", 1L },
                { "longKey2", 1 },
                { "doubleKey", 1D },
                { "doubleKey2", 1F },
                { "boolKey", true },
            }, 0);
            var events = TimedEvents <IEvent> .Create(new List <ITimedEvent <IEvent> >
            {
                TimedEvent <IEvent> .Create(
                    eventTimestamp,
                    Event.Create(
                        "Event1",
                        new Dictionary <string, object>
                {
                    { "key", "value" },
                }
                        )
                    ),
                TimedEvent <IEvent> .Create(
                    eventTimestamp,
                    Event.Create(
                        "Event2",
                        new Dictionary <string, object>
                {
                    { "key", "value" },
                }
                        )
                    ),
            }, 0);

            var linkedSpanId = ActivitySpanId.CreateFromString("888915b6286b9c41".AsSpan());

            var link = Link.FromSpanContext(SpanContext.Create(
                                                traceId,
                                                linkedSpanId,
                                                ActivityTraceFlags.Recorded,
                                                Tracestate.Empty));

            var linkTraceIdAsInt = new Int128(link.Context.TraceId);
            var linkSpanIdAsInt  = new Int128(link.Context.SpanId);

            var links = LinkList.Create(new List <ILink> {
                link
            }, 0);

            return(SpanData.Create(
                       SpanContext.Create(
                           traceId,
                           spanId,
                           ActivityTraceFlags.Recorded,
                           Tracestate.Empty
                           ),
                       parentSpanId,
                       Resource.Empty,
                       "Name",
                       startTimestamp,
                       attributes,
                       events,
                       links,
                       null,
                       Status.Ok,
                       SpanKind.Client,
                       endTimestamp
                       ));
        }