private static OtlpTrace.Span.Types.Link ToOtlpLink(ActivityLink activityLink)
        {
            // protobuf doesn't understand Span<T> yet: https://github.com/protocolbuffers/protobuf/issues/3431
            Span <byte> traceIdBytes = stackalloc byte[16];
            Span <byte> spanIdBytes  = stackalloc byte[8];

            activityLink.Context.TraceId.CopyTo(traceIdBytes);
            activityLink.Context.SpanId.CopyTo(spanIdBytes);

            var otlpLink = new OtlpTrace.Span.Types.Link
            {
                TraceId = ByteString.CopyFrom(traceIdBytes.ToArray()),
                SpanId  = ByteString.CopyFrom(spanIdBytes.ToArray()),
            };

            if (activityLink.Tags != null)
            {
                foreach (var attribute in from tag in activityLink.Tags
                         let attribute = ToOtlpAttributes(tag)
                                         where attribute != null && attribute.Any()
                                         select attribute)
                {
                    otlpLink.Attributes.AddRange(attribute);
                }
            }

            return(otlpLink);
        }
Ejemplo n.º 2
0
        private void SetLinkRoutePoints(DiagramPageViewModel vw)
        {
            if (vw == null)
            {
                return;
            }

            TabItem tabItem = (TabItem)this.tabControl.Items.Single(p => ((TabItem)p).DataContext == vw);

            if (tabItem == null)
            {
                return;
            }

            var links = ((DiagramPage)tabItem.Content).mainDiagram.Links;

            foreach (Link link in links)
            {
                ActivityLink linkData = link.Data as ActivityLink;
                if (linkData != null)
                {
                    linkData.Points = new List <Point>(link.Route.Points);
                }
            }
        }
Ejemplo n.º 3
0
        public ProbabilityActivitySamplerTest()
        {
            this.traceId = ActivityTraceId.CreateRandom();
            var parentSpanId = ActivitySpanId.CreateRandom();

            this.sampledActivityContext    = new ActivityContext(this.traceId, parentSpanId, ActivityTraceFlags.Recorded);
            this.notSampledActivityContext = new ActivityContext(this.traceId, parentSpanId, ActivityTraceFlags.None);
            this.sampledLink = new ActivityLink(this.sampledActivityContext);
        }
Ejemplo n.º 4
0
        public void LinksAreTruncatedWhenCannotFitInMaxLength(string telemetryType)
        {
            using ActivitySource activitySource = new ActivitySource(ActivitySourceName);
            List <ActivityLink> links = new List <ActivityLink>();

            // Arbitrary number > 100
            int numberOfLinks = 150;

            for (int i = 0; i < numberOfLinks; i++)
            {
                ActivityLink activityLink = new ActivityLink(new ActivityContext(
                                                                 ActivityTraceId.CreateRandom(),
                                                                 ActivitySpanId.CreateRandom(),
                                                                 ActivityTraceFlags.None), null);
                links.Add(activityLink);
            }

            string expectedMSlinks = GetExpectedMSlinks(links.GetRange(0, MaxLinksAllowed));
            string actualMSlinks   = null;

            using var activity = activitySource.StartActivity(
                      ActivityName,
                      ActivityKind.Client,
                      parentContext: default,
                      null,
                      links,
                      startTime: DateTime.UtcNow);

            var monitorTags = TraceHelper.EnumerateActivityTags(activity);

            if (telemetryType == "RequestData")
            {
                var requestData = new RequestData(2, activity, ref monitorTags);
                Assert.True(requestData.Properties.TryGetValue(msLinks, out actualMSlinks));
            }
            if (telemetryType == "RemoteDependencyData")
            {
                var remoteDependencyData = new RemoteDependencyData(2, activity, ref monitorTags);
                Assert.True(remoteDependencyData.Properties.TryGetValue(msLinks, out actualMSlinks));
            }

            // Check for valid JSON string
            try
            {
                JsonDocument document = JsonDocument.Parse(actualMSlinks);
            }
            catch (Exception)
            {
                Assert.True(false, "_MSlinks should be a JSON formatted string");
            }

            Assert.True(actualMSlinks.Length <= MaxLength);
            Assert.Equal(actualMSlinks, expectedMSlinks);
        }
Ejemplo n.º 5
0
        public void AlwaysOffSampler_AlwaysReturnFalse(ActivityTraceFlags flags)
        {
            var parentContext = new ActivityContext(this.traceId, this.parentSpanId, flags);
            var link          = new ActivityLink(parentContext);

            Assert.Equal(
                SamplingDecision.Drop,
                new AlwaysOffSampler().ShouldSample(new SamplingParameters(parentContext, this.traceId, "Another name", ActivityKindServer, null, new List <ActivityLink> {
                link
            })).Decision);
        }
            public static void Enumerate(ActivityLink activityLink, ref TState state)
            {
                var tags = activityLink.Tags;

                if (tags is null)
                {
                    return;
                }

                ActivityTagsCollectionEnumerator(
                    tags,
                    ref state,
                    ForEachTagValueCallbackRef);
            }
Ejemplo n.º 7
0
        private void UpdateRoutes(object sender, DiagramEventArgs e)
        {
            this.mainDiagram.LayoutCompleted -= UpdateRoutes;

            foreach (Link link in mainDiagram.Links)
            {
                ActivityLink linkData = link.Data as ActivityLink;
                if (linkData != null && linkData.Points != null && linkData.Points.Count() > 1)
                {
                    link.Route.Points = (IList <Point>)linkData.Points;
                }
            }
            mainDiagram.PartManager.UpdatesRouteDataPoints = true;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 将 link 信息转化成 info 信息
        /// </summary>
        /// <param name="link"></param>
        /// <returns></returns>
        public static TransitionInfo ExtractTransitionInfo(ActivityLink link)
        {
            TransitionInfo tranInfo = new TransitionInfo()
            {
                Key             = link.Key,
                Name            = link.Text,
                Enabled         = link.WfEnabled,
                FromActivityKey = link.From,
                ToActivityKey   = link.To,
                IsReturn        = link.WfReturnLine
            };

            return(tranInfo);
        }
Ejemplo n.º 9
0
        protected override void UpdateRouteDataPoints(Link link)
        {
            if (!this.UpdatesRouteDataPoints)
            {
                return;
            }

            ActivityLink data = link.Data as ActivityLink;

            if (data != null)
            {
                data.Points = new List <Point>(link.Route.Points);
            }
        }
Ejemplo n.º 10
0
        public void AlwaysOnSampler_AlwaysReturnTrue(ActivityTraceFlags flags)
        {
            var parentContext = new ActivityContext(this.traceId, this.parentSpanId, flags);
            var link          = new ActivityLink(parentContext);

            Assert.True(
                new AlwaysOnSampler()
                .ShouldSample(new SamplingParameters(
                                  parentContext,
                                  this.traceId,
                                  "Another name",
                                  ActivityKindServer,
                                  null,
                                  new List <ActivityLink> {
                link
            })).IsSampled);
        }
Ejemplo n.º 11
0
        public override void DoDeactivate()
        {
            base.DoDeactivate();
            var link = this.Diagram.SelectedLink;

            ActivityLink linkData = (ActivityLink)link.Data;

            linkData.WfReturnLine = false;

            if (linkData.From == linkData.To || linkData.To == "N0")
            {
                linkData.WfReturnLine = true;
            }

            DiagramUtils.WebInterAct.LoadProperty(WorkflowUtils.CLIENTSCRIPT_PARAM_TRANSITION,
                                                  this.Diagram.Tag.ToString(),
                                                  WorkflowUtils.ExtractTransitionInfoJson(linkData));
        }
        public void AlwaysOffSampler_AlwaysReturnFalse(ActivityTraceFlags flags)
        {
            var parentContext = new ActivityContext(traceId, parentSpanId, flags);
            var link          = new ActivityLink(parentContext);

            Assert.False(
                new AlwaysOffActivitySampler()
                .ShouldSample(
                    parentContext,
                    traceId,
                    spanId,
                    "Another name",
                    ActivityKindServer,
                    null,
                    new List <ActivityLink>()
            {
                link
            }).IsSampled);
        }
        private static OtlpTrace.Span.Types.Link ToOtlpLink(ActivityLink activityLink)
        {
            // protobuf doesn't understand Span<T> yet: https://github.com/protocolbuffers/protobuf/issues/3431
            Span <byte> traceIdBytes = stackalloc byte[16];
            Span <byte> spanIdBytes  = stackalloc byte[8];

            activityLink.Context.TraceId.CopyTo(traceIdBytes);
            activityLink.Context.SpanId.CopyTo(spanIdBytes);

            var otlpLink = new OtlpTrace.Span.Types.Link
            {
                TraceId = ByteString.CopyFrom(traceIdBytes.ToArray()),
                SpanId  = ByteString.CopyFrom(spanIdBytes.ToArray()),
            };

            otlpLink.Attributes.AddRange(activityLink.Attributes.Select(ToOtlpAttribute));

            return(otlpLink);
        }
Ejemplo n.º 14
0
        static ActivityBenchmarks()
        {
            using ActivitySource activitySource = new ActivitySource("Benchmarks");

            ActivitySource.AddActivityListener(
                new ActivityListener
            {
                ShouldListenTo = (source) => true,
                Sample         = (ref ActivityCreationOptions <ActivityContext> options) => ActivitySamplingResult.AllData,
            });

            var activityTagCollection = new ActivityTagsCollection(new Dictionary <string, object>
            {
                ["tag1"] = "value1",
                ["tag2"] = "value2",
                ["tag3"] = "value3",
            });

            ActivityLink = new ActivityLink(default, activityTagCollection);
Ejemplo n.º 15
0
        private void Link_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            e.Handled = true;
            Northwoods.GoXam.PartManager.PartBinding currentBinding = (Northwoods.GoXam.PartManager.PartBinding)((sender as FrameworkElement).DataContext);
            ActivityLink linkData = currentBinding.Data as ActivityLink;

            if (linkData == null)
            {
                return;
            }

            string strKey = string.Format("{0}@{1}", this.mainDiagram.Tag.ToString(), linkData.Key);

            if (string.Compare(strKey, WorkflowUtils.CurrentKey) != 0)
            {
                this.WebMethod.LoadProperty(WorkflowUtils.CLIENTSCRIPT_PARAM_TRANSITION,
                                            this.mainDiagram.Tag.ToString(),
                                            WorkflowUtils.ExtractTransitionInfoJson(linkData));

                WorkflowUtils.CurrentKey = strKey;
            }
        }
        public void TelemetryPartBPropertiesContainsMSLinksWhenActivityHasLinks(string telemetryType)
        {
            using ActivitySource activitySource = new ActivitySource(ActivitySourceName);
            ActivityLink activityLink = new ActivityLink(new ActivityContext(
                                                             ActivityTraceId.CreateRandom(),
                                                             ActivitySpanId.CreateRandom(),
                                                             ActivityTraceFlags.None), null);

            List <ActivityLink> links = new List <ActivityLink>();

            links.Add(activityLink);

            using var activity = activitySource.StartActivity(
                      ActivityName,
                      ActivityKind.Client,
                      parentContext: default,
                      null,
                      links,
                      startTime: DateTime.UtcNow);

            string expectedMSlinks = GetExpectedMSlinks(links);
            string actualMSlinks   = null;

            var monitorTags = TraceHelper.EnumerateActivityTags(activity);

            if (telemetryType == "RequestData")
            {
                var telemetryPartBRequestData = new RequestData(2, activity, ref monitorTags);
                Assert.True(telemetryPartBRequestData.Properties.TryGetValue(msLinks, out actualMSlinks));
            }
            if (telemetryType == "RemoteDependencyData")
            {
                var telemetryPartBRemoteDependencyData = new RemoteDependencyData(2, activity, ref monitorTags);
                Assert.True(telemetryPartBRemoteDependencyData.Properties.TryGetValue(msLinks, out actualMSlinks));
            }

            Assert.Equal(expectedMSlinks, actualMSlinks);
        }
        public static Span.Types.Link ToLink(this ActivityLink link)
        {
            var ret = new Span.Types.Link
            {
                SpanId  = link.Context.SpanId.ToHexString(),
                TraceId = link.Context.TraceId.ToHexString(),
            };

            if (link.Tags != null)
            {
                ret.Attributes = new Span.Types.Attributes
                {
                    AttributeMap =
                    {
                        link.Tags.ToDictionary(
                            att => att.Key,
                            att => att.Value.ToAttributeValue()),
                    },
                };
            }

            return(ret);
        }
        private static bool ProcessActivityLink(ref PooledListState <JaegerSpanRef> state, ActivityLink link)
        {
            if (!state.Created)
            {
                state.List = PooledList <JaegerSpanRef> .Create();

                state.Created = true;
            }

            PooledList <JaegerSpanRef> .Add(ref state.List, link.ToJaegerSpanRef());

            return(true);
        }
Ejemplo n.º 19
0
        public static string ExtractTransitionInfoJson(ActivityLink link)
        {
            var info = ExtractTransitionInfo(link);

            return(JsonConvert.SerializeObject(info));
        }
Ejemplo n.º 20
0
		private void ProcessLinks()
		{
			//删除旧线
			var links = DiagramModel.LinksSource as ObservableCollection<ActivityLink>;
			var removedLinks = new List<ActivityLink>();
			foreach (var link in links)
			{
				//if (WfInfo.Transitions.Count(p => p.Key == link.Key) == 0)
				var linkInfo = WfInfo.Transitions.FirstOrDefault(p => p.FromActivityKey == link.From && p.ToActivityKey == link.To);
				if (linkInfo == null)
				{
					removedLinks.Add(link);
					continue;
				}
				else
				{
					link.WfRuntimeIsPassed = linkInfo.IsPassed;
					link.WfReturnLine = linkInfo.WfReturnLine;
				}
			}

			removedLinks.ForEach(p => DiagramModel.RemoveLink(p));

			//增加新线
			foreach (var tran in WfInfo.Transitions)
			{
				if (links.Count(p => p.From == tran.FromActivityKey && p.To == tran.ToActivityKey) == 0)
				{
					ActivityLink item = new ActivityLink()
					{
						Key = tran.Key,
						From = tran.FromActivityKey,
						To = tran.ToActivityKey,
						WfEnabled = tran.Enabled,
						WfRuntimeIsPassed = tran.IsPassed,
						WfReturnLine = tran.WfReturnLine
					};

					if (item.WfReturnLine && item.WfRuntimeIsPassed)
					{
						item.Category = "PassedAndReturnTemplate";
					}
					else
					{
						if (item.WfEnabled == false)
							item.Category = "EnabledTemplate";
						else if (item.WfRuntimeIsPassed)
							item.Category = "PassedTemplate";
						else if (item.WfReturnLine)
							item.Category = "ReturnTemplate";
						else
							item.Category = "LinkTemplate";
					}

					DiagramModel.AddLink(item);
				}
			}

			foreach (var item in links)
			{
				item.FromPort = "portBottom";
				item.ToPort = "portTop";
			}
		}
 private static bool ForEachLinkCallback(ref TState state, ActivityLink item)
 => state.ForEach(item);
Ejemplo n.º 22
0
        private void ProcessLinks()
        {
            //删除旧线
            var links        = DiagramModel.LinksSource as ObservableCollection <ActivityLink>;
            var removedLinks = new List <ActivityLink>();

            foreach (var link in links)
            {
                //if (WfInfo.Transitions.Count(p => p.Key == link.Key) == 0)
                var linkInfo = WfInfo.Transitions.FirstOrDefault(p => p.FromActivityKey == link.From && p.ToActivityKey == link.To);
                if (linkInfo == null)
                {
                    removedLinks.Add(link);
                    continue;
                }
                else
                {
                    link.WfRuntimeIsPassed = linkInfo.IsPassed;
                    link.WfReturnLine      = linkInfo.WfReturnLine;
                }
            }

            removedLinks.ForEach(p => DiagramModel.RemoveLink(p));

            //增加新线
            foreach (var tran in WfInfo.Transitions)
            {
                if (links.Count(p => p.From == tran.FromActivityKey && p.To == tran.ToActivityKey) == 0)
                {
                    ActivityLink item = new ActivityLink()
                    {
                        Key               = tran.Key,
                        From              = tran.FromActivityKey,
                        To                = tran.ToActivityKey,
                        WfEnabled         = tran.Enabled,
                        WfRuntimeIsPassed = tran.IsPassed,
                        WfReturnLine      = tran.WfReturnLine
                    };

                    if (item.WfReturnLine && item.WfRuntimeIsPassed)
                    {
                        item.Category = "PassedAndReturnTemplate";
                    }
                    else
                    {
                        if (item.WfEnabled == false)
                        {
                            item.Category = "EnabledTemplate";
                        }
                        else if (item.WfRuntimeIsPassed)
                        {
                            item.Category = "PassedTemplate";
                        }
                        else if (item.WfReturnLine)
                        {
                            item.Category = "ReturnTemplate";
                        }
                        else
                        {
                            item.Category = "LinkTemplate";
                        }
                    }

                    DiagramModel.AddLink(item);
                }
            }

            foreach (var item in links)
            {
                item.FromPort = "portBottom";
                item.ToPort   = "portTop";
            }
        }
 public static void EnumerateTags <T>(this ActivityLink activityLink, ref T tagEnumerator)
     where T : struct, IActivityEnumerator <KeyValuePair <string, object> >
 {
     ActivityTagsEnumeratorFactory <T> .Enumerate(activityLink, ref tagEnumerator);
 }