Skip to content

Commit 06a3edf

Browse files
committed
trace2: add regions to OAuth
Add region tracing to key methods in OAuth2Client. This was deemed a good starting point for regions due to the server interaction required to obtain tokens. Additional regions can and should be added to additional sections of the code that are deemed performance-critical in the future.
1 parent a0599d0 commit 06a3edf

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/shared/Core/Authentication/OAuth/OAuth2Client.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ public async Task<OAuth2AuthorizationCodeResult> GetAuthorizationCodeAsync(IEnum
183183

184184
public async Task<OAuth2DeviceCodeResult> GetDeviceCodeAsync(IEnumerable<string> scopes, CancellationToken ct)
185185
{
186+
var label = "get device code";
187+
using IDisposable region = _trace2.CreateRegion(OAuth2Constants.Trace2Category, label);
188+
186189
if (_endpoints.DeviceAuthorizationEndpoint is null)
187190
{
188191
throw new Trace2InvalidOperationException(_trace2,
@@ -218,6 +221,9 @@ public async Task<OAuth2DeviceCodeResult> GetDeviceCodeAsync(IEnumerable<string>
218221

219222
public async Task<OAuth2TokenResult> GetTokenByAuthorizationCodeAsync(OAuth2AuthorizationCodeResult authorizationCodeResult, CancellationToken ct)
220223
{
224+
var label = "get token by auth code";
225+
using IDisposable region = _trace2.CreateRegion(OAuth2Constants.Trace2Category, label);
226+
221227
var formData = new Dictionary<string, string>
222228
{
223229
[OAuth2Constants.TokenEndpoint.GrantTypeParameter] = OAuth2Constants.TokenEndpoint.AuthorizationCodeGrantType,
@@ -254,6 +260,9 @@ public async Task<OAuth2TokenResult> GetTokenByAuthorizationCodeAsync(OAuth2Auth
254260

255261
public async Task<OAuth2TokenResult> GetTokenByRefreshTokenAsync(string refreshToken, CancellationToken ct)
256262
{
263+
var label = "get token by refresh token";
264+
using IDisposable region = _trace2.CreateRegion(OAuth2Constants.Trace2Category, label);
265+
257266
var formData = new Dictionary<string, string>
258267
{
259268
[OAuth2Constants.TokenEndpoint.GrantTypeParameter] = OAuth2Constants.TokenEndpoint.RefreshTokenGrantType,

src/shared/Core/Authentication/OAuth/OAuth2Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public static class OAuth2Constants
77
public const string ClientSecretParameter = "client_secret";
88
public const string RedirectUriParameter = "redirect_uri";
99
public const string ScopeParameter = "scope";
10+
public const string Trace2Category = "oauth2";
1011

1112
public static class AuthorizationEndpoint
1213
{

0 commit comments

Comments
 (0)