-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Track ApiId when getting and setting accounts in cache #8219
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
Conversation
lib/msal-browser/src/custom_auth/core/interaction_client/CustomAuthInteractionClientBase.ts
Fixed
Show fixed
Hide fixed
…tion or class' Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
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 pull request enhances telemetry and debugging capabilities by tracking the API identifier (ApiId) for all account cache operations across the MSAL browser, node, and common packages. This enables better observability by associating each cached account with the specific API call that created it.
Key Changes:
- Added
cachedByApiIdproperty toAccountEntityfor tracking which API cached each account - Updated cache manager interfaces and implementations to accept and store
apiIdparameter in account operations - Enhanced telemetry in
BrowserCacheManagerto log the API name that cached each account when retrieved - Added new
ApiIdconstants forhydrateCache,loadExternalTokens,acquireTokenByOBO, andacquireTokenWithManagedIdentity
Reviewed changes
Copilot reviewed 45 out of 45 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
lib/msal-common/src/cache/entities/AccountEntity.ts |
Added optional cachedByApiId property to track which API cached the account |
lib/msal-common/src/cache/interface/ICacheManager.ts |
Updated setAccount and saveCacheRecord interface signatures to include apiId parameter |
lib/msal-common/src/cache/CacheManager.ts |
Updated abstract method signatures and implementation to propagate apiId through cache operations |
lib/msal-common/src/response/ResponseHandler.ts |
Added apiId parameter to handleServerTokenResponse and passed it to cache operations |
lib/msal-common/src/client/AuthorizationCodeClient.ts |
Added apiId parameter to acquireToken method signature |
lib/msal-common/src/client/RefreshTokenClient.ts |
Added apiId parameter to acquireToken and acquireTokenByRefreshToken methods |
lib/msal-browser/src/cache/BrowserCacheManager.ts |
Implemented apiId tracking with telemetry logging in getAccount and setAccount methods |
lib/msal-browser/src/cache/TokenCache.ts |
Updated loadExternalTokens to pass ApiId.loadExternalTokens when caching accounts |
lib/msal-browser/src/utils/BrowserConstants.ts |
Added new ApiId constants, ApiName mapping, and apiIdToName helper function |
lib/msal-browser/src/interaction_handler/InteractionHandler.ts |
Updated to accept and propagate apiId through code response handling |
lib/msal-browser/src/interaction_client/SilentRefreshClient.ts |
Updated to pass ApiId.acquireTokenSilent_silentFlow to refresh token operations |
lib/msal-browser/src/interaction_client/SilentAuthCodeClient.ts |
Updated to pass apiId when handling code responses |
lib/msal-browser/src/interaction_client/PlatformAuthInteractionClient.ts |
Updated to pass apiId when caching accounts and tokens |
lib/msal-browser/src/controllers/StandardController.ts |
Updated hydrateCache to pass ApiId.hydrateCache when caching accounts |
lib/msal-browser/src/controllers/NestedAppAuthController.ts |
Updated hydrateCache to pass ApiId.hydrateCache when caching accounts |
lib/msal-browser/src/protocol/Authorize.ts |
Updated response handling to propagate apiId parameter |
lib/msal-browser/src/custom_auth/**/*.ts |
Updated custom auth clients to propagate apiId through token response handling |
lib/msal-node/src/utils/Constants.ts |
Added acquireTokenByOBO and acquireTokenWithManagedIdentity ApiId constants |
lib/msal-node/src/client/*.ts |
Updated client classes to pass appropriate ApiId when handling token responses |
lib/msal-node/src/client/ClientApplication.ts |
Updated token acquisition methods to pass ApiId parameters |
lib/msal-common/test/**/*.spec.ts |
Updated all test files to pass apiId parameter (typically 0 for test purposes) |
lib/msal-browser/test/**/*.spec.ts |
Updated all test files to pass appropriate ApiId constants and added new test for cachedByApiId |
change/@azure-msal-*.json |
Added beachball changefile entries documenting the patch-level changes |
Comments suppressed due to low confidence (2)
lib/msal-common/src/response/ResponseHandler.ts:196
- The JSDoc comment for the
handleServerTokenResponsemethod should be updated to document the newapiIdparameter (line 190). This parameter is used for telemetry tracking to identify which API call initiated the token response handling.
lib/msal-browser/src/custom_auth/core/interaction_client/CustomAuthInteractionClientBase.ts:6 - Unused import PublicApiId.
import { ICustomAuthApiClient } from "../network_client/custom_auth_api/ICustomAuthApiClient.js";
change/@azure-msal-common-88d25b3c-41ef-46f9-a62d-3e1ddc67ba05.json
Outdated
Show resolved
Hide resolved
…osoft-authentication-library-for-js into track-account-apiId
….json Co-authored-by: Copilot <[email protected]>
|
@copilot Please address the Copilot feedback in this PR |
Addresses Copilot PR reviewer feedback by documenting the `apiId` parameter added to cache and authentication methods for telemetry tracking. **Updated JSDoc comments:** - `CacheManager.ts` - abstract `setAccount` method: documented `kmsi` and `apiId` parameters - `ICacheManager.ts` - `setAccount` method: documented `apiId` parameter - `AuthorizationCodeClient.ts` - `acquireToken` method: documented `apiId` parameter - `CacheManager.ts` - `saveCacheRecord` method: documented `apiId` parameter All `apiId` parameters are documented as "API identifier for telemetry tracking" for consistency with the existing codebase patterns. <!-- START COPILOT CODING AGENT TIPS --> --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs. --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: tnorling <[email protected]>
…osoft-authentication-library-for-js into track-account-apiId
This pull request adds tracking of the
ApiIdwhen setting and retrieving accounts across the MSAL browser, node, and common packages. This change improves telemetry and debugging by associating account cache operations with the specific API calls that triggered them. The update includes passing theApiIdthrough several layers of account and token handling logic, and updating the public changelogs for relevant packages.Telemetry and API Tracking Improvements:
Added
ApiIdas a parameter to account and token cache operations, ensuring that every set/get account action is tracked with the originating API for better telemetry and diagnostics. (BrowserCacheManager.ts,TokenCache.ts,InteractionHandler.ts,PlatformAuthInteractionClient.ts,SilentAuthCodeClient.ts,SilentRefreshClient.ts,CustomAuthInteractionClientBase.ts,SignInClient.ts,JitClient.ts,MfaClient.ts,CustomAuthSilentCacheClient.ts,Authorize.ts) [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26]Updated the
BrowserCacheManagerto store thecachedByApiIdproperty on account entities, and to log this information with each cache access for enhanced performance tracking. [1] [2]Changelog Updates:
@azure/msal-browser,@azure/msal-common, and@azure/msal-nodeto document the new API tracking feature. [1] [2] [3]Internal Refactoring:
ApiIdparameter through various authentication and cache management flows, including silent and interactive authentication, to ensure consistent tracking throughout the codebase. [1] [2] [3] [4] [5]These changes collectively enhance observability and traceability of account operations, making it easier to diagnose issues and analyze API usage patterns.