internal void DependencyTargetIsNullByDefault(PartBType type) { var PartBTags = AzMonList.Initialize(); string target = PartBTags.GetDependencyTarget(type); Assert.Null(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 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 PartCTags, new KeyValuePair <string, object>(activityTag.Key, sw.ToString())); continue; } if (!Part_B_Mapping.TryGetValue(activityTag.Key, out tempActivityType)) { AzMonList.Add(ref PartCTags, activityTag); continue; } 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); } } }
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); }
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); }
internal static PartBType ToAzureMonitorTags(this IEnumerable <KeyValuePair <string, object> > tagObjects, out Dictionary <string, string> partBTags, out Dictionary <string, string> partCTags) { if (tagObjects == null) { partBTags = null; partCTags = null; return(PartBType.Unknown); } PartBType tempActivityType; PartBType activityType = PartBType.Unknown; partBTags = new Dictionary <string, string>(); partCTags = new Dictionary <string, string>(); foreach (var entry in tagObjects) { if (entry.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--; } partCTags.Add(entry.Key, sw.ToString()); continue; } if (entry.Value != null) { if (!Part_B_Mapping.TryGetValue(entry.Key, out tempActivityType)) { partCTags.Add(entry.Key, entry.Value.ToString()); continue; } if (activityType == PartBType.Unknown || activityType == PartBType.Common) { activityType = tempActivityType; } if (tempActivityType == activityType || tempActivityType == PartBType.Common) { partBTags.Add(entry.Key, entry.Value.ToString()); } else { partCTags.Add(entry.Key, entry.Value.ToString()); } } } return(activityType); }
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); }
///<summary> /// Gets Http dependency target from activity tag objects. ///</summary> internal static string GetDependencyTarget(this AzMonList tagObjects, PartBType type) { string target; string defaultPort; switch (type) { case PartBType.Http: defaultPort = GetDefaultHttpPort(AzMonList.GetTagValue(ref tagObjects, SemanticConventions.AttributeHttpScheme)?.ToString()); break; case PartBType.Db: defaultPort = GetDefaultDbPort(AzMonList.GetTagValue(ref tagObjects, SemanticConventions.AttributeDbSystem)?.ToString()); break; default: defaultPort = "0"; break; } var peerService = AzMonList.GetTagValue(ref tagObjects, SemanticConventions.AttributePeerService)?.ToString(); if (!string.IsNullOrEmpty(peerService)) { target = peerService; return(target); } if (type == PartBType.Http) { var httpHost = AzMonList.GetTagValue(ref tagObjects, SemanticConventions.AttributeHttpHost)?.ToString(); if (!string.IsNullOrEmpty(httpHost)) { string portSection = $":{defaultPort}"; if (httpHost.EndsWith(portSection, StringComparison.OrdinalIgnoreCase)) { var truncatedHost = httpHost.Substring(0, httpHost.IndexOf(portSection, StringComparison.OrdinalIgnoreCase)); target = truncatedHost; } else { target = httpHost; } return(target); } var httpUrl = AzMonList.GetTagValue(ref tagObjects, SemanticConventions.AttributeHttpUrl)?.ToString(); if (!string.IsNullOrEmpty(httpUrl) && Uri.TryCreate(httpUrl.ToString(), UriKind.RelativeOrAbsolute, out var uri) && uri.IsAbsoluteUri) { target = uri.Authority; if (!string.IsNullOrEmpty(target)) { return(target); } } } target = tagObjects.GetHostUsingNetPeerAttributes(); if (!string.IsNullOrEmpty(target)) { var netPeerPort = AzMonList.GetTagValue(ref tagObjects, SemanticConventions.AttributeNetPeerPort)?.ToString(); if (!string.IsNullOrEmpty(netPeerPort) && netPeerPort != defaultPort) { target = $"{target}:{netPeerPort}"; } return(target); } return(target); }
internal static Dictionary <string, string> ToAzureMonitorTags(this IEnumerable <KeyValuePair <string, string> > tags, out PartBType activityType) { Dictionary <string, string> partBTags = new Dictionary <string, string>(); activityType = PartBType.Unknown; foreach (var entry in tags) { // TODO: May need to store unknown to write to properties as Part C if ((activityType == PartBType.Unknown || activityType == PartBType.Net) && !Part_B_Mapping.TryGetValue(entry.Key, out activityType)) { if (activityType == PartBType.Net) { partBTags.Add(entry.Key, entry.Value); activityType = PartBType.Unknown; } continue; } if (Part_B_Mapping.TryGetValue(entry.Key, out var tempActivityType) && (tempActivityType == activityType || tempActivityType == PartBType.Net)) { partBTags.Add(entry.Key, entry.Value); } } return(partBTags); }