From c01e0f231f6149af0d6e71b5d7b0430ef9fa6a3d Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Tue, 18 Jul 2023 13:21:11 -0700 Subject: [PATCH 1/7] Update location ip mapping --- .../src/Internals/ActivityTagsProcessor.cs | 1 + .../src/Internals/SemanticConventions.cs | 1 + .../src/Internals/TraceHelper.cs | 8 +++---- .../TelemetryItemTests.cs | 23 +------------------ 4 files changed, 7 insertions(+), 26 deletions(-) diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/ActivityTagsProcessor.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/ActivityTagsProcessor.cs index 8771638e95bda..45873ee9e5d0e 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/ActivityTagsProcessor.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/ActivityTagsProcessor.cs @@ -37,6 +37,7 @@ internal struct ActivityTagsProcessor SemanticConventions.AttributeUrlScheme, SemanticConventions.AttributeUrlQuery, SemanticConventions.AttributeUserAgentOriginal, + SemanticConventions.AttributeClientAddress, // required - Azure SemanticConventions.AttributeAzureNameSpace, diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/SemanticConventions.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/SemanticConventions.cs index f544ff0e1a264..2a3b7bf4506a4 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/SemanticConventions.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/SemanticConventions.cs @@ -152,6 +152,7 @@ internal static class SemanticConventions public const string AttributeExceptionStacktrace = "exception.stacktrace"; // Http v1.21.0 https://github.com/open-telemetry/opentelemetry-specification/blob/v1.21.0/specification/trace/semantic_conventions/http.md + public const string AttributeClientAddress = "client.address"; // replaces: "http.client_ip" (AttributeHttpClientIp) public const string AttributeHttpRequestMethod = "http.request.method"; // replaces: "http.method" (AttributeHttpMethod) public const string AttributeHttpResponseStatusCode = "http.response.status_code"; // replaces: "http.status_code" (AttributeHttpStatusCode) public const string AttributeNetworkProtocolVersion = "network.protocol.version"; // replaces: "http.flavor" (AttributeHttpFlavor) 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 79d4404657b64..a3c29fb0d9396 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/TraceHelper.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/TraceHelper.cs @@ -140,13 +140,13 @@ internal static ActivityTagsProcessor EnumerateActivityTags(Activity activity) internal static string? GetLocationIp(ref AzMonList MappedTags) { - var httpClientIp = AzMonList.GetTagValue(ref MappedTags, SemanticConventions.AttributeHttpClientIP)?.ToString(); - if (!string.IsNullOrWhiteSpace(httpClientIp)) + var clientIp = AzMonList.GetTagValue(ref MappedTags, SemanticConventions.AttributeClientAddress)?.ToString(); + if (!string.IsNullOrWhiteSpace(clientIp)) { - return httpClientIp; + return clientIp; } - return AzMonList.GetTagValue(ref MappedTags, SemanticConventions.AttributeNetPeerIp)?.ToString(); + return null; } internal static string GetOperationName(Activity activity, ref AzMonList MappedTags) diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/tests/Azure.Monitor.OpenTelemetry.Exporter.Tests/TelemetryItemTests.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/tests/Azure.Monitor.OpenTelemetry.Exporter.Tests/TelemetryItemTests.cs index eb16549607fef..b50b22d246828 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/tests/Azure.Monitor.OpenTelemetry.Exporter.Tests/TelemetryItemTests.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/tests/Azure.Monitor.OpenTelemetry.Exporter.Tests/TelemetryItemTests.cs @@ -204,28 +204,7 @@ public void AiLocationIpIsSetAsHttpClientIpForHttpServerSpans() startTime: DateTime.UtcNow); Assert.NotNull(activity); - activity.SetTag(SemanticConventions.AttributeHttpClientIP, "127.0.0.1"); - activity.SetTag(SemanticConventions.AttributeHttpRequestMethod, "GET"); - - var activityTagsProcessor = TraceHelper.EnumerateActivityTags(activity); - var telemetryItems = TraceHelper.OtelToAzureMonitorTrace(new Batch(new Activity[] { activity }, 1), null, "instrumentationKey"); - var telemetryItem = telemetryItems.FirstOrDefault(); - - Assert.Equal("127.0.0.1", telemetryItem?.Tags[ContextTagKeys.AiLocationIp.ToString()]); - } - - [Fact] - public void AiLocationIpIsSetAsNetPeerIpForServerSpans() - { - using ActivitySource activitySource = new ActivitySource(ActivitySourceName); - using var activity = activitySource.StartActivity( - ActivityName, - ActivityKind.Server, - null, - startTime: DateTime.UtcNow); - - Assert.NotNull(activity); - activity.SetTag(SemanticConventions.AttributeNetPeerIp, "127.0.0.1"); + activity.SetTag(SemanticConventions.AttributeClientAddress, "127.0.0.1"); activity.SetTag(SemanticConventions.AttributeHttpRequestMethod, "GET"); var activityTagsProcessor = TraceHelper.EnumerateActivityTags(activity); From e2441761472ecd68eaccc3aadfdaa3a64743a6f5 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Tue, 18 Jul 2023 13:26:36 -0700 Subject: [PATCH 2/7] update changelog --- sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/CHANGELOG.md b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/CHANGELOG.md index c34a412f963b4..55213c6aca092 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/CHANGELOG.md +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/CHANGELOG.md @@ -6,6 +6,9 @@ ### Breaking Changes +* Location ip will now look up `client.address` instead of `http.client_ip`. + ([#37707](https://github.com/Azure/azure-sdk-for-net/pull/37707)) + ### Bugs Fixed ### Other Changes From ba6829db925406edb39a4af382fd54c374eb3a47 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Tue, 18 Jul 2023 13:28:34 -0700 Subject: [PATCH 3/7] reword --- sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/CHANGELOG.md b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/CHANGELOG.md index 55213c6aca092..e0d2190cf2c17 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/CHANGELOG.md +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/CHANGELOG.md @@ -6,7 +6,8 @@ ### Breaking Changes -* Location ip will now look up `client.address` instead of `http.client_ip`. +* Location ip on server spans will now be set using `client.address` tag key on + activity instead of `http.client_ip`. ([#37707](https://github.com/Azure/azure-sdk-for-net/pull/37707)) ### Bugs Fixed From 3bb597deafbb38dd567abf2b3fb413bd34706e41 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Tue, 18 Jul 2023 13:37:24 -0700 Subject: [PATCH 4/7] refactor --- .../src/Customizations/Models/TelemetryItem.cs | 2 +- .../src/Internals/TraceHelper.cs | 11 ----------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Customizations/Models/TelemetryItem.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Customizations/Models/TelemetryItem.cs index d03e513a73892..e8576a0afc118 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Customizations/Models/TelemetryItem.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Customizations/Models/TelemetryItem.cs @@ -41,7 +41,7 @@ public TelemetryItem(Activity activity, ref ActivityTagsProcessor activityTagsPr // Set ip in case of server spans only. if (activity.Kind == ActivityKind.Server) { - var locationIp = TraceHelper.GetLocationIp(ref activityTagsProcessor.MappedTags); + var locationIp = AzMonList.GetTagValue(ref activityTagsProcessor.MappedTags, SemanticConventions.AttributeClientAddress)?.ToString(); if (locationIp != null) { Tags[ContextTagKeys.AiLocationIp.ToString()] = locationIp; 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 a3c29fb0d9396..fa1ff61243786 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/TraceHelper.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/TraceHelper.cs @@ -138,17 +138,6 @@ internal static ActivityTagsProcessor EnumerateActivityTags(Activity activity) return activityTagsProcessor; } - internal static string? GetLocationIp(ref AzMonList MappedTags) - { - var clientIp = AzMonList.GetTagValue(ref MappedTags, SemanticConventions.AttributeClientAddress)?.ToString(); - if (!string.IsNullOrWhiteSpace(clientIp)) - { - return clientIp; - } - - return null; - } - internal static string GetOperationName(Activity activity, ref AzMonList MappedTags) { var httpMethod = AzMonList.GetTagValue(ref MappedTags, SemanticConventions.AttributeHttpMethod)?.ToString(); From 2d44dbb62e9dc4ebb6790b9809c658b6880dac88 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Tue, 18 Jul 2023 13:59:55 -0700 Subject: [PATCH 5/7] address pr feedback --- .../src/Internals/SemanticConventions.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/SemanticConventions.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/SemanticConventions.cs index 2a3b7bf4506a4..36b3af8db4e76 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/SemanticConventions.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/SemanticConventions.cs @@ -86,7 +86,6 @@ internal static class SemanticConventions public const string AttributeHttpHostName = "host.name"; public const string AttributeHttpHostPort = "host.port"; public const string AttributeHttpRoute = "http.route"; - public const string AttributeHttpClientIP = "http.client_ip"; public const string AttributeHttpUserAgent = "http.user_agent"; public const string AttributeHttpRequestContentLength = "http.request_content_length"; public const string AttributeHttpRequestContentLengthUncompressed = "http.request_content_length_uncompressed"; From 863fd561973eaa68fe6ff05ce0b46bb20d9a6130 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Wed, 19 Jul 2023 08:56:41 -0700 Subject: [PATCH 6/7] remove client ip --- .../src/Internals/ActivityTagsProcessor.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/ActivityTagsProcessor.cs b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/ActivityTagsProcessor.cs index 45873ee9e5d0e..c5b03fe4b952d 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/ActivityTagsProcessor.cs +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/ActivityTagsProcessor.cs @@ -23,7 +23,6 @@ internal struct ActivityTagsProcessor SemanticConventions.AttributeHttpHostPort, SemanticConventions.AttributeHttpTarget, SemanticConventions.AttributeHttpUserAgent, - SemanticConventions.AttributeHttpClientIP, SemanticConventions.AttributeHttpRoute, // required - HTTP V2 From 261987f876fa76df870fbe540f53338b8ccb995d Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Wed, 19 Jul 2023 09:11:44 -0700 Subject: [PATCH 7/7] fix link issue --- sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/CHANGELOG.md b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/CHANGELOG.md index e0d2190cf2c17..7517c75ec9533 100644 --- a/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/CHANGELOG.md +++ b/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/CHANGELOG.md @@ -163,7 +163,7 @@ - Users may disable by setting `AzureMonitorExporterOptions.DisableOfflineStorage` ([#28446](https://github.com/Azure/azure-sdk-for-net/pull/28446)) * Added support for exception telemetry from ILogger ([#26670](https://github.com/Azure/azure-sdk-for-net/pull/26670)) * Support for exporting Activity exception event ([#29676](https://github.com/Azure/azure-sdk-for-net/pull/29676)) -* Added support for sampling using [Application Insights based sampler](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/tree/main/src/OpenTelemetry.Extensions.AzureMonitor) ([#31118](https://github.com/Azure/azure-sdk-for-net/pull/31118)) +* Added support for sampling using [Application Insights based sampler](https://www.nuget.org/packages/OpenTelemetry.Extensions.AzureMonitor/) ([#31118](https://github.com/Azure/azure-sdk-for-net/pull/31118)) ### Breaking Changes