/// <inheritdoc/>
        public void AddEvent(string name, IDictionary <string, object> eventAttributes)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (eventAttributes == null)
            {
                throw new ArgumentNullException(nameof(eventAttributes));
            }

            if (!this.IsRecordingEvents)
            {
                return;
            }

            lock (this.@lock)
            {
                if (this.HasEnded)
                {
                    // logger.log(Level.FINE, "Calling AddEvent() on an ended Span.");
                    return;
                }

                this.InitializedEvents.AddEvent(TimedEvent <IEvent> .Create(PreciseTimestamp.GetUtcNow(), Event.Create(name, eventAttributes)));
            }
        }
Exemple #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);
        }
Exemple #3
0
        public SpanDataTest()
        {
            spanContext  = SpanContext.Create(TraceId.GenerateRandomId(random), SpanId.GenerateRandomId(random), TraceOptions.Default, Tracestate.Empty);
            parentSpanId = SpanId.GenerateRandomId(random);

            attributesMap.Add("MyAttributeKey1", AttributeValue.LongAttributeValue(10));
            attributesMap.Add("MyAttributeKey2", AttributeValue.BooleanAttributeValue(true));
            attributes = Attributes.Create(attributesMap, 1);

            eventList.Add(TimedEvent <IEvent> .Create(eventTimestamp1, spanEvent));
            eventList.Add(TimedEvent <IEvent> .Create(eventTimestamp3, spanEvent));
            events = TimedEvents <IEvent> .Create(eventList, 2);

            linksList.Add(Link.FromSpanContext(spanContext, LinkType.ChildLinkedSpan));
            links = LinkList.Create(linksList, 0);
        }
        public SpanDataTest()
        {
            spanContext  = SpanContext.Create(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.None, Tracestate.Empty);
            parentSpanId = ActivitySpanId.CreateRandom();

            attributesMap.Add("MyAttributeKey1", 10L);
            attributesMap.Add("MyAttributeKey2", true);
            attributes = Attributes.Create(new ReadOnlyDictionary <string, object>(attributesMap), 1);

            eventList.Add(TimedEvent <IEvent> .Create(eventTimestamp1, spanEvent));
            eventList.Add(TimedEvent <IEvent> .Create(eventTimestamp3, spanEvent));
            events = TimedEvents <IEvent> .Create(eventList, 2);

            linksList.Add(Link.FromSpanContext(spanContext));
            links = LinkList.Create(linksList, 0);
        }
        /// <inheritdoc/>
        public void AddEvent(IEvent addEvent)
        {
            if (addEvent == null)
            {
                throw new ArgumentNullException(nameof(addEvent));
            }

            if (!this.IsRecordingEvents)
            {
                return;
            }

            lock (this.@lock)
            {
                if (this.HasEnded)
                {
                    // logger.log(Level.FINE, "Calling AddEvent() on an ended Span.");
                    return;
                }

                this.InitializedEvents.AddEvent(TimedEvent <IEvent> .Create(PreciseTimestamp.GetUtcNow(), addEvent));
            }
        }
Exemple #6
0
        public SpanDataTest()
        {
            spanContext  = SpanContext.Create(TraceId.GenerateRandomId(random), SpanId.GenerateRandomId(random), TraceOptions.DEFAULT);
            parentSpanId = SpanId.GenerateRandomId(random);

            attributesMap.Add("MyAttributeKey1", AttributeValue.LongAttributeValue(10));
            attributesMap.Add("MyAttributeKey2", AttributeValue.BooleanAttributeValue(true));
            attributes = Attributes.Create(attributesMap, 1);

            annotationsList.Add(TimedEvent <IAnnotation> .Create(eventTimestamp1, annotation));
            annotationsList.Add(TimedEvent <IAnnotation> .Create(eventTimestamp3, annotation));
            annotations = TimedEvents <IAnnotation> .Create(annotationsList, 2);

            //networkEventsList.add(SpanData.TimedEvent.Create(eventTimestamp1, recvNetworkEvent));
            //networkEventsList.add(SpanData.TimedEvent.Create(eventTimestamp2, sentNetworkEvent));
            //networkEvents = TimedEvents.Create(networkEventsList, 3);

            messageEventsList.Add(TimedEvent <IMessageEvent> .Create(eventTimestamp1, recvMessageEvent));
            messageEventsList.Add(TimedEvent <IMessageEvent> .Create(eventTimestamp2, sentMessageEvent));
            messageEvents = TimedEvents <IMessageEvent> .Create(messageEventsList, 3);

            linksList.Add(Link.FromSpanContext(spanContext, LinkType.CHILD_LINKED_SPAN));
            links = LinkList.Create(linksList, 0);
        }
        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));
        }
 internal ITimedEvent <T> ToSpanDataTimedEvent(ITimestampConverter timestampConverter)
 {
     return(TimedEvent <T> .Create(timestampConverter.ConvertNanoTime(this.nanoTime), this.@event));
 }
 internal ITimedEvent <T> ToSpanDataTimedEvent(Timer timestampConverter)
 {
     return(TimedEvent <T> .Create(Timestamp.FromDateTimeOffset(this.nanoTime), this.@event));
 }
Exemple #10
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));
        }
Exemple #12
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);
        }
Exemple #13
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);
        }
Exemple #14
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
                       ));
        }