Skip to content

Commit c3cb40e

Browse files
committed
Update
1 parent d45fc2e commit c3cb40e

File tree

2 files changed

+99
-46
lines changed

2 files changed

+99
-46
lines changed

src/Identity/Core/src/SignInManagerMetrics.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ public SignInManagerMetrics(IMeterFactory meterFactory)
4242

4343
internal void CheckPasswordSignIn(string userType, SignInResult? result, Exception? exception = null)
4444
{
45+
if (!_checkPasswordCounter.Enabled)
46+
{
47+
return;
48+
}
49+
4550
var tags = new TagList
4651
{
4752
{ "aspnetcore.identity.user_type", userType },
@@ -54,6 +59,11 @@ internal void CheckPasswordSignIn(string userType, SignInResult? result, Excepti
5459

5560
internal void AuthenticateSignIn(string userType, string authenticationScheme, SignInResult? result, SignInType signInType, bool isPersistent, Exception? exception = null)
5661
{
62+
if (!_authenticateCounter.Enabled)
63+
{
64+
return;
65+
}
66+
5767
var tags = new TagList
5868
{
5969
{ "aspnetcore.identity.user_type", userType },
@@ -69,6 +79,11 @@ internal void AuthenticateSignIn(string userType, string authenticationScheme, S
6979

7080
internal void SignInUserPrincipal(string userType, string authenticationScheme, Exception? exception = null)
7181
{
82+
if (!_signInUserPrincipalCounter.Enabled)
83+
{
84+
return;
85+
}
86+
7287
var tags = new TagList
7388
{
7489
{ "aspnetcore.identity.user_type", userType },
@@ -81,6 +96,11 @@ internal void SignInUserPrincipal(string userType, string authenticationScheme,
8196

8297
internal void SignOutUserPrincipal(string userType, string authenticationScheme, Exception? exception = null)
8398
{
99+
if (!_signOutUserPrincipalCounter.Enabled)
100+
{
101+
return;
102+
}
103+
84104
var tags = new TagList
85105
{
86106
{ "aspnetcore.identity.user_type", userType },
@@ -93,6 +113,11 @@ internal void SignOutUserPrincipal(string userType, string authenticationScheme,
93113

94114
internal void RememberTwoFactorClient(string userType, string authenticationScheme, Exception? exception = null)
95115
{
116+
if (!_rememberTwoFactorClientCounter.Enabled)
117+
{
118+
return;
119+
}
120+
96121
var tags = new TagList
97122
{
98123
{ "aspnetcore.identity.user_type", userType },
@@ -105,6 +130,11 @@ internal void RememberTwoFactorClient(string userType, string authenticationSche
105130

106131
internal void ForgetTwoFactorClient(string userType, string authenticationScheme, Exception? exception = null)
107132
{
133+
if (!_forgetTwoFactorCounter.Enabled)
134+
{
135+
return;
136+
}
137+
108138
var tags = new TagList
109139
{
110140
{ "aspnetcore.identity.user_type", userType },
@@ -117,6 +147,11 @@ internal void ForgetTwoFactorClient(string userType, string authenticationScheme
117147

118148
internal void RefreshSignIn(string userType, string authenticationScheme, bool? success, bool? isPersistent, Exception? exception = null)
119149
{
150+
if (!_refreshCounter.Enabled)
151+
{
152+
return;
153+
}
154+
120155
var tags = new TagList
121156
{
122157
{ "aspnetcore.identity.user_type", userType },

src/Identity/Extensions.Core/src/UserManagerMetrics.cs

Lines changed: 64 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -42,78 +42,83 @@ public UserManagerMetrics(IMeterFactory meterFactory)
4242

4343
internal void CreateUser(string userType, IdentityResult? result, Exception? exception = null)
4444
{
45-
if (_createCounter.Enabled)
45+
if (!_createCounter.Enabled)
4646
{
47-
var tags = new TagList
48-
{
49-
{ "aspnetcore.identity.user_type", userType }
50-
};
51-
AddIdentityResultTags(ref tags, result);
52-
AddExceptionTags(ref tags, exception);
53-
54-
_createCounter.Add(1, tags);
47+
return;
5548
}
56-
}
5749

58-
private static void AddExceptionTags(ref TagList tags, Exception? exception)
59-
{
60-
if (exception != null)
50+
var tags = new TagList
6151
{
62-
tags.Add("error.type", exception.GetType().FullName!);
63-
}
52+
{ "aspnetcore.identity.user_type", userType }
53+
};
54+
AddIdentityResultTags(ref tags, result);
55+
AddExceptionTags(ref tags, exception);
56+
57+
_createCounter.Add(1, tags);
6458
}
6559

6660
internal void UpdateUser(string userType, IdentityResult? result, UserUpdateType updateType, Exception? exception = null)
6761
{
68-
if (_updateCounter.Enabled)
62+
if (!_updateCounter.Enabled)
6963
{
70-
var tags = new TagList
71-
{
72-
{ "aspnetcore.identity.user_type", userType },
73-
{ "aspnetcore.identity.user.update_type", GetUpdateType(updateType) },
74-
};
75-
AddIdentityResultTags(ref tags, result);
76-
AddExceptionTags(ref tags, exception);
77-
78-
_updateCounter.Add(1, tags);
64+
return;
7965
}
66+
67+
var tags = new TagList
68+
{
69+
{ "aspnetcore.identity.user_type", userType },
70+
{ "aspnetcore.identity.user.update_type", GetUpdateType(updateType) },
71+
};
72+
AddIdentityResultTags(ref tags, result);
73+
AddExceptionTags(ref tags, exception);
74+
75+
_updateCounter.Add(1, tags);
8076
}
8177

8278
internal void DeleteUser(string userType, IdentityResult? result, Exception? exception = null)
8379
{
84-
if (_deleteCounter.Enabled)
80+
if (!_deleteCounter.Enabled)
8581
{
86-
var tags = new TagList
87-
{
88-
{ "aspnetcore.identity.user_type", userType }
89-
};
90-
AddIdentityResultTags(ref tags, result);
91-
AddExceptionTags(ref tags, exception);
92-
93-
_deleteCounter.Add(1, tags);
82+
return;
9483
}
84+
85+
var tags = new TagList
86+
{
87+
{ "aspnetcore.identity.user_type", userType }
88+
};
89+
AddIdentityResultTags(ref tags, result);
90+
AddExceptionTags(ref tags, exception);
91+
92+
_deleteCounter.Add(1, tags);
9593
}
9694

9795
internal void CheckPassword(string userType, bool? userMissing, PasswordVerificationResult? result, Exception? exception = null)
9896
{
99-
if (_checkPasswordCounter.Enabled)
97+
if (!_checkPasswordCounter.Enabled)
10098
{
101-
var tags = new TagList
102-
{
103-
{ "aspnetcore.identity.user_type", userType },
104-
};
105-
if (userMissing != null || result != null)
106-
{
107-
tags.Add("aspnetcore.identity.user.password_result", GetPasswordResult(result, passwordMissing: null, userMissing));
108-
}
109-
AddExceptionTags(ref tags, exception);
110-
111-
_checkPasswordCounter.Add(1, tags);
99+
return;
112100
}
101+
102+
var tags = new TagList
103+
{
104+
{ "aspnetcore.identity.user_type", userType },
105+
};
106+
if (userMissing != null || result != null)
107+
{
108+
tags.Add("aspnetcore.identity.user.password_result", GetPasswordResult(result, passwordMissing: null, userMissing));
109+
}
110+
AddExceptionTags(ref tags, exception);
111+
112+
_checkPasswordCounter.Add(1, tags);
113113
}
114114

115115
internal void VerifyToken(string userType, bool? result, string purpose, Exception? exception = null)
116116
{
117+
if (!_verifyTokenCounter.Enabled)
118+
{
119+
return;
120+
}
121+
117122
var tags = new TagList
118123
{
119124
{ "aspnetcore.identity.user_type", userType },
@@ -130,6 +135,11 @@ internal void VerifyToken(string userType, bool? result, string purpose, Excepti
130135

131136
internal void GenerateToken(string userType, string purpose, Exception? exception = null)
132137
{
138+
if (!_generateTokenCounter.Enabled)
139+
{
140+
return;
141+
}
142+
133143
var tags = new TagList
134144
{
135145
{ "aspnetcore.identity.user_type", userType },
@@ -177,6 +187,14 @@ private static void AddIdentityResultTags(ref TagList tags, IdentityResult? resu
177187
}
178188
}
179189

190+
private static void AddExceptionTags(ref TagList tags, Exception? exception)
191+
{
192+
if (exception != null)
193+
{
194+
tags.Add("error.type", exception.GetType().FullName!);
195+
}
196+
}
197+
180198
private static string GetPasswordResult(PasswordVerificationResult? result, bool? passwordMissing, bool? userMissing)
181199
{
182200
return (result, passwordMissing ?? false, userMissing ?? false) switch

0 commit comments

Comments
 (0)