Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecation message for legacy telemetry #673

Merged
merged 25 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Hosting.Services/HostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public static IHost BuildStatefulService(
/// <summary>
/// Registering Dependency Injection classes that will provide Service Fabric specific information for logging
/// </summary>
[Obsolete($"This method also adds Legacy OmexLogger and ActivityEventSender and they are deprecated. This legacy telemetry is pending for removal by 1 July 2024. Consider adding a different telemetry solution. Code: 8913598")]
Gnol-VN marked this conversation as resolved.
Show resolved Hide resolved
public static IServiceCollection AddOmexServiceFabricDependencies<TContext>(this IServiceCollection collection)
where TContext : ServiceContext
{
Expand Down Expand Up @@ -87,12 +88,14 @@ private static IHost BuildServiceFabricService<TRunner, TService, TContext>(
IHost host = builder
.ConfigureServices((context, collection) =>
{
#pragma warning disable CS0618 // Type or member is obsolete
collection
.Configure<ServiceRegistratorOptions>(options =>
{
options.ServiceTypeName = serviceName;
})
.AddOmexServiceFabricDependencies<TContext>()
#pragma warning restore CS0618 // Type or member is obsolete
.AddSingleton<IOmexServiceRegistrator, TRunner>()
.AddHostedService<OmexHostedService>();
})
Expand All @@ -101,16 +104,20 @@ private static IHost BuildServiceFabricService<TRunner, TService, TContext>(
options.ValidateOnBuild = true;
options.ValidateScopes = true;
})
.ConfigureLogging(builder => builder.AddOmexLogging())
.Build();
Gnol-VN marked this conversation as resolved.
Show resolved Hide resolved

#pragma warning disable CS0618 // InitializationLogger using OmexLogger is obsolete. Code: 8913598
InitializationLogger.LogInitializationSucceed(serviceNameForLogging);
Gnol-VN marked this conversation as resolved.
Show resolved Hide resolved
Gnol-VN marked this conversation as resolved.
Show resolved Hide resolved
#pragma warning restore CS0618 // InitializationLogger using OmexLogger is obsolete. Code: 8913598

return host;
}
catch (Exception e)
{
#pragma warning disable CS0618 // InitializationLogger using OmexLogger is obsolete. Code: 8913598
InitializationLogger.LogInitializationFail(serviceNameForLogging, e);
#pragma warning restore CS0618 // InitializationLogger using OmexLogger is obsolete. Code: 8913598

throw;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Hosting/Certificates/InitializationCertificateReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public static class InitializationCertificateReader
/// <summary>
/// Instance of CertificateReader
/// </summary>
#pragma warning disable CS0618 // InitializationLogger using OmexLogger is obsolete and is pending for removal by 1 July 2024. Code: 8913598
public static ICertificateReader Instance { get; } = new CertificateReader(new CertificateStore(), InitializationLogger.Instance);
#pragma warning restore CS0618 // InitializationLogger using OmexLogger is obsolete and is pending for removal by 1 July 2024. Code: 8913598
}
}
3 changes: 3 additions & 0 deletions src/Hosting/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,13 +18,15 @@ public static class ServiceCollectionExtensions
/// <summary>
/// Add Omex Logging and ActivitySource dependencies
/// </summary>
[Obsolete($"Please do not use {nameof(AddOmexServices)} if you just want to use Legacy OmexLogger and ActivityEventSender because they are deprecated. Consider using a different telemetry solution. This method is pending for removal by 1 July 2024. Code: 8913598.")]
public static IHostBuilder AddOmexServices(this IHostBuilder builder) =>
builder
.ConfigureServices((context, collection) => collection.AddOmexServices());

/// <summary>
/// Add Omex Logging and ActivitySource dependencies
/// </summary>
[Obsolete($"Please do not use {nameof(AddOmexServices)} if you just want to use Legacy OmexLogger and ActivityEventSender because they are deprecated. Consider using a different telemetry solution. This method is pending for removal by 1 July 2024. Code: 8913598.")]
public static IServiceCollection AddOmexServices(this IServiceCollection collection) =>
collection
.AddOmexLogging()
Expand Down
3 changes: 2 additions & 1 deletion src/Logging/InitializationLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license.

using System;
using System.Diagnostics;
using Microsoft.Extensions.Logging;
using Microsoft.Omex.Extensions.Abstractions;

Expand All @@ -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.
/// </summary>
[Obsolete($"{nameof(InitializationLogger)} using {nameof(OmexLogger)} is obsolete and is pending for removal by 1 July 2024. Code: 8913598.")]
public static class InitializationLogger
Gnol-VN marked this conversation as resolved.
Show resolved Hide resolved
{
/// <summary>
Expand Down Expand Up @@ -56,6 +56,7 @@ public static void LogInitializationSucceed(string serviceNameForLogging, string
/// <param name="serviceNameForLogging">Service name for logging</param>
/// <param name="ex">Exception to log</param>
/// <param name="message">Message to log</param>
[Obsolete("InitializationLogger using OmexLogger is obsolete and is pending for removal by 1 July 2024. Code: 8913598.")]
public static void LogInitializationFail(string serviceNameForLogging, Exception? ex = null, string message = "")
{
ServiceInitializationEventSource.Instance.LogHostFailed(ex?.ToString() ?? string.Empty, serviceNameForLogging, message);
Expand Down
2 changes: 2 additions & 0 deletions src/Logging/Internal/OmexLoggerProvider.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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. Code: 8913598.")]
internal class OmexLoggerProvider : ILoggerProvider, ISupportExternalScope
{
public OmexLoggerProvider(
Expand Down
13 changes: 11 additions & 2 deletions src/Logging/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -30,6 +31,7 @@ public static IServiceCollection AddOmexServiceContext<TServiceContext>(this ISe
/// Adds Omex event logger to the factory
/// </summary>
/// <param name="builder">The extension method argument</param>
[Obsolete($"{nameof(OmexLogger)} and {nameof(OmexLogEventSource)} are obsolete and pending for removal by 1 July 2024. Please consider using a different Logger. Code: 8913598.")]
public static ILoggingBuilder AddOmexLogging(this ILoggingBuilder builder)
{
builder.AddConfiguration();
Expand All @@ -42,6 +44,7 @@ public static ILoggingBuilder AddOmexLogging(this ILoggingBuilder builder)
/// </summary>
/// <param name="serviceCollection">The extension method argument</param>
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained</returns>
[Obsolete($"{nameof(OmexLogger)} and {nameof(OmexLogEventSource)} are obsolete and pending for removal by 1 July 2024. Please consider using a different Logger. Code: 8913598.")]
Gnol-VN marked this conversation as resolved.
Show resolved Hide resolved
public static IServiceCollection AddOmexLogging(this IServiceCollection serviceCollection)
{
serviceCollection.AddLogging();
Expand All @@ -50,14 +53,20 @@ public static IServiceCollection AddOmexLogging(this IServiceCollection serviceC
serviceCollection.TryAddTransient<IExecutionContext, BaseExecutionContext>();
serviceCollection.TryAddTransient<IExternalScopeProvider, LoggerExternalScopeProvider>();

AddOmexLegacyLogging(serviceCollection);
Gnol-VN marked this conversation as resolved.
Show resolved Hide resolved

return serviceCollection;
}

[Obsolete($"{nameof(OmexLogger)} and {nameof(OmexLogEventSource)} are obsolete and pending for removal by 1 July 2024. Please consider using a different Logger. Code: 8913598.")]
private static void AddOmexLegacyLogging(IServiceCollection serviceCollection)
{
serviceCollection.TryAddSingleton(_ => OmexLogEventSource.Instance);
serviceCollection.TryAddSingleton<ILogEventReplayer, OmexLogEventReplayer>();
serviceCollection.TryAddSingleton<ILogEventSender, OmexLogEventSender>();

serviceCollection.TryAddEnumerable(ServiceDescriptor.Transient<IActivityStopObserver, ReplayableActivityStopObserver>());
serviceCollection.TryAddEnumerable(ServiceDescriptor.Singleton<ILoggerProvider, OmexLoggerProvider>());

return serviceCollection;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ public void AddOmexServiceFabricDependencies_TypesRegistered(Type typeToResolve,
{
void CheckTypeRegistration<TContext>() where TContext : ServiceContext
{
#pragma warning disable CS0618 // AddOmexServiceFabricDependencies also adds Legacy OmexLogger and ActivityEventSender and they are deprecated. This legacy telemetry is pending for removal by 1 July 2024. Consider adding a different telemetry solution. Code: 8913598
object? obj = new ServiceCollection()
.AddOmexServiceFabricDependencies<TContext>()
#pragma warning restore CS0618 // AddOmexServiceFabricDependencies also adds Legacy OmexLogger and ActivityEventSender and they are deprecated. This legacy telemetry is pending for removal by 1 July 2024. Consider adding a different telemetry solution. Code: 8913598
.AddSingleton(new Mock<IHostEnvironment>().Object)
.BuildServiceProvider()
.GetService(typeToResolve);
Expand Down
1 change: 1 addition & 0 deletions tests/Hosting.UnitTests/HostBuilderExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class HostBuilderExtensionsTests
[DataTestMethod]
[DataRow(typeof(ILogger<HostBuilderExtensionsTests>))]
[DataRow(typeof(ActivitySource))]
[Obsolete("AddOmexServices is Obsolete and pending for removal on 1 July 2024. Code: 8913598.")]
public void AddOmexServices_TypesRegistered(Type type)
{
object? collectionObj = new ServiceCollection()
Expand Down
1 change: 1 addition & 0 deletions tests/Logging.UnitTests/OmexLogEventSenderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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. Code: 8913598.")]
[TestClass]
public class OmexLogEventSenderTests
{
Expand Down
1 change: 1 addition & 0 deletions tests/Logging.UnitTests/OmexLoggerProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace Microsoft.Omex.Extensions.Logging.UnitTests
{
[TestClass]
[Obsolete("OmexLogger is Obsolete and pending for removal on 1 July 2024. Code: 8913598.")]
public class OmexLoggerProviderTests
{
[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ public void AddRegexLogScrubbingRule_Scrubs(string input, string expected)

private static ILogScrubbingRule[] GetTypeRegistrations(IServiceCollection collection)
{
#pragma warning disable CS0618 // AddOmexLogging uses OmexLogger and OmexLogEventSource which are obsolete and pending for removal by 1 July 2024. Code: 8913598.
IEnumerable<ILogScrubbingRule> objects = collection
.AddOmexLogging()
#pragma warning restore CS0618 // AddOmexLogging uses OmexLogger and OmexLogEventSource which are obsolete and pending for removal by 1 July 2024. Code: 8913598.
.BuildServiceProvider(new ServiceProviderOptions
{
ValidateOnBuild = true,
Expand Down
11 changes: 9 additions & 2 deletions tests/Logging.UnitTests/ServiceCollectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ public void AddOmexServiceContext_RegisterServiceContext()
public void AddOmexServiceContext_OverridesContextType()
{
IServiceCollection collection = new ServiceCollection()
.AddOmexServiceContext<MockServiceContext>()
.AddOmexLogging();
.AddOmexServiceContext<MockServiceContext>();

#pragma warning disable CS0618 // Type or member is obsolete
collection.AddOmexLogging();
#pragma warning restore CS0618 // Type or member is obsolete

IServiceContext context = ValidateTypeRegistration<IServiceContext>(collection);

Expand All @@ -35,13 +38,15 @@ public void AddOmexServiceContext_OverridesContextType()
}

[TestMethod]
[Obsolete]
public void AddOmexLoggerOnServiceCollection_RegistersLogger()
{
IServiceCollection collection = new ServiceCollection().AddOmexLogging();
ValidateTypeRegistration<ILogger<ServiceCollectionTests>>(collection);
}

[TestMethod]
[Obsolete]
public void AddOmexLoggerOnLogBuilder_RegistersLogger()
{
ILoggingBuilder builder = new MockLoggingBuilder().AddOmexLogging();
Expand All @@ -51,8 +56,10 @@ public void AddOmexLoggerOnLogBuilder_RegistersLogger()
private T ValidateTypeRegistration<T>(IServiceCollection collection)
where T : class
{
#pragma warning disable CS0618 // Type or member is obsolete
T obj = collection
.AddOmexLogging()
#pragma warning restore CS0618 // Type or member is obsolete
.BuildServiceProvider(new ServiceProviderOptions
{
ValidateOnBuild = true,
Expand Down
Loading