Skip to content

Comments

Internal logging utility: _DeferredString#205

Merged
rodrigobr-msft merged 6 commits intomainfrom
users/robrandao/deferred-log
Oct 27, 2025
Merged

Internal logging utility: _DeferredString#205
rodrigobr-msft merged 6 commits intomainfrom
users/robrandao/deferred-log

Conversation

@rodrigobr-msft
Copy link
Contributor

This pull request introduces a new utility for deferred string evaluation and refactors logging in the MSAL authentication code to improve performance and maintainability. The main changes are the addition of the _DeferredString class and its use for deferred logging, replacing a custom implementation.

Deferred string evaluation utility:

  • Added _DeferredString class in microsoft_agents/activity/_utils/_deferred_string.py to allow deferred evaluation of expensive string operations, improving logging efficiency.
  • Exposed _DeferredString through the package’s __init__.py for easier import.

Refactoring logging in MSAL authentication:

  • Removed the custom _DeferredLogOfBlueprintId class from msal_auth.py and replaced its usage with the new _DeferredString utility for deferred logging of decoded JWT blueprint IDs.
  • Updated the debug log statement in get_agentic_instance_token to use _DeferredString, ensuring JWT decoding only occurs if the log level is set to DEBUG.
  • Imported the new utility in msal_auth.py for use in logging.

Copilot AI review requested due to automatic review settings October 23, 2025 21:23
@rodrigobr-msft rodrigobr-msft marked this pull request as ready for review October 23, 2025 21:23
@rodrigobr-msft rodrigobr-msft requested a review from a team as a code owner October 23, 2025 21:23
Copy link
Contributor

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 a reusable _DeferredString utility class to optimize logging performance by deferring expensive string operations until they're actually needed. The implementation replaces a custom deferred logging class in the MSAL authentication code with this new generalized utility.

Key Changes:

  • Added a new _DeferredString utility class that defers function execution until string conversion
  • Refactored MSAL authentication logging to use the new utility instead of a custom implementation
  • Improved code maintainability by centralizing deferred string evaluation logic

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
_deferred_string.py Introduces the _DeferredString class for deferred function evaluation
_utils/__init__.py Exports the _DeferredString class from the utils module
msal_auth.py Replaces custom _DeferredLogOfBlueprintId class with _DeferredString utility

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Collaborator

@cleemullins cleemullins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nice.

Are there other places we're doing logging that this should be used?

I image there are a number of "Activity Log" type calls, which need to be replaced. I think Claude 4.5 or Copilot should be able to find them all for you quick quickly.

@rodrigobr-msft
Copy link
Contributor Author

This is nice.

Are there other places we're doing logging that this should be used?

I image there are a number of "Activity Log" type calls, which need to be replaced. I think Claude 4.5 or Copilot should be able to find them all for you quick quickly.

Fortunately, those are already handled by replacing format strings substitution with "%s" for lazy evaluation. We don't often go out of our way to perform lazy computation in this codebase. I asked Copilot, and all I found were uses of format strings. There's a lot of those, and I already started the conversion in the UserTokenClient and ConnectorClient classes in a separate PR. Thus, I will proceed and merge this.

@rodrigobr-msft rodrigobr-msft merged commit c9b648f into main Oct 27, 2025
10 checks passed
@rodrigobr-msft rodrigobr-msft deleted the users/robrandao/deferred-log branch October 27, 2025 15:28
Copilot AI mentioned this pull request Dec 2, 2025
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