wangzhibo
2026-05-09 53418655c061ac26f66058253f39200aced1ab1d
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
/*
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License.
 */
 
import { DataBoundary } from "../../account/AccountInfo.js";
 
/**
 * State of the performance event.
 *
 * @export
 * @enum {number}
 */
export const PerformanceEventStatus = {
    NotStarted: 0,
    InProgress: 1,
    Completed: 2,
} as const;
export type PerformanceEventStatus =
    (typeof PerformanceEventStatus)[keyof typeof PerformanceEventStatus];
 
export type SubMeasurement = {
    name: string;
    startTimeMs: number;
};
 
/**
 * Performance measurement taken by the library, including metadata about the request and application.
 *
 * @export
 * @typedef {PerformanceEvent}
 */
export type PerformanceEvent = {
    /**
     * Unique id for the event
     *
     * @type {string}
     */
    eventId: string;
 
    /**
     * State of the perforance measure.
     *
     * @type {PerformanceEventStatus}
     */
    status: PerformanceEventStatus;
 
    /**
     * Login authority used for the request
     *
     * @type {string}
     */
    authority: string;
 
    /**
     * Client id for the application
     *
     * @type {string}
     */
    clientId: string;
 
    /**
     * Correlation ID used for the request
     *
     * @type {string}
     */
    correlationId: string;
 
    /**
     * End-to-end duration in milliseconds.
     * @date 3/22/2022 - 3:40:05 PM
     *
     * @type {number}
     */
    durationMs?: number;
 
    /**
     * Visibility of the page when the event completed.
     * Read from: https://developer.mozilla.org/docs/Web/API/Page_Visibility_API
     *
     * @type {?(string | null)}
     */
    endPageVisibility?: string | null;
 
    /**
     * Whether the result was retrieved from the cache.
     *
     * @type {(boolean | null)}
     */
    fromCache?: boolean | null;
 
    /**
     * Event name (usually in the form of classNameFunctionName)
     *
     * @type {string}
     */
    name: string;
 
    /**
     * Visibility of the page when the event completed.
     * Read from: https://developer.mozilla.org/docs/Web/API/Page_Visibility_API
     *
     * @type {?(string | null)}
     */
    startPageVisibility?: string | null;
 
    /**
     * Online status when the event started.
     * Read from: https://developer.mozilla.org/docs/Web/API/NavigatorOnLine/onLine
     */
    startOnlineStatus?: boolean | null;
 
    /**
     * Unix millisecond timestamp when the event was initiated.
     *
     * @type {number}
     */
    startTimeMs: number;
 
    /**
     * Whether or the operation completed successfully.
     *
     * @type {(boolean | null)}
     */
    success?: boolean | null;
 
    /**
     * Add specific error code in case of failure
     *
     * @type {string}
     */
    errorCode?: string;
 
    /**
     * Add specific sub error code in case of failure
     *
     * @type {string}
     */
    subErrorCode?: string;
 
    /**
     * Server error number
     */
    serverErrorNo?: string;
 
    /**
     * Server sub error number
     */
    serverSubErrorNo?: string;
 
    /**
     * Name of the library used for the operation.
     *
     * @type {string}
     */
    libraryName: string;
 
    /**
     * Version of the library used for the operation.
     *
     * @type {string}
     */
    libraryVersion: string;
 
    /**
     * Version of the library used last. Used to track upgrades and downgrades
     */
    previousLibraryVersion?: string;
 
    /**
     * Whether the response is from a native component (e.g., WAM)
     *
     * @type {?boolean}
     */
    isNativeBroker?: boolean;
 
    /**
     * Platform-specific fields, when calling STS and/or broker for token requests
     */
    isPlatformAuthorizeRequest?: boolean;
    isPlatformBrokerRequest?: boolean;
    brokerErrorName?: string;
    brokerErrorCode?: string;
 
    /**
     * Request ID returned from the response
     *
     * @type {?string}
     */
    requestId?: string;
 
    /**
     * Cache lookup policy
     *
     * @type {?number}
     */
    cacheLookupPolicy?: number | undefined;
 
    /**
     * Cache Outcome
     * @type {?number}
     */
    cacheOutcome?: number;
 
    /**
     * Sub-measurements for internal use. To be deleted before flushing.
     */
    incompleteSubMeasurements?: Map<string, SubMeasurement>;
 
    visibilityChangeCount?: number;
    onlineStatusChangeCount?: number;
    incompleteSubsCount?: number;
 
    /**
     * Network connection info from the Network Information API (Chromium only).
     * Read from: https://developer.mozilla.org/docs/Web/API/NetworkInformation
     */
    networkEffectiveType?: string;
    networkRtt?: number;
 
    /**
     * CorrelationId of the in progress iframe request that was awaited
     */
    awaitIframeCorrelationId?: string;
    /**
     * Monitor_window_timeout debugging telemetry
     */
    redirectBridgeTimeoutMs?: number;
    isRedirectUriCrossOrigin?: boolean;
    redirectBridgeMessageVersion?: number;
    lateResponseExperimentEnabled?: boolean;
 
    /**
     * Size of the id token
     *
     * @type {number}
     */
    idTokenSize?: number;
 
    /**
     *
     * Size of the access token
     *
     * @type {number}
     */
 
    accessTokenSize?: number;
 
    /**
     *
     * Size of the refresh token
     *
     * @type {number}
     */
 
    refreshTokenSize?: number | undefined;
 
    /**
     * Application name as specified by the app.
     *
     * @type {?string}
     */
    appName?: string;
 
    /**
     * Application version as specified by the app.
     *
     * @type {?string}
     */
    appVersion?: string;
 
    /**
     * The following are fields that may be emitted in native broker scenarios
     */
    extensionId?: string;
    extensionVersion?: string;
    matsBrokerVersion?: string;
    matsAccountJoinOnStart?: string;
    matsAccountJoinOnEnd?: string;
    matsDeviceJoin?: string;
    matsPromptBehavior?: string;
    matsApiErrorCode?: number;
    matsUiVisible?: boolean;
    matsSilentCode?: number;
    matsSilentBiSubCode?: number;
    matsSilentMessage?: string;
    matsSilentStatus?: number;
    matsHttpStatus?: number;
    matsHttpEventCount?: number;
 
    /**
     * Http POST metadata
     */
    httpVerToken?: string;
    httpStatus?: number;
    contentTypeHeader?: string;
    contentLengthHeader?: string;
 
    /**
     * Platform broker fields
     */
    allowPlatformBroker?: boolean;
    extensionInstalled?: boolean;
    extensionHandshakeTimeoutMs?: number;
    extensionHandshakeTimedOut?: boolean;
 
    /**
     * Nested App Auth Fields
     */
    nestedAppAuthRequest?: boolean;
 
    /**
     * Multiple matched access/id/refresh tokens in the cache
     */
    multiMatchedAT?: number;
    multiMatchedID?: number;
    multiMatchedRT?: number;
 
    errorName?: string;
    errorStack?: string[];
 
    // Event context as JSON string
    context?: string;
 
    // Cache Data
    cacheLocation?: string;
    cacheRetentionDays?: number;
    accountCachedBy?: string;
    acntLoggedOut?: boolean;
 
    // Number of cached accounts matched by homeAccountId in buildAccountToCache
    cacheMatchedAccounts?: number;
 
    // Number of tokens in the cache to be reported when cache quota is exceeded
    cacheRtCount?: number;
    cacheIdCount?: number;
    cacheAtCount?: number;
 
    // Scenario id to track custom user prompts
    scenarioId?: string;
 
    accountType?: "AAD" | "MSA" | "B2C";
 
    /**
     * Server error that triggers a request retry
     *
     * @type {string}
     */
    retryError?: string;
 
    embeddedClientId?: string;
    embeddedRedirectUri?: string;
 
    isAsyncPopup?: boolean;
 
    cacheRtExpiresOnSeconds?: number;
    ntwkRtExpiresOnSeconds?: number;
    extRtExpiresOnSeconds?: number;
    rtOffsetSeconds?: number;
 
    sidFromClaim?: boolean;
    // Backward-compatible alias for sidFromClaim
    sidFromClaims?: boolean;
    sidFromRequest?: boolean;
    loginHintFromRequest?: boolean;
    loginHintFromUpn?: boolean;
    loginHintFromClaim?: boolean;
    domainHintFromRequest?: boolean;
 
    prompt?: string;
 
    usePreGeneratedPkce?: boolean;
 
    // Number of MSAL JS instances in the frame
    msalInstanceCount?: number;
    // Number of MSAL JS instances using the same client id in the frame
    sameClientIdInstanceCount?: number;
 
    navigateCallbackResult?: boolean;
 
    dataBoundary?: DataBoundary;
 
    // Hashed logs in the format [millis1,hash1;millis2,hash2;...]
    logs?: string;
 
    // Whether the application is configured for MCP flows
    isMcp?: boolean;
 
    /**
     * Source of cloud discovery metadata (config, cache, network, hardcoded_values)
     */
    cloudDiscoverySource?: string;
 
    /**
     * Source of authority endpoint metadata (config, cache, network, hardcoded_values)
     */
    authorityEndpointSource?: string;
 
    /**
     * Number of accounts removed during cache cleanup
     */
    accountsRemoved?: number;
 
    /**
     * Number of access tokens removed during cache cleanup
     */
    accessTokensRemoved?: number;
 
    /**
     * Number of failures when removing token binding keys
     */
    removeTokenBindingKeyFailure?: number;
 
    /**
     * Reason for silent refresh fallback to iframe
     * Format: errorCode or errorCode|subError
     *
     * @type {?string}
     */
    silentRefreshReason?: string;
 
    /**
     * Whether this request was deduped with another in-flight request
     */
    deduped?: boolean;
 
    /**
     * Whether the user has "Keep Me Signed In" enabled
     */
    kmsi?: boolean;
 
    /**
     * Cached SSO capability status from the most recent SSO verification
     */
    ssoCapable?: boolean;
 
    /**
     * Whether this event was executed in the background
     */
    isBackground?: boolean;
 
    /**
     * Cache migration telemetry — pre-migration counts
     */
    preMigrateAcntCount?: number;
    preMigrateATCount?: number;
    preMigrateITCount?: number;
    preMigrateRTCount?: number;
 
    /**
     * Cache migration telemetry — post-migration counts
     */
    postMigrateAcntCount?: number;
    postMigrateATCount?: number;
    postMigrateITCount?: number;
    postMigrateRTCount?: number;
 
    /**
     * Cache migration telemetry — old schema counts
     */
    oldAcntCount?: number;
    oldATCount?: number;
    oldITCount?: number;
    oldRTCount?: number;
 
    /**
     * Cache migration telemetry — skipped and migrated counts
     */
    skipATMigrateCount?: number;
    skipITMigrateCount?: number;
    skipRTMigrateCount?: number;
    migratedATCount?: number;
    migratedITCount?: number;
    migratedRTCount?: number;
 
    /**
     * Cache telemetry — expired, invalid, and removed counts
     */
    expiredCacheRemovedCount?: number;
    expiredAcntRemovedCount?: number;
    invalidCacheCount?: number;
 
    /**
     * Encrypted cache telemetry
     */
    unencryptedCacheCount?: number;
    encryptedCacheCount?: number;
    encryptedCacheExpiredCount?: number;
    encryptedCacheCorruptionCount?: number;
 
    /**
     * Container for dynamically-named telemetry fields.
     * Fields whose names are constructed at runtime (e.g., "[eventName]CallCount")
     * should be stored here instead of being set as top-level properties.
     * Use the "ext." prefix when calling addFields/incrementFields to automatically
     * route fields to this sub-object.
     *
     * @remarks
     * This property is typed as `Record<string, string | number>`.
     */
    ext?: Record<string, string | number>;
};
 
export type PerformanceEventContext = {
    dur?: number;
    err?: string;
    subErr?: string;
    fail?: number;
};
 
export type PerformanceEventStackedContext = PerformanceEventContext & {
    name?: string;
    childErr?: string;
};
 
/**
 * Prefix used to mark telemetry field names as dynamic.
 * Fields with this prefix in addFields/incrementFields calls will be routed
 * to the PerformanceEvent.ext sub-object.
 */
export const EXT_FIELD_PREFIX = "ext.";
 
export const IntFields: ReadonlySet<string> = new Set([
    "accessTokenSize",
    "durationMs",
    "idTokenSize",
    "matsSilentStatus",
    "matsHttpStatus",
    "refreshTokenSize",
    "startTimeMs",
    "status",
    "multiMatchedAT",
    "multiMatchedID",
    "multiMatchedRT",
    "unencryptedCacheCount",
    "encryptedCacheExpiredCount",
    "oldAccountCount",
    "oldAccessCount",
    "oldIdCount",
    "oldRefreshCount",
    "currAccountCount",
    "currAccessCount",
    "currIdCount",
    "currRefreshCount",
    "expiredCacheRemovedCount",
    "upgradedCacheCount",
    "cacheMatchedAccounts",
    "networkRtt",
    "redirectBridgeTimeoutMs",
    "redirectBridgeMessageVersion",
]);