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 12 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
11 changes: 1 addition & 10 deletions src/Hosting.Services/HostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,7 @@ public static IServiceCollection AddOmexServiceFabricDependencies<TContext>(this
collection.TryAddSingleton<IServiceContext, OmexServiceFabricContext>();
collection.TryAddSingleton<IExecutionContext, ServiceFabricExecutionContext>();

collection.AddLogging();

collection.TryAddTransient<IServiceContext, EmptyServiceContext>();
collection.TryAddTransient<IExecutionContext, BaseExecutionContext>();
collection.TryAddTransient<IExternalScopeProvider, LoggerExternalScopeProvider>();

#pragma warning disable OMEX188 // This method also adds Legacy OmexLogger and ActivityEventSender which are deprecated. They are pending for removal by 1 July 2024. Consider adding a different telemetry solution. DiagnosticId = "OMEX188"
return collection.AddOmexServices();
#pragma warning restore OMEX188 // This method also adds Legacy OmexLogger and ActivityEventSender which are deprecated. They are pending for removal by 1 July 2024. Consider adding a different telemetry solution. DiagnosticId = "OMEX188"
}

private static IHost BuildServiceFabricService<TRunner, TService, TContext>(
Expand All @@ -97,13 +89,12 @@ private static IHost BuildServiceFabricService<TRunner, TService, TContext>(
IHost host = builder
.ConfigureServices((context, collection) =>
{
collection.AddOmexServiceFabricDependencies<TContext>();

collection
.Configure<ServiceRegistratorOptions>(options =>
{
options.ServiceTypeName = serviceName;
})
.AddOmexServiceFabricDependencies<TContext>()
.AddSingleton<IOmexServiceRegistrator, TRunner>()
.AddHostedService<OmexHostedService>();
})
Expand Down
5 changes: 3 additions & 2 deletions src/Hosting/Certificates/InitializationCertificateReader.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.Omex.Extensions.Logging;

namespace Microsoft.Omex.Extensions.Hosting.Certificates
Expand All @@ -16,8 +17,8 @@ public static class InitializationCertificateReader
/// <summary>
/// Instance of CertificateReader
/// </summary>
#pragma warning disable OMEX188 // InitializationLogger using OmexLogger is obsolete and is pending for removal by 1 July 2024. DiagnosticId = "OMEX188"
#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. DiagnosticId = "OMEX188"
#pragma warning restore OMEX188 // InitializationLogger using OmexLogger is obsolete and is pending for removal by 1 July 2024.
}
}
4 changes: 2 additions & 2 deletions src/Hosting/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ 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.", DiagnosticId = "OMEX188")]
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.", DiagnosticId = "OMEX188")]
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();

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion src/Logging/InitializationLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ 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.", DiagnosticId = "OMEX188")]
public static void LogInitializationFail(string serviceNameForLogging, Exception? ex = null, string message = "")
{
ServiceInitializationEventSource.Instance.LogHostFailed(ex?.ToString() ?? string.Empty, serviceNameForLogging, message);
Expand Down
8 changes: 1 addition & 7 deletions src/Logging/Internal/EventSource/EmptyServiceContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,10 @@ namespace Microsoft.Omex.Extensions.Logging
/// <summary>
/// IServiceContext without any information
/// </summary>
public class EmptyServiceContext : IServiceContext
internal class EmptyServiceContext : IServiceContext
{
/// <summary>
/// PartitionId
/// </summary>
public Guid PartitionId => Guid.Empty;

/// <summary>
/// ReplicaOrInstanceId
/// </summary>
public long ReplicaOrInstanceId => 0;
}
}
1 change: 1 addition & 0 deletions src/Logging/Internal/EventSource/OmexLogEventSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions src/Logging/Internal/EventSource/OmexLogEventSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
14 changes: 4 additions & 10 deletions src/Logging/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +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.", DiagnosticId = "OMEX188")]
[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();
Expand All @@ -44,7 +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.", DiagnosticId = "OMEX188")]
[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();
Expand All @@ -53,20 +53,14 @@ public static IServiceCollection AddOmexLogging(this IServiceCollection serviceC
serviceCollection.TryAddTransient<IExecutionContext, BaseExecutionContext>();
serviceCollection.TryAddTransient<IExternalScopeProvider, LoggerExternalScopeProvider>();

AddOmexLegacyLogging(serviceCollection);

return serviceCollection;
}

[Obsolete($"{nameof(OmexLogger)} and {nameof(OmexLogEventSource)} are obsolete and pending for removal by 1 July 2024. Please consider using a different Logger.", DiagnosticId = "OMEX188")]
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
@@ -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;

Expand All @@ -18,6 +19,8 @@ public class ServiceFabricClientFactory
/// Creates service fabric client wrapper instance and returns it.
/// </summary>
public static IServiceFabricClientWrapper Create(ServiceFabricRestClientOptions options) =>
#pragma warning disable OMEX188 // InitializationCertificateReader using OmexLogger is obsolete. DiagnosticId = "OMEX188"
Gnol-VN marked this conversation as resolved.
Show resolved Hide resolved
new ServiceFabricClientWrapper(Options.Create(options), InitializationCertificateReader.Instance);
#pragma warning restore OMEX188 // InitializationCertificateReader using OmexLogger is obsolete. DiagnosticId = "OMEX188"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ 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. DiagnosticId = "OMEX188"
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. DiagnosticId = "OMEX188"
.AddSingleton(new Mock<IHostEnvironment>().Object)
.BuildServiceProvider()
.GetService(typeToResolve);
Expand Down
1 change: 0 additions & 1 deletion tests/Hosting.UnitTests/HostBuilderExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class HostBuilderExtensionsTests
[DataTestMethod]
[DataRow(typeof(ILogger<HostBuilderExtensionsTests>))]
[DataRow(typeof(ActivitySource))]
[Obsolete("AddOmexServices is Obsolete and pending for removal on 1 July 2024.", DiagnosticId = "OMEX188")]
public void AddOmexServices_TypesRegistered(Type type)
{
object? collectionObj = new ServiceCollection()
Expand Down
Loading