From 57f1663e2a00675555654cb739da7158757e9976 Mon Sep 17 00:00:00 2001 From: Yun-Ting Date: Fri, 5 Aug 2022 12:38:05 -0700 Subject: [PATCH 1/6] httpListener changes --- src/OpenTelemetry.Api/Internal/SpanHelper.cs | 6 +++--- .../Implementation/HttpInListener.cs | 8 +++----- .../BasicTests.cs | 6 +----- .../InProcServerTests.cs | 3 ++- ...comingRequestsCollectionsIsAccordingToTheSpecTests.cs | 9 ++++----- 5 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/OpenTelemetry.Api/Internal/SpanHelper.cs b/src/OpenTelemetry.Api/Internal/SpanHelper.cs index a69e3579281..6f909db58c0 100644 --- a/src/OpenTelemetry.Api/Internal/SpanHelper.cs +++ b/src/OpenTelemetry.Api/Internal/SpanHelper.cs @@ -30,15 +30,15 @@ internal static class SpanHelper /// The span kind. /// Http status code. /// Resolved span for the Http status code. - public static Status ResolveSpanStatusForHttpStatusCode(ActivityKind kind, int httpStatusCode) + public static ActivityStatusCode ResolveSpanStatusForHttpStatusCode(ActivityKind kind, int httpStatusCode) { var upperBound = kind == ActivityKind.Client ? 399 : 499; if (httpStatusCode >= 100 && httpStatusCode <= upperBound) { - return Status.Unset; + return ActivityStatusCode.Unset; } - return Status.Error; + return ActivityStatusCode.Error; } } } diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs index 6f848651386..1f045021234 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs @@ -200,19 +200,17 @@ public override void OnStopActivity(Activity activity, object payload) var response = context.Response; - activity.SetTag(SemanticConventions.AttributeHttpStatusCode, response.StatusCode); - #if !NETSTANDARD2_0 if (this.options.EnableGrpcAspNetCoreSupport && TryGetGrpcMethod(activity, out var grpcMethod)) { AddGrpcAttributes(activity, grpcMethod, context); } - else if (activity.GetStatus().StatusCode == StatusCode.Unset) + else if (activity.Status == ActivityStatusCode.Unset) { activity.SetStatus(SpanHelper.ResolveSpanStatusForHttpStatusCode(activity.Kind, response.StatusCode)); } #else - if (activity.GetStatus().StatusCode == StatusCode.Unset) + if (activity.Status == ActivityStatusCode.Unset) { activity.SetStatus(SpanHelper.ResolveSpanStatusForHttpStatusCode(activity.Kind, response.StatusCode)); } @@ -298,7 +296,7 @@ public override void OnException(Activity activity, object payload) activity.RecordException(exc); } - activity.SetStatus(Status.Error.WithDescription(exc.Message)); + activity.SetStatus(ActivityStatusCode.Error, exc.Message); try { diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs index 887df85b935..ffb1529685b 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs @@ -91,11 +91,7 @@ void ConfigureTestServices(IServiceCollection services) Assert.Single(exportedItems); var activity = exportedItems[0]; - Assert.Equal(200, activity.GetTagValue(SemanticConventions.AttributeHttpStatusCode)); - - var status = activity.GetStatus(); - Assert.Equal(status, Status.Unset); - + Assert.Equal(ActivityStatusCode.Unset, activity.Status); ValidateAspNetCoreActivity(activity, "/api/values"); } diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/InProcServerTests.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/InProcServerTests.cs index 20b3ef3c602..96d160a7c95 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/InProcServerTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/InProcServerTests.cs @@ -74,7 +74,8 @@ public async void ExampleTest() Assert.Equal("localhost:5000", activity.GetTagValue(SemanticConventions.AttributeHttpHost)); Assert.Equal("GET", activity.GetTagValue(SemanticConventions.AttributeHttpMethod)); Assert.Equal("1.1", activity.GetTagValue(SemanticConventions.AttributeHttpFlavor)); - Assert.Equal(200, activity.GetTagValue(SemanticConventions.AttributeHttpStatusCode)); + Assert.True(activity.Status == ActivityStatusCode.Unset); + Assert.True(activity.StatusDescription is null); } public async void Dispose() diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/IncomingRequestsCollectionsIsAccordingToTheSpecTests.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/IncomingRequestsCollectionsIsAccordingToTheSpecTests.cs index 969ebf8e704..bd6ea44ad1e 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/IncomingRequestsCollectionsIsAccordingToTheSpecTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/IncomingRequestsCollectionsIsAccordingToTheSpecTests.cs @@ -116,26 +116,25 @@ public async Task SuccessfulTemplateControllerCallGeneratesASpan( Assert.Equal("http", activity.GetTagValue(SemanticConventions.AttributeHttpScheme)); Assert.Equal(urlPath, activity.GetTagValue(SemanticConventions.AttributeHttpTarget)); Assert.Equal($"http://localhost{urlPath}{query}", activity.GetTagValue(SemanticConventions.AttributeHttpUrl)); - Assert.Equal(statusCode, activity.GetTagValue(SemanticConventions.AttributeHttpStatusCode)); if (statusCode == 503) { - Assert.Equal(Status.Error.StatusCode, activity.GetStatus().StatusCode); + Assert.Equal(ActivityStatusCode.Error, activity.Status); } else { - Assert.Equal(Status.Unset, activity.GetStatus()); + Assert.Equal(ActivityStatusCode.Unset, activity.Status); } // Instrumentation is not expected to set status description // as the reason can be inferred from SemanticConventions.AttributeHttpStatusCode if (!urlPath.EndsWith("exception")) { - Assert.True(string.IsNullOrEmpty(activity.GetStatus().Description)); + Assert.True(string.IsNullOrEmpty(activity.StatusDescription)); } else { - Assert.Equal("exception description", activity.GetStatus().Description); + Assert.Equal("exception description", activity.StatusDescription); } if (recordException) From 6f30976b4b398b10aa1070615cff7973cbf8c68b Mon Sep 17 00:00:00 2001 From: Yun-Ting Date: Fri, 5 Aug 2022 15:24:43 -0700 Subject: [PATCH 2/6] http --- .../HttpHandlerDiagnosticListener.cs | 14 +++---- .../HttpWebRequestActivitySource.netfx.cs | 17 +++++--- .../HttpClientTests.cs | 8 ++-- .../http-out-test-cases.json | 40 +++++++++---------- 4 files changed, 41 insertions(+), 38 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs index 3ba894e0fdf..c1ffd5cedff 100644 --- a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs +++ b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs @@ -168,22 +168,22 @@ public override void OnStopActivity(Activity activity, object payload) // requestTaskStatus is not null _ = this.stopRequestStatusFetcher.TryFetch(payload, out var requestTaskStatus); - StatusCode currentStatusCode = activity.GetStatus().StatusCode; + ActivityStatusCode currentStatusCode = activity.Status; if (requestTaskStatus != TaskStatus.RanToCompletion) { if (requestTaskStatus == TaskStatus.Canceled) { - if (currentStatusCode == StatusCode.Unset) + if (currentStatusCode == ActivityStatusCode.Unset) { - activity.SetStatus(Status.Error); + activity.SetStatus(ActivityStatusCode.Error); } } else if (requestTaskStatus != TaskStatus.Faulted) { - if (currentStatusCode == StatusCode.Unset) + if (currentStatusCode == ActivityStatusCode.Unset) { // Faults are handled in OnException and should already have a span.Status of Error w/ Description. - activity.SetStatus(Status.Error); + activity.SetStatus(ActivityStatusCode.Error); } } } @@ -192,7 +192,7 @@ public override void OnStopActivity(Activity activity, object payload) { activity.SetTag(SemanticConventions.AttributeHttpStatusCode, (int)response.StatusCode); - if (currentStatusCode == StatusCode.Unset) + if (currentStatusCode == ActivityStatusCode.Unset) { activity.SetStatus(SpanHelper.ResolveSpanStatusForHttpStatusCode(activity.Kind, (int)response.StatusCode)); } @@ -235,7 +235,7 @@ public override void OnException(Activity activity, object payload) if (exc is HttpRequestException) { - activity.SetStatus(Status.Error.WithDescription(exc.Message)); + activity.SetStatus(ActivityStatusCode.Error, exc.Message); } try diff --git a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs index 48a2b584c04..1eb7c9cd2dc 100644 --- a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs +++ b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpWebRequestActivitySource.netfx.cs @@ -141,7 +141,9 @@ private static void AddExceptionTags(Exception exception, Activity activity) return; } - Status status; + ActivityStatusCode status; + string exceptionMessage = null; + if (exception is WebException wexc) { if (wexc.Response is HttpWebResponse response) @@ -156,7 +158,7 @@ private static void AddExceptionTags(Exception exception, Activity activity) { case WebExceptionStatus.Timeout: case WebExceptionStatus.RequestCanceled: - status = Status.Error; + status = ActivityStatusCode.Error; break; case WebExceptionStatus.SendFailure: case WebExceptionStatus.ConnectFailure: @@ -164,20 +166,23 @@ private static void AddExceptionTags(Exception exception, Activity activity) case WebExceptionStatus.TrustFailure: case WebExceptionStatus.ServerProtocolViolation: case WebExceptionStatus.MessageLengthLimitExceeded: - status = Status.Error.WithDescription(exception.Message); + status = ActivityStatusCode.Error; + exceptionMessage = exception.Message; break; default: - status = Status.Error.WithDescription(exception.Message); + status = ActivityStatusCode.Error; + exceptionMessage = exception.Message; break; } } } else { - status = Status.Error.WithDescription(exception.Message); + status = ActivityStatusCode.Error; + exceptionMessage = exception.Message; } - activity.SetStatus(status); + activity.SetStatus(status, exceptionMessage); if (Options.RecordException) { activity.RecordException(exception); diff --git a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.cs b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.cs index db24a44050b..7407e134527 100644 --- a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.cs +++ b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpClientTests.cs @@ -110,13 +110,11 @@ public async Task HttpOutCallsAreCollectedSuccessfullyAsync(HttpTestData.HttpOut Assert.Equal(tc.SpanName, activity.DisplayName); // Assert.Equal(tc.SpanStatus, d[span.Status.CanonicalCode]); - Assert.Equal( - tc.SpanStatus, - activity.GetTagValue(SpanAttributeConstants.StatusCodeKey) as string); + Assert.Equal(tc.SpanStatus, activity.Status.ToString()); if (tc.SpanStatusHasDescription.HasValue) { - var desc = activity.GetTagValue(SpanAttributeConstants.StatusDescriptionKey) as string; + var desc = activity.StatusDescription; Assert.Equal(tc.SpanStatusHasDescription.Value, !string.IsNullOrEmpty(desc)); } @@ -194,7 +192,7 @@ public async Task DebugIndividualTestAsync() ""responseCode"": 399, ""responseExpected"": true, ""spanName"": ""HTTP GET"", - ""spanStatus"": ""UNSET"", + ""spanStatus"": ""Unset"", ""spanKind"": ""Client"", ""spanAttributes"": { ""http.scheme"": ""http"", diff --git a/test/OpenTelemetry.Instrumentation.Http.Tests/http-out-test-cases.json b/test/OpenTelemetry.Instrumentation.Http.Tests/http-out-test-cases.json index 3441e152d92..a0b9eb51984 100644 --- a/test/OpenTelemetry.Instrumentation.Http.Tests/http-out-test-cases.json +++ b/test/OpenTelemetry.Instrumentation.Http.Tests/http-out-test-cases.json @@ -4,7 +4,7 @@ "method": "GET", "url": "http://{host}:{port}/", "spanName": "HTTP GET", - "spanStatus": "UNSET", + "spanStatus": "Unset", "responseExpected": true, "spanAttributes": { "http.scheme": "http", @@ -20,7 +20,7 @@ "method": "POST", "url": "http://{host}:{port}/", "spanName": "HTTP POST", - "spanStatus": "UNSET", + "spanStatus": "Unset", "responseExpected": true, "spanAttributes": { "http.scheme": "http", @@ -37,7 +37,7 @@ "url": "http://{host}:{port}/path/to/resource/", "responseCode": 200, "spanName": "HTTP GET", - "spanStatus": "UNSET", + "spanStatus": "Unset", "responseExpected": true, "spanAttributes": { "http.scheme": "http", @@ -54,7 +54,7 @@ "url": "http://{host}:{port}/path/to/resource#fragment", "responseCode": 200, "spanName": "HTTP GET", - "spanStatus": "UNSET", + "spanStatus": "Unset", "responseExpected": true, "spanAttributes": { "http.scheme": "http", @@ -71,7 +71,7 @@ "url": "http://username:password@{host}:{port}/path/to/resource#fragment", "responseCode": 200, "spanName": "HTTP GET", - "spanStatus": "UNSET", + "spanStatus": "Unset", "responseExpected": true, "spanAttributes": { "http.scheme": "http", @@ -87,7 +87,7 @@ "method": "GET", "url": "https://sdlfaldfjalkdfjlkajdflkajlsdjf.sdlkjafsdjfalfadslkf.com/", "spanName": "HTTP GET", - "spanStatus": "ERROR", + "spanStatus": "Error", "spanStatusHasDescription": true, "responseExpected": false, "recordException": false, @@ -104,7 +104,7 @@ "method": "GET", "url": "https://sdlfaldfjalkdfjlkajdflkajlsdjf.sdlkjafsdjfalfadslkf.com/", "spanName": "HTTP GET", - "spanStatus": "ERROR", + "spanStatus": "Error", "spanStatusHasDescription": true, "responseExpected": false, "recordException": true, @@ -122,7 +122,7 @@ "url": "http://{host}:{port}/", "responseCode": 200, "spanName": "HTTP GET", - "spanStatus": "UNSET", + "spanStatus": "Unset", "responseExpected": true, "spanAttributes": { "http.scheme": "http", @@ -139,7 +139,7 @@ "url": "http://{host}:{port}/", "responseCode": 200, "spanName": "HTTP GET", - "spanStatus": "UNSET", + "spanStatus": "Unset", "responseExpected": true, "spanAttributes": { "http.scheme": "http", @@ -156,7 +156,7 @@ "url": "http://{host}:{port}/", "responseCode": 399, "spanName": "HTTP GET", - "spanStatus": "UNSET", + "spanStatus": "Unset", "responseExpected": true, "spanAttributes": { "http.scheme": "http", @@ -173,7 +173,7 @@ "url": "http://{host}:{port}/", "responseCode": 400, "spanName": "HTTP GET", - "spanStatus": "ERROR", + "spanStatus": "Error", "responseExpected": true, "spanAttributes": { "http.scheme": "http", @@ -190,7 +190,7 @@ "url": "http://{host}:{port}/", "responseCode": 401, "spanName": "HTTP GET", - "spanStatus": "ERROR", + "spanStatus": "Error", "responseExpected": true, "spanAttributes": { "http.scheme": "http", @@ -207,7 +207,7 @@ "url": "http://{host}:{port}/", "responseCode": 403, "spanName": "HTTP GET", - "spanStatus": "ERROR", + "spanStatus": "Error", "responseExpected": true, "spanAttributes": { "http.scheme": "http", @@ -224,7 +224,7 @@ "url": "http://{host}:{port}/", "responseCode": 404, "spanName": "HTTP GET", - "spanStatus": "ERROR", + "spanStatus": "Error", "responseExpected": true, "spanAttributes": { "http.scheme": "http", @@ -241,7 +241,7 @@ "url": "http://{host}:{port}/", "responseCode": 429, "spanName": "HTTP GET", - "spanStatus": "ERROR", + "spanStatus": "Error", "responseExpected": true, "spanAttributes": { "http.scheme": "http", @@ -258,7 +258,7 @@ "url": "http://{host}:{port}/", "responseCode": 501, "spanName": "HTTP GET", - "spanStatus": "ERROR", + "spanStatus": "Error", "responseExpected": true, "spanAttributes": { "http.scheme": "http", @@ -275,7 +275,7 @@ "url": "http://{host}:{port}/", "responseCode": 503, "spanName": "HTTP GET", - "spanStatus": "ERROR", + "spanStatus": "Error", "responseExpected": true, "spanAttributes": { "http.scheme": "http", @@ -292,7 +292,7 @@ "url": "http://{host}:{port}/", "responseCode": 504, "spanName": "HTTP GET", - "spanStatus": "ERROR", + "spanStatus": "Error", "responseExpected": true, "spanAttributes": { "http.scheme": "http", @@ -309,7 +309,7 @@ "url": "http://{host}:{port}/", "responseCode": 600, "spanName": "HTTP GET", - "spanStatus": "ERROR", + "spanStatus": "Error", "responseExpected": true, "spanAttributes": { "http.scheme": "http", @@ -326,7 +326,7 @@ "url": "http://{host}:{port}/", "responseCode": 200, "spanName": "HTTP GET", - "spanStatus": "UNSET", + "spanStatus": "Unset", "responseExpected": true, "spanAttributes": { "http.scheme": "http", From ea2174495b0d25d307d37094b2b8d17329ea830e Mon Sep 17 00:00:00 2001 From: Yun-Ting Date: Fri, 5 Aug 2022 16:03:50 -0700 Subject: [PATCH 3/6] fix tests --- .../HttpWebRequestActivitySourceTests.netfx.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestActivitySourceTests.netfx.cs b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestActivitySourceTests.netfx.cs index 8f42f6b59c9..bea4ecb9102 100644 --- a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestActivitySourceTests.netfx.cs +++ b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestActivitySourceTests.netfx.cs @@ -544,8 +544,8 @@ public async Task TestRequestWithException(string method) Assert.True(eventRecords.Records.TryDequeue(out KeyValuePair exceptionEvent)); Assert.Equal("Stop", exceptionEvent.Key); - Assert.NotNull(activity.GetTagValue(SpanAttributeConstants.StatusCodeKey)); - Assert.NotNull(activity.GetTagValue(SpanAttributeConstants.StatusDescriptionKey)); + Assert.True(exceptionEvent.Value.Status != ActivityStatusCode.Unset); + Assert.NotNull(exceptionEvent.Value.StatusDescription); } /// @@ -583,8 +583,8 @@ public async Task TestCanceledRequest(string method) Assert.True(eventRecords.Records.TryDequeue(out KeyValuePair exceptionEvent)); Assert.Equal("Stop", exceptionEvent.Key); - Assert.NotNull(exceptionEvent.Value.GetTagValue(SpanAttributeConstants.StatusCodeKey)); - Assert.Null(exceptionEvent.Value.GetTagValue(SpanAttributeConstants.StatusDescriptionKey)); + Assert.True(exceptionEvent.Value.Status != ActivityStatusCode.Unset); + Assert.True(exceptionEvent.Value.StatusDescription == null); } /// @@ -622,8 +622,8 @@ public async Task TestSecureTransportFailureRequest(string method) Assert.True(eventRecords.Records.TryDequeue(out KeyValuePair exceptionEvent)); Assert.Equal("Stop", exceptionEvent.Key); - Assert.NotNull(exceptionEvent.Value.GetTagValue(SpanAttributeConstants.StatusCodeKey)); - Assert.NotNull(exceptionEvent.Value.GetTagValue(SpanAttributeConstants.StatusDescriptionKey)); + Assert.True(exceptionEvent.Value.Status != ActivityStatusCode.Unset); + Assert.NotNull(exceptionEvent.Value.StatusDescription); } /// @@ -664,8 +664,8 @@ public async Task TestSecureTransportRetryFailureRequest(string method) Assert.True(eventRecords.Records.TryDequeue(out KeyValuePair exceptionEvent)); Assert.Equal("Stop", exceptionEvent.Key); - Assert.NotNull(exceptionEvent.Value.GetTagValue(SpanAttributeConstants.StatusCodeKey)); - Assert.NotNull(exceptionEvent.Value.GetTagValue(SpanAttributeConstants.StatusDescriptionKey)); + Assert.True(exceptionEvent.Value.Status != ActivityStatusCode.Unset); + Assert.NotNull(exceptionEvent.Value.StatusDescription); } [Fact] From b5ef5c2bd001995701ac6dc55252f3569e714db9 Mon Sep 17 00:00:00 2001 From: Yun-Ting Lin Date: Tue, 9 Aug 2022 14:57:38 -0700 Subject: [PATCH 4/6] comments --- .../Implementation/HttpInListener.cs | 2 ++ .../BasicTests.cs | 1 + .../InProcServerTests.cs | 1 + .../IncomingRequestsCollectionsIsAccordingToTheSpecTests.cs | 1 + 4 files changed, 5 insertions(+) diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs index 1f045021234..25229662de3 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs @@ -200,6 +200,8 @@ public override void OnStopActivity(Activity activity, object payload) var response = context.Response; + activity.SetTag(SemanticConventions.AttributeHttpStatusCode, response.StatusCode); + #if !NETSTANDARD2_0 if (this.options.EnableGrpcAspNetCoreSupport && TryGetGrpcMethod(activity, out var grpcMethod)) { diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs index ffb1529685b..2d0cf65212f 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs @@ -91,6 +91,7 @@ void ConfigureTestServices(IServiceCollection services) Assert.Single(exportedItems); var activity = exportedItems[0]; + Assert.Equal(200, activity.GetTagValue(SemanticConventions.AttributeHttpStatusCode)); Assert.Equal(ActivityStatusCode.Unset, activity.Status); ValidateAspNetCoreActivity(activity, "/api/values"); } diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/InProcServerTests.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/InProcServerTests.cs index 96d160a7c95..9f39e9c2035 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/InProcServerTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/InProcServerTests.cs @@ -74,6 +74,7 @@ public async void ExampleTest() Assert.Equal("localhost:5000", activity.GetTagValue(SemanticConventions.AttributeHttpHost)); Assert.Equal("GET", activity.GetTagValue(SemanticConventions.AttributeHttpMethod)); Assert.Equal("1.1", activity.GetTagValue(SemanticConventions.AttributeHttpFlavor)); + Assert.Equal(200, activity.GetTagValue(SemanticConventions.AttributeHttpStatusCode)); Assert.True(activity.Status == ActivityStatusCode.Unset); Assert.True(activity.StatusDescription is null); } diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/IncomingRequestsCollectionsIsAccordingToTheSpecTests.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/IncomingRequestsCollectionsIsAccordingToTheSpecTests.cs index bd6ea44ad1e..f9550766421 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/IncomingRequestsCollectionsIsAccordingToTheSpecTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/IncomingRequestsCollectionsIsAccordingToTheSpecTests.cs @@ -116,6 +116,7 @@ public async Task SuccessfulTemplateControllerCallGeneratesASpan( Assert.Equal("http", activity.GetTagValue(SemanticConventions.AttributeHttpScheme)); Assert.Equal(urlPath, activity.GetTagValue(SemanticConventions.AttributeHttpTarget)); Assert.Equal($"http://localhost{urlPath}{query}", activity.GetTagValue(SemanticConventions.AttributeHttpUrl)); + Assert.Equal(statusCode, activity.GetTagValue(SemanticConventions.AttributeHttpStatusCode)); if (statusCode == 503) { From e75d0ea848b042e4413c603128d622bfccaf6aa6 Mon Sep 17 00:00:00 2001 From: Yun-Ting Lin Date: Tue, 9 Aug 2022 17:29:22 -0700 Subject: [PATCH 5/6] comment --- .../HttpWebRequestActivitySourceTests.netfx.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestActivitySourceTests.netfx.cs b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestActivitySourceTests.netfx.cs index bea4ecb9102..1d10b03d65d 100644 --- a/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestActivitySourceTests.netfx.cs +++ b/test/OpenTelemetry.Instrumentation.Http.Tests/HttpWebRequestActivitySourceTests.netfx.cs @@ -544,8 +544,8 @@ public async Task TestRequestWithException(string method) Assert.True(eventRecords.Records.TryDequeue(out KeyValuePair exceptionEvent)); Assert.Equal("Stop", exceptionEvent.Key); - Assert.True(exceptionEvent.Value.Status != ActivityStatusCode.Unset); - Assert.NotNull(exceptionEvent.Value.StatusDescription); + Assert.True(activity.Status != ActivityStatusCode.Unset); + Assert.NotNull(activity.StatusDescription); } /// From 3dd84e7e76d4642016691dbb4229ae3b3ebe40fb Mon Sep 17 00:00:00 2001 From: Yun-Ting Lin Date: Tue, 9 Aug 2022 17:47:18 -0700 Subject: [PATCH 6/6] changelog --- src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md | 5 +++++ src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md index 7dd26e20f5d..40127aacd7d 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +* Updated to use Activity native support from `System.Diagnostics.DiagnosticSource` + to set activity status. + ([#3118](https://github.com/open-telemetry/opentelemetry-dotnet/issues/3118)) + ([#3555](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3555)) + ## 1.0.0-rc9.5 Released 2022-Aug-02 diff --git a/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md index 51919bb3e00..90f445f087e 100644 --- a/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +* Updated to use Activity native support from `System.Diagnostics.DiagnosticSource` + to set activity status. + ([#3118](https://github.com/open-telemetry/opentelemetry-dotnet/issues/3118)) + ([#3555](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3555)) + * Changed activity source name from `OpenTelemetry.HttpWebRequest` to `OpenTelemetry.Instrumentation.Http.HttpWebRequest` for `HttpWebRequest`s and from `OpenTelemetry.Instrumentation.Http`