Skip to content

Commit 2fa5442

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 auth codes, device codes, and tokens. Additional regions can and should be added to additional sections of the code that are deemed performance-critical in the future.
1 parent d12a7c5 commit 2fa5442

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ public IOAuth2CodeGenerator CodeGenerator
104104
public async Task<OAuth2AuthorizationCodeResult> GetAuthorizationCodeAsync(IEnumerable<string> scopes,
105105
IOAuth2WebBrowser browser, IDictionary<string, string> extraQueryParams, CancellationToken ct)
106106
{
107+
var label = "get auth code";
108+
using IDisposable region = _trace2.CreateRegion(OAuth2Constants.Trace2Category, label);
109+
107110
string state = CodeGenerator.CreateNonce();
108111
string codeVerifier = CodeGenerator.CreatePkceCodeVerifier();
109112
string codeChallenge = CodeGenerator.CreatePkceCodeChallenge(OAuth2PkceChallengeMethod.Sha256, codeVerifier);
@@ -183,6 +186,9 @@ public async Task<OAuth2AuthorizationCodeResult> GetAuthorizationCodeAsync(IEnum
183186

184187
public async Task<OAuth2DeviceCodeResult> GetDeviceCodeAsync(IEnumerable<string> scopes, CancellationToken ct)
185188
{
189+
var label = "get device code";
190+
using IDisposable region = _trace2.CreateRegion(OAuth2Constants.Trace2Category, label);
191+
186192
if (_endpoints.DeviceAuthorizationEndpoint is null)
187193
{
188194
throw new Trace2InvalidOperationException(_trace2,
@@ -218,6 +224,9 @@ public async Task<OAuth2DeviceCodeResult> GetDeviceCodeAsync(IEnumerable<string>
218224

219225
public async Task<OAuth2TokenResult> GetTokenByAuthorizationCodeAsync(OAuth2AuthorizationCodeResult authorizationCodeResult, CancellationToken ct)
220226
{
227+
var label = "get token by auth code";
228+
using IDisposable region = _trace2.CreateRegion(OAuth2Constants.Trace2Category, label);
229+
221230
var formData = new Dictionary<string, string>
222231
{
223232
[OAuth2Constants.TokenEndpoint.GrantTypeParameter] = OAuth2Constants.TokenEndpoint.AuthorizationCodeGrantType,
@@ -254,6 +263,9 @@ public async Task<OAuth2TokenResult> GetTokenByAuthorizationCodeAsync(OAuth2Auth
254263

255264
public async Task<OAuth2TokenResult> GetTokenByRefreshTokenAsync(string refreshToken, CancellationToken ct)
256265
{
266+
var label = "get token by refresh token";
267+
using IDisposable region = _trace2.CreateRegion(OAuth2Constants.Trace2Category, label);
268+
257269
var formData = new Dictionary<string, string>
258270
{
259271
[OAuth2Constants.TokenEndpoint.GrantTypeParameter] = OAuth2Constants.TokenEndpoint.RefreshTokenGrantType,
@@ -284,6 +296,9 @@ public async Task<OAuth2TokenResult> GetTokenByRefreshTokenAsync(string refreshT
284296

285297
public async Task<OAuth2TokenResult> GetTokenByDeviceCodeAsync(OAuth2DeviceCodeResult deviceCodeResult, CancellationToken ct)
286298
{
299+
var label = "get token by device code";
300+
using IDisposable region = _trace2.CreateRegion(OAuth2Constants.Trace2Category, label);
301+
287302
var formData = new Dictionary<string, string>
288303
{
289304
[OAuth2Constants.DeviceAuthorization.GrantTypeParameter] = OAuth2Constants.DeviceAuthorization.DeviceCodeGrantType,

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)