public void HttpDependencyTargetIsSetUsingHttpUrl(string port) { var PartBTags = AzMonList.Initialize(); if (port == "80") { AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpUrl, $"http://www.wiki.com:{port}/")); } else { AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpUrl, $"https://www.wiki.com:{port}/")); } string expectedTarget; if (port == "80" || port == "443") { expectedTarget = "www.wiki.com"; } else { expectedTarget = $"www.wiki.com:{port}"; } string target = PartBTags.GetDependencyTarget(PartBType.Http); Assert.Equal(expectedTarget, target); }
public void HttpRequestUrlIsSetUsing_Scheme_NetHostName_Port_Target(string port) { var PartBTags = AzMonList.Initialize(); string httpScheme; if (port == "80") { httpScheme = "http"; } else { httpScheme = "https"; } AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpScheme, httpScheme)); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeNetHostName, "localhost")); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeNetHostPort, port)); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpTarget, "/path")); string expectedUrl; if (port == "80" || port == "443") { expectedUrl = $"{httpScheme}://localhost/path"; } else { expectedUrl = $"{httpScheme}://localhost:{port}/path"; } string url = PartBTags.GetRequestUrl(); Assert.Equal(expectedUrl, url); }
public void DbNameIsAppendedToTargetDerivedFromNetAttributesforDBDependencyTarget(string peerService, string netPeerName, string netPeerIp, string netPeerPort) { var PartBTags = AzMonList.Initialize(); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributePeerService, peerService)); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeNetPeerName, netPeerName)); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeNetPeerIp, netPeerIp)); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeNetPeerPort, netPeerPort)); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeDbName, "DbName")); string hostName = null; if (peerService != null) { hostName = peerService; } if (netPeerName != null) { hostName = $"{netPeerName}:{netPeerPort}"; } if (netPeerIp != null) { hostName = $"{netPeerIp}:{netPeerPort}"; } string expectedTarget = $"{hostName}/DbName"; string target = PartBTags.GetDbDependencyTarget(); Assert.Equal(expectedTarget, target); }
public void HttpDependencyUrlIsSetUsing_Scheme_PeerIp_Port_Target(string port) { var PartBTags = AzMonList.Initialize(); string httpScheme; if (port == "80") { httpScheme = "http"; } else { httpScheme = "https"; } AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpScheme, httpScheme)); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeNetPeerIp, "127.0.0.1")); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeNetPeerPort, port)); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpTarget, "/path")); string expectedUrl; if (port == "80" || port == "443") { expectedUrl = $"{httpScheme}://127.0.0.1/path"; } else { expectedUrl = $"{httpScheme}://127.0.0.1:{port}/path"; } string url = PartBTags.GetDependencyUrl(); Assert.Equal(expectedUrl, url); }
public void DbDependencyTargetIsSetToDbSystemWhenNetAndDbNameAttributesAreNotPresent() { var PartBTags = AzMonList.Initialize(); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeDbSystem, "DbSystem")); string target = PartBTags.GetDbDependencyTarget(); Assert.Equal("DbSystem", target); }
internal void DependencyTargetIsSetUsingPeerService(PartBType type) { var PartBTags = AzMonList.Initialize(); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributePeerService, "servicename")); string expectedTarget = "servicename"; string target = PartBTags.GetDependencyTarget(type); Assert.Equal(expectedTarget, target); }
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); }
public void HttpDependencyUrlIsSetUsingHttpUrl() { var PartBTags = AzMonList.Initialize(); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpUrl, "https://www.wiki.com")); string url = PartBTags.GetDependencyUrl(); Assert.Equal("https://www.wiki.com", url); }
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); }
public void ForEach(IEnumerable <KeyValuePair <string, object> > activityTags) { foreach (KeyValuePair <string, object> activityTag in activityTags) { if (activityTag.Value == null) { continue; } if (activityTag.Value is Array array) { StringBuilder sw = new StringBuilder(); foreach (var item in array) { // TODO: Consider changing it to JSon array. if (item != null) { sw.Append(item); sw.Append(','); } } if (sw.Length > 0) { sw.Length--; } AzMonList.Add(ref UnMappedTags, new KeyValuePair <string, object>(activityTag.Key, sw.ToString())); continue; } if (!s_part_B_Mapping.TryGetValue(activityTag.Key, out _tempActivityType)) { AzMonList.Add(ref UnMappedTags, activityTag); continue; } if (activityType == OperationType.Unknown || activityType == OperationType.Common) { activityType = _tempActivityType; } if (_tempActivityType == activityType || _tempActivityType == OperationType.Common) { AzMonList.Add(ref MappedTags, activityTag); } else { AzMonList.Add(ref UnMappedTags, activityTag); } } }
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); }
public void NetPeerIpAttributeTakesPrecedenceSettingHttpDependencyUrl() { var PartBTags = AzMonList.Initialize(); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpScheme, "http")); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeNetPeerIp, "127.0.0.1")); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeNetPeerPort, "8888")); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpTarget, "/path")); string expectedUrl = "http://127.0.0.1:8888/path"; string url = PartBTags.GetDependencyUrl(); Assert.Equal(expectedUrl, url); }
public void NetHostNameAttributeTakesPrecedenceSettingHttpRequestUrl() { var PartBTags = AzMonList.Initialize(); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpScheme, "http")); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeNetHostName, "localhost")); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeNetHostPort, "8888")); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpTarget, "/path")); string expectedUrl = "http://localhost:8888/path"; string url = PartBTags.GetRequestUrl(); Assert.Equal(expectedUrl, url); }
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); }
public bool ForEach(KeyValuePair <string, object> activityTag) { if (activityTag.Value == null) { return(true); } if (activityTag.Value is Array array) { StringBuilder sw = new StringBuilder(); foreach (var item in array) { // TODO: Consider changing it to JSon array. if (item != null) { sw.Append(item); sw.Append(','); } } if (sw.Length > 0) { sw.Length--; } AzMonList.Add(ref PartCTags, new KeyValuePair <string, object>(activityTag.Key, sw.ToString())); return(true); } if (!Part_B_Mapping.TryGetValue(activityTag.Key, out tempActivityType)) { AzMonList.Add(ref PartCTags, activityTag); return(true); } if (activityType == PartBType.Unknown || activityType == PartBType.Common) { activityType = tempActivityType; } if (tempActivityType == activityType || tempActivityType == PartBType.Common) { AzMonList.Add(ref PartBTags, activityTag); } else { AzMonList.Add(ref PartCTags, activityTag); } return(true); }
internal void PeerIpTakesPrecedenceSettingDependencyTarget(PartBType type) { var PartBTags = AzMonList.Initialize(); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpScheme, "http")); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeDbSystem, "mssql")); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeNetPeerIp, $"127.0.0.1")); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeNetPeerPort, "8888")); string expectedTarget = "127.0.0.1:8888"; string target = PartBTags.GetDependencyTarget(type); Assert.Equal(expectedTarget, target); }
/// <summary> /// Converts Activity Links to custom property with key as _MS.links. /// Value will be a JSON string formatted as [{"operation_Id":"{TraceId}","id":"{SpanId}"}]. /// </summary> private static void AddActivityLinksToPartCTags(IEnumerable <ActivityLink> links, ref AzMonList PartCTags) { string msLinks = "_MS.links"; // max number of links that can fit in this json formatted string is 107. it is based on assumption that traceid and spanid will be of fixed length. // Keeping max at 100 for now. int maxLinks = MaxlinksAllowed; if (links != null && links.Any()) { var linksJson = new StringBuilder(); linksJson.Append('['); foreach (var link in links) { linksJson .Append('{') .Append("\"operation_Id\":") .Append('\"') .Append(link.Context.TraceId.ToHexString()) .Append('\"') .Append(','); linksJson .Append("\"id\":") .Append('\"') .Append(link.Context.SpanId.ToHexString()) .Append('\"'); linksJson.Append("},"); maxLinks--; if (maxLinks == 0) { if (MaxlinksAllowed < links.Count()) { AzureMonitorExporterEventSource.Log.Write($"ActivityLinksIgnored{EventLevelSuffix.Informational}", $"Max count of {MaxlinksAllowed} has reached."); } break; } } if (linksJson.Length > 0) { // trim trailing comma - json does not support it linksJson.Remove(linksJson.Length - 1, 1); } linksJson.Append(']'); AzMonList.Add(ref PartCTags, new KeyValuePair <string, object>(msLinks, linksJson.ToString())); } }
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); }
public void HttpUrlTakesPrecedenceSettingHttpDependencyTarget() { var PartBTags = AzMonList.Initialize(); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpUrl, $"http://www.wiki.com:8888/")); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpScheme, "http")); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeNetPeerName, $"servername.com")); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeNetPeerIp, $"127.0.0.1")); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeNetPeerPort, "8888")); string expectedTarget = "www.wiki.com:8888"; string target = PartBTags.GetDependencyTarget(PartBType.Http); Assert.Equal(expectedTarget, target); }
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); }
public void HttpUrlAttributeTakesPrecedenceSettingHttpDependencyUrl() { var PartBTags = AzMonList.Initialize(); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpUrl, "https://www.wiki.com")); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpScheme, "http")); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeNetPeerName, "servername.com")); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpHost, "www.httphost.org")); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeNetPeerIp, "127.0.0.1")); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeNetPeerPort, "8888")); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpTarget, "/path")); string expectedUrl = "https://www.wiki.com"; string url = PartBTags.GetDependencyUrl(); Assert.Equal(expectedUrl, url); }
internal void PeerServiceTakesPrecedenceSettingDependencyTarget(PartBType type) { var PartBTags = AzMonList.Initialize(); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributePeerService, "servicename")); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpHost, $"www.httphost.org:8888")); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpUrl, $"http://www.wiki.com:8888/")); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpScheme, "http")); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeDbSystem, "mssql")); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeNetPeerName, $"servername.com")); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeNetPeerIp, $"127.0.0.1")); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeNetPeerPort, "8888")); string expectedTarget = "servicename"; string target = PartBTags.GetDependencyTarget(type); Assert.Equal(expectedTarget, target); }
public void HttpDependencyTargetIsSetUsingHttpHost(string httpScheme, string port) { var PartBTags = AzMonList.Initialize(); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpScheme, httpScheme)); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpHost, $"www.httphost.org:{port}")); string expectedTarget; if (port == "80" || port == "443") { expectedTarget = "www.httphost.org"; } else { expectedTarget = $"www.httphost.org:{port}"; } string target = PartBTags.GetDependencyTarget(PartBType.Http); Assert.Equal(expectedTarget, target); }
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); } }
public void HttpRequestUrlIsSetUsing_Scheme_Host_Target(string httpScheme, string port) { var PartBTags = AzMonList.Initialize(); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpScheme, httpScheme)); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpHost, $"www.httphost.org:{port}")); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpTarget, "/path")); string expectedUrl; if (port == "80" || port == "443") { expectedUrl = $"{httpScheme}://www.httphost.org/path"; } else { expectedUrl = $"{httpScheme}://www.httphost.org:{port}/path"; } string url = PartBTags.GetRequestUrl(); Assert.Equal(expectedUrl, url); }
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); }
internal void DependencyTargetIsSetUsingNetPeerIp(string httpScheme, string port, PartBType type) { var PartBTags = AzMonList.Initialize(); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeHttpScheme, httpScheme)); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeDbSystem, "mssql")); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeNetPeerIp, $"127.0.0.1")); AzMonList.Add(ref PartBTags, new KeyValuePair <string, object>(SemanticConventions.AttributeNetPeerPort, port)); string expectedTarget; if (port == "80" || port == "443" || port == "1433") { expectedTarget = "127.0.0.1"; } else { expectedTarget = $"127.0.0.1:{port}"; } string target = PartBTags.GetDependencyTarget(type); Assert.Equal(expectedTarget, target); }