From 13e48298dae415ca71e5543b7fec15604d523396 Mon Sep 17 00:00:00 2001
From: Madalyn Redding <66138537+m-redding@users.noreply.github.com>
Date: Mon, 11 Dec 2023 15:46:46 -0500
Subject: [PATCH] [Core] Remove netcoreapp2.1 and net5.0 targets (#40635)
* update targets
* Update Azure.Core.Expressions.DataFactory.csproj
* remove netcoreapp2.1 preprocessor directives
* update changelog
* Update CHANGELOG.md
---
.../Azure.Core.Expressions.DataFactory.csproj | 5 -
sdk/core/Azure.Core/CHANGELOG.md | 1 +
sdk/core/Azure.Core/src/Azure.Core.csproj | 14 +-
.../Internal/RequestActivityPolicy.cs | 24 -
.../Azure.Core/src/Shared/DiagnosticScope.cs | 624 +-----------------
.../src/Shared/DiagnosticScopeFactory.cs | 22 +-
6 files changed, 5 insertions(+), 685 deletions(-)
diff --git a/sdk/core/Azure.Core.Expressions.DataFactory/src/Azure.Core.Expressions.DataFactory.csproj b/sdk/core/Azure.Core.Expressions.DataFactory/src/Azure.Core.Expressions.DataFactory.csproj
index 790fc3e67355..b6d669ff92af 100644
--- a/sdk/core/Azure.Core.Expressions.DataFactory/src/Azure.Core.Expressions.DataFactory.csproj
+++ b/sdk/core/Azure.Core.Expressions.DataFactory/src/Azure.Core.Expressions.DataFactory.csproj
@@ -9,11 +9,6 @@
$(RequiredTargetFrameworks)
true
false
-
- $(NoWarn);NETSDK1138
diff --git a/sdk/core/Azure.Core/CHANGELOG.md b/sdk/core/Azure.Core/CHANGELOG.md
index b28d118051d4..f373e2b6e7f1 100644
--- a/sdk/core/Azure.Core/CHANGELOG.md
+++ b/sdk/core/Azure.Core/CHANGELOG.md
@@ -9,6 +9,7 @@
### Bugs Fixed
### Other Changes
+- Remove targets for .NET Core 2.1 and .NET 5 since they are out of support. Azure.Core is no longer compatible with .NET Core 2.1 after removal of target. The remaining targets are unchanged.
## 1.36.0 (2023-11-10)
diff --git a/sdk/core/Azure.Core/src/Azure.Core.csproj b/sdk/core/Azure.Core/src/Azure.Core.csproj
index ae010c15dbbf..3365f2e3004d 100644
--- a/sdk/core/Azure.Core/src/Azure.Core.csproj
+++ b/sdk/core/Azure.Core/src/Azure.Core.csproj
@@ -1,4 +1,4 @@
-
+
This is the implementation of the Azure Client Pipeline
Microsoft Azure Client Pipeline
@@ -8,15 +8,10 @@
Microsoft Azure Client Pipeline
enable
$(DefineConstants);AZURE_NULLABLE;HAS_INTERNALS_VISIBLE_CORE
- $(RequiredTargetFrameworks);net461;net472;netcoreapp2.1;net5.0;net6.0
+ $(RequiredTargetFrameworks);net461;net472;net6.0
true
true
false
-
- $(NoWarn);NETSDK1138
net461
@@ -34,11 +29,6 @@
-
-
-
-
-
diff --git a/sdk/core/Azure.Core/src/Pipeline/Internal/RequestActivityPolicy.cs b/sdk/core/Azure.Core/src/Pipeline/Internal/RequestActivityPolicy.cs
index 3c2cba9c5137..1e0aab46a717 100644
--- a/sdk/core/Azure.Core/src/Pipeline/Internal/RequestActivityPolicy.cs
+++ b/sdk/core/Azure.Core/src/Pipeline/Internal/RequestActivityPolicy.cs
@@ -20,11 +20,7 @@ internal class RequestActivityPolicy : HttpPipelinePolicy
private const string RequestIdHeaderName = "Request-Id";
private static readonly DiagnosticListener s_diagnosticSource = new DiagnosticListener("Azure.Core");
-#if NETCOREAPP2_1
- private static readonly object? s_activitySource = ActivityExtensions.CreateActivitySource("Azure.Core.Http");
-#else
private static readonly ActivitySource s_activitySource = new ActivitySource("Azure.Core.Http");
-#endif
public RequestActivityPolicy(bool isDistributedTracingEnabled, string? resourceProviderNamespace, HttpMessageSanitizer httpMessageSanitizer)
{
@@ -135,11 +131,7 @@ private async ValueTask ProcessAsync(HttpMessage message, ReadOnlyMemory(T sourceArgs)
{
-#if NETCOREAPP2_1
- return new DiagnosticScope("Azure.Core.Http.Request", s_diagnosticSource, sourceArgs, s_activitySource, DiagnosticScope.ActivityKind.Client, false);
-#else
return new DiagnosticScope("Azure.Core.Http.Request", s_diagnosticSource, sourceArgs, s_activitySource, System.Diagnostics.ActivityKind.Client, false);
-#endif
}
private static ValueTask ProcessNextAsync(HttpMessage message, ReadOnlyMemory pipeline, bool async)
@@ -149,20 +141,12 @@ private static ValueTask ProcessNextAsync(HttpMessage message, ReadOnlyMemory
_isDistributedTracingEnabled &&
-#if NETCOREAPP2_1
- (s_diagnosticSource.IsEnabled() || ActivityExtensions.ActivitySourceHasListeners(s_activitySource));
-#else
(s_diagnosticSource.IsEnabled() || IsActivitySourceEnabled);
-#endif
-#if NETCOREAPP2_1
- private bool IsActivitySourceEnabled => _isDistributedTracingEnabled && ActivityExtensions.ActivitySourceHasListeners(s_activitySource);
-#else
private bool IsActivitySourceEnabled => _isDistributedTracingEnabled && s_activitySource.HasListeners();
-#endif
}
}
diff --git a/sdk/core/Azure.Core/src/Shared/DiagnosticScope.cs b/sdk/core/Azure.Core/src/Shared/DiagnosticScope.cs
index 0728952aad4b..01494122acf0 100644
--- a/sdk/core/Azure.Core/src/Shared/DiagnosticScope.cs
+++ b/sdk/core/Azure.Core/src/Shared/DiagnosticScope.cs
@@ -24,31 +24,18 @@ namespace Azure.Core.Pipeline
// https://github.com/open-telemetry/semantic-conventions/blob/v1.23.0
internal const string OpenTelemetrySchemaVersion = "https://opentelemetry.io/schemas/1.23.0";
private static readonly object AzureSdkScopeValue = bool.TrueString;
-
private readonly ActivityAdapter? _activityAdapter;
private readonly bool _suppressNestedClientActivities;
[RequiresUnreferencedCode("The diagnosticSourceArgs are used in a call to DiagnosticSource.Write, all necessary properties need to be preserved on the type being passed in using DynamicDependency attributes.")]
-#if NETCOREAPP2_1
- internal DiagnosticScope(string scopeName, DiagnosticListener source, object? diagnosticSourceArgs, object? activitySource, ActivityKind kind, bool suppressNestedClientActivities)
-#else
internal DiagnosticScope(string scopeName, DiagnosticListener source, object? diagnosticSourceArgs, ActivitySource? activitySource, System.Diagnostics.ActivityKind kind, bool suppressNestedClientActivities)
-#endif
{
// ActivityKind.Internal and Client both can represent public API calls depending on the SDK
-#if NETCOREAPP2_1
- _suppressNestedClientActivities = (kind == ActivityKind.Client || kind == ActivityKind.Internal) ? suppressNestedClientActivities : false;
-#else
_suppressNestedClientActivities = (kind == ActivityKind.Client || kind == System.Diagnostics.ActivityKind.Internal) ? suppressNestedClientActivities : false;
-#endif
// outer scope presence is enough to suppress any inner scope, regardless of inner scope configuation.
bool hasListeners;
-#if NETCOREAPP2_1
- hasListeners = ActivityExtensions.ActivitySourceHasListeners(activitySource);
-#else
hasListeners = activitySource?.HasListeners() ?? false;
-#endif
IsEnabled = source.IsEnabled() || hasListeners;
if (_suppressNestedClientActivities)
@@ -168,40 +155,6 @@ public void Failed(string errorCode)
_activityAdapter?.MarkFailed((Exception?)null, errorCode);
}
-#if NETCOREAPP2_1
- ///
- /// Kind describes the relationship between the Activity, its parents, and its children in a Trace.
- ///
- public enum ActivityKind
- {
- ///
- /// Default value.
- /// Indicates that the Activity represents an internal operation within an application, as opposed to an operations with remote parents or children.
- ///
- Internal = 0,
-
- ///
- /// Server activity represents request incoming from external component.
- ///
- Server = 1,
-
- ///
- /// Client activity represents outgoing request to the external component.
- ///
- Client = 2,
-
- ///
- /// Producer activity represents output provided to external components.
- ///
- Producer = 3,
-
- ///
- /// Consumer activity represents output received from an external component.
- ///
- Consumer = 4,
- }
-#endif
-
private class DiagnosticActivity : Activity
{
#pragma warning disable 109 // extra new modifier
@@ -215,39 +168,23 @@ public DiagnosticActivity(string operationName) : base(operationName)
private class ActivityAdapter : IDisposable
{
-#if NETCOREAPP2_1
- private readonly object? _activitySource;
-#else
private readonly ActivitySource? _activitySource;
-#endif
private readonly DiagnosticSource _diagnosticSource;
private readonly string _activityName;
-#if NETCOREAPP2_1
- private readonly ActivityKind _kind;
-#else
private readonly System.Diagnostics.ActivityKind _kind;
-#endif
private readonly object? _diagnosticSourceArgs;
private Activity? _currentActivity;
private Activity? _sampleOutActivity;
-#if NETCOREAPP2_1
- private ICollection>? _tagCollection;
-#else
private ActivityTagsCollection? _tagCollection;
-#endif
private DateTimeOffset _startTime;
private List? _links;
private string? _traceparent;
private string? _tracestate;
private string? _displayName;
-#if NETCOREAPP2_1
- public ActivityAdapter(object? activitySource, DiagnosticSource diagnosticSource, string activityName, ActivityKind kind, object? diagnosticSourceArgs)
-#else
public ActivityAdapter(ActivitySource? activitySource, DiagnosticSource diagnosticSource, string activityName, System.Diagnostics.ActivityKind kind, object? diagnosticSourceArgs)
-#endif
{
_activitySource = activitySource;
_diagnosticSource = diagnosticSource;
@@ -262,13 +199,8 @@ public void AddTag(string name, object value)
{
// Activity is not started yet, add the value to the collection
// that is going to be passed to StartActivity
-#if NETCOREAPP2_1
- _tagCollection ??= ActivityExtensions.CreateTagsCollection() ?? new List>();
- _tagCollection?.Add(new KeyValuePair(name, value!));
-#else
_tagCollection ??= new ActivityTagsCollection();
_tagCollection[name] = value!;
-#endif
}
else
{
@@ -276,45 +208,17 @@ public void AddTag(string name, object value)
}
}
-#if NETCOREAPP2_1
- private IList? GetActivitySourceLinkCollection()
-#else
private List? GetActivitySourceLinkCollection()
-#endif
{
if (_links == null)
{
return null;
}
-#if NETCOREAPP2_1
- var linkCollection = ActivityExtensions.CreateLinkCollection();
- if (linkCollection == null)
- {
- return null;
- }
-#else
var linkCollection = new List();
-#endif
foreach (var activity in _links)
{
-#if NETCOREAPP2_1
- ICollection>? linkTagsCollection = ActivityExtensions.CreateTagsCollection();
- if (linkTagsCollection != null)
- {
- foreach (var tag in activity.Tags)
- {
- linkTagsCollection.Add(new KeyValuePair(tag.Key, tag.Value!));
- }
- }
-
- var link = ActivityExtensions.CreateActivityLink(activity.ParentId!, activity.GetTraceState(), linkTagsCollection);
- if (link != null)
- {
- linkCollection.Add(link);
- }
-#else
ActivityTagsCollection linkTagsCollection = new();
foreach (var tag in activity.Tags)
{
@@ -327,7 +231,6 @@ public void AddTag(string name, object value)
var link = new ActivityLink(context, linkTagsCollection);
linkCollection.Add(link);
}
-#endif
}
return linkCollection;
@@ -337,13 +240,8 @@ public void AddLink(string traceparent, string? tracestate, IDictionary?)_links ?? Array.Empty(),
};
-#if NETCOREAPP2_1
- _currentActivity.SetW3CFormat();
-#else
_currentActivity.SetIdFormat(ActivityIdFormat.W3C);
-#endif
if (_startTime != default)
{
@@ -434,11 +324,7 @@ public void AddLink(string traceparent, string? tracestate, IDictionary
- /// Until we can reference the 5.0 of System.Diagnostics.DiagnosticSource
- ///
- internal static class ActivityExtensions
- {
- static ActivityExtensions()
- {
- ResetFeatureSwitch();
- }
-
- private static bool SupportsActivitySourceSwitch;
-
- private static readonly Type? ActivitySourceType = Type.GetType("System.Diagnostics.ActivitySource, System.Diagnostics.DiagnosticSource");
- private static readonly Type? ActivityKindType = Type.GetType("System.Diagnostics.ActivityKind, System.Diagnostics.DiagnosticSource");
- private static readonly Type? ActivityTagsCollectionType = Type.GetType("System.Diagnostics.ActivityTagsCollection, System.Diagnostics.DiagnosticSource");
- private static readonly Type? ActivityLinkType = Type.GetType("System.Diagnostics.ActivityLink, System.Diagnostics.DiagnosticSource");
- private static readonly Type? ActivityContextType = Type.GetType("System.Diagnostics.ActivityContext, System.Diagnostics.DiagnosticSource");
- private static readonly Type? ActivityStatusCodeType = Type.GetType("System.Diagnostics.ActivityStatusCode, System.Diagnostics.DiagnosticSource");
-
- private static Action? SetIdFormatMethod;
- private static Func? GetTraceStateStringMethod;
- private static Action? SetTraceStateStringMethod;
- private static Action? SetErrorStatusMethod;
- private static Func? GetIdFormatMethod;
- private static Func? GetAllDataRequestedMethod;
- private static Action? ActivityAddTagMethod;
- private static Func