Reduce redundant logging during ChainedTokenCredential.get_token()#19283
Merged
chlowell merged 3 commits intoAzure:mainfrom Jul 20, 2021
Merged
Reduce redundant logging during ChainedTokenCredential.get_token()#19283chlowell merged 3 commits intoAzure:mainfrom
chlowell merged 3 commits intoAzure:mainfrom
Conversation
b85316b to
469f2df
Compare
469f2df to
8c6be31
Compare
mccoyp
approved these changes
Jul 19, 2021
Member
mccoyp
left a comment
There was a problem hiding this comment.
I think this is a reasonable solution -- at least, I can't think of a better one. I feel bad excluding 2.7, but I don't think the necessary work to support it would be justifiable when this is a cosmetic change, albeit a really nice one.
I do wonder if it would be good to include a note in the changelog that these changes are available on 3.6 if you pip install the backport
Member
Author
|
It turns out the backport doesn't work correctly in all cases and likely never will given the impending 3.6 EOL (see MagicStack/contextvars/issues/2). I'll stick with 3.7+ here and recommend upgrading Python to anyone running 3.6 who really wants this change. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR closes #18972 by reducing redundant logging during
ChainedTokenCredential.get_token()and, by inheritance,DefaultAzureCredential.get_token(). The rationale is that whenget_token()fails for a credential chain, it logs an aggregate of the inner credentials' error messages, making those credentials' logging of same redundant. Similarly, whenget_token()succeeds, users will seldom find error messages from unavailable inner credentials interesting. On the contrary, those messages can be confusing: "Why do I see half a dozen error messages when authentication succeeds?"Here's the diff for DefaultAzureCredential failure given typical logging configuration (filtering
DEBUGmessages):Similarly, DefaultAzureCredential success:
Inner credentials still log these messages, however they do so at
DEBUGlevel when they're invoked by ChainedTokenCredential, using a ContextVar to determine whether that's the case. Unfortunately, ContextVar was added in Python 3.7. For Python 3.6, we have a backport. The nearest equivalent available to 2.7 isthreading.local, which isn't concurrency-safe. Another alternative that works everywhere is to pass around an internal keyword argument, but 🤮In the end, because this isn't a functional or API change, I don't mind excluding 2.7. Similarly, if the backport is unacceptable, I observe that 3.6 will be EOL in 6 months. But that's just my opinion, please feel free to change my mind or propose alternative solutions 😄