Skip to content
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

Instrument correlation between silent and interactive requests #7146

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Instrument a correlation between silent and interactive requests #7146",
"packageName": "@azure/msal-browser",
"email": "kshabelko@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Instrument a correlation between silent and interactive requests #7146",
"packageName": "@azure/msal-common",
"email": "kshabelko@microsoft.com",
"dependentChangeType": "patch"
}
4 changes: 4 additions & 0 deletions lib/msal-browser/apiReview/msal-browser.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,10 @@ export class BrowserPerformanceClient extends PerformanceClient implements IPerf
generateId(): string;
// Warning: (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
// Warning: (tsdoc-param-tag-with-invalid-type) The @param block should not include a JSDoc-style '{type}'
// Warning: (tsdoc-undefined-tag) The TSDoc tag "@return" is not defined in this configuration
generateRequestThumbprint(request: SilentRequest | SsoSilentRequest | PopupRequest | RedirectRequest): string;
// Warning: (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
// Warning: (tsdoc-param-tag-with-invalid-type) The @param block should not include a JSDoc-style '{type}'
Copy link
Member

Choose a reason for hiding this comment

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

nit: Are these duplicated?

// Warning: (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen
// Warning: (tsdoc-param-tag-with-invalid-type) The @param block should not include a JSDoc-style '{type}'
setPreQueueTime(eventName: PerformanceEvents, correlationId?: string): void;
Expand Down
7 changes: 6 additions & 1 deletion lib/msal-browser/src/controllers/StandardController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ export class StandardController implements IController {
atPopupMeasurement.add({
scenarioId: request.scenarioId,
accountType: getAccountType(request.account),
request,
});

try {
Expand Down Expand Up @@ -879,6 +880,7 @@ export class StandardController implements IController {
this.ssoSilentMeasurement?.add({
scenarioId: request.scenarioId,
accountType: getAccountType(request.account),
request,
});
preflightCheck(this.initialized, this.ssoSilentMeasurement);
this.ssoSilentMeasurement?.increment({
Expand Down Expand Up @@ -1873,7 +1875,10 @@ export class StandardController implements IController {
if (!account) {
throw createBrowserAuthError(BrowserAuthErrorCodes.noAccountError);
}
atsMeasurement.add({ accountType: getAccountType(account) });
atsMeasurement.add({
accountType: getAccountType(account),
request,
});

const thumbprint: RequestThumbprint = {
clientId: this.config.auth.clientId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ export class NativeInteractionClient extends BaseInteractionClient {
this.accountId,
nativeRequest
);
nativeATMeasurement.add({
request: {
...request,
account: result.account,
},
});
nativeATMeasurement.end({
success: true,
isNativeBroker: false, // Should be true only when the result is coming directly from the broker
Expand Down Expand Up @@ -188,6 +194,12 @@ export class NativeInteractionClient extends BaseInteractionClient {
reqTimestamp
)
.then((result: AuthenticationResult) => {
nativeATMeasurement.add({
request: {
...request,
account: result.account,
},
});
nativeATMeasurement.end({
success: true,
isNativeBroker: true,
Expand Down
10 changes: 10 additions & 0 deletions lib/msal-browser/src/interaction_client/PopupClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,16 @@ export class PopupClient extends StandardInteractionClient {
validRequest
);

this.performanceClient.addFields(
{
request: {
...request,
account: result.account,
},
},
this.correlationId
);

return result;
} catch (e) {
if (popup) {
Expand Down
21 changes: 20 additions & 1 deletion lib/msal-browser/src/interaction_client/RedirectClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,10 @@ export class RedirectClient extends StandardInteractionClient {
}

const cachedRequest = this.browserStorage.getCachedRequest(state);
this.performanceClient.addFields(
{ request: { cachedRequest } },
this.correlationId
);
this.logger.verbose("handleResponse called, retrieved cached request");

if (serverParams.accountId) {
Expand Down Expand Up @@ -488,7 +492,22 @@ export class RedirectClient extends StandardInteractionClient {
this.logger,
this.performanceClient
);
return interactionHandler.handleCodeResponse(serverParams, state);
const result = await interactionHandler.handleCodeResponse(
serverParams,
state
);

this.performanceClient.addFields(
{
request: {
...cachedRequest,
account: result.account,
},
},
this.correlationId
);

return result;
}

/**
Expand Down
31 changes: 31 additions & 0 deletions lib/msal-browser/src/telemetry/BrowserPerformanceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
PerformanceEvent,
PerformanceEvents,
PreQueueEvent,
RequestThumbprint,
SubMeasurement,
} from "@azure/msal-common";
import { Configuration } from "../config/Configuration";
Expand All @@ -21,6 +22,11 @@ import {
BrowserCacheLocation,
} from "../utils/BrowserConstants";
import * as BrowserCrypto from "../crypto/BrowserCrypto";
import { SilentRequest } from "../request/SilentRequest";
import { SsoSilentRequest } from "../request/SsoSilentRequest";
import { RedirectRequest } from "../request/RedirectRequest";
import { PopupRequest } from "../request/PopupRequest";
import { base64Encode } from "../encode/Base64Encode";

/**
* Returns browser performance measurement module if session flag is enabled. Returns undefined otherwise.
Expand Down Expand Up @@ -97,6 +103,31 @@ export class BrowserPerformanceClient
return BrowserCrypto.createNewGuid();
}

/**
* Generates base64 encoded request thumbprint
* @param request { SilentRequest | SsoSilentRequest | RedirectRequest | PopupRequest }
* @return string
*/
generateRequestThumbprint(
request:
| SilentRequest
| SsoSilentRequest
| PopupRequest
| RedirectRequest
): string {
const thumbprint: RequestThumbprint = {
clientId: this.clientId,
authority: request.authority || "",
scopes: request.scopes || [],
authenticationScheme: request.authenticationScheme,
resourceRequestMethod: request.resourceRequestMethod,
resourceRequestUri: request.resourceRequestUri,
sshKid: request.sshKid,
shrOptions: request.shrOptions,
};
return base64Encode(JSON.stringify(thumbprint));
}

private getPageVisibility(): string | null {
return document.visibilityState?.toString() || null;
}
Expand Down
Loading
Loading