예제 #1
0
        public void GetUrl_NetPeerName_NullOrEmpty()
        {
            var url = HttpHelper.GetUrl(new Dictionary <string, string>
            {
                [SemanticConventions.AttributeHttpScheme]  = "https",
                [SemanticConventions.AttributeNetPeerName] = null,
                [SemanticConventions.AttributeNetPeerPort] = null
            });

            Assert.Null(url);

            url = HttpHelper.GetUrl(new Dictionary <string, string>
            {
                [SemanticConventions.AttributeHttpScheme]  = "https",
                [SemanticConventions.AttributeNetPeerName] = string.Empty,
                [SemanticConventions.AttributeNetPeerPort] = null
            });

            Assert.Null(url);

            url = HttpHelper.GetUrl(new Dictionary <string, string>
            {
                [SemanticConventions.AttributeHttpScheme]  = "https",
                [SemanticConventions.AttributeNetPeerName] = "netpeername",
                [SemanticConventions.AttributeNetPeerPort] = null
            });

            Assert.Equal("https://netpeername", url);
        }
예제 #2
0
        public void GetUrl_HttpPort_NullEmptyOrDefault()
        {
            var url = HttpHelper.GetUrl(new Dictionary <string, string>
            {
                [SemanticConventions.AttributeHttpScheme]   = "https",
                [SemanticConventions.AttributeHttpHost]     = "localhost",
                [SemanticConventions.AttributeHttpHostPort] = null
            });

            Assert.Equal("https://localhost", url);

            url = HttpHelper.GetUrl(new Dictionary <string, string>
            {
                [SemanticConventions.AttributeHttpScheme]   = "http",
                [SemanticConventions.AttributeHttpHost]     = "localhost",
                [SemanticConventions.AttributeHttpHostPort] = "80"
            });

            Assert.Equal("http://localhost", url);

            url = HttpHelper.GetUrl(new Dictionary <string, string>
            {
                [SemanticConventions.AttributeHttpScheme]   = "https",
                [SemanticConventions.AttributeHttpHost]     = "localhost",
                [SemanticConventions.AttributeHttpHostPort] = "443"
            });

            Assert.Equal("https://localhost", url);
        }
예제 #3
0
        public void GetUrl_HttpUrl_Success()
        {
            var url = HttpHelper.GetUrl(new Dictionary <string, string> {
                [SemanticConventions.AttributeHttpUrl] = "https://www.wiki.com"
            });

            Assert.Equal("https://www.wiki.com", url);
        }
예제 #4
0
        public void GetUrl_With_HttpScheme_And_Null_HttpHost()
        {
            var url = HttpHelper.GetUrl(new Dictionary <string, string>
            {
                [SemanticConventions.AttributeHttpScheme] = "https",
                [SemanticConventions.AttributeHttpHost]   = null
            });

            Assert.Null(url);
        }
예제 #5
0
        public void GetUrl_HttpHost_NullOrEmpty()
        {
            var url = HttpHelper.GetUrl(new Dictionary <string, string> {
                [SemanticConventions.AttributeHttpHost] = null
            });

            Assert.Null(url);
            url = HttpHelper.GetUrl(new Dictionary <string, string> {
                [SemanticConventions.AttributeHttpHost] = string.Empty
            });
            Assert.Null(url);
        }
예제 #6
0
        private static MonitorBase GenerateTelemetryData(Activity activity)
        {
            var         telemetryType = activity.GetTelemetryType();
            var         activityType  = activity.TagObjects.ToAzureMonitorTags(out var partBTags, out var PartCTags);
            MonitorBase telemetry     = new MonitorBase
            {
                BaseType = Telemetry_Base_Type_Mapping[telemetryType]
            };

            if (telemetryType == TelemetryType.Request)
            {
                var url        = activity.Kind == ActivityKind.Server ? HttpHelper.GetUrl(partBTags) : GetMessagingUrl(partBTags);
                var statusCode = HttpHelper.GetHttpStatusCode(partBTags);
                var success    = HttpHelper.GetSuccessFromHttpStatusCode(statusCode);
                var request    = new RequestData(2, activity.Context.SpanId.ToHexString(), activity.Duration.ToString("c", CultureInfo.InvariantCulture), success, statusCode)
                {
                    Name = activity.DisplayName,
                    Url  = url,
                    // TODO: Handle request.source.
                };

                // TODO: Handle activity.TagObjects, extract well-known tags
                AddPropertiesToTelemetry(request.Properties, 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()
                };

                // TODO: Handle activity.TagObjects
                // ExtractPropertiesFromTags(dependency.Properties, activity.Tags);

                if (activityType == PartBType.Http)
                {
                    dependency.Data = HttpHelper.GetUrl(partBTags);
                    dependency.Type = "HTTP"; // TODO: Parse for storage / SB.
                    var statusCode = HttpHelper.GetHttpStatusCode(partBTags);
                    dependency.ResultCode = statusCode;
                    dependency.Success    = HttpHelper.GetSuccessFromHttpStatusCode(statusCode);
                }

                // TODO: Handle dependency.target.
                AddPropertiesToTelemetry(dependency.Properties, PartCTags);
                telemetry.BaseData = dependency;
            }

            return(telemetry);
        }
예제 #7
0
        public void GetUrl_HttpHost_Success()
        {
            var url = HttpHelper.GetUrl(new Dictionary <string, string>
            {
                [SemanticConventions.AttributeHttpHost] = "localhost",
            });

            Assert.Equal("localhost", url);

            url = HttpHelper.GetUrl(new Dictionary <string, string>
            {
                [SemanticConventions.AttributeHttpHost]     = "localhost",
                [SemanticConventions.AttributeHttpHostPort] = "8888",
            });

            Assert.Equal("localhost:8888", url);

            url = HttpHelper.GetUrl(new Dictionary <string, string>
            {
                [SemanticConventions.AttributeHttpHost]     = "localhost",
                [SemanticConventions.AttributeHttpHostPort] = "8080",
                [SemanticConventions.AttributeHttpTarget]   = "/test"
            });

            Assert.Equal("localhost:8080/test", url);

            url = HttpHelper.GetUrl(new Dictionary <string, string>
            {
                [SemanticConventions.AttributeHttpHost]     = "localhost",
                [SemanticConventions.AttributeHttpHostPort] = null,
                [SemanticConventions.AttributeHttpTarget]   = null
            });

            Assert.Equal("localhost", url);

            url = HttpHelper.GetUrl(new Dictionary <string, string>
            {
                [SemanticConventions.AttributeHttpHost]     = "localhost",
                [SemanticConventions.AttributeHttpHostPort] = string.Empty,
                [SemanticConventions.AttributeHttpTarget]   = string.Empty
            });

            Assert.Equal("localhost", url);
        }
예제 #8
0
        public void GetUrl_HttpPort_RandomPort_With_HttpTarget()
        {
            var url = HttpHelper.GetUrl(new Dictionary <string, string>
            {
                [SemanticConventions.AttributeHttpScheme]   = "https",
                [SemanticConventions.AttributeHttpHost]     = "localhost",
                [SemanticConventions.AttributeHttpHostPort] = "8888"
            });

            Assert.Equal("https://localhost:8888", url);

            url = HttpHelper.GetUrl(new Dictionary <string, string>
            {
                [SemanticConventions.AttributeHttpScheme]   = "http",
                [SemanticConventions.AttributeHttpHost]     = "localhost",
                [SemanticConventions.AttributeHttpHostPort] = "80",
                [SemanticConventions.AttributeHttpTarget]   = "/test"
            });

            Assert.Equal("http://localhost/test", url);

            url = HttpHelper.GetUrl(new Dictionary <string, string>
            {
                [SemanticConventions.AttributeHttpScheme]   = "https",
                [SemanticConventions.AttributeHttpHost]     = "localhost",
                [SemanticConventions.AttributeHttpHostPort] = "443",
                [SemanticConventions.AttributeHttpTarget]   = "/test"
            });

            Assert.Equal("https://localhost/test", url);

            url = HttpHelper.GetUrl(new Dictionary <string, string>
            {
                [SemanticConventions.AttributeHttpScheme]   = "https",
                [SemanticConventions.AttributeHttpHost]     = "localhost",
                [SemanticConventions.AttributeHttpHostPort] = "8888",
                [SemanticConventions.AttributeHttpTarget]   = "/test"
            });

            Assert.Equal("https://localhost:8888/test", url);
        }
예제 #9
0
        public void GetUrl_NetPeerName_Success()
        {
            var url = HttpHelper.GetUrl(new Dictionary <string, string>
            {
                [SemanticConventions.AttributeHttpScheme]  = "https",
                [SemanticConventions.AttributeNetPeerName] = "localhost",
                [SemanticConventions.AttributeNetPeerPort] = "443"
            });

            Assert.Equal("https://localhost:443", url);

            url = HttpHelper.GetUrl(new Dictionary <string, string>
            {
                [SemanticConventions.AttributeHttpScheme]  = "https",
                [SemanticConventions.AttributeNetPeerName] = "localhost",
                [SemanticConventions.AttributeNetPeerPort] = "443",
                [SemanticConventions.AttributeHttpTarget]  = "/test"
            });

            Assert.Equal("https://localhost:443/test", url);
        }
예제 #10
0
        public void GetUrl_Null()
        {
            var url = HttpHelper.GetUrl(new Dictionary <string, string>());

            Assert.Null(url);
        }