[correlationId] Make correlationId a required parameter on AuthError constructors#8609
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves MSAL telemetry/debuggability by propagating the current request correlationId into errors created via msal-common/msal-browser error factory helpers, and updates internal throw sites and unit tests accordingly.
Changes:
- Add optional
correlationIdparameters to several error creation helpers and forwardcorrelationIdat key throw sites. - Update native broker error translation (
createNativeAuthError) to applycorrelationIdacross translated error types. - Add/extend unit tests to verify
correlationIdbehavior for updated helpers.
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/msal-common/test/error/InteractionRequiredAuthError.spec.ts | Adds tests asserting correlationId behavior for interaction-required error factory. |
| lib/msal-common/test/error/ClientConfigurationError.spec.ts | Adds tests asserting correlationId behavior for client configuration error factory. |
| lib/msal-common/test/error/ClientAuthError.spec.ts | Adds tests asserting correlationId behavior for client auth error factory. |
| lib/msal-common/test/error/AuthError.spec.ts | Adds tests asserting correlationId behavior for base auth error factory. |
| lib/msal-common/src/error/InteractionRequiredAuthError.ts | Extends interaction-required error factory signature to accept correlationId. |
| lib/msal-common/src/error/ClientConfigurationError.ts | Extends configuration error factory signature to accept/set correlationId. |
| lib/msal-common/src/error/ClientAuthError.ts | Extends client auth error factory signature to accept/set correlationId. |
| lib/msal-common/src/error/AuthError.ts | Extends base auth error factory signature to accept/set correlationId. |
| lib/msal-common/src/client/SilentFlowClient.ts | Forwards request.correlationId when throwing client auth errors. |
| lib/msal-common/src/client/RefreshTokenClient.ts | Forwards request.correlationId when throwing interaction-required errors. |
| lib/msal-common/src/client/AuthorizationCodeClient.ts | Forwards request.correlationId when throwing client/configuration errors. |
| lib/msal-browser/test/error/NativeAuthError.spec.ts | Adds tests asserting correlationId is preserved on translated native errors. |
| lib/msal-browser/test/error/BrowserConfigurationAuthError.spec.ts | Adds tests asserting correlationId behavior for browser configuration error factory. |
| lib/msal-browser/test/error/BrowserAuthError.spec.ts | Adds tests asserting correlationId behavior for browser auth error factory. |
| lib/msal-browser/src/interaction_client/SilentAuthCodeClient.ts | Forwards correlationId into thrown browser auth errors. |
| lib/msal-browser/src/interaction_client/PopupClient.ts | Forwards correlationId into thrown browser auth errors in popup flows. |
| lib/msal-browser/src/interaction_client/PlatformAuthInteractionClient.ts | Forwards correlationId into thrown common/browser errors in platform auth flows. |
| lib/msal-browser/src/interaction_client/BaseInteractionClient.ts | Forwards correlationId into thrown common configuration errors. |
| lib/msal-browser/src/error/NativeAuthError.ts | Extends native error translation to accept/apply correlationId. |
| lib/msal-browser/src/error/BrowserConfigurationAuthError.ts | Extends browser configuration error factory to accept/set correlationId. |
| lib/msal-browser/src/error/BrowserAuthError.ts | Extends browser auth error factory to accept/set correlationId. |
| lib/msal-browser/src/controllers/StandardController.ts | Forwards correlationId into thrown common/browser errors in controller paths. |
| lib/msal-browser/src/broker/nativeBroker/PlatformAuthExtensionHandler.ts | Forwards correlationId when translating/throwing native and auth errors. |
| lib/msal-browser/src/broker/nativeBroker/PlatformAuthDOMHandler.ts | Forwards correlationId when translating/throwing native and auth errors. |
| change/@azure-msal-common-151e2ba1-220e-4a47-a4dc-e421d262da2a.json | Adds patch changefile for msal-common. |
| change/@azure-msal-browser-7c559b7a-066d-486b-b68f-4b4359e3f053.json | Adds patch changefile for msal-browser. |
b372320 to
098cb6e
Compare
|
@copilot Let us get to a restoration Point. Do you recall the 4 PRs reated as a part of the correlationId addition to errors? |
From the current PR context I can reliably identify these stacked items:
I don’t have a confirmed 4th PR identifier in the thread metadata here. If you share the 4th PR number/title, I can align to the exact restoration point you want. |
|
@copilot *created |
Yes — the 4 created PRs are:
|
|
@copilot Is the format fixed? |
|
@copilot Push api extractor changes |
Regenerated and pushed the API extractor reports. Only |
|
@copilot Push api extractor changes |
The API extractor changes are already pushed — the msal-browser apiReview update is in commit |
|
@copilot Pipelines are failing with 1P compat. Can you try debug? |
Debugged it. The failure is expected breakage in the 1P consumer, not a regression in this repo. What's failing: The "MSAL JS Build" / 1P compat job (
This repo is clean: all 4 lib packages build, To get 1P compat green, a companion change is needed in
I don't have access to that internal repo, so I can't push that change from here. If you can point me at it (or want to keep this fully backward-compatible instead), the alternative is to keep |
8723b13 to
605aaaa
Compare
…constructors Squash-rebased onto dev. Threads a required correlationId through error constructors and creation helpers across msal-common, msal-browser, msal-node, msal-react, msal-angular, and msal-node-extensions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
605aaaa to
c4835e8
Compare
Summary
** Makes
correlationIda required parameter on theAuthErrorconstructor (and all subclass error constructors) across every MSAL package. This ensures thrown errors carry correlation context consistently for telemetry and debugging.Previously
correlationIdwas attached after construction viasetCorrelationId(), which was inconsistently called. That helper is removed; the value is now required at construction.Scope of this PR
This PR now serves as the single consolidated PR for the correlationId error propagation work (instead of the original stacked split).
Beyond making the constructor parameter required, residual
""(placeholder) sites are being addressed per-component, starting with the lowest instance counts. For each component the throw sites are categorized into "realcorrelationIdin scope → thread it" vs. "genuinely no request context → keep""" (e.g. interface/stub "not implemented" throws, static factory methods, pre-request config validation).Changes
@azure/msal-commonAuthErrorconstructor signature changed from(errorCode, errorMessage?, suberror?)to(errorCode, correlationId, errorMessage?, suberror?).ClientAuthError,ClientConfigurationError,InteractionRequiredAuthError,ServerError,JoseHeaderError,NetworkError,CacheError.setCorrelationId()removed.correlationId(or""where not yet in scope).correlationIdis already in scope, it is now passed instead of""(e.g.Token.sendPostRequestnetwork error fallback). Remaining""sites are low-level utilities (e.g.ProtocolUtils,AuthToken) whose signatures don't yet carrycorrelationId; threading it through them is deferred follow-up.@azure/msal-browsercorrelationId.correlationId(instead of"") atPkceGenerator(generateCodeVerifier,generateCodeChallengeFromVerifier) and theBrowserUtilsredirect-bridge empty-response path.@azure/msal-reactReactAuthError.createInvalidInteractionTypeErrorandcreateUnableToFallbackToInteractionErrornow accept an optionalcorrelationId.useMsalAuthenticationpasses the in-scope value (loginRequest?.correlationIdon the login path, the localcorrelationIdon the acquireToken fallback path) instead of"".@azure/msal-node-extensionsNativeBrokerPlugin.wrapError()now takes acorrelationId, threaded from the request context at every call site, so the wrappedPlatformBrokerError,InteractionRequiredAuthError,ServerError, andcreateClient*Errorbranches all carry it. ThesignOutno-account throw now passesrequest.correlationId. The only remaining""is thesetLogger→RegisterLoggercatch, which runs during logger registration with no request context.@azure/msal-nodecorrelationId.correlationId(instead of"") through error paths where a real value was available:NodeAuthErrorfactory methods (createRedirectUriNotSupportedError,createNoAuthCodeInResponseError,createLoopbackServerTimeoutError,createStateNotFoundError) now accept an optionalcorrelationId.PublicClientApplication(acquireTokenInteractive/acquireTokenSilent, plus threadingcorrelationIdinto the privatewaitForRedirectUri),ClientApplication.validateState,ConfidentialClientApplication(missingTenantIdError),ClientCredentialClientandOnBehalfOfClientcache throws (multipleMatchingTokens,tokenRefreshRequired),DeviceCodeClient(threaded into the privatecontinuePollingand the unknown-error throw), andBaseManagedIdentitySource(network-error catch).""sites are pre-request config/input validation, boot-time managed-identity source selection/static factories, and interface/public-method signatures lacking acorrelationIdarg (INetworkModule/HttpClient, the managed-identitygetServerTokenResponseAsync/getServerTokenResponseoverride chain,getManagedIdentityUserAssignedIdQueryParameterKey,ClientAssertion.getJwt); threading those requires wider shared/public signature changes and is tracked as continuing follow-up.@azure/msal-angularcorrelationId(or""where not in scope). Bothinvalid_interaction_typethrows (msal.guard.ts,msal.interceptor.ts) are pre-request configuration validation with nocorrelationIdin scope, so they correctly remain"".""sites in the larger msal-common/msal-browser sets is tracked as continuing per-component follow-up.Change files
Migration