Skip to content

Commit

Permalink
Update location ip mapping (#37707)
Browse files Browse the repository at this point in the history
* Update location ip mapping

* update changelog

* reword

* refactor

* address pr feedback

* remove client ip

* fix link issue
  • Loading branch information
vishweshbankwar authored Jul 19, 2023
1 parent 5dae1c3 commit 962ba50
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

### Breaking Changes

* 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

### Other Changes
Expand Down Expand Up @@ -159,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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ internal struct ActivityTagsProcessor
SemanticConventions.AttributeHttpHostPort,
SemanticConventions.AttributeHttpTarget,
SemanticConventions.AttributeHttpUserAgent,
SemanticConventions.AttributeHttpClientIP,
SemanticConventions.AttributeHttpRoute,

// required - HTTP V2
Expand All @@ -37,6 +36,7 @@ internal struct ActivityTagsProcessor
SemanticConventions.AttributeUrlScheme,
SemanticConventions.AttributeUrlQuery,
SemanticConventions.AttributeUserAgentOriginal,
SemanticConventions.AttributeClientAddress,

// required - Azure
SemanticConventions.AttributeAzureNameSpace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -152,6 +151,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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,6 @@ internal static ActivityTagsProcessor EnumerateActivityTags(Activity activity)
return activityTagsProcessor;
}

internal static string? GetLocationIp(ref AzMonList MappedTags)
{
var httpClientIp = AzMonList.GetTagValue(ref MappedTags, SemanticConventions.AttributeHttpClientIP)?.ToString();
if (!string.IsNullOrWhiteSpace(httpClientIp))
{
return httpClientIp;
}

return AzMonList.GetTagValue(ref MappedTags, SemanticConventions.AttributeNetPeerIp)?.ToString();
}

internal static string GetOperationName(Activity activity, ref AzMonList MappedTags)
{
var httpMethod = AzMonList.GetTagValue(ref MappedTags, SemanticConventions.AttributeHttpMethod)?.ToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Activity>(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);
Expand Down

0 comments on commit 962ba50

Please sign in to comment.