diff --git a/src/OpenTelemetry.Instrumentation.AspNet/Implementation/HttpInListener.cs b/src/OpenTelemetry.Instrumentation.AspNet/Implementation/HttpInListener.cs index 379a57b2c6..908ca21081 100644 --- a/src/OpenTelemetry.Instrumentation.AspNet/Implementation/HttpInListener.cs +++ b/src/OpenTelemetry.Instrumentation.AspNet/Implementation/HttpInListener.cs @@ -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 diff --git a/src/Shared/SemanticConventions.cs b/src/Shared/SemanticConventions.cs index d6e811990d..b960a9409e 100644 --- a/src/Shared/SemanticConventions.cs +++ b/src/Shared/SemanticConventions.cs @@ -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 } diff --git a/test/OpenTelemetry.Instrumentation.AspNet.Tests/HttpInListenerTests.cs b/test/OpenTelemetry.Instrumentation.AspNet.Tests/HttpInListenerTests.cs index a1947507c8..45a89e5580 100644 --- a/test/OpenTelemetry.Instrumentation.AspNet.Tests/HttpInListenerTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNet.Tests/HttpInListenerTests.cs @@ -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) { diff --git a/test/OpenTelemetry.Instrumentation.AspNet.Tests/TestHttpWorkerRequest.cs b/test/OpenTelemetry.Instrumentation.AspNet.Tests/TestHttpWorkerRequest.cs index c9b1bb5058..80b37bbc81 100644 --- a/test/OpenTelemetry.Instrumentation.AspNet.Tests/TestHttpWorkerRequest.cs +++ b/test/OpenTelemetry.Instrumentation.AspNet.Tests/TestHttpWorkerRequest.cs @@ -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();