예제 #1
0
        public void GetUrl_Null()
        {
            var PartBTags = AzMonList.Initialize();

            PartBTags.GenerateUrlAndAuthority(out var url, out var urlAuthority);
            Assert.Null(url);
            Assert.Null(urlAuthority);
        }
예제 #2
0
        public void GetUrl_HttpUrl_Success()
        {
            var PartBTags = AzMonList.Initialize();

            AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpUrl, "https://www.wiki.com"));

            PartBTags.GenerateUrlAndAuthority(out var url, out var urlAuthority);
            Assert.Equal("https://www.wiki.com/", url);
            Assert.Equal("www.wiki.com", urlAuthority);
        }
예제 #3
0
        public void GetUrl_With_HttpScheme_And_Null_HttpHost()
        {
            var PartBTags = AzMonList.Initialize();

            AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpScheme, null));
            AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpHost, null));

            PartBTags.GenerateUrlAndAuthority(out var url, out var urlAuthority);
            Assert.Null(url);
            Assert.Null(urlAuthority);
        }
예제 #4
0
        private static TagEnumerationState EnumerateActivityTags(Activity activity)
        {
            var monitorTags = new TagEnumerationState
            {
                PartBTags = AzMonList.Initialize(),
                PartCTags = AzMonList.Initialize()
            };

            activity.EnumerateTags(ref monitorTags);
            return(monitorTags);
        }
예제 #5
0
        public void GetUrl_HttpPort_NullEmptyOrDefault(string scheme, string httpHost, string hostPort)
        {
            var PartBTags = AzMonList.Initialize();

            AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpScheme, scheme));
            AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpHost, httpHost));
            AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpHostPort, hostPort));

            PartBTags.GenerateUrlAndAuthority(out var url, out var urlAuthority);

            Assert.Equal("https://localhost", url);
            Assert.Equal("localhost", urlAuthority);
        }
예제 #6
0
        public void GetUrl_NetPeerName_Success(string scheme, string peerName, string peerPort, string target)
        {
            var PartBTags = AzMonList.Initialize();

            AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpScheme, scheme));
            AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeNetPeerName, peerName));
            AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeNetPeerPort, peerPort));
            AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpTarget, target));

            PartBTags.GenerateUrlAndAuthority(out var url, out var urlAuthority);
            Assert.Equal($"https://localhost:443{target}", url);
            Assert.Equal($"localhost:443", urlAuthority);
        }
예제 #7
0
        public void GetUrl_HttpPort_RandomPort_With_HttpTarget(string scheme, string httpHost, string hostPort, string target)
        {
            var PartBTags = AzMonList.Initialize();

            AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpScheme, scheme));
            AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpHost, httpHost));
            AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpHostPort, hostPort));
            AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpTarget, target));

            PartBTags.GenerateUrlAndAuthority(out var url, out var urlAuthority);

            hostPort = hostPort == "8888" ? ":8888" : null;
            Assert.Equal($"{scheme}://localhost{hostPort}{target}", url);
            Assert.Equal($"localhost{hostPort}", urlAuthority);
        }
예제 #8
0
        public void GetUrl_NullOrEmpty(string attribute)
        {
            var PartBTags = AzMonList.Initialize();

            AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(attribute, null));

            PartBTags.GenerateUrlAndAuthority(out var url, out var urlAuthority);
            Assert.Null(url);
            Assert.Null(urlAuthority);

            AzMonList.Clear(ref PartBTags);
            AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(attribute, string.Empty));
            PartBTags.GenerateUrlAndAuthority(out url, out urlAuthority);
            Assert.Null(url);
            Assert.Null(urlAuthority);
        }
예제 #9
0
        public void GetUrl_NetPeerName_NullOrEmpty(string scheme, string peerName, string peerPort)
        {
            var PartBTags = AzMonList.Initialize();

            AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpScheme, scheme));
            AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeNetPeerName, peerName));
            AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeNetPeerPort, peerPort));

            PartBTags.GenerateUrlAndAuthority(out var url, out var urlAuthority);

            if (string.IsNullOrEmpty(peerName))
            {
                Assert.Null(url);
                Assert.Null(urlAuthority);
            }
            else
            {
                Assert.Equal("https://netpeername", url);
                Assert.Equal("netpeername", urlAuthority);
            }
        }
예제 #10
0
        public void GetUrl_HttpHost_Success(string httpHost, string hostPort, string target)
        {
            var PartBTags = AzMonList.Initialize();

            AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpHost, httpHost));

            if (hostPort != "")
            {
                AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpHostPort, hostPort));
            }

            if (target != "")
            {
                AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpTarget, target));
            }

            PartBTags.GenerateUrlAndAuthority(out var url, out var urlAuthority);
            hostPort = hostPort == "8888" ? ":8888" : null;
            Assert.Equal($"localhost{hostPort}{target}", url);
            Assert.Equal($"localhost{hostPort}", urlAuthority);
        }
예제 #11
0
        private static MonitorBase GenerateTelemetryData(Activity activity)
        {
            var telemetryType = activity.GetTelemetryType();
            var monitorTags   = new TagEnumerationState
            {
                PartBTags = AzMonList.Initialize(),
                PartCTags = AzMonList.Initialize()
            };

            activity.EnumerateTags(ref monitorTags);

            MonitorBase telemetry = new MonitorBase
            {
                BaseType = Telemetry_Base_Type_Mapping[telemetryType]
            };

            if (telemetryType == TelemetryType.Request)
            {
                monitorTags.PartBTags.GenerateUrlAndAuthority(out var url, out var urlAuthority);
                var statusCode = AzMonList.GetTagValue(ref monitorTags.PartBTags, SemanticConventions.AttributeHttpStatusCode)?.ToString() ?? "0";
                var success    = activity.GetStatus() != Status.Error;
                var request    = new RequestData(2, activity.Context.SpanId.ToHexString(), activity.Duration.ToString("c", CultureInfo.InvariantCulture), success, statusCode)
                {
                    Name   = activity.DisplayName,
                    Url    = url,
                    Source = urlAuthority
                };

                // TODO: Handle activity.TagObjects, extract well-known tags
                AddPropertiesToTelemetry(request.Properties, monitorTags.PartCTags);
                telemetry.BaseData = request;
            }
            else if (telemetryType == TelemetryType.Dependency)
            {
                var dependency = new RemoteDependencyData(2, activity.DisplayName, activity.Duration.ToString("c", CultureInfo.InvariantCulture))
                {
                    Id      = activity.Context.SpanId.ToHexString(),
                    Success = activity.GetStatus() != Status.Error
                };

                switch (monitorTags.activityType)
                {
                case PartBType.Http:
                    monitorTags.PartBTags.GenerateUrlAndAuthority(out var url, out var urlAuthority);
                    dependency.Data       = url;
                    dependency.Target     = urlAuthority;
                    dependency.Type       = "Http";
                    dependency.ResultCode = AzMonList.GetTagValue(ref monitorTags.PartBTags, SemanticConventions.AttributeHttpStatusCode)?.ToString() ?? "0";
                    break;

                case PartBType.Db:
                    var depDataAndType = AzMonList.GetTagValues(ref monitorTags.PartBTags, SemanticConventions.AttributeDbStatement, SemanticConventions.AttributeDbSystem);
                    dependency.Data = depDataAndType[0]?.ToString();
                    dependency.Type = depDataAndType[1]?.ToString();
                    break;

                case PartBType.Rpc:
                    var depInfo = AzMonList.GetTagValues(ref monitorTags.PartBTags, SemanticConventions.AttributeRpcService, SemanticConventions.AttributeRpcSystem, SemanticConventions.AttributeRpcStatus);
                    dependency.Data       = depInfo[0]?.ToString();
                    dependency.Type       = depInfo[1]?.ToString();
                    dependency.ResultCode = depInfo[2]?.ToString();
                    break;

                case PartBType.Messaging:
                    depDataAndType  = AzMonList.GetTagValues(ref monitorTags.PartBTags, SemanticConventions.AttributeMessagingUrl, SemanticConventions.AttributeMessagingSystem);
                    dependency.Data = depDataAndType[0]?.ToString();
                    dependency.Type = depDataAndType[1]?.ToString();
                    break;
                }

                AddPropertiesToTelemetry(dependency.Properties, monitorTags.PartCTags);
                telemetry.BaseData = dependency;
            }

            return(telemetry);
        }