Skip to content

Commit

Permalink
Fix user_agent.original
Browse files Browse the repository at this point in the history
  • Loading branch information
Kielek committed Mar 11, 2024
1 parent 5677f4f commit 78e266a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private void OnStartActivity(Activity activity, HttpContext context)
}

activity.SetTag(SemanticConventions.AttributeHttpTarget, path);
activity.SetTag(SemanticConventions.AttributeHttpUserAgent, request.UserAgent);
activity.SetTag(SemanticConventions.AttributeUserAgentOriginal, request.UserAgent);
activity.SetTag(SemanticConventions.AttributeHttpUrl, GetUriTagValueFromRequestUri(request.Url));

try
Expand Down
1 change: 1 addition & 0 deletions src/Shared/SemanticConventions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,6 @@ internal static class SemanticConventions
public const string AttributeNetworkProtocolVersion = "network.protocol.version"; // replaces: "http.flavor" (AttributeHttpFlavor)
public const string AttributeServerAddress = "server.address"; // replaces: "net.host.name" (AttributeNetHostName)
public const string AttributeServerPort = "server.port"; // replaces: "net.host.port" (AttributeNetHostPort)
public const string AttributeUserAgentOriginal = "user_agent.original"; // replaces: http.user_agent (AttributeHttpUserAgent)
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void AspNetRequestsAreCollectedSuccessfully(
Assert.Equal(expectedOriginalRequestMethod, span.GetTagValue("http.request.method_original"));

Assert.Equal(HttpContext.Current.Request.Path, span.GetTagValue(SemanticConventions.AttributeHttpTarget) as string);
Assert.Equal(HttpContext.Current.Request.UserAgent, span.GetTagValue(SemanticConventions.AttributeHttpUserAgent) as string);
Assert.Equal("Custom User Agent v1.2.3", span.GetTagValue("user_agent.original"));

if (recordException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ namespace OpenTelemetry.Instrumentation.AspNet.Tests;

internal class TestHttpWorkerRequest : HttpWorkerRequest
{
public override string GetKnownRequestHeader(int index)
{
if (index == 39)
{
return "Custom User Agent v1.2.3";
}

return base.GetKnownRequestHeader(index);
}

public override void EndOfRequest()
{
throw new NotImplementedException();
Expand Down

0 comments on commit 78e266a

Please sign in to comment.