Skip to content

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

lmolkova
Copy link
Member

@lmolkova lmolkova commented May 12, 2025

  • use new throwableAt* instead of logThrowableAs* - the new one creates exception message with context
  • use structured logging instead of string formatting
  • don't duplicated logs for exceptions
  • minor clean up in logging and exception handling

Related to #45136

@Copilot Copilot AI review requested due to automatic review settings May 12, 2025 21:22
Copy link
Contributor

@Copilot Copilot AI left a 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.");

}

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.");
Copy link
Member

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()
Copy link
Member

@g2vinay g2vinay May 23, 2025

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()
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants