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 static ISpanData Create( ISpanContext context, ISpanId parentSpanId, bool?hasRemoteParent, string name, Timestamp startTimestamp, IAttributes attributes, ITimedEvents <IAnnotation> annotations, ITimedEvents <IMessageEvent> messageOrNetworkEvents, ILinks links, int?childSpanCount, Status status, SpanKind kind, Timestamp endTimestamp) { if (messageOrNetworkEvents == null) { messageOrNetworkEvents = TimedEvents <IMessageEvent> .Create(new List <ITimedEvent <IMessageEvent> >(), 0); } var messageEventsList = new List <ITimedEvent <IMessageEvent> >(); foreach (ITimedEvent <IMessageEvent> timedEvent in messageOrNetworkEvents.Events) { messageEventsList.Add(timedEvent); } ITimedEvents <IMessageEvent> messageEvents = TimedEvents <IMessageEvent> .Create(messageEventsList, messageOrNetworkEvents.DroppedEventsCount); return(new SpanData( context, parentSpanId, hasRemoteParent, name, startTimestamp, attributes, annotations, messageEvents, links, childSpanCount, status, kind, endTimestamp)); }
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 annotations = TimedEvents <IAnnotation> .Create( new List <ITimedEvent <IAnnotation> >() { TimedEvent <IAnnotation> .Create(Timestamp.FromMillis(timestamp.ToUnixTimeMilliseconds()), Annotation.FromDescription("Enqueued")), TimedEvent <IAnnotation> .Create(Timestamp.FromMillis((timestamp = timestamp.Add(command.EnqueuedToSending)).ToUnixTimeMilliseconds()), Annotation.FromDescription("Sent")), TimedEvent <IAnnotation> .Create(Timestamp.FromMillis((timestamp = timestamp.Add(command.SentToResponse)).ToUnixTimeMilliseconds()), Annotation.FromDescription("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); ITimedEvents <IMessageEvent> messageOrNetworkEvents = null; 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, annotations, messageOrNetworkEvents, links, childSpanCount, status, kind, endTimestamp)); }
internal SpanData( ISpanContext context, ISpanId parentSpanId, bool?hasRemoteParent, string name, ITimestamp startTimestamp, IAttributes attributes, ITimedEvents <IAnnotation> annotations, ITimedEvents <IMessageEvent> messageEvents, ILinks links, int?childSpanCount, Status status, ITimestamp endTimestamp) { if (context == null) { throw new ArgumentNullException(nameof(context)); } this.Context = context; this.ParentSpanId = parentSpanId; this.HasRemoteParent = hasRemoteParent; if (name == null) { throw new ArgumentNullException(nameof(name)); } this.Name = name; if (startTimestamp == null) { throw new ArgumentNullException(nameof(startTimestamp)); } this.StartTimestamp = startTimestamp; if (attributes == null) { throw new ArgumentNullException(nameof(attributes)); } this.Attributes = attributes; if (annotations == null) { throw new ArgumentNullException(nameof(annotations)); } this.Annotations = annotations; if (messageEvents == null) { throw new ArgumentNullException(nameof(messageEvents)); } this.MessageEvents = messageEvents; if (links == null) { throw new ArgumentNullException(nameof(links)); } this.Links = links; this.ChildSpanCount = childSpanCount; this.Status = status; this.EndTimestamp = endTimestamp; }
private static Span.Types.TimeEvents FromITimeEvents(ITimedEvents <IMessageEvent> messages, ITimedEvents <IAnnotation> annotations) { var timedEvents = new Span.Types.TimeEvents { DroppedMessageEventsCount = messages.DroppedEventsCount, DroppedAnnotationsCount = annotations.DroppedEventsCount, TimeEvent = { messages.Events.Select(FromITimeEvent), }, }; timedEvents.TimeEvent.AddRange(annotations.Events.Select(FromITimeEvent)); return(timedEvents); }