From 88b74b3c3cd3fe94f4d032250889edcdb373409b Mon Sep 17 00:00:00 2001 From: Gnol Long Date: Tue, 21 May 2024 15:49:18 +0100 Subject: [PATCH] Deprecation message for legacy telemetry (#673) --- .../Internal/EventSource/ActivityEventSender.cs | 1 + .../Internal/EventSource/ActivityEventSource.cs | 2 ++ .../EventSource/AggregatedActivitiesEventSender.cs | 2 ++ src/Activities/ServiceCollectionExtensions.cs | 7 +++++-- src/Hosting.Services/HostBuilderExtensions.cs | 9 +++++++++ .../Certificates/InitializationCertificateReader.cs | 3 +++ src/Hosting/ServiceCollectionExtensions.cs | 3 +++ src/Logging/InitializationLogger.cs | 2 +- .../Internal/EventSource/OmexLogEventSender.cs | 1 + .../Internal/EventSource/OmexLogEventSource.cs | 1 + .../EventSource/ServiceInitializationEventSource.cs | 1 + src/Logging/Internal/OmexLoggerProvider.cs | 2 ++ src/Logging/ServiceCollectionExtensions.cs | 3 +++ .../ServiceFabricClientFactory.cs | 3 +++ .../Internal/ActivitiesEventSourceTests.cs | 1 + tests/Logging.UnitTests/OmexLogEventSenderTests.cs | 1 + tests/Logging.UnitTests/OmexLoggerProviderTests.cs | 1 + .../Scrubbing/ServiceCollectionExtensionsTests.cs | 2 ++ tests/Logging.UnitTests/ServiceCollectionTests.cs | 11 +++++++++-- 19 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/Activities/Internal/EventSource/ActivityEventSender.cs b/src/Activities/Internal/EventSource/ActivityEventSender.cs index ad7806bc1..96a95b3bc 100644 --- a/src/Activities/Internal/EventSource/ActivityEventSender.cs +++ b/src/Activities/Internal/EventSource/ActivityEventSender.cs @@ -15,6 +15,7 @@ namespace Microsoft.Omex.Extensions.Activities { + [Obsolete($"{nameof(ActivityEventSender)} is obsolete and pending for removal by 1 July 2024.", DiagnosticId = "OMEX188")] internal sealed class ActivityEventSender : IActivitiesEventSender { public ActivityEventSender(ActivityEventSource eventSource, IExecutionContext executionContext, ILogger logger, IOptions options) diff --git a/src/Activities/Internal/EventSource/ActivityEventSource.cs b/src/Activities/Internal/EventSource/ActivityEventSource.cs index 09ef5be55..15b526ed7 100644 --- a/src/Activities/Internal/EventSource/ActivityEventSource.cs +++ b/src/Activities/Internal/EventSource/ActivityEventSource.cs @@ -1,12 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. +using System; using System.Diagnostics.Tracing; using Microsoft.Omex.Extensions.Abstractions.EventSources; namespace Microsoft.Omex.Extensions.Activities { // Renamed from Microsoft-OMEX-TimedScopes to avoid conflict with sources in other libraries + [Obsolete($"{nameof(ActivityEventSource)} is obsolete and pending for removal by 1 July 2024.", DiagnosticId = "OMEX188")] [EventSource(Name = "Microsoft-OMEX-TimedScopes-Ext")] internal sealed class ActivityEventSource : EventSource { diff --git a/src/Activities/Internal/EventSource/AggregatedActivitiesEventSender.cs b/src/Activities/Internal/EventSource/AggregatedActivitiesEventSender.cs index 3cf09469e..814ea0e09 100644 --- a/src/Activities/Internal/EventSource/AggregatedActivitiesEventSender.cs +++ b/src/Activities/Internal/EventSource/AggregatedActivitiesEventSender.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. +using System; using System.Diagnostics; namespace Microsoft.Omex.Extensions.Activities @@ -8,6 +9,7 @@ namespace Microsoft.Omex.Extensions.Activities /// /// Type created to temporary combine ActivityEventSender and ActivityMetricsSender, it should be deleted after removal for ActivityEventSender /// + [Obsolete($"{nameof(AggregatedActivitiesEventSender)} is obsolete and pending for removal by 1 July 2024. On the removal, only {nameof(ActivityMetricsSender)} is available to send metrics by OpenTelemetry.", DiagnosticId = "OMEX188")] internal sealed class AggregatedActivitiesEventSender : IActivitiesEventSender { private readonly ActivityEventSender m_etwSender; diff --git a/src/Activities/ServiceCollectionExtensions.cs b/src/Activities/ServiceCollectionExtensions.cs index 59a855a0b..3d76eb720 100644 --- a/src/Activities/ServiceCollectionExtensions.cs +++ b/src/Activities/ServiceCollectionExtensions.cs @@ -35,10 +35,14 @@ public static IServiceCollection AddOmexActivitySource(this IServiceCollection s serviceCollection.TryAddSingleton(); - // eventually ActivityMetricsSender will be default implementation of IActivitiesEventSender and we should remove ActivityEventSender, and AggregatedActivitiesEventSender serviceCollection.TryAddSingleton(); + +#pragma warning disable OMEX188 // ActivityEventSender and AggregatedActivitiesEventSender are obsolete and pending for removal by 1 July 2024. DiagnosticId = "OMEX188" serviceCollection.TryAddSingleton(); serviceCollection.TryAddSingleton(); + serviceCollection.TryAddSingleton(p => ActivityEventSource.Instance); +#pragma warning restore OMEX188 // ActivityEventSender and AggregatedActivitiesEventSender are obsolete and pending for removal by 1 July 2024. DiagnosticId = "OMEX188" + serviceCollection.TryAddSingleton(_ => new CustomBaggageDimensions()); serviceCollection.TryAddSingleton(_ => new CustomTagObjectsDimensions()); @@ -50,7 +54,6 @@ public static IServiceCollection AddOmexActivitySource(this IServiceCollection s serviceCollection.TryAddSingleton(); serviceCollection.TryAddSingleton(p => new ActivitySource(ActivitySourceName, ActivitySourceVersion)); - serviceCollection.TryAddSingleton(p => ActivityEventSource.Instance); return serviceCollection; } diff --git a/src/Hosting.Services/HostBuilderExtensions.cs b/src/Hosting.Services/HostBuilderExtensions.cs index f568e86d4..6fb4ede52 100644 --- a/src/Hosting.Services/HostBuilderExtensions.cs +++ b/src/Hosting.Services/HostBuilderExtensions.cs @@ -7,6 +7,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; using Microsoft.Omex.Extensions.Abstractions; using Microsoft.Omex.Extensions.Abstractions.Accessors; using Microsoft.Omex.Extensions.Abstractions.ExecutionContext; @@ -60,6 +61,7 @@ public static IServiceCollection AddOmexServiceFabricDependencies(this collection.TryAddSingleton(); collection.TryAddSingleton(); + return collection.AddOmexServices(); } @@ -101,16 +103,23 @@ private static IHost BuildServiceFabricService( options.ValidateOnBuild = true; options.ValidateScopes = true; }) +#pragma warning disable OMEX188 // AddOmexLogging using OmexLogger is obsolete. DiagnosticId = "OMEX188" .ConfigureLogging(builder => builder.AddOmexLogging()) +#pragma warning restore OMEX188 // AddOmexLogging using OmexLogger is obsolete. DiagnosticId = "OMEX188" .Build(); +#pragma warning disable OMEX188 // InitializationLogger using OmexLogger is obsolete. DiagnosticId = "OMEX188" InitializationLogger.LogInitializationSucceed(serviceNameForLogging); +#pragma warning restore OMEX188 // InitializationLogger using OmexLogger is obsolete. DiagnosticId = "OMEX188" return host; } catch (Exception e) { +#pragma warning disable OMEX188 // InitializationLogger using OmexLogger is obsolete. DiagnosticId = "OMEX188" InitializationLogger.LogInitializationFail(serviceNameForLogging, e); +#pragma warning restore OMEX188 // InitializationLogger using OmexLogger is obsolete. DiagnosticId = "OMEX188" + throw; } } diff --git a/src/Hosting/Certificates/InitializationCertificateReader.cs b/src/Hosting/Certificates/InitializationCertificateReader.cs index ffb403002..ca2ac21ce 100644 --- a/src/Hosting/Certificates/InitializationCertificateReader.cs +++ b/src/Hosting/Certificates/InitializationCertificateReader.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. +using System; using Microsoft.Omex.Extensions.Logging; namespace Microsoft.Omex.Extensions.Hosting.Certificates @@ -16,6 +17,8 @@ public static class InitializationCertificateReader /// /// Instance of CertificateReader /// +#pragma warning disable OMEX188 // InitializationLogger using OmexLogger is obsolete and is pending for removal by 1 July 2024. public static ICertificateReader Instance { get; } = new CertificateReader(new CertificateStore(), InitializationLogger.Instance); +#pragma warning restore OMEX188 // InitializationLogger using OmexLogger is obsolete and is pending for removal by 1 July 2024. } } diff --git a/src/Hosting/ServiceCollectionExtensions.cs b/src/Hosting/ServiceCollectionExtensions.cs index 44e1d8cb2..5e23f8e09 100644 --- a/src/Hosting/ServiceCollectionExtensions.cs +++ b/src/Hosting/ServiceCollectionExtensions.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. +using System; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Hosting; @@ -25,8 +26,10 @@ public static IHostBuilder AddOmexServices(this IHostBuilder builder) => /// Add Omex Logging and ActivitySource dependencies /// public static IServiceCollection AddOmexServices(this IServiceCollection collection) => +#pragma warning disable OMEX188 // OmexLogger and OmexLogEventSource are obsolete and pending for removal by 1 July 2024. Please consider using a different Logger. collection .AddOmexLogging() +#pragma warning restore OMEX188 // OmexLogger and OmexLogEventSource are obsolete and pending for removal by 1 July 2024. Please consider using a different Logger. .AddOmexActivitySource(); /// diff --git a/src/Logging/InitializationLogger.cs b/src/Logging/InitializationLogger.cs index 5f82e8dc4..44d0b978c 100644 --- a/src/Logging/InitializationLogger.cs +++ b/src/Logging/InitializationLogger.cs @@ -2,7 +2,6 @@ // Licensed under the MIT license. using System; -using System.Diagnostics; using Microsoft.Extensions.Logging; using Microsoft.Omex.Extensions.Abstractions; @@ -12,6 +11,7 @@ namespace Microsoft.Omex.Extensions.Logging /// InitializationLogger is the logger to be used before the proper ILogger from DI is set. /// Not to be used as main logger. /// + [Obsolete($"{nameof(InitializationLogger)} using {nameof(OmexLogger)} is obsolete and is pending for removal by 1 July 2024.", DiagnosticId = "OMEX188")] public static class InitializationLogger { /// diff --git a/src/Logging/Internal/EventSource/OmexLogEventSender.cs b/src/Logging/Internal/EventSource/OmexLogEventSender.cs index 4d112b48a..1cb810177 100644 --- a/src/Logging/Internal/EventSource/OmexLogEventSender.cs +++ b/src/Logging/Internal/EventSource/OmexLogEventSender.cs @@ -11,6 +11,7 @@ namespace Microsoft.Omex.Extensions.Logging { + [Obsolete($"{nameof(OmexLogEventSender)} is obsolete and pending for removal by 1 July 2024.", DiagnosticId = "OMEX188")] internal sealed class OmexLogEventSender : ILogEventSender { static OmexLogEventSender() diff --git a/src/Logging/Internal/EventSource/OmexLogEventSource.cs b/src/Logging/Internal/EventSource/OmexLogEventSource.cs index 247820a6b..50678e51a 100644 --- a/src/Logging/Internal/EventSource/OmexLogEventSource.cs +++ b/src/Logging/Internal/EventSource/OmexLogEventSource.cs @@ -8,6 +8,7 @@ namespace Microsoft.Omex.Extensions.Logging { // Renamed from Microsoft-OMEX-Logs to avoid conflict with sources in other libraries + [Obsolete($"{nameof(OmexLogEventSource)} is obsolete and pending for removal by 1 July 2024.", DiagnosticId = "OMEX188")] [EventSource(Name = "Microsoft-OMEX-Logs-Ext")] internal sealed class OmexLogEventSource : EventSource { diff --git a/src/Logging/Internal/EventSource/ServiceInitializationEventSource.cs b/src/Logging/Internal/EventSource/ServiceInitializationEventSource.cs index db9c18399..1bb7f6da3 100644 --- a/src/Logging/Internal/EventSource/ServiceInitializationEventSource.cs +++ b/src/Logging/Internal/EventSource/ServiceInitializationEventSource.cs @@ -11,6 +11,7 @@ namespace Microsoft.Omex.Extensions.Logging /// Service Fabric event source /// [EventSource(Name = "Microsoft-OMEX-HostLogs")] + [Obsolete($"{nameof(ServiceInitializationEventSource)} is obsolete and is pending for removal by 1 July 2024.", DiagnosticId = "OMEX188")] internal sealed class ServiceInitializationEventSource : EventSource { /// diff --git a/src/Logging/Internal/OmexLoggerProvider.cs b/src/Logging/Internal/OmexLoggerProvider.cs index 17190655b..2aa49c4a5 100644 --- a/src/Logging/Internal/OmexLoggerProvider.cs +++ b/src/Logging/Internal/OmexLoggerProvider.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. +using System; using System.Collections.Generic; using Microsoft.Extensions.Logging; using Microsoft.Omex.Extensions.Logging.Replayable; @@ -9,6 +10,7 @@ namespace Microsoft.Omex.Extensions.Logging { [ProviderAlias("Omex")] + [Obsolete($"{nameof(OmexLogger)} and {nameof(OmexLogEventSource)} are obsolete and pending for removal by 1 July 2024. Please consider using a different logging solution.", DiagnosticId = "OMEX188")] internal class OmexLoggerProvider : ILoggerProvider, ISupportExternalScope { public OmexLoggerProvider( diff --git a/src/Logging/ServiceCollectionExtensions.cs b/src/Logging/ServiceCollectionExtensions.cs index 1543ee39a..70dc2b111 100644 --- a/src/Logging/ServiceCollectionExtensions.cs +++ b/src/Logging/ServiceCollectionExtensions.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. +using System; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Logging; @@ -30,6 +31,7 @@ public static IServiceCollection AddOmexServiceContext(this ISe /// Adds Omex event logger to the factory /// /// The extension method argument + [Obsolete("OmexLogger and OmexLogEventSource are obsolete and pending for removal by 1 July 2024. Please consider using a different Logger.", DiagnosticId = "OMEX188")] public static ILoggingBuilder AddOmexLogging(this ILoggingBuilder builder) { builder.AddConfiguration(); @@ -42,6 +44,7 @@ public static ILoggingBuilder AddOmexLogging(this ILoggingBuilder builder) /// /// The extension method argument /// The so that additional calls can be chained + [Obsolete("OmexLogger and OmexLogEventSource are obsolete and pending for removal by 1 July 2024. Please consider using a different Logger.", DiagnosticId = "OMEX188")] public static IServiceCollection AddOmexLogging(this IServiceCollection serviceCollection) { serviceCollection.AddLogging(); diff --git a/src/ServiceFabricGuest.Abstractions/ServiceFabricClientFactory.cs b/src/ServiceFabricGuest.Abstractions/ServiceFabricClientFactory.cs index 080669cfe..a2ed31ee2 100644 --- a/src/ServiceFabricGuest.Abstractions/ServiceFabricClientFactory.cs +++ b/src/ServiceFabricGuest.Abstractions/ServiceFabricClientFactory.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. +using System; using Microsoft.Extensions.Options; using Microsoft.Omex.Extensions.Hosting.Certificates; @@ -18,6 +19,8 @@ public class ServiceFabricClientFactory /// Creates service fabric client wrapper instance and returns it. /// public static IServiceFabricClientWrapper Create(ServiceFabricRestClientOptions options) => +#pragma warning disable OMEX188 // InitializationCertificateReader using OmexLogger is obsolete. DiagnosticId = "OMEX188" new ServiceFabricClientWrapper(Options.Create(options), InitializationCertificateReader.Instance); +#pragma warning restore OMEX188 // InitializationCertificateReader using OmexLogger is obsolete. DiagnosticId = "OMEX188" } } diff --git a/tests/Activities.UnitTests/Internal/ActivitiesEventSourceTests.cs b/tests/Activities.UnitTests/Internal/ActivitiesEventSourceTests.cs index 4ae392230..748ddc91e 100644 --- a/tests/Activities.UnitTests/Internal/ActivitiesEventSourceTests.cs +++ b/tests/Activities.UnitTests/Internal/ActivitiesEventSourceTests.cs @@ -17,6 +17,7 @@ namespace Microsoft.Omex.Extensions.Activities.UnitTests { [TestClass] + [Obsolete($"{nameof(ActivityEventSender)} is obsolete and pending for removal by 1 July 2024.", DiagnosticId = "OMEX188")] public class ActivitiesEventSourceTests { [DataTestMethod] diff --git a/tests/Logging.UnitTests/OmexLogEventSenderTests.cs b/tests/Logging.UnitTests/OmexLogEventSenderTests.cs index f5fd44ca6..0651c706f 100644 --- a/tests/Logging.UnitTests/OmexLogEventSenderTests.cs +++ b/tests/Logging.UnitTests/OmexLogEventSenderTests.cs @@ -15,6 +15,7 @@ namespace Microsoft.Omex.Extensions.Logging.UnitTests { + [Obsolete("InitializationLogger using OmexLogger is obsolete and is pending for removal by 1 July 2024.", DiagnosticId = "OMEX188")] [TestClass] public class OmexLogEventSenderTests { diff --git a/tests/Logging.UnitTests/OmexLoggerProviderTests.cs b/tests/Logging.UnitTests/OmexLoggerProviderTests.cs index c1326fe07..3d0997818 100644 --- a/tests/Logging.UnitTests/OmexLoggerProviderTests.cs +++ b/tests/Logging.UnitTests/OmexLoggerProviderTests.cs @@ -11,6 +11,7 @@ namespace Microsoft.Omex.Extensions.Logging.UnitTests { [TestClass] + [Obsolete("OmexLogger is Obsolete and pending for removal on 1 July 2024.", DiagnosticId = "OMEX188")] public class OmexLoggerProviderTests { [TestMethod] diff --git a/tests/Logging.UnitTests/Scrubbing/ServiceCollectionExtensionsTests.cs b/tests/Logging.UnitTests/Scrubbing/ServiceCollectionExtensionsTests.cs index 0f622ef52..9b67a16d5 100644 --- a/tests/Logging.UnitTests/Scrubbing/ServiceCollectionExtensionsTests.cs +++ b/tests/Logging.UnitTests/Scrubbing/ServiceCollectionExtensionsTests.cs @@ -142,8 +142,10 @@ public void AddRegexLogScrubbingRule_Scrubs(string input, string expected) private static ILogScrubbingRule[] GetTypeRegistrations(IServiceCollection collection) { +#pragma warning disable OMEX188 // AddOmexLogging uses OmexLogger and OmexLogEventSource which are obsolete and pending for removal by 1 July 2024. DiagnosticId = "OMEX188" IEnumerable objects = collection .AddOmexLogging() +#pragma warning restore OMEX188 // AddOmexLogging uses OmexLogger and OmexLogEventSource which are obsolete and pending for removal by 1 July 2024. DiagnosticId = "OMEX188" .BuildServiceProvider(new ServiceProviderOptions { ValidateOnBuild = true, diff --git a/tests/Logging.UnitTests/ServiceCollectionTests.cs b/tests/Logging.UnitTests/ServiceCollectionTests.cs index d5cb96989..9eca29b15 100644 --- a/tests/Logging.UnitTests/ServiceCollectionTests.cs +++ b/tests/Logging.UnitTests/ServiceCollectionTests.cs @@ -24,8 +24,11 @@ public void AddOmexServiceContext_RegisterServiceContext() public void AddOmexServiceContext_OverridesContextType() { IServiceCollection collection = new ServiceCollection() - .AddOmexServiceContext() - .AddOmexLogging(); + .AddOmexServiceContext(); + +#pragma warning disable OMEX188 // AddOmexLogging method is obsolete. DiagnosticId = "OMEX188" + collection.AddOmexLogging(); +#pragma warning restore OMEX188 // AddOmexLogging method is obsolete. DiagnosticId = "OMEX188" IServiceContext context = ValidateTypeRegistration(collection); @@ -35,6 +38,7 @@ public void AddOmexServiceContext_OverridesContextType() } [TestMethod] + [Obsolete("AddOmexLogging method is obsolete.", DiagnosticId = "OMEX188")] public void AddOmexLoggerOnServiceCollection_RegistersLogger() { IServiceCollection collection = new ServiceCollection().AddOmexLogging(); @@ -42,6 +46,7 @@ public void AddOmexLoggerOnServiceCollection_RegistersLogger() } [TestMethod] + [Obsolete("AddOmexLogging method is obsolete.", DiagnosticId = "OMEX188")] public void AddOmexLoggerOnLogBuilder_RegistersLogger() { ILoggingBuilder builder = new MockLoggingBuilder().AddOmexLogging(); @@ -51,8 +56,10 @@ public void AddOmexLoggerOnLogBuilder_RegistersLogger() private T ValidateTypeRegistration(IServiceCollection collection) where T : class { +#pragma warning disable OMEX188 // AddOmexLogging method is obsolete. DiagnosticId = "OMEX188" T obj = collection .AddOmexLogging() +#pragma warning restore OMEX188 // AddOmexLogging method is obsolete. DiagnosticId = "OMEX188" .BuildServiceProvider(new ServiceProviderOptions { ValidateOnBuild = true,