Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set ai.user.useragent to userAgentOriginal #37571

Merged
merged 3 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -23,7 +23,7 @@ public TelemetryItem(Activity activity, ref ActivityTagsProcessor activityTagsPr

Tags[ContextTagKeys.AiOperationId.ToString()] = activity.TraceId.ToHexString();

var userAgent = AzMonList.GetTagValue(ref activityTagsProcessor.MappedTags, SemanticConventions.AttributeHttpUserAgent)?.ToString();
var userAgent = AzMonList.GetTagValue(ref activityTagsProcessor.MappedTags, SemanticConventions.AttributeUserAgentOriginal)?.ToString() ?? AzMonList.GetTagValue(ref activityTagsProcessor.MappedTags, SemanticConventions.AttributeHttpUserAgent)?.ToString();
vishweshbankwar marked this conversation as resolved.
Show resolved Hide resolved

if (userAgent != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,26 @@ public void AiUserAgentIsSetAsHttpUserAgent()
Assert.Equal(userAgent, telemetryItem.Tags["ai.user.userAgent"]);
}

[Fact]
public void AiUserAgentIsSetAsUserAgentOriginal()
{
using ActivitySource activitySource = new ActivitySource(ActivitySourceName);
using var activity = activitySource.StartActivity(
ActivityName,
ActivityKind.Server,
null,
startTime: DateTime.UtcNow);

Assert.NotNull(activity);
var userAgent = "Mozilla / 5.0(Windows NT 10.0;WOW64) AppleWebKit / 537.36(KHTML, like Gecko) Chrome / 91.0.4472.101 Safari / 537.36";
activity.SetTag(SemanticConventions.AttributeUserAgentOriginal, userAgent);

var activityTagsProcessor = TraceHelper.EnumerateActivityTags(activity);
var telemetryItem = new TelemetryItem(activity, ref activityTagsProcessor, null, string.Empty);

Assert.Equal(userAgent, telemetryItem.Tags["ai.user.userAgent"]);
}

[Fact]
public void AiLocationIpIsNullByDefault()
{
Expand Down