Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions change/@azure-msal-browser-naa-bridge-type.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Identify Nested App Auth performance events with the NAA bridge type [#8864](https://github.com/AzureAD/microsoft-authentication-library-for-js/pull/8864)",
"packageName": "@azure/msal-browser",
"email": "Sameera.Gajjarapu@microsoft.com",
"dependentChangeType": "patch"
}
7 changes: 7 additions & 0 deletions change/@azure-msal-common-naa-bridge-type.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Add a bridge type field to performance telemetry [#8864](https://github.com/AzureAD/microsoft-authentication-library-for-js/pull/8864)",
"packageName": "@azure/msal-common",
"email": "Sameera.Gajjarapu@microsoft.com",
"dependentChangeType": "patch"
}
53 changes: 8 additions & 45 deletions lib/msal-browser/docs/performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,51 +84,14 @@ The complete details for `PerformanceEvents` objects can be found [here](../../m
| **Property** | Type | Description |
| ---------------------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------- |
| `name` | `string` | Name of the operation, usually matches the top-level API name (e.g. `acquireTokenSilent`, `acquireTokenByCode`, `ssoSilent`). |
| `durationMs` | `number` | End-to-end duration in milliseconds for the operation. |
| `success` | `boolean` | Whether the operation was successful or not. |
| `fromCache` | `boolean` | Whether the operation retrieved the result from the cache. |
| `correlationId` | `string` | Correlation ID used for the operation (preferably unique per request). |
| `libraryVersion` | `string` | Version of MSAL.js used for the operation. |
| `authority` | `string` | Authority used for the operation. |
| `<internalFunctionName>DurationMs` | `number` | Duration in milliseconds for an internal operation. |

### Platform broker measurements

When platform brokering is enabled, MSAL measures provider discovery and provider creation during initialization, and extension or DOM transport, response validation, request initialization, response processing, and cache updates during authentication. These child measurements are folded into their enclosing top-level event as `<measurementName>DurationMs` fields under the same `correlationId`; they are not emitted as separate callback events. During initialization, extension handshake duration is available as `ext.nativeMessageHandlerHandshakeDurationMs` and extension provider creation duration is available as `ext.platformAuthExtensionCreateProviderDurationMs`.

The root event includes the following platform broker context:

| **Property** | Type | Description |
| ------------------------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `allowPlatformBroker` | `boolean` | Whether the application enabled platform broker support. |
| `platformAuthProviderAvailable` | `boolean` | Whether MSAL created a platform authentication provider. |
| `platformAuthProviderType` | `string` | `PlatformAuthDOMHandler` or `PlatformAuthExtensionHandler` when a provider is available. This property is omitted when `platformAuthProviderAvailable` is false. |
| `extensionInstalled` | `boolean` | Whether an extension handshake response identified a compatible Microsoft Single Sign On extension. Omitted when no extension responds. |
| `extensionHandshakeTimedOut` | `boolean` | Whether extension discovery failed because no extension responded before the handshake timeout. |
| `extensionHandshakeTimeoutMs` | `number` | Configured extension handshake timeout in milliseconds. |

Platform broker telemetry does not include tokens, claims, account identifiers, request or response payloads, URLs, or exception messages.

#### Diagnosing platform broker flows

Use the following fields as query or dashboard dimensions:

| **Question** | **Filter or grouping** |
| --------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Did the application enable brokering? | Filter on `allowPlatformBroker === true`. |
| Was a provider created? | Filter on `platformAuthProviderAvailable`; group available providers by `platformAuthProviderType`. |
| Did extension discovery succeed? | Filter on `extensionInstalled`; use `extensionHandshakeTimedOut` to distinguish a timeout from a response that did not identify a compatible extension. |
| Did the broker return an error? | Filter on `brokerErrorName` and `brokerErrorCode`; `user_cancelled` identifies user cancellation. |
| Which platform broker stage was slow? | Inspect the `<measurementName>DurationMs` fields in `ext`, including `nativeMessageHandlerHandshakeDurationMs` and provider, transport, validation, and cache durations. |
| Did a web flow run after broker failure? | When `platformAuthProviderAvailable` is false or broker error fields are present, inspect the enclosing top-level event's outcome to determine whether fallback succeeded. |

To troubleshoot an individual request:

1. Find the top-level performance event by `correlationId`.
2. Confirm `allowPlatformBroker`, then check `platformAuthProviderAvailable` and the conditional `platformAuthProviderType`.
3. For the extension flow, inspect `extensionInstalled`, `extensionHandshakeTimedOut`, and `extensionHandshakeTimeoutMs`.
4. Compare the nested duration fields in `ext` to identify the lifecycle stage where time was spent.
5. Inspect `brokerErrorName` and `brokerErrorCode`, then use the top-level event's outcome to distinguish a terminal broker failure from a successful web fallback.
| `durationMs` | `number` | End-to-end duration in milliseconds for the operation. |
| `success` | `boolean` | Whether the operation was successful or not. |
| `fromCache` | `boolean` | Whether the operation retrieved the result from the cache. |
| `correlationId` | `string` | Correlation ID used for the operation (preferably unique per request). |
| `libraryVersion` | `string` | Version of MSAL.js used for the operation. |
| `authority` | `string` | Authority used for the operation. |
| `bridgeType` | `"NAA" \| "PWB"` | Bridge type used for the operation. |
| `<internalFunctionName>DurationMs` | `number` | Duration in milliseconds for an internal operation. |
Comment thread
sameerag marked this conversation as resolved.
Resolved

### removePerformanceCallback

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,10 @@ export class NestedAppAuthController implements IController {
correlationId
);

atPopupMeasurement.add({ nestedAppAuthRequest: true });
atPopupMeasurement.add({
nestedAppAuthRequest: true,
bridgeType: "NAA",
});

try {
enforceResourceParameter(this.config.auth.isMcp, validRequest);
Expand Down Expand Up @@ -345,6 +348,7 @@ export class NestedAppAuthController implements IController {
});
ssoSilentMeasurement.add({
nestedAppAuthRequest: true,
bridgeType: "NAA",
});

try {
Expand Down Expand Up @@ -438,6 +442,7 @@ export class NestedAppAuthController implements IController {

atsMeasurement?.add({
nestedAppAuthRequest: true,
bridgeType: "NAA",
});

// if the request has claims, we cannot look up in the cache
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,11 @@ describe("NestedAppAuthController.ts Class Unit Tests", () => {

const result = await localPca.acquireTokenPopup(testRequest);

expect(mockMeasurement.add).toHaveBeenCalledWith({
nestedAppAuthRequest: true,
bridgeType: "NAA",
});

// Verify measurement.end was called with account parameter
expect(mockMeasurement.end).toHaveBeenCalledWith(
expect.objectContaining({ success: true }),
Expand Down Expand Up @@ -1072,6 +1077,11 @@ describe("NestedAppAuthController.ts Class Unit Tests", () => {

const result = await localPca.acquireTokenSilent(silentRequest);

expect(mockMeasurement.add).toHaveBeenCalledWith({
nestedAppAuthRequest: true,
bridgeType: "NAA",
});

// Verify measurement.end was called with account parameter
expect(mockMeasurement.end).toHaveBeenCalledWith(
expect.objectContaining({ success: true }),
Expand All @@ -1089,6 +1099,41 @@ describe("NestedAppAuthController.ts Class Unit Tests", () => {
expect(result.account).toBeDefined();
});

it("should add the NAA bridge type to silent cache measurements", async () => {
const mockMeasurement = {
end: jest.fn().mockReturnValue({}),
discard: jest.fn(),
add: jest.fn(),
increment: jest.fn(),
event: {
eventId: "test-event-id",
status: "InProgress" as any,
authority: TEST_CONFIG.validAuthority,
clientId: TEST_CONFIG.MSAL_CLIENT_ID,
correlationId: RANDOM_TEST_GUID,
name: "test-event",
startTimeMs: Date.now(),
libraryName: "msal-browser",
libraryVersion: "test-version",
},
measurement: {},
};

jest.spyOn(performanceClient, "startMeasurement").mockReturnValue(
mockMeasurement as any
);

await (localPca as any).controller.acquireTokenFromCache({
scopes: ["user.read"],
forceRefresh: true,
});

expect(mockMeasurement.add).toHaveBeenCalledWith({
nestedAppAuthRequest: true,
bridgeType: "NAA",
});
});

it("should not pass account when account is not provided in request", async () => {
const silentRequest = {
scopes: ["user.read"],
Expand Down
1 change: 1 addition & 0 deletions lib/msal-common/apiReview/msal-common.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2488,6 +2488,7 @@ export type PerformanceEvent = {
platformAuthProviderType?: string;
platformAuthRequestCorrelationId?: string;
nestedAppAuthRequest?: boolean;
bridgeType?: "NAA" | "PWB";
multiMatchedAT?: number;
multiMatchedID?: number;
multiMatchedRT?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ export type PerformanceEvent = {
* Nested App Auth Fields
*/
nestedAppAuthRequest?: boolean;
bridgeType?: "NAA" | "PWB";
Comment thread
sameerag marked this conversation as resolved.
Resolved

/**
* Multiple matched access/id/refresh tokens in the cache
Expand Down