diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/AzMonList.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/AzMonList.cs index 20af41e4197c0..af403d1cd8d20 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/AzMonList.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/AzMonList.cs @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#nullable disable // TODO: remove and fix errors - using System; using System.Buffers; using System.Collections; @@ -14,9 +12,9 @@ namespace Azure.Monitor.OpenTelemetry.Exporter.Internals { private static int s_allocationSize = 8; - private readonly KeyValuePair[] data; + private readonly KeyValuePair[] data; - private AzMonList(KeyValuePair[] data, int length) + private AzMonList(KeyValuePair[] data, int length) { this.data = data; this.Length = length; @@ -24,35 +22,30 @@ private AzMonList(KeyValuePair[] data, int length) public int Length { get; } - public ref KeyValuePair this[int index] + public ref KeyValuePair this[int index] { get => ref this.data[index]; } public static AzMonList Initialize() { - return new AzMonList(ArrayPool>.Shared.Rent(s_allocationSize), 0); + return new AzMonList(ArrayPool>.Shared.Rent(s_allocationSize), 0); } - public static void Add(ref AzMonList list, KeyValuePair keyValuePair) + public static void Add(ref AzMonList list, KeyValuePair keyValuePair) { - var data = list.data; - - if (data == null) - { - throw new InvalidOperationException("AzMonList instance is not initialized."); - } + var data = list.data ?? throw new InvalidOperationException("AzMonList instance is not initialized."); if (list.Length >= data.Length) { s_allocationSize = data.Length * 2; var previousData = data; - data = ArrayPool>.Shared.Rent(s_allocationSize); + data = ArrayPool>.Shared.Rent(s_allocationSize); var span = previousData.AsSpan(); span.CopyTo(data); - ArrayPool>.Shared.Return(previousData); + ArrayPool>.Shared.Return(previousData); } data[list.Length] = keyValuePair; @@ -64,7 +57,7 @@ public static void Clear(ref AzMonList list) list = new AzMonList(list.data, 0); } - public static object GetTagValue(ref AzMonList list, string tagName) + public static object? GetTagValue(ref AzMonList list, string tagName) { int length = list.Length; @@ -79,11 +72,11 @@ public static object GetTagValue(ref AzMonList list, string tagName) return null; } - internal static object[] GetTagValues(ref AzMonList list, params string[] tagNames) + internal static object?[] GetTagValues(ref AzMonList list, params string[] tagNames) { int lengthTagNames = tagNames.Length; int lengthList = list.Length; - object[] values = new object[lengthTagNames]; + object?[] values = new object[lengthTagNames]; for (int i = 0; i < lengthList; i++) { @@ -108,7 +101,7 @@ public void Return() var data = this.data; if (data != null) { - ArrayPool>.Shared.Return(data); + ArrayPool>.Shared.Return(data); } } @@ -119,10 +112,10 @@ IEnumerator IEnumerable.GetEnumerator() public struct Enumerator : IEnumerator { - private readonly KeyValuePair[] data; + private readonly KeyValuePair[] data; private readonly int length; private int index; - private KeyValuePair current; + private KeyValuePair current; public Enumerator(in AzMonList list) { diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/AzMonListExtensions.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/AzMonListExtensions.cs index 88cf2e0105f28..0aaa8c1736af4 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/AzMonListExtensions.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/AzMonListExtensions.cs @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#nullable disable // TODO: remove and fix errors - using System; using System.Runtime.CompilerServices; using Azure.Monitor.OpenTelemetry.Exporter.Models; @@ -14,7 +12,7 @@ internal static class AzMonListExtensions /// /// Gets http request url from activity tag objects. /// - internal static string GetRequestUrl(this AzMonList tagObjects) + internal static string? GetRequestUrl(this AzMonList tagObjects) { // From spec: one of the following combinations is required in case of server spans: // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#http-server-semantic-conventions @@ -22,7 +20,7 @@ internal static string GetRequestUrl(this AzMonList tagObjects) // http.scheme, http.host, http.target // http.scheme, http.server_name, net.host.port, http.target // http.scheme, net.host.name, net.host.port, http.target - string url = null; + string? url = null; url = tagObjects.GetUrlUsingHttpUrl(); if (url != null) { @@ -41,14 +39,14 @@ internal static string GetRequestUrl(this AzMonList tagObjects) } string defaultPort = GetDefaultHttpPort(httpScheme); - url = tagObjects.GetUrlUsingHttpHost(httpScheme, defaultPort, httpTarget); + url = tagObjects.GetUrlUsingHttpHost(httpScheme!, defaultPort, httpTarget!); if (url != null) { return url; } var httpServerName = AzMonList.GetTagValue(ref tagObjects, SemanticConventions.AttributeHttpServerName)?.ToString(); - string host; + string? host; if (!string.IsNullOrWhiteSpace(httpServerName)) { host = httpServerName; @@ -62,7 +60,7 @@ internal static string GetRequestUrl(this AzMonList tagObjects) var netHostPort = AzMonList.GetTagValue(ref tagObjects, SemanticConventions.AttributeNetHostPort)?.ToString(); if (!string.IsNullOrWhiteSpace(netHostPort)) { - url = tagObjects.GetUrlUsingHostAndPort(httpScheme, host, netHostPort, defaultPort, httpTarget); + url = tagObjects.GetUrlUsingHostAndPort(httpScheme!, host!, netHostPort!, defaultPort, httpTarget!); return url; } } @@ -74,7 +72,7 @@ internal static string GetRequestUrl(this AzMonList tagObjects) /// /// Gets http dependency url from activity tag objects. /// - internal static string GetDependencyUrl(this AzMonList tagObjects) + internal static string? GetDependencyUrl(this AzMonList tagObjects) { // From spec: one of the following combinations is required in case of client spans: // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#http-client @@ -82,7 +80,7 @@ internal static string GetDependencyUrl(this AzMonList tagObjects) // http.scheme, http.host, http.target // http.scheme, net.peer.name, net.peer.port, http.target // http.scheme, net.peer.ip, net.peer.port, http.target - string url = null; + string? url = null; url = tagObjects.GetUrlUsingHttpUrl(); if (url != null) { @@ -101,7 +99,7 @@ internal static string GetDependencyUrl(this AzMonList tagObjects) } string defaultPort = GetDefaultHttpPort(httpScheme); - url = tagObjects.GetUrlUsingHttpHost(httpScheme, defaultPort, httpTarget); + url = tagObjects.GetUrlUsingHttpHost(httpScheme!, defaultPort, httpTarget!); if (url != null) { return url; @@ -113,7 +111,7 @@ internal static string GetDependencyUrl(this AzMonList tagObjects) var netPeerPort = AzMonList.GetTagValue(ref tagObjects, SemanticConventions.AttributeNetPeerPort)?.ToString(); if (!string.IsNullOrWhiteSpace(netPeerPort)) { - url = tagObjects.GetUrlUsingHostAndPort(httpScheme, host, netPeerPort, defaultPort, httpTarget); + url = tagObjects.GetUrlUsingHostAndPort(httpScheme!, host!, netPeerPort!, defaultPort, httpTarget!); return url; } } @@ -123,7 +121,7 @@ internal static string GetDependencyUrl(this AzMonList tagObjects) } [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static string GetDefaultHttpPort(string httpScheme) + internal static string GetDefaultHttpPort(string? httpScheme) { if (string.Equals(httpScheme, "http", StringComparison.OrdinalIgnoreCase)) { @@ -140,9 +138,13 @@ internal static string GetDefaultHttpPort(string httpScheme) } [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static string GetDefaultDbPort(string dbSystem) + internal static string GetDefaultDbPort(string? dbSystem) { - if (string.Equals(dbSystem, "mssql", StringComparison.OrdinalIgnoreCase)) + if (dbSystem == null) + { + return "0"; + } + else if (string.Equals(dbSystem, "mssql", StringComparison.OrdinalIgnoreCase)) { return "1433"; } @@ -157,9 +159,9 @@ internal static string GetDefaultDbPort(string dbSystem) } [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static string GetUrlUsingHttpUrl(this AzMonList tagObjects) + internal static string? GetUrlUsingHttpUrl(this AzMonList tagObjects) { - string url = null; + string? url = null; var httpUrl = AzMonList.GetTagValue(ref tagObjects, SemanticConventions.AttributeHttpUrl)?.ToString(); if (!string.IsNullOrWhiteSpace(httpUrl)) { @@ -169,14 +171,14 @@ internal static string GetUrlUsingHttpUrl(this AzMonList tagObjects) return url; } - internal static string GetUrlUsingHttpHost(this AzMonList tagObjects, string httpScheme, string defaultPort, string httpTarget) + internal static string? GetUrlUsingHttpHost(this AzMonList tagObjects, string httpScheme, string defaultPort, string httpTarget) { - string url = null; + string? url = null; var httpHost = AzMonList.GetTagValue(ref tagObjects, SemanticConventions.AttributeHttpHost)?.ToString(); if (!string.IsNullOrWhiteSpace(httpHost)) { string portSection = $":{defaultPort}"; - if (httpHost.EndsWith(portSection, StringComparison.OrdinalIgnoreCase)) + if (httpHost!.EndsWith(portSection, StringComparison.OrdinalIgnoreCase)) { var truncatedHost = httpHost.Substring(0, httpHost.IndexOf(portSection, StringComparison.OrdinalIgnoreCase)); url = $"{httpScheme}://{truncatedHost}{httpTarget}"; @@ -190,9 +192,9 @@ internal static string GetUrlUsingHttpHost(this AzMonList tagObjects, string htt return url; } - internal static string GetUrlUsingHostAndPort(this AzMonList tagObjects, string httpScheme, string host, string port, string defaultPort, string httpTarget) + internal static string? GetUrlUsingHostAndPort(this AzMonList tagObjects, string httpScheme, string host, string port, string defaultPort, string httpTarget) { - string url = null; + string? url = null; if (port == defaultPort) { url = $"{httpScheme}://{host}{httpTarget}"; @@ -205,10 +207,10 @@ internal static string GetUrlUsingHostAndPort(this AzMonList tagObjects, string return url; } - internal static string GetHostUsingNetPeerAttributes(this AzMonList tagObjects) + internal static string? GetHostUsingNetPeerAttributes(this AzMonList tagObjects) { var netPeerName = AzMonList.GetTagValue(ref tagObjects, SemanticConventions.AttributeNetPeerName)?.ToString(); - string host; + string? host; if (!string.IsNullOrWhiteSpace(netPeerName)) { host = netPeerName; @@ -222,9 +224,9 @@ internal static string GetHostUsingNetPeerAttributes(this AzMonList tagObjects) } [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static string GetTargetUsingNetPeerAttributes(this AzMonList tagObjects, string defaultPort) + internal static string? GetTargetUsingNetPeerAttributes(this AzMonList tagObjects, string defaultPort) { - string target = tagObjects.GetHostUsingNetPeerAttributes(); + string? target = tagObjects.GetHostUsingNetPeerAttributes(); if (!string.IsNullOrWhiteSpace(target)) { var netPeerPort = AzMonList.GetTagValue(ref tagObjects, SemanticConventions.AttributeNetPeerPort)?.ToString(); @@ -240,9 +242,9 @@ internal static string GetTargetUsingNetPeerAttributes(this AzMonList tagObjects /// /// Gets Http dependency target from activity tag objects. /// - internal static string GetHttpDependencyTarget(this AzMonList tagObjects) + internal static string? GetHttpDependencyTarget(this AzMonList tagObjects) { - string target; + string? target; string defaultPort = GetDefaultHttpPort(AzMonList.GetTagValue(ref tagObjects, SemanticConventions.AttributeHttpScheme)?.ToString()); var peerService = AzMonList.GetTagValue(ref tagObjects, SemanticConventions.AttributePeerService)?.ToString(); if (!string.IsNullOrWhiteSpace(peerService)) @@ -255,7 +257,7 @@ internal static string GetHttpDependencyTarget(this AzMonList tagObjects) if (!string.IsNullOrWhiteSpace(httpHost)) { string portSection = $":{defaultPort}"; - if (httpHost.EndsWith(portSection, StringComparison.OrdinalIgnoreCase)) + if (httpHost!.EndsWith(portSection, StringComparison.OrdinalIgnoreCase)) { var truncatedHost = httpHost.Substring(0, httpHost.IndexOf(portSection, StringComparison.OrdinalIgnoreCase)); target = truncatedHost; @@ -268,7 +270,9 @@ internal static string GetHttpDependencyTarget(this AzMonList tagObjects) } var httpUrl = AzMonList.GetTagValue(ref tagObjects, SemanticConventions.AttributeHttpUrl)?.ToString(); - if (!string.IsNullOrWhiteSpace(httpUrl) && Uri.TryCreate(httpUrl.ToString(), UriKind.RelativeOrAbsolute, out var uri) && uri.IsAbsoluteUri) + if (!string.IsNullOrWhiteSpace(httpUrl) + && Uri.TryCreate(httpUrl!.ToString(), UriKind.RelativeOrAbsolute, out var uri) + && uri.IsAbsoluteUri) { target = uri.Authority; if (!string.IsNullOrWhiteSpace(target)) @@ -285,9 +289,9 @@ internal static string GetHttpDependencyTarget(this AzMonList tagObjects) /// /// Gets Database dependency target from activity tag objects. /// - internal static string GetDbDependencyTarget(this AzMonList tagObjects) + internal static string? GetDbDependencyTarget(this AzMonList tagObjects) { - string target = null; + string? target = null; string defaultPort = GetDefaultDbPort(AzMonList.GetTagValue(ref tagObjects, SemanticConventions.AttributeDbSystem)?.ToString()); var peerService = AzMonList.GetTagValue(ref tagObjects, SemanticConventions.AttributePeerService)?.ToString(); if (!string.IsNullOrWhiteSpace(peerService)) @@ -299,7 +303,7 @@ internal static string GetDbDependencyTarget(this AzMonList tagObjects) target = tagObjects.GetTargetUsingNetPeerAttributes(defaultPort); } - string dbName = AzMonList.GetTagValue(ref tagObjects, SemanticConventions.AttributeDbName)?.ToString(); + string? dbName = AzMonList.GetTagValue(ref tagObjects, SemanticConventions.AttributeDbName)?.ToString(); bool isTargetEmpty = string.IsNullOrWhiteSpace(target); bool isDbNameEmpty = string.IsNullOrWhiteSpace(dbName); if (!isTargetEmpty && !isDbNameEmpty) @@ -321,7 +325,7 @@ internal static string GetDbDependencyTarget(this AzMonList tagObjects) /// /// Gets dependency target from activity tag objects. /// - internal static string GetDependencyTarget(this AzMonList tagObjects, OperationType type) + internal static string? GetDependencyTarget(this AzMonList tagObjects, OperationType type) { switch (type) { @@ -334,7 +338,7 @@ internal static string GetDependencyTarget(this AzMonList tagObjects, OperationT } } - internal static string GetHttpDependencyName(this AzMonList tagObjects, string httpUrl) + internal static string? GetHttpDependencyName(this AzMonList tagObjects, string? httpUrl) { if (string.IsNullOrWhiteSpace(httpUrl)) { @@ -344,7 +348,7 @@ internal static string GetHttpDependencyName(this AzMonList tagObjects, string h var httpMethod = AzMonList.GetTagValue(ref tagObjects, SemanticConventions.AttributeHttpMethod)?.ToString(); if (!string.IsNullOrWhiteSpace(httpMethod)) { - if (Uri.TryCreate(httpUrl.ToString(), UriKind.RelativeOrAbsolute, out var uri) && uri.IsAbsoluteUri) + if (Uri.TryCreate(httpUrl!.ToString(), UriKind.RelativeOrAbsolute, out var uri) && uri.IsAbsoluteUri) { return $"{httpMethod} {uri.AbsolutePath}"; } @@ -353,7 +357,7 @@ internal static string GetHttpDependencyName(this AzMonList tagObjects, string h return null; } - internal static string GetDependencyType(this AzMonList tagObjects, OperationType operationType) + internal static string? GetDependencyType(this AzMonList tagObjects, OperationType operationType) { switch (operationType) { diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/TagEnumerationState.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/TagEnumerationState.cs index 682e6847ef57b..5f18eba179fe4 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/TagEnumerationState.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/TagEnumerationState.cs @@ -79,7 +79,7 @@ public void ForEach(IEnumerable> activityTags) if (activityTag.Value is Array array) { - AzMonList.Add(ref UnMappedTags, new KeyValuePair(activityTag.Key, array.ToCommaDelimitedString())); + AzMonList.Add(ref UnMappedTags, new KeyValuePair(activityTag.Key, array.ToCommaDelimitedString())); continue; } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/TraceHelper.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/TraceHelper.cs index 0a07d56f3c291..47ad7eeb6b73a 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/TraceHelper.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/TraceHelper.cs @@ -133,7 +133,7 @@ internal static void AddActivityLinksToProperties(Activity activity, ref AzMonLi linksJson.Append(']'); - AzMonList.Add(ref UnMappedTags, new KeyValuePair(msLinks, linksJson.ToString())); + AzMonList.Add(ref UnMappedTags, new KeyValuePair(msLinks, linksJson.ToString())); } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/tests/Azure.Monitor.OpenTelemetry.Exporter.Tests/AzMonListExtensionsTests.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/tests/Azure.Monitor.OpenTelemetry.Exporter.Tests/AzMonListExtensionsTests.cs index b52d13f7c9686..d05096a417945 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/tests/Azure.Monitor.OpenTelemetry.Exporter.Tests/AzMonListExtensionsTests.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/tests/Azure.Monitor.OpenTelemetry.Exporter.Tests/AzMonListExtensionsTests.cs @@ -15,9 +15,9 @@ public class AzMonListExtensionsTests public void HttpRequestUrlIsSetUsingHttpUrl() { var mappedTags = AzMonList.Initialize(); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpUrl, "https://www.wiki.com")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpUrl, "https://www.wiki.com")); - string url = mappedTags.GetRequestUrl(); + string? url = mappedTags.GetRequestUrl(); Assert.Equal("https://www.wiki.com", url); } @@ -29,9 +29,9 @@ public void HttpRequestUrlIsSetUsingHttpUrl() public void HttpRequestUrlIsSetUsing_Scheme_Host_Target(string httpScheme, string port) { var mappedTags = AzMonList.Initialize(); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, httpScheme)); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpHost, $"www.httphost.org:{port}")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpTarget, "/path")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, httpScheme)); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpHost, $"www.httphost.org:{port}")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpTarget, "/path")); string expectedUrl; if (port == "80" || port == "443") { @@ -41,7 +41,7 @@ public void HttpRequestUrlIsSetUsing_Scheme_Host_Target(string httpScheme, strin { expectedUrl = $"{httpScheme}://www.httphost.org:{port}/path"; } - string url = mappedTags.GetRequestUrl(); + string? url = mappedTags.GetRequestUrl(); Assert.Equal(expectedUrl, url); } @@ -62,10 +62,10 @@ public void HttpRequestUrlIsSetUsing_Scheme_ServerName_Port_Target(string port) { httpScheme = "https"; } - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, httpScheme)); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpServerName, "servername.com")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetHostPort, port)); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpTarget, "/path")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, httpScheme)); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpServerName, "servername.com")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetHostPort, port)); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpTarget, "/path")); string expectedUrl; if (port == "80" || port == "443") { @@ -75,7 +75,7 @@ public void HttpRequestUrlIsSetUsing_Scheme_ServerName_Port_Target(string port) { expectedUrl = $"{httpScheme}://servername.com:{port}/path"; } - string url = mappedTags.GetRequestUrl(); + string? url = mappedTags.GetRequestUrl(); Assert.Equal(expectedUrl, url); } @@ -96,10 +96,10 @@ public void HttpRequestUrlIsSetUsing_Scheme_NetHostName_Port_Target(string port) { httpScheme = "https"; } - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, httpScheme)); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetHostName, "localhost")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetHostPort, port)); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpTarget, "/path")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, httpScheme)); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetHostName, "localhost")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetHostPort, port)); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpTarget, "/path")); string expectedUrl; if (port == "80" || port == "443") { @@ -109,7 +109,7 @@ public void HttpRequestUrlIsSetUsing_Scheme_NetHostName_Port_Target(string port) { expectedUrl = $"{httpScheme}://localhost:{port}/path"; } - string url = mappedTags.GetRequestUrl(); + string? url = mappedTags.GetRequestUrl(); Assert.Equal(expectedUrl, url); } @@ -117,15 +117,15 @@ public void HttpRequestUrlIsSetUsing_Scheme_NetHostName_Port_Target(string port) public void HttpUrlAttributeTakesPrecedenceSettingHttpRequestUrl() { var mappedTags = AzMonList.Initialize(); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpUrl, "https://www.wiki.com")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, "http")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetHostName, "localhost")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpHost, "www.httphost.org")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpServerName, "servername.com")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetHostPort, "8888")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpTarget, "/path")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpUrl, "https://www.wiki.com")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, "http")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetHostName, "localhost")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpHost, "www.httphost.org")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpServerName, "servername.com")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetHostPort, "8888")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpTarget, "/path")); string expectedUrl = "https://www.wiki.com"; - string url = mappedTags.GetRequestUrl(); + string? url = mappedTags.GetRequestUrl(); Assert.Equal(expectedUrl, url); } @@ -133,14 +133,14 @@ public void HttpUrlAttributeTakesPrecedenceSettingHttpRequestUrl() public void HttpHostAttributeTakesPrecedenceSettingHttpRequestUrl() { var mappedTags = AzMonList.Initialize(); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, "http")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetHostName, "localhost")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpHost, "www.httphost.org")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpServerName, "servername.com")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetHostPort, "8888")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpTarget, "/path")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, "http")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetHostName, "localhost")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpHost, "www.httphost.org")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpServerName, "servername.com")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetHostPort, "8888")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpTarget, "/path")); string expectedUrl = "http://www.httphost.org/path"; - string url = mappedTags.GetRequestUrl(); + string? url = mappedTags.GetRequestUrl(); Assert.Equal(expectedUrl, url); } @@ -148,13 +148,13 @@ public void HttpHostAttributeTakesPrecedenceSettingHttpRequestUrl() public void HttpServerNameAttributeTakesPrecedenceSettingHttpRequestUrl() { var mappedTags = AzMonList.Initialize(); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, "http")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetHostName, "localhost")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpServerName, "servername.com")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetHostPort, "8888")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpTarget, "/path")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, "http")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetHostName, "localhost")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpServerName, "servername.com")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetHostPort, "8888")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpTarget, "/path")); string expectedUrl = "http://servername.com:8888/path"; - string url = mappedTags.GetRequestUrl(); + string? url = mappedTags.GetRequestUrl(); Assert.Equal(expectedUrl, url); } @@ -162,12 +162,12 @@ public void HttpServerNameAttributeTakesPrecedenceSettingHttpRequestUrl() public void NetHostNameAttributeTakesPrecedenceSettingHttpRequestUrl() { var mappedTags = AzMonList.Initialize(); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, "http")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetHostName, "localhost")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetHostPort, "8888")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpTarget, "/path")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, "http")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetHostName, "localhost")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetHostPort, "8888")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpTarget, "/path")); string expectedUrl = "http://localhost:8888/path"; - string url = mappedTags.GetRequestUrl(); + string? url = mappedTags.GetRequestUrl(); Assert.Equal(expectedUrl, url); } @@ -175,9 +175,9 @@ public void NetHostNameAttributeTakesPrecedenceSettingHttpRequestUrl() public void HttpDependencyUrlIsSetUsingHttpUrl() { var mappedTags = AzMonList.Initialize(); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpUrl, "https://www.wiki.com")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpUrl, "https://www.wiki.com")); - string url = mappedTags.GetDependencyUrl(); + string? url = mappedTags.GetDependencyUrl(); Assert.Equal("https://www.wiki.com", url); } @@ -189,9 +189,9 @@ public void HttpDependencyUrlIsSetUsingHttpUrl() public void HttpDependencyUrlIsSetUsing_Scheme_Host_Target(string httpScheme, string port) { var mappedTags = AzMonList.Initialize(); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, httpScheme)); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpHost, $"www.httphost.org:{port}")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpTarget, "/path")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, httpScheme)); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpHost, $"www.httphost.org:{port}")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpTarget, "/path")); string expectedUrl; if (port == "80" || port == "443") { @@ -201,7 +201,7 @@ public void HttpDependencyUrlIsSetUsing_Scheme_Host_Target(string httpScheme, st { expectedUrl = $"{httpScheme}://www.httphost.org:{port}/path"; } - string url = mappedTags.GetDependencyUrl(); + string? url = mappedTags.GetDependencyUrl(); Assert.Equal(expectedUrl, url); } @@ -222,10 +222,10 @@ public void HttpDependencyUrlIsSetUsing_Scheme_PeerName_Port_Target(string port) { httpScheme = "https"; } - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, httpScheme)); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerName, "servername.com")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerPort, port)); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpTarget, "/path")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, httpScheme)); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerName, "servername.com")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerPort, port)); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpTarget, "/path")); string expectedUrl; if (port == "80" || port == "443") { @@ -235,7 +235,7 @@ public void HttpDependencyUrlIsSetUsing_Scheme_PeerName_Port_Target(string port) { expectedUrl = $"{httpScheme}://servername.com:{port}/path"; } - string url = mappedTags.GetDependencyUrl(); + string? url = mappedTags.GetDependencyUrl(); Assert.Equal(expectedUrl, url); } @@ -256,10 +256,10 @@ public void HttpDependencyUrlIsSetUsing_Scheme_PeerIp_Port_Target(string port) { httpScheme = "https"; } - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, httpScheme)); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerIp, "127.0.0.1")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerPort, port)); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpTarget, "/path")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, httpScheme)); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerIp, "127.0.0.1")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerPort, port)); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpTarget, "/path")); string expectedUrl; if (port == "80" || port == "443") { @@ -269,7 +269,7 @@ public void HttpDependencyUrlIsSetUsing_Scheme_PeerIp_Port_Target(string port) { expectedUrl = $"{httpScheme}://127.0.0.1:{port}/path"; } - string url = mappedTags.GetDependencyUrl(); + string? url = mappedTags.GetDependencyUrl(); Assert.Equal(expectedUrl, url); } @@ -277,15 +277,15 @@ public void HttpDependencyUrlIsSetUsing_Scheme_PeerIp_Port_Target(string port) public void HttpUrlAttributeTakesPrecedenceSettingHttpDependencyUrl() { var mappedTags = AzMonList.Initialize(); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpUrl, "https://www.wiki.com")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, "http")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerName, "servername.com")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpHost, "www.httphost.org")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerIp, "127.0.0.1")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerPort, "8888")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpTarget, "/path")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpUrl, "https://www.wiki.com")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, "http")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerName, "servername.com")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpHost, "www.httphost.org")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerIp, "127.0.0.1")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerPort, "8888")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpTarget, "/path")); string expectedUrl = "https://www.wiki.com"; - string url = mappedTags.GetDependencyUrl(); + string? url = mappedTags.GetDependencyUrl(); Assert.Equal(expectedUrl, url); } @@ -293,14 +293,14 @@ public void HttpUrlAttributeTakesPrecedenceSettingHttpDependencyUrl() public void HttpHostAttributeTakesPrecedenceSettingHttpDependencyUrl() { var mappedTags = AzMonList.Initialize(); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, "http")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerName, "servername.com")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpHost, "www.httphost.org")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerIp, "127.0.0.1")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerPort, "8888")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpTarget, "/path")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, "http")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerName, "servername.com")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpHost, "www.httphost.org")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerIp, "127.0.0.1")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerPort, "8888")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpTarget, "/path")); string expectedUrl = "http://www.httphost.org/path"; - string url = mappedTags.GetDependencyUrl(); + string? url = mappedTags.GetDependencyUrl(); Assert.Equal(expectedUrl, url); } @@ -308,13 +308,13 @@ public void HttpHostAttributeTakesPrecedenceSettingHttpDependencyUrl() public void NetPeerNameAttributeTakesPrecedenceSettingHttpDependencyUrl() { var mappedTags = AzMonList.Initialize(); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, "http")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerName, "servername.com")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerIp, "127.0.0.1")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerPort, "8888")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpTarget, "/path")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, "http")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerName, "servername.com")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerIp, "127.0.0.1")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerPort, "8888")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpTarget, "/path")); string expectedUrl = "http://servername.com:8888/path"; - string url = mappedTags.GetDependencyUrl(); + string? url = mappedTags.GetDependencyUrl(); Assert.Equal(expectedUrl, url); } @@ -322,12 +322,12 @@ public void NetPeerNameAttributeTakesPrecedenceSettingHttpDependencyUrl() public void NetPeerIpAttributeTakesPrecedenceSettingHttpDependencyUrl() { var mappedTags = AzMonList.Initialize(); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, "http")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerIp, "127.0.0.1")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerPort, "8888")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpTarget, "/path")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, "http")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerIp, "127.0.0.1")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerPort, "8888")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpTarget, "/path")); string expectedUrl = "http://127.0.0.1:8888/path"; - string url = mappedTags.GetDependencyUrl(); + string? url = mappedTags.GetDependencyUrl(); Assert.Equal(expectedUrl, url); } @@ -345,9 +345,9 @@ public void HttpUrlIsNullByDefault() internal void DependencyTargetIsSetUsingPeerService(OperationType type) { var mappedTags = AzMonList.Initialize(); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributePeerService, "servicename")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributePeerService, "servicename")); string expectedTarget = "servicename"; - string target = mappedTags.GetDependencyTarget(type); + string? target = mappedTags.GetDependencyTarget(type); Assert.Equal(expectedTarget, target); } @@ -359,8 +359,8 @@ internal void DependencyTargetIsSetUsingPeerService(OperationType type) public void HttpDependencyTargetIsSetUsingHttpHost(string httpScheme, string port) { var mappedTags = AzMonList.Initialize(); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, httpScheme)); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpHost, $"www.httphost.org:{port}")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, httpScheme)); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpHost, $"www.httphost.org:{port}")); string expectedTarget; if (port == "80" || port == "443") { @@ -370,7 +370,7 @@ public void HttpDependencyTargetIsSetUsingHttpHost(string httpScheme, string por { expectedTarget = $"www.httphost.org:{port}"; } - string target = mappedTags.GetDependencyTarget(OperationType.Http); + string? target = mappedTags.GetDependencyTarget(OperationType.Http); Assert.Equal(expectedTarget, target); } @@ -383,11 +383,11 @@ public void HttpDependencyTargetIsSetUsingHttpUrl(string port) var mappedTags = AzMonList.Initialize(); if (port == "80") { - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpUrl, $"http://www.wiki.com:{port}/")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpUrl, $"http://www.wiki.com:{port}/")); } else { - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpUrl, $"https://www.wiki.com:{port}/")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpUrl, $"https://www.wiki.com:{port}/")); } string expectedTarget; if (port == "80" || port == "443") @@ -398,7 +398,7 @@ public void HttpDependencyTargetIsSetUsingHttpUrl(string port) { expectedTarget = $"www.wiki.com:{port}"; } - string target = mappedTags.GetDependencyTarget(OperationType.Http); + string? target = mappedTags.GetDependencyTarget(OperationType.Http); Assert.Equal(expectedTarget, target); } @@ -411,10 +411,10 @@ public void HttpDependencyTargetIsSetUsingHttpUrl(string port) internal void DependencyTargetIsSetUsingNetPeerName(string httpScheme, string port, OperationType type) { var mappedTags = AzMonList.Initialize(); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, httpScheme)); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerName, $"servername.com")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerPort, port)); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeDbSystem, "mssql")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, httpScheme)); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerName, $"servername.com")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerPort, port)); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeDbSystem, "mssql")); string expectedTarget; if (port == "80" || port == "443" || port == "1433") { @@ -424,7 +424,7 @@ internal void DependencyTargetIsSetUsingNetPeerName(string httpScheme, string po { expectedTarget = $"servername.com:{port}"; } - string target = mappedTags.GetDependencyTarget(type); + string? target = mappedTags.GetDependencyTarget(type); Assert.Equal(expectedTarget, target); } @@ -437,10 +437,10 @@ internal void DependencyTargetIsSetUsingNetPeerName(string httpScheme, string po internal void DependencyTargetIsSetUsingNetPeerIp(string httpScheme, string port, OperationType type) { var mappedTags = AzMonList.Initialize(); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, httpScheme)); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeDbSystem, "mssql")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerIp, $"127.0.0.1")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerPort, port)); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, httpScheme)); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeDbSystem, "mssql")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerIp, $"127.0.0.1")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerPort, port)); string expectedTarget; if (port == "80" || port == "443" || port == "1433") { @@ -450,7 +450,7 @@ internal void DependencyTargetIsSetUsingNetPeerIp(string httpScheme, string port { expectedTarget = $"127.0.0.1:{port}"; } - string target = mappedTags.GetDependencyTarget(type); + string? target = mappedTags.GetDependencyTarget(type); Assert.Equal(expectedTarget, target); } @@ -460,17 +460,17 @@ internal void DependencyTargetIsSetUsingNetPeerIp(string httpScheme, string port internal void PeerServiceTakesPrecedenceSettingDependencyTarget(OperationType type) { var mappedTags = AzMonList.Initialize(); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributePeerService, "servicename")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpHost, $"www.httphost.org:8888")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpUrl, $"http://www.wiki.com:8888/")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, "http")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeDbSystem, "mssql")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerName, $"servername.com")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerIp, $"127.0.0.1")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerPort, "8888")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributePeerService, "servicename")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpHost, $"www.httphost.org:8888")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpUrl, $"http://www.wiki.com:8888/")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, "http")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeDbSystem, "mssql")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerName, $"servername.com")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerIp, $"127.0.0.1")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerPort, "8888")); string expectedTarget = "servicename"; - string target = mappedTags.GetDependencyTarget(type); + string? target = mappedTags.GetDependencyTarget(type); Assert.Equal(expectedTarget, target); } @@ -478,15 +478,15 @@ internal void PeerServiceTakesPrecedenceSettingDependencyTarget(OperationType ty public void HttpHostTakesPrecedenceSettingHttpDependencyTarget() { var mappedTags = AzMonList.Initialize(); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpHost, $"www.httphost.org:8888")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpUrl, $"http://www.wiki.com:8888/")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, "http")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerName, $"servername.com")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerIp, $"127.0.0.1")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerPort, "8888")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpHost, $"www.httphost.org:8888")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpUrl, $"http://www.wiki.com:8888/")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, "http")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerName, $"servername.com")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerIp, $"127.0.0.1")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerPort, "8888")); string expectedTarget = "www.httphost.org:8888"; - string target = mappedTags.GetDependencyTarget(OperationType.Http); + string? target = mappedTags.GetDependencyTarget(OperationType.Http); Assert.Equal(expectedTarget, target); } @@ -494,14 +494,14 @@ public void HttpHostTakesPrecedenceSettingHttpDependencyTarget() public void HttpUrlTakesPrecedenceSettingHttpDependencyTarget() { var mappedTags = AzMonList.Initialize(); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpUrl, $"http://www.wiki.com:8888/")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, "http")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerName, $"servername.com")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerIp, $"127.0.0.1")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerPort, "8888")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpUrl, $"http://www.wiki.com:8888/")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, "http")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerName, $"servername.com")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerIp, $"127.0.0.1")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerPort, "8888")); string expectedTarget = "www.wiki.com:8888"; - string target = mappedTags.GetDependencyTarget(OperationType.Http); + string? target = mappedTags.GetDependencyTarget(OperationType.Http); Assert.Equal(expectedTarget, target); } @@ -511,14 +511,14 @@ public void HttpUrlTakesPrecedenceSettingHttpDependencyTarget() internal void PeerNameTakesPrecedenceSettingDependencyTarget(OperationType type) { var mappedTags = AzMonList.Initialize(); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, "http")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeDbSystem, "mssql")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerName, $"servername.com")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerIp, $"127.0.0.1")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerPort, "8888")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, "http")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeDbSystem, "mssql")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerName, $"servername.com")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerIp, $"127.0.0.1")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerPort, "8888")); string expectedTarget = "servername.com:8888"; - string target = mappedTags.GetDependencyTarget(type); + string? target = mappedTags.GetDependencyTarget(type); Assert.Equal(expectedTarget, target); } @@ -528,13 +528,13 @@ internal void PeerNameTakesPrecedenceSettingDependencyTarget(OperationType type) internal void PeerIpTakesPrecedenceSettingDependencyTarget(OperationType type) { var mappedTags = AzMonList.Initialize(); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, "http")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeDbSystem, "mssql")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerIp, $"127.0.0.1")); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerPort, "8888")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeHttpScheme, "http")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeDbSystem, "mssql")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerIp, $"127.0.0.1")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerPort, "8888")); string expectedTarget = "127.0.0.1:8888"; - string target = mappedTags.GetDependencyTarget(type); + string? target = mappedTags.GetDependencyTarget(type); Assert.Equal(expectedTarget, target); } @@ -544,7 +544,7 @@ internal void PeerIpTakesPrecedenceSettingDependencyTarget(OperationType type) internal void DependencyTargetIsNullByDefault(OperationType type) { var mappedTags = AzMonList.Initialize(); - string target = mappedTags.GetDependencyTarget(type); + string? target = mappedTags.GetDependencyTarget(type); Assert.Null(target); } @@ -555,11 +555,11 @@ internal void DependencyTargetIsNullByDefault(OperationType type) public void DbNameIsAppendedToTargetDerivedFromNetAttributesforDBDependencyTarget(string peerService, string netPeerName, string netPeerIp, string netPeerPort) { var mappedTags = AzMonList.Initialize(); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributePeerService, peerService)); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerName, netPeerName)); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerIp, netPeerIp)); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerPort, netPeerPort)); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeDbName, "DbName")); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributePeerService, peerService)); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerName, netPeerName)); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerIp, netPeerIp)); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeNetPeerPort, netPeerPort)); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeDbName, "DbName")); string? hostName = null; if (peerService != null) { @@ -574,7 +574,7 @@ public void DbNameIsAppendedToTargetDerivedFromNetAttributesforDBDependencyTarge hostName = $"{netPeerIp}:{netPeerPort}"; } string expectedTarget = $"{hostName} | DbName"; - string target = mappedTags.GetDbDependencyTarget(); + string? target = mappedTags.GetDbDependencyTarget(); Assert.Equal(expectedTarget, target); } @@ -582,8 +582,8 @@ public void DbNameIsAppendedToTargetDerivedFromNetAttributesforDBDependencyTarge public void DbDependencyTargetIsSetToDbNameWhenNetAttributesAreNotPresent() { var mappedTags = AzMonList.Initialize(); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeDbName, "DbName")); - string target = mappedTags.GetDbDependencyTarget(); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeDbName, "DbName")); + string? target = mappedTags.GetDbDependencyTarget(); Assert.Equal("DbName", target); } @@ -591,8 +591,8 @@ public void DbDependencyTargetIsSetToDbNameWhenNetAttributesAreNotPresent() public void DbDependencyTargetIsSetToDbSystemWhenNetAndDbNameAttributesAreNotPresent() { var mappedTags = AzMonList.Initialize(); - AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeDbSystem, "DbSystem")); - string target = mappedTags.GetDbDependencyTarget(); + AzMonList.Add(ref mappedTags, new KeyValuePair(SemanticConventions.AttributeDbSystem, "DbSystem")); + string? target = mappedTags.GetDbDependencyTarget(); Assert.Equal("DbSystem", target); } @@ -600,7 +600,7 @@ public void DbDependencyTargetIsSetToDbSystemWhenNetAndDbNameAttributesAreNotPre public void DbDependencyTargetIsSetToNullByDefault() { var mappedTags = AzMonList.Initialize(); - string target = mappedTags.GetDbDependencyTarget(); + string? target = mappedTags.GetDbDependencyTarget(); Assert.Null(target); } } diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/tests/Azure.Monitor.OpenTelemetry.Exporter.Tests/TagsTests.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/tests/Azure.Monitor.OpenTelemetry.Exporter.Tests/TagsTests.cs index b3367f847811c..99f1886bedfc1 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/tests/Azure.Monitor.OpenTelemetry.Exporter.Tests/TagsTests.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/tests/Azure.Monitor.OpenTelemetry.Exporter.Tests/TagsTests.cs @@ -318,7 +318,7 @@ public void TagObjects_Diff_DataTypes() Assert.Equal(1.1, AzMonList.GetTagValue(ref monitorTags.UnMappedTags, "doubleKey")); Assert.Equal("test", AzMonList.GetTagValue(ref monitorTags.UnMappedTags, "stringKey")); Assert.Equal(true, AzMonList.GetTagValue(ref monitorTags.UnMappedTags, "boolKey")); - Assert.Equal("Azure.Monitor.OpenTelemetry.Exporter.Tests.TagsTests+Test", AzMonList.GetTagValue(ref monitorTags.UnMappedTags, "objectKey").ToString()); + Assert.Equal("Azure.Monitor.OpenTelemetry.Exporter.Tests.TagsTests+Test", AzMonList.GetTagValue(ref monitorTags.UnMappedTags, "objectKey")?.ToString()); Assert.Equal("1,2,3", AzMonList.GetTagValue(ref monitorTags.UnMappedTags, "arrayKey")); }