Skip to content

Conversation

@tnorling
Copy link
Collaborator

@tnorling tnorling commented Jan 7, 2026

This pull request adds tracking of the ApiId when 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 the ApiId through several layers of account and token handling logic, and updating the public changelogs for relevant packages.

Telemetry and API Tracking Improvements:

  • Added ApiId as 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 BrowserCacheManager to store the cachedByApiId property on account entities, and to log this information with each cache access for enhanced performance tracking. [1] [2]

Changelog Updates:

  • Added patch changelog entries for @azure/msal-browser, @azure/msal-common, and @azure/msal-node to document the new API tracking feature. [1] [2] [3]

Internal Refactoring:

  • Propagated the ApiId parameter 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.

…tion or class'

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
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 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 cachedByApiId property to AccountEntity for tracking which API cached each account
  • Updated cache manager interfaces and implementations to accept and store apiId parameter in account operations
  • Enhanced telemetry in BrowserCacheManager to log the API name that cached each account when retrieved
  • Added new ApiId constants for hydrateCache, loadExternalTokens, acquireTokenByOBO, and acquireTokenWithManagedIdentity

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 handleServerTokenResponse method should be updated to document the new apiId parameter (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";

@tnorling
Copy link
Collaborator Author

tnorling commented Jan 7, 2026

@copilot Please address the Copilot feedback in this PR

Copy link
Contributor

Copilot AI commented Jan 7, 2026

@tnorling I've opened a new pull request, #8220, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 6 commits January 7, 2026 14:41
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]>
@tnorling tnorling marked this pull request as ready for review January 8, 2026 00:26
konstantin-msft
konstantin-msft previously approved these changes Jan 8, 2026
@tnorling tnorling enabled auto-merge (squash) January 8, 2026 23:52
@tnorling tnorling disabled auto-merge January 9, 2026 19:30
@tnorling tnorling merged commit d86bde8 into dev Jan 9, 2026
8 checks passed
@tnorling tnorling deleted the track-account-apiId branch January 9, 2026 19:30
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.

5 participants