@azure/msal-common 14.7.2-alpha.0 → 14.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/account/AccountInfo.mjs +1 -1
- package/dist/account/AuthToken.mjs +1 -1
- package/dist/account/CcsCredential.mjs +1 -1
- package/dist/account/ClientInfo.mjs +1 -1
- package/dist/account/TokenClaims.mjs +1 -1
- package/dist/authority/Authority.d.ts +2 -3
- package/dist/authority/Authority.d.ts.map +1 -1
- package/dist/authority/Authority.mjs +4 -8
- package/dist/authority/Authority.mjs.map +1 -1
- package/dist/authority/AuthorityFactory.mjs +1 -1
- package/dist/authority/AuthorityMetadata.mjs +1 -1
- package/dist/authority/AuthorityOptions.mjs +1 -1
- package/dist/authority/AuthorityType.mjs +1 -1
- package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs +1 -1
- package/dist/authority/CloudInstanceDiscoveryResponse.mjs +1 -1
- package/dist/authority/OpenIdConfigResponse.mjs +1 -1
- package/dist/authority/ProtocolMode.mjs +1 -1
- package/dist/authority/RegionDiscovery.mjs +1 -1
- package/dist/cache/CacheManager.mjs +1 -1
- package/dist/cache/entities/AccountEntity.mjs +1 -1
- package/dist/cache/entities/CacheRecord.mjs +1 -1
- package/dist/cache/persistence/TokenCacheContext.mjs +1 -1
- package/dist/cache/utils/CacheHelpers.mjs +1 -1
- package/dist/client/AuthorizationCodeClient.mjs +1 -1
- package/dist/client/BaseClient.mjs +1 -1
- package/dist/client/RefreshTokenClient.mjs +1 -1
- package/dist/client/SilentFlowClient.mjs +1 -1
- package/dist/config/ClientConfiguration.d.ts.map +1 -1
- package/dist/config/ClientConfiguration.mjs +4 -2
- package/dist/config/ClientConfiguration.mjs.map +1 -1
- package/dist/constants/AADServerParamKeys.mjs +1 -1
- package/dist/crypto/ICrypto.mjs +1 -1
- package/dist/crypto/JoseHeader.mjs +1 -1
- package/dist/crypto/PopTokenGenerator.mjs +1 -1
- package/dist/error/AuthError.mjs +1 -1
- package/dist/error/AuthErrorCodes.mjs +1 -1
- package/dist/error/ClientAuthError.mjs +1 -1
- package/dist/error/ClientAuthErrorCodes.mjs +1 -1
- package/dist/error/ClientConfigurationError.mjs +1 -1
- package/dist/error/ClientConfigurationErrorCodes.mjs +1 -1
- package/dist/error/InteractionRequiredAuthError.mjs +1 -1
- package/dist/error/InteractionRequiredAuthErrorCodes.mjs +1 -1
- package/dist/error/JoseHeaderError.mjs +1 -1
- package/dist/error/JoseHeaderErrorCodes.mjs +1 -1
- package/dist/error/ServerError.mjs +1 -1
- package/dist/index.cjs +401 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/logger/Logger.mjs +1 -1
- package/dist/network/INetworkModule.mjs +1 -1
- package/dist/network/NetworkManager.mjs +1 -1
- package/dist/network/ThrottlingUtils.mjs +1 -1
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/packageMetadata.d.ts.map +1 -1
- package/dist/packageMetadata.mjs +2 -2
- package/dist/request/AuthenticationHeaderParser.mjs +1 -1
- package/dist/request/RequestParameterBuilder.mjs +1 -1
- package/dist/request/RequestValidator.mjs +1 -1
- package/dist/request/ScopeSet.mjs +1 -1
- package/dist/response/ResponseHandler.mjs +1 -1
- package/dist/telemetry/performance/IPerformanceClient.d.ts +1 -1
- package/dist/telemetry/performance/IPerformanceClient.d.ts.map +1 -1
- package/dist/telemetry/performance/PerformanceClient.d.ts +55 -5
- package/dist/telemetry/performance/PerformanceClient.d.ts.map +1 -1
- package/dist/telemetry/performance/PerformanceClient.mjs +183 -13
- package/dist/telemetry/performance/PerformanceClient.mjs.map +1 -1
- package/dist/telemetry/performance/PerformanceEvent.d.ts +14 -0
- package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -1
- package/dist/telemetry/performance/PerformanceEvent.mjs +215 -2
- package/dist/telemetry/performance/PerformanceEvent.mjs.map +1 -1
- package/dist/telemetry/performance/StubPerformanceClient.mjs +1 -1
- package/dist/telemetry/server/ServerTelemetryManager.mjs +1 -1
- package/dist/url/UrlString.mjs +1 -1
- package/dist/utils/Constants.d.ts +0 -10
- package/dist/utils/Constants.d.ts.map +1 -1
- package/dist/utils/Constants.mjs +2 -13
- package/dist/utils/Constants.mjs.map +1 -1
- package/dist/utils/FunctionWrappers.d.ts.map +1 -1
- package/dist/utils/FunctionWrappers.mjs +3 -3
- package/dist/utils/FunctionWrappers.mjs.map +1 -1
- package/dist/utils/ProtocolUtils.mjs +1 -1
- package/dist/utils/StringUtils.mjs +1 -1
- package/dist/utils/TimeUtils.mjs +1 -1
- package/dist/utils/UrlUtils.mjs +1 -1
- package/package.json +1 -1
- package/src/authority/Authority.ts +3 -9
- package/src/config/ClientConfiguration.ts +4 -4
- package/src/index.ts +0 -1
- package/src/packageMetadata.ts +1 -1
- package/src/telemetry/performance/IPerformanceClient.ts +4 -1
- package/src/telemetry/performance/PerformanceClient.ts +281 -16
- package/src/telemetry/performance/PerformanceEvent.ts +237 -0
- package/src/utils/Constants.ts +0 -12
- package/src/utils/FunctionWrappers.ts +12 -6
|
@@ -6,10 +6,7 @@
|
|
|
6
6
|
import { INetworkModule } from "../network/INetworkModule";
|
|
7
7
|
import { DEFAULT_CRYPTO_IMPLEMENTATION, ICrypto } from "../crypto/ICrypto";
|
|
8
8
|
import { ILoggerCallback, Logger, LogLevel } from "../logger/Logger";
|
|
9
|
-
import {
|
|
10
|
-
Constants,
|
|
11
|
-
DEFAULT_TOKEN_RENEWAL_OFFSET_SEC,
|
|
12
|
-
} from "../utils/Constants";
|
|
9
|
+
import { Constants } from "../utils/Constants";
|
|
13
10
|
import { version } from "../packageMetadata";
|
|
14
11
|
import { Authority } from "../authority/Authority";
|
|
15
12
|
import { AzureCloudInstance } from "../authority/AuthorityOptions";
|
|
@@ -24,6 +21,9 @@ import {
|
|
|
24
21
|
createClientAuthError,
|
|
25
22
|
} from "../error/ClientAuthError";
|
|
26
23
|
|
|
24
|
+
// Token renewal offset default in seconds
|
|
25
|
+
const DEFAULT_TOKEN_RENEWAL_OFFSET_SEC = 300;
|
|
26
|
+
|
|
27
27
|
/**
|
|
28
28
|
* Use the configuration object to configure MSAL Modules and initialize the base interfaces for MSAL.
|
|
29
29
|
*
|
package/src/index.ts
CHANGED
package/src/packageMetadata.ts
CHANGED
|
@@ -9,7 +9,10 @@ import { IPerformanceMeasurement } from "./IPerformanceMeasurement";
|
|
|
9
9
|
export type PerformanceCallbackFunction = (events: PerformanceEvent[]) => void;
|
|
10
10
|
|
|
11
11
|
export type InProgressPerformanceEvent = {
|
|
12
|
-
end: (
|
|
12
|
+
end: (
|
|
13
|
+
event?: Partial<PerformanceEvent>,
|
|
14
|
+
error?: unknown
|
|
15
|
+
) => PerformanceEvent | null;
|
|
13
16
|
discard: () => void;
|
|
14
17
|
add: (fields: { [key: string]: {} | undefined }) => void;
|
|
15
18
|
increment: (fields: { [key: string]: number | undefined }) => void;
|
|
@@ -14,17 +14,227 @@ import {
|
|
|
14
14
|
import {
|
|
15
15
|
IntFields,
|
|
16
16
|
PerformanceEvent,
|
|
17
|
+
PerformanceEventAbbreviations,
|
|
18
|
+
PerformanceEventContext,
|
|
17
19
|
PerformanceEvents,
|
|
20
|
+
PerformanceEventStackedContext,
|
|
18
21
|
PerformanceEventStatus,
|
|
19
22
|
} from "./PerformanceEvent";
|
|
20
23
|
import { IPerformanceMeasurement } from "./IPerformanceMeasurement";
|
|
21
24
|
import { StubPerformanceMeasurement } from "./StubPerformanceClient";
|
|
25
|
+
import { AuthError } from "../../error/AuthError";
|
|
22
26
|
|
|
23
27
|
export interface PreQueueEvent {
|
|
24
28
|
name: PerformanceEvents;
|
|
25
29
|
time: number;
|
|
26
30
|
}
|
|
27
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Starts context by adding payload to the stack
|
|
34
|
+
* @param event {PerformanceEvent}
|
|
35
|
+
* @param abbreviations {Map<string, string>} event name abbreviations
|
|
36
|
+
* @param stack {?PerformanceEventStackedContext[]} stack
|
|
37
|
+
*/
|
|
38
|
+
export function startContext(
|
|
39
|
+
event: PerformanceEvent,
|
|
40
|
+
abbreviations: Map<string, string>,
|
|
41
|
+
stack?: PerformanceEventStackedContext[]
|
|
42
|
+
): void {
|
|
43
|
+
if (!stack) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
stack.push({
|
|
48
|
+
name: abbreviations.get(event.name) || event.name,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Ends context by removing payload from the stack and returning parent or self, if stack is empty, payload
|
|
54
|
+
*
|
|
55
|
+
* @param event {PerformanceEvent}
|
|
56
|
+
* @param abbreviations {Map<string, string>} event name abbreviations
|
|
57
|
+
* @param stack {?PerformanceEventStackedContext[]} stack
|
|
58
|
+
* @param error {?unknown} error
|
|
59
|
+
*/
|
|
60
|
+
export function endContext(
|
|
61
|
+
event: PerformanceEvent,
|
|
62
|
+
abbreviations: Map<string, string>,
|
|
63
|
+
stack?: PerformanceEventStackedContext[],
|
|
64
|
+
error?: unknown
|
|
65
|
+
): PerformanceEventContext | undefined {
|
|
66
|
+
if (!stack?.length) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const peek = (stack: PerformanceEventStackedContext[]) => {
|
|
71
|
+
return stack.length ? stack[stack.length - 1] : undefined;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const abbrEventName = abbreviations.get(event.name) || event.name;
|
|
75
|
+
const top = peek(stack);
|
|
76
|
+
if (top?.name !== abbrEventName) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const current = stack?.pop();
|
|
81
|
+
if (!current) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const errorCode =
|
|
86
|
+
error instanceof AuthError
|
|
87
|
+
? error.errorCode
|
|
88
|
+
: error instanceof Error
|
|
89
|
+
? error.name
|
|
90
|
+
: undefined;
|
|
91
|
+
const subErr = error instanceof AuthError ? error.subError : undefined;
|
|
92
|
+
|
|
93
|
+
if (errorCode && current.childErr !== errorCode) {
|
|
94
|
+
current.err = errorCode;
|
|
95
|
+
if (subErr) {
|
|
96
|
+
current.subErr = subErr;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
delete current.name;
|
|
101
|
+
delete current.childErr;
|
|
102
|
+
|
|
103
|
+
const context: PerformanceEventContext = {
|
|
104
|
+
...current,
|
|
105
|
+
dur: event.durationMs,
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
if (!event.success) {
|
|
109
|
+
context.fail = 1;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const parent = peek(stack);
|
|
113
|
+
if (!parent) {
|
|
114
|
+
return { [abbrEventName]: context };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (errorCode) {
|
|
118
|
+
parent.childErr = errorCode;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
let childName: string;
|
|
122
|
+
if (!parent[abbrEventName]) {
|
|
123
|
+
childName = abbrEventName;
|
|
124
|
+
} else {
|
|
125
|
+
const siblings = Object.keys(parent).filter((key) =>
|
|
126
|
+
key.startsWith(abbrEventName)
|
|
127
|
+
).length;
|
|
128
|
+
childName = `${abbrEventName}_${siblings + 1}`;
|
|
129
|
+
}
|
|
130
|
+
parent[childName] = context;
|
|
131
|
+
return parent;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Adds error name and stack trace to the telemetry event
|
|
136
|
+
* @param error {Error}
|
|
137
|
+
* @param logger {Logger}
|
|
138
|
+
* @param event {PerformanceEvent}
|
|
139
|
+
* @param stackMaxSize {number} max error stack size to capture
|
|
140
|
+
*/
|
|
141
|
+
export function addError(
|
|
142
|
+
error: unknown,
|
|
143
|
+
logger: Logger,
|
|
144
|
+
event: PerformanceEvent,
|
|
145
|
+
stackMaxSize: number = 5
|
|
146
|
+
): void {
|
|
147
|
+
if (!(error instanceof Error)) {
|
|
148
|
+
logger.trace(
|
|
149
|
+
"PerformanceClient.addErrorStack: Input error is not instance of Error",
|
|
150
|
+
event.correlationId
|
|
151
|
+
);
|
|
152
|
+
return;
|
|
153
|
+
} else if (error instanceof AuthError) {
|
|
154
|
+
event.errorCode = error.errorCode;
|
|
155
|
+
event.subErrorCode = error.subError;
|
|
156
|
+
return;
|
|
157
|
+
} else if (event.errorStack?.length) {
|
|
158
|
+
logger.trace(
|
|
159
|
+
"PerformanceClient.addErrorStack: Stack already exist",
|
|
160
|
+
event.correlationId
|
|
161
|
+
);
|
|
162
|
+
return;
|
|
163
|
+
} else if (!error.stack?.length) {
|
|
164
|
+
logger.trace(
|
|
165
|
+
"PerformanceClient.addErrorStack: Input stack is empty",
|
|
166
|
+
event.correlationId
|
|
167
|
+
);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (error.stack) {
|
|
172
|
+
event.errorStack = compactStack(error.stack, stackMaxSize);
|
|
173
|
+
}
|
|
174
|
+
event.errorName = error.name;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Compacts error stack into array by fetching N first entries
|
|
179
|
+
* @param stack {string} error stack
|
|
180
|
+
* @param stackMaxSize {number} max error stack size to capture
|
|
181
|
+
* @returns {string[]}
|
|
182
|
+
*/
|
|
183
|
+
export function compactStack(stack: string, stackMaxSize: number): string[] {
|
|
184
|
+
if (stackMaxSize < 0) {
|
|
185
|
+
return [];
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const stackArr = stack.split("\n") || [];
|
|
189
|
+
if (stackArr.length < 2) {
|
|
190
|
+
return [];
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const res = [];
|
|
194
|
+
// Get top N stack lines
|
|
195
|
+
for (
|
|
196
|
+
// Skip first line as it may contain PII data
|
|
197
|
+
let ix = Math.max(stackArr.length - stackMaxSize - 1, 1);
|
|
198
|
+
ix < stackArr.length;
|
|
199
|
+
ix++
|
|
200
|
+
) {
|
|
201
|
+
const line = stackArr[ix];
|
|
202
|
+
if (res.length >= stackMaxSize) {
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
res.push(compactStackLine(line));
|
|
206
|
+
}
|
|
207
|
+
return res;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Compacts error stack line by shortening file path
|
|
212
|
+
* Example: https://localhost/msal-common/src/authority/Authority.js:100:1 -> Authority.js:100:1
|
|
213
|
+
* @param line {string} stack line
|
|
214
|
+
* @returns {string}
|
|
215
|
+
*/
|
|
216
|
+
export function compactStackLine(line: string): string {
|
|
217
|
+
const filePathIx = line.lastIndexOf(" ") + 1;
|
|
218
|
+
if (filePathIx < 1) {
|
|
219
|
+
return line;
|
|
220
|
+
}
|
|
221
|
+
const filePath = line.substring(filePathIx);
|
|
222
|
+
|
|
223
|
+
let fileNameIx = filePath.lastIndexOf("/");
|
|
224
|
+
fileNameIx = fileNameIx < 0 ? filePath.lastIndexOf("\\") : fileNameIx;
|
|
225
|
+
|
|
226
|
+
if (fileNameIx >= 0) {
|
|
227
|
+
return (
|
|
228
|
+
line.substring(0, filePathIx) +
|
|
229
|
+
"(" +
|
|
230
|
+
filePath.substring(fileNameIx + 1) +
|
|
231
|
+
(filePath.charAt(filePath.length - 1) === ")" ? "" : ")")
|
|
232
|
+
).trimStart();
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return line.trimStart();
|
|
236
|
+
}
|
|
237
|
+
|
|
28
238
|
export abstract class PerformanceClient implements IPerformanceClient {
|
|
29
239
|
protected authority: string;
|
|
30
240
|
protected libraryName: string;
|
|
@@ -59,6 +269,20 @@ export abstract class PerformanceClient implements IPerformanceClient {
|
|
|
59
269
|
|
|
60
270
|
protected intFields: Set<string>;
|
|
61
271
|
|
|
272
|
+
/**
|
|
273
|
+
* Map of stacked events by correlation id.
|
|
274
|
+
*
|
|
275
|
+
* @protected
|
|
276
|
+
*/
|
|
277
|
+
protected eventStack: Map<string, PerformanceEventStackedContext[]>;
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Event name abbreviations
|
|
281
|
+
*
|
|
282
|
+
* @protected
|
|
283
|
+
*/
|
|
284
|
+
protected abbreviations: Map<string, string>;
|
|
285
|
+
|
|
62
286
|
/**
|
|
63
287
|
* Creates an instance of PerformanceClient,
|
|
64
288
|
* an abstract class containing core performance telemetry logic.
|
|
@@ -71,6 +295,7 @@ export abstract class PerformanceClient implements IPerformanceClient {
|
|
|
71
295
|
* @param {string} libraryVersion Version of the library
|
|
72
296
|
* @param {ApplicationTelemetry} applicationTelemetry application name and version
|
|
73
297
|
* @param {Set<String>} intFields integer fields to be truncated
|
|
298
|
+
* @param {Map<string, string>} abbreviations event name abbreviations
|
|
74
299
|
*/
|
|
75
300
|
constructor(
|
|
76
301
|
clientId: string,
|
|
@@ -79,7 +304,8 @@ export abstract class PerformanceClient implements IPerformanceClient {
|
|
|
79
304
|
libraryName: string,
|
|
80
305
|
libraryVersion: string,
|
|
81
306
|
applicationTelemetry: ApplicationTelemetry,
|
|
82
|
-
intFields?: Set<string
|
|
307
|
+
intFields?: Set<string>,
|
|
308
|
+
abbreviations?: Map<string, string>
|
|
83
309
|
) {
|
|
84
310
|
this.authority = authority;
|
|
85
311
|
this.libraryName = libraryName;
|
|
@@ -89,12 +315,17 @@ export abstract class PerformanceClient implements IPerformanceClient {
|
|
|
89
315
|
this.logger = logger;
|
|
90
316
|
this.callbacks = new Map();
|
|
91
317
|
this.eventsByCorrelationId = new Map();
|
|
318
|
+
this.eventStack = new Map();
|
|
92
319
|
this.queueMeasurements = new Map();
|
|
93
320
|
this.preQueueTimeByCorrelationId = new Map();
|
|
94
321
|
this.intFields = intFields || new Set();
|
|
95
322
|
for (const item of IntFields) {
|
|
96
323
|
this.intFields.add(item);
|
|
97
324
|
}
|
|
325
|
+
this.abbreviations = abbreviations || new Map();
|
|
326
|
+
for (const [key, value] of PerformanceEventAbbreviations) {
|
|
327
|
+
this.abbreviations.set(key, value);
|
|
328
|
+
}
|
|
98
329
|
}
|
|
99
330
|
|
|
100
331
|
/**
|
|
@@ -292,18 +523,27 @@ export abstract class PerformanceClient implements IPerformanceClient {
|
|
|
292
523
|
|
|
293
524
|
// Store in progress events so they can be discarded if not ended properly
|
|
294
525
|
this.cacheEventByCorrelationId(inProgressEvent);
|
|
526
|
+
startContext(
|
|
527
|
+
inProgressEvent,
|
|
528
|
+
this.abbreviations,
|
|
529
|
+
this.eventStack.get(eventCorrelationId)
|
|
530
|
+
);
|
|
295
531
|
|
|
296
532
|
// Return the event and functions the caller can use to properly end/flush the measurement
|
|
297
533
|
return {
|
|
298
534
|
end: (
|
|
299
|
-
event?: Partial<PerformanceEvent
|
|
535
|
+
event?: Partial<PerformanceEvent>,
|
|
536
|
+
error?: unknown
|
|
300
537
|
): PerformanceEvent | null => {
|
|
301
|
-
return this.endMeasurement(
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
538
|
+
return this.endMeasurement(
|
|
539
|
+
{
|
|
540
|
+
// Initial set of event properties
|
|
541
|
+
...inProgressEvent,
|
|
542
|
+
// Properties set when event ends
|
|
543
|
+
...event,
|
|
544
|
+
},
|
|
545
|
+
error
|
|
546
|
+
);
|
|
307
547
|
},
|
|
308
548
|
discard: () => {
|
|
309
549
|
return this.discardMeasurements(inProgressEvent.correlationId);
|
|
@@ -329,10 +569,13 @@ export abstract class PerformanceClient implements IPerformanceClient {
|
|
|
329
569
|
* otherwise.
|
|
330
570
|
*
|
|
331
571
|
* @param {PerformanceEvent} event
|
|
332
|
-
* @param {
|
|
572
|
+
* @param {unknown} error
|
|
333
573
|
* @returns {(PerformanceEvent | null)}
|
|
334
574
|
*/
|
|
335
|
-
endMeasurement(
|
|
575
|
+
endMeasurement(
|
|
576
|
+
event: PerformanceEvent,
|
|
577
|
+
error?: unknown
|
|
578
|
+
): PerformanceEvent | null {
|
|
336
579
|
const rootEvent: PerformanceEvent | undefined =
|
|
337
580
|
this.eventsByCorrelationId.get(event.correlationId);
|
|
338
581
|
if (!rootEvent) {
|
|
@@ -349,6 +592,20 @@ export abstract class PerformanceClient implements IPerformanceClient {
|
|
|
349
592
|
totalQueueCount: 0,
|
|
350
593
|
manuallyCompletedCount: 0,
|
|
351
594
|
};
|
|
595
|
+
|
|
596
|
+
event.durationMs = Math.round(
|
|
597
|
+
event.durationMs || this.getDurationMs(event.startTimeMs)
|
|
598
|
+
);
|
|
599
|
+
|
|
600
|
+
const context = JSON.stringify(
|
|
601
|
+
endContext(
|
|
602
|
+
event,
|
|
603
|
+
this.abbreviations,
|
|
604
|
+
this.eventStack.get(rootEvent.correlationId),
|
|
605
|
+
error
|
|
606
|
+
)
|
|
607
|
+
);
|
|
608
|
+
|
|
352
609
|
if (isRoot) {
|
|
353
610
|
queueInfo = this.getQueueInfo(event.correlationId);
|
|
354
611
|
this.discardCache(rootEvent.correlationId);
|
|
@@ -356,19 +613,21 @@ export abstract class PerformanceClient implements IPerformanceClient {
|
|
|
356
613
|
rootEvent.incompleteSubMeasurements?.delete(event.eventId);
|
|
357
614
|
}
|
|
358
615
|
|
|
359
|
-
const durationMs =
|
|
360
|
-
event.durationMs || this.getDurationMs(event.startTimeMs);
|
|
361
616
|
this.logger.trace(
|
|
362
|
-
`PerformanceClient: Performance measurement ended for ${event.name}: ${durationMs} ms`,
|
|
617
|
+
`PerformanceClient: Performance measurement ended for ${event.name}: ${event.durationMs} ms`,
|
|
363
618
|
event.correlationId
|
|
364
619
|
);
|
|
365
620
|
|
|
366
621
|
// Add sub-measurement attribute to root event.
|
|
367
622
|
if (!isRoot) {
|
|
368
|
-
rootEvent[event.name + "DurationMs"] = Math.floor(durationMs);
|
|
623
|
+
rootEvent[event.name + "DurationMs"] = Math.floor(event.durationMs);
|
|
369
624
|
return { ...rootEvent };
|
|
370
625
|
}
|
|
371
626
|
|
|
627
|
+
if (error) {
|
|
628
|
+
addError(error, this.logger, rootEvent);
|
|
629
|
+
}
|
|
630
|
+
|
|
372
631
|
let finalEvent: PerformanceEvent = { ...rootEvent, ...event };
|
|
373
632
|
let incompleteSubsCount: number = 0;
|
|
374
633
|
// Incomplete sub-measurements are discarded. They are likely an instrumentation bug that should be fixed.
|
|
@@ -383,12 +642,12 @@ export abstract class PerformanceClient implements IPerformanceClient {
|
|
|
383
642
|
|
|
384
643
|
finalEvent = {
|
|
385
644
|
...finalEvent,
|
|
386
|
-
durationMs: Math.round(durationMs),
|
|
387
645
|
queuedTimeMs: queueInfo.totalQueueTime,
|
|
388
646
|
queuedCount: queueInfo.totalQueueCount,
|
|
389
647
|
queuedManuallyCompletedCount: queueInfo.manuallyCompletedCount,
|
|
390
648
|
status: PerformanceEventStatus.Completed,
|
|
391
649
|
incompleteSubsCount,
|
|
650
|
+
context,
|
|
392
651
|
};
|
|
393
652
|
this.truncateIntegralFields(finalEvent);
|
|
394
653
|
this.emitEvents([finalEvent], event.correlationId);
|
|
@@ -476,6 +735,7 @@ export abstract class PerformanceClient implements IPerformanceClient {
|
|
|
476
735
|
event.correlationId
|
|
477
736
|
);
|
|
478
737
|
this.eventsByCorrelationId.set(event.correlationId, { ...event });
|
|
738
|
+
this.eventStack.set(event.correlationId, []);
|
|
479
739
|
}
|
|
480
740
|
}
|
|
481
741
|
|
|
@@ -540,6 +800,12 @@ export abstract class PerformanceClient implements IPerformanceClient {
|
|
|
540
800
|
correlationId
|
|
541
801
|
);
|
|
542
802
|
this.preQueueTimeByCorrelationId.delete(correlationId);
|
|
803
|
+
|
|
804
|
+
this.logger.trace(
|
|
805
|
+
"PerformanceClient: Event stack discarded",
|
|
806
|
+
correlationId
|
|
807
|
+
);
|
|
808
|
+
this.eventStack.delete(correlationId);
|
|
543
809
|
}
|
|
544
810
|
|
|
545
811
|
/**
|
|
@@ -606,7 +872,6 @@ export abstract class PerformanceClient implements IPerformanceClient {
|
|
|
606
872
|
/**
|
|
607
873
|
* Enforce truncation of integral fields in performance event.
|
|
608
874
|
* @param {PerformanceEvent} event performance event to update.
|
|
609
|
-
* @param {Set<string>} intFields integral fields.
|
|
610
875
|
*/
|
|
611
876
|
private truncateIntegralFields(event: PerformanceEvent): void {
|
|
612
877
|
this.intFields.forEach((key) => {
|