Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 @@ -37,6 +37,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 @@ -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)
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