From 7fd9cb34ab7586d1fa48a66ed10bbc5b6b5a1724 Mon Sep 17 00:00:00 2001 From: Vishwesh Bankwar Date: Wed, 17 Aug 2022 17:26:35 -0700 Subject: [PATCH] Remove netstandard targets from asp.netcore instrumentation (#3567) --- .../CHANGELOG.md | 7 +++-- .../Implementation/HttpInListener.cs | 27 ++----------------- .../Implementation/HttpInMetricsListener.cs | 15 ----------- ...elemetry.Instrumentation.AspNetCore.csproj | 12 +-------- test/Benchmarks/Benchmarks.csproj | 2 +- .../GrpcTests.client.cs | 4 ++- .../GrpcTests.server.cs | 4 +-- ...elemetry.Instrumentation.Grpc.Tests.csproj | 5 +++- 8 files changed, 17 insertions(+), 59 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md index d928592402..29183fb04a 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md @@ -2,12 +2,15 @@ ## Unreleased +* Removed `netstandard2.0` and `netstandard2.1` targets + ([#3576](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3567)) + * Fixed an issue where activity started within middleware was modified by instrumentation library. ([#3498](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3498)) -* Updated to use Activity native support from `System.Diagnostics.DiagnosticSource` - to set activity status. +* 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)) diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs index 6507ab56d1..2addd21c57 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs @@ -19,15 +19,11 @@ using System.Diagnostics; using System.Linq; using System.Reflection; -#if !NETSTANDARD2_0 using System.Runtime.CompilerServices; -#endif using Microsoft.AspNetCore.Http; using OpenTelemetry.Context.Propagation; -using OpenTelemetry.Internal; -#if !NETSTANDARD2_0 using OpenTelemetry.Instrumentation.GrpcNetClient; -#endif +using OpenTelemetry.Internal; using OpenTelemetry.Trace; namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation @@ -202,7 +198,6 @@ public override void OnStopActivity(Activity activity, object payload) activity.SetTag(SemanticConventions.AttributeHttpStatusCode, response.StatusCode); -#if !NETSTANDARD2_0 if (this.options.EnableGrpcAspNetCoreSupport && TryGetGrpcMethod(activity, out var grpcMethod)) { AddGrpcAttributes(activity, grpcMethod, context); @@ -211,12 +206,6 @@ public override void OnStopActivity(Activity activity, object payload) { activity.SetStatus(SpanHelper.ResolveSpanStatusForHttpStatusCode(activity.Kind, response.StatusCode)); } -#else - if (activity.Status == ActivityStatusCode.Unset) - { - activity.SetStatus(SpanHelper.ResolveSpanStatusForHttpStatusCode(activity.Kind, response.StatusCode)); - } -#endif try { @@ -350,7 +339,7 @@ private static string GetUri(HttpRequest request) var queryString = request.QueryString.Value ?? string.Empty; var length = scheme.Length + Uri.SchemeDelimiter.Length + host.Length + pathBase.Length + path.Length + queryString.Length; -#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER + return string.Create(length, (scheme, host, pathBase, path, queryString), (span, parts) => { CopyTo(ref span, parts.scheme); @@ -369,19 +358,8 @@ static void CopyTo(ref Span buffer, ReadOnlySpan text) } } }); -#else - return new System.Text.StringBuilder(length) - .Append(scheme) - .Append(Uri.SchemeDelimiter) - .Append(host) - .Append(pathBase) - .Append(path) - .Append(queryString) - .ToString(); -#endif } -#if !NETSTANDARD2_0 [MethodImpl(MethodImplOptions.AggressiveInlining)] private static bool TryGetGrpcMethod(Activity activity, out string grpcMethod) { @@ -429,6 +407,5 @@ private static void AddGrpcAttributes(Activity activity, string grpcMethod, Http } } } -#endif } } diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInMetricsListener.cs b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInMetricsListener.cs index 6d99477051..5c5238baa9 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInMetricsListener.cs +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInMetricsListener.cs @@ -17,9 +17,7 @@ using System.Diagnostics; using System.Diagnostics.Metrics; using Microsoft.AspNetCore.Http; -#if NETCOREAPP using Microsoft.AspNetCore.Routing; -#endif using OpenTelemetry.Trace; namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation @@ -67,9 +65,6 @@ public override void OnStopActivity(Activity activity, object payload) TagList tags; - // We need following directive as - // RouteEndpoint is not available in netstandard2.0 and netstandard2.1 -#if NETCOREAPP var target = (context.GetEndpoint() as RouteEndpoint)?.RoutePattern.RawText; // TODO: This is just a minimal set of attributes. See the spec for additional attributes: @@ -97,17 +92,7 @@ public override void OnStopActivity(Activity activity, object payload) { SemanticConventions.AttributeHttpStatusCode, context.Response.StatusCode.ToString() }, }; } -#else - tags = new TagList - { - { SemanticConventions.AttributeHttpFlavor, context.Request.Protocol }, - { SemanticConventions.AttributeHttpScheme, context.Request.Scheme }, - { SemanticConventions.AttributeHttpMethod, context.Request.Method }, - { SemanticConventions.AttributeHttpHost, host }, - { SemanticConventions.AttributeHttpStatusCode, context.Response.StatusCode.ToString() }, - }; -#endif this.httpServerDuration.Record(activity.Duration.TotalMilliseconds, tags); } } diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/OpenTelemetry.Instrumentation.AspNetCore.csproj b/src/OpenTelemetry.Instrumentation.AspNetCore/OpenTelemetry.Instrumentation.AspNetCore.csproj index 39a7475389..71361bf191 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/OpenTelemetry.Instrumentation.AspNetCore.csproj +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/OpenTelemetry.Instrumentation.AspNetCore.csproj @@ -1,7 +1,7 @@ - net7.0;net6.0;netstandard2.1;netstandard2.0 + net7.0;net6.0 ASP.NET Core instrumentation for OpenTelemetry .NET $(PackageTags);distributed-tracing;AspNetCore true @@ -18,16 +18,6 @@ - - - - - - - - - - diff --git a/test/Benchmarks/Benchmarks.csproj b/test/Benchmarks/Benchmarks.csproj index 6cb7f6277f..680cbf3101 100644 --- a/test/Benchmarks/Benchmarks.csproj +++ b/test/Benchmarks/Benchmarks.csproj @@ -19,6 +19,7 @@ + @@ -27,7 +28,6 @@ - diff --git a/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs b/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs index 05a071fd23..5e7b244860 100644 --- a/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs +++ b/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.client.cs @@ -23,7 +23,9 @@ using Greet; using Grpc.Core; using Grpc.Net.Client; +#if NET6_0_OR_GREATER using Microsoft.AspNetCore.Http; +#endif using Moq; using OpenTelemetry.Context.Propagation; using OpenTelemetry.Instrumentation.Grpc.Tests.GrpcTestHelpers; @@ -117,7 +119,7 @@ public void GrpcClientCallsAreCollectedSuccessfully(string baseAddress, bool sho Assert.Equal(0, activity.GetTagValue(SemanticConventions.AttributeRpcGrpcStatusCode)); } -#if !NETFRAMEWORK +#if NET6_0_OR_GREATER [Theory] [InlineData(true)] [InlineData(false)] diff --git a/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.server.cs b/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.server.cs index 701694653e..91db02187a 100644 --- a/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.server.cs +++ b/test/OpenTelemetry.Instrumentation.Grpc.Tests/GrpcTests.server.cs @@ -14,7 +14,7 @@ // limitations under the License. // -#if !NETFRAMEWORK +#if NET6_0_OR_GREATER using System; using System.Collections.Generic; using System.Diagnostics; @@ -115,8 +115,6 @@ public void GrpcAspNetCoreInstrumentationAddsCorrectAttributes(bool? enableGrpcA #if NET6_0_OR_GREATER [Theory(Skip = "Skipping for .NET 6 and higher due to bug #3023")] -#else - [Theory] #endif [InlineData(null)] [InlineData(true)] diff --git a/test/OpenTelemetry.Instrumentation.Grpc.Tests/OpenTelemetry.Instrumentation.Grpc.Tests.csproj b/test/OpenTelemetry.Instrumentation.Grpc.Tests/OpenTelemetry.Instrumentation.Grpc.Tests.csproj index f780997f34..a9416a98a6 100644 --- a/test/OpenTelemetry.Instrumentation.Grpc.Tests/OpenTelemetry.Instrumentation.Grpc.Tests.csproj +++ b/test/OpenTelemetry.Instrumentation.Grpc.Tests/OpenTelemetry.Instrumentation.Grpc.Tests.csproj @@ -30,10 +30,13 @@ + + + + -