-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Identity v2 logging impovements #45296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces logging improvements for Identity v2 by switching to the new throwableAt* methods, using structured logging, and consolidating duplicate exception logs. Key changes include:
- Replacing the old logThrowableAs* methods with the new logAndThrowTokenError and throwableAt* variants.
- Updating structured logging usage across multiple credential implementations.
- Minor cleanup in logging and exception handling and a dependency version bump in pom.xml.
Reviewed Changes
Copilot reviewed 38 out of 38 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
ManagedIdentityCredential.java | Updates logging for unavailable credentials and exception handling using throwableAt* |
InteractiveBrowserCredentialBuilder.java | Uses throwableAtError().log in place of logThrowableAsError for URI syntax issues |
InteractiveBrowserCredential.java | Changes catch blocks to RuntimeException and updates logging for interactive authentication requirements |
EnvironmentCredential.java | Updates structured logging and exception logging for different authentication flows |
DeviceCodeCredential.java | Standardizes exception logging with throwableAt* methods |
DefaultAzureCredentialBuilder.java | Enforces single identity configuration via updated exception logging |
ClientSecretCredential.java, ClientCertificateCredential.java, ClientAssertionCredential.java | Standardizes exception logging using logAndThrowTokenError for authentication errors |
ChainedTokenCredential.java | Refactors cached credential logging and exception handling with structured logging |
AzureToolkitCredential.java, AzurePowerShellCredential.java, AzurePipelinesCredential.java, AzureDeveloperCliCredential.java, AzureCliCredential.java, AuthorizationCodeCredentialBuilder.java, AuthorizationCodeCredential.java | Updates logging throughout to adopt the new logging patterns |
pom.xml | Bumps clientcore dependency version from beta.9 to beta.10 |
checkstyle-suppressions.xml | Adds a new suppression entry for throw-from-client-logger checks across credential files |
Comments suppressed due to low confidence (1)
sdk/identity-v2/azure-identity/src/main/java/com/azure/v2/identity/ManagedIdentityCredential.java:102
- [nitpick] Consider enhancing structured logging here by including key-value pairs (for example, adding the managedIdentitySourceType as a key-value) instead of relying solely on string concatenation for increased clarity and consistency.
LOGGER.atError().log("ManagedIdentityCredential authentication unavailable. " + "the ManagedIdentityCredentialBuilder.");
...dentity-v2/azure-identity/src/main/java/com/azure/v2/identity/AzurePowerShellCredential.java
Show resolved
Hide resolved
sdk/identity-v2/azure-identity/src/main/java/com/azure/v2/identity/DeviceCodeCredential.java
Outdated
Show resolved
Hide resolved
...tity-v2/azure-identity/src/main/java/com/azure/v2/identity/InteractiveBrowserCredential.java
Outdated
Show resolved
Hide resolved
...dentity-v2/azure-identity/src/main/java/com/azure/v2/identity/ManagedIdentityCredential.java
Outdated
Show resolved
Hide resolved
...2/azure-identity/src/main/java/com/azure/v2/identity/implementation/client/PublicClient.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
if (output.contains("Run Connect-AzAccount to login")) { | ||
LoggingUtil.logCredentialUnavailableException(LOGGER, | ||
new CredentialUnavailableException("Run Connect-AzAccount to login to Azure account in PowerShell.")); | ||
LOGGER.atError().log("Run Connect-AzAccount to login to Azure account in PowerShell."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to throw the Credential Unavailable exception here too.
LoggingUtil.logCredentialUnavailableException(LOGGER, | ||
new CredentialUnavailableException("Az.Account module with version >= 2.2.0 is not installed. " | ||
+ "It needs to be installed to use Azure PowerShell " + "Credential.")); | ||
LOGGER.atError() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to throw cred unavailable exception
@@ -152,8 +147,9 @@ private AccessToken getAccessTokenFromPowerShell(TokenRequestContext request, Po | |||
OffsetDateTime expiresOn = OffsetDateTime.parse(time).withOffsetSameInstant(ZoneOffset.UTC); | |||
return new AccessToken(accessToken, expiresOn); | |||
} catch (IOException e) { | |||
LoggingUtil.logCredentialUnavailableException(LOGGER, new CredentialUnavailableException( | |||
"Encountered error when deserializing response from Azure Power Shell.", e)); | |||
LOGGER.atError() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same, need to throw cred unavilable exception.
throwableAt*
instead oflogThrowableAs*
- the new one creates exception message with contextRelated to #45136