Skip to content

Commit 2286b20

Browse files
authored
Log new event when CredentialType is selected for DefaultAzureCredential (Azure#18906)
* logged more specific event for credential selection
1 parent 4878ccd commit 2286b20

File tree

4 files changed

+185
-302
lines changed

4 files changed

+185
-302
lines changed

sdk/identity/Azure.Identity/src/AzureIdentityEventSource.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ internal sealed class AzureIdentityEventSource : AzureEventSource
2727
private const int MsalLogErrorEvent = 10;
2828
private const int InteractiveAuthenticationThreadPoolExecutionEvent = 11;
2929
private const int InteractiveAuthenticationInlineExecutionEvent = 12;
30+
private const int DefaultAzureCredentialCredentialSelectedEvent = 13;
3031

3132
private AzureIdentityEventSource() : base(EventSourceName) { }
3233

@@ -176,8 +177,6 @@ public void LogMsal(Microsoft.Identity.Client.LogLevel level, string message, bo
176177
case Microsoft.Identity.Client.LogLevel.Verbose when IsEnabled(EventLevel.Verbose, EventKeywords.All):
177178
LogMsalVerbose(message);
178179
break;
179-
default:
180-
break;
181180
}
182181
}
183182
}
@@ -223,5 +222,11 @@ public void InteractiveAuthenticationExecutingInline()
223222
{
224223
WriteEvent(InteractiveAuthenticationInlineExecutionEvent);
225224
}
225+
226+
[Event(DefaultAzureCredentialCredentialSelectedEvent, Level = EventLevel.Informational, Message = "DefaultAzureCredential credential selected: {0}")]
227+
public void DefaultAzureCredentialCredentialSelected(string credentialType)
228+
{
229+
WriteEvent(DefaultAzureCredentialCredentialSelectedEvent, credentialType);
230+
}
226231
}
227232
}

sdk/identity/Azure.Identity/src/DefaultAzureCredential.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,14 @@ private async ValueTask<AccessToken> GetTokenImplAsync(bool async, TokenRequestC
134134
(token, credential) = await GetTokenFromSourcesAsync(_sources, requestContext, async, cancellationToken).ConfigureAwait(false);
135135
_sources = default;
136136
asyncLock.SetValue(credential);
137+
AzureIdentityEventSource.Singleton.DefaultAzureCredentialCredentialSelected(credential.GetType().FullName);
137138
}
138139

139140
return scope.Succeeded(token);
140141
}
141142
catch (Exception e)
142143
{
143-
throw scope.FailWrapAndThrow(e);
144+
throw scope.FailWrapAndThrow(e);
144145
}
145146
}
146147

0 commit comments

Comments
 (0)