mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-04-17 03:49:23 +01:00
Frontend performance metrics (#2439)
* Added enriched metrics * Add more traces for observability
This commit is contained in:
@@ -10,7 +10,7 @@ import { DatabaseAccount } from "../Contracts/DataModels";
|
||||
import * as ViewModels from "../Contracts/ViewModels";
|
||||
import { isExpectedError } from "../Metrics/ErrorClassification";
|
||||
import { scenarioMonitor } from "../Metrics/ScenarioMonitor";
|
||||
import { trace, traceFailure } from "../Shared/Telemetry/TelemetryProcessor";
|
||||
import { trace, traceFailure, traceStart, traceSuccess } from "../Shared/Telemetry/TelemetryProcessor";
|
||||
import { UserContext, userContext } from "../UserContext";
|
||||
|
||||
export function getAuthorizationHeader(): ViewModels.AuthorizationTokenHeaderMetadata {
|
||||
@@ -74,7 +74,11 @@ export async function acquireMsalTokenForAccount(
|
||||
silent: boolean = false,
|
||||
user_hint?: string,
|
||||
) {
|
||||
const msalStartKey = traceStart(Action.AcquireMsalToken, {
|
||||
acquireTokenType: silent ? "silent" : "interactive",
|
||||
});
|
||||
if (userContext.databaseAccount.properties?.documentEndpoint === undefined) {
|
||||
traceFailure(Action.AcquireMsalToken, { error: "No document endpoint" }, msalStartKey);
|
||||
throw new Error("Database account has no document endpoint defined");
|
||||
}
|
||||
let hrefEndpoint = "";
|
||||
@@ -107,6 +111,7 @@ export async function acquireMsalTokenForAccount(
|
||||
// See https://learn.microsoft.com/en-us/entra/identity-platform/msal-js-sso#sso-between-different-apps
|
||||
try {
|
||||
const loginResponse = await msalInstance.ssoSilent(loginRequest);
|
||||
traceSuccess(Action.AcquireMsalToken, { method: "ssoSilent" }, msalStartKey);
|
||||
return loginResponse.accessToken;
|
||||
} catch (silentError) {
|
||||
trace(Action.SignInAad, ActionModifiers.Mark, {
|
||||
@@ -122,6 +127,7 @@ export async function acquireMsalTokenForAccount(
|
||||
// See https://learn.microsoft.com/en-us/entra/identity-platform/msal-js-prompt-behavior#interactive-requests-with-promptnone
|
||||
// The hint will be used to pre-fill the username field in the popup if silent is false.
|
||||
const loginResponse = await msalInstance.loginPopup({ prompt: silent ? "none" : "login", ...loginRequest });
|
||||
traceSuccess(Action.AcquireMsalToken, { method: "loginPopup" }, msalStartKey);
|
||||
return loginResponse.accessToken;
|
||||
} catch (error) {
|
||||
traceFailure(Action.SignInAad, {
|
||||
@@ -129,6 +135,7 @@ export async function acquireMsalTokenForAccount(
|
||||
acquireTokenType: silent ? "silent" : "interactive",
|
||||
errorMessage: JSON.stringify(error),
|
||||
});
|
||||
traceFailure(Action.AcquireMsalToken, { error: JSON.stringify(error) }, msalStartKey);
|
||||
// Mark expected failure for health metrics so timeout emits healthy
|
||||
if (isExpectedError(error)) {
|
||||
scenarioMonitor.markExpectedFailure();
|
||||
@@ -161,7 +168,8 @@ export async function acquireTokenWithMsal(
|
||||
|
||||
try {
|
||||
// attempt silent acquisition first
|
||||
return (await msalInstance.acquireTokenSilent(tokenRequest)).accessToken;
|
||||
const token = (await msalInstance.acquireTokenSilent(tokenRequest)).accessToken;
|
||||
return token;
|
||||
} catch (silentError) {
|
||||
if (silentError instanceof msal.InteractionRequiredAuthError && silent === false) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user