Skip to content

Commit f32f048

Browse files
authored
Remove .NET 10 Identity metrics workaround (#4743)
The workaround for manually registering UserManagerMetrics and SignInManagerMetrics types in the DI container is no longer needed as the fix has been included in .NET 10.0.1+. The upstream ASP.NET Core issue (dotnet/aspnetcore#64271) has been resolved and the metrics classes are now instantiated directly without requiring DI registration. Changes: - Removed manual registration code for UserManagerMetrics type - Removed unused using statements (System.Diagnostics.Metrics and Microsoft.Extensions.DependencyInjection.Extensions) Fixes #4623
1 parent 3248f42 commit f32f048

File tree

1 file changed

+0
-22
lines changed
  • test/test-applications/integrations/TestApplication.Http

1 file changed

+0
-22
lines changed

test/test-applications/integrations/TestApplication.Http/Startup.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
using Microsoft.AspNetCore.Authentication.Cookies;
88
using Microsoft.AspNetCore.Authorization;
99
#if NET10_0_OR_GREATER
10-
using System.Diagnostics.Metrics;
1110
using Microsoft.AspNetCore.Identity;
12-
using Microsoft.Extensions.DependencyInjection.Extensions;
1311
#endif
1412

1513
namespace TestApplication.Http;
@@ -54,26 +52,6 @@ public static void ConfigureServices(IServiceCollection services)
5452
services.AddIdentityCore<TestUser>()
5553
.AddUserManager<UserManager<TestUser>>();
5654

57-
// Workaround for .NET 10 bug: Manually register the internal UserManagerMetrics type
58-
// Remove this workaround when upgrading to a .NET version that contains the fix
59-
// Tracked under https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/issues/4623
60-
var userManagerMetricsType = typeof(UserManager<>).Assembly.GetType("Microsoft.AspNetCore.Identity.UserManagerMetrics");
61-
if (userManagerMetricsType != null)
62-
{
63-
services.TryAddSingleton(
64-
userManagerMetricsType,
65-
serviceProvider =>
66-
{
67-
var meterFactory = serviceProvider.GetRequiredService<IMeterFactory>();
68-
return Activator.CreateInstance(
69-
userManagerMetricsType,
70-
System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic,
71-
null,
72-
[meterFactory],
73-
null)!;
74-
});
75-
}
76-
7755
// Add in-memory user store for testing
7856
services.AddSingleton<IUserStore<TestUser>, InMemoryUserStore>();
7957
#endif

0 commit comments

Comments
 (0)