@fluidframework/telemetry-utils 2.12.0 → 2.20.0
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/CHANGELOG.md +15 -0
- package/api-report/telemetry-utils.legacy.alpha.api.md +0 -18
- package/dist/errorLogging.js +2 -2
- package/dist/errorLogging.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/legacy.d.ts +0 -1
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +7 -8
- package/dist/logger.js.map +1 -1
- package/dist/mockLogger.d.ts +5 -34
- package/dist/mockLogger.d.ts.map +1 -1
- package/dist/mockLogger.js +18 -48
- package/dist/mockLogger.js.map +1 -1
- package/dist/package.json +2 -1
- package/lib/errorLogging.js +2 -2
- package/lib/errorLogging.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/legacy.d.ts +0 -1
- package/lib/logger.d.ts.map +1 -1
- package/lib/logger.js +7 -8
- package/lib/logger.js.map +1 -1
- package/lib/mockLogger.d.ts +5 -34
- package/lib/mockLogger.d.ts.map +1 -1
- package/lib/mockLogger.js +17 -46
- package/lib/mockLogger.js.map +1 -1
- package/package.json +13 -9
- package/src/errorLogging.ts +2 -2
- package/src/index.ts +0 -1
- package/src/logger.ts +10 -8
- package/src/mockLogger.ts +18 -47
package/src/logger.ts
CHANGED
|
@@ -289,11 +289,10 @@ export abstract class TelemetryLogger implements ITelemetryLoggerExt {
|
|
|
289
289
|
}
|
|
290
290
|
for (const props of properties) {
|
|
291
291
|
if (props !== undefined) {
|
|
292
|
-
for (const key of Object.
|
|
292
|
+
for (const [key, getterOrValue] of Object.entries(props)) {
|
|
293
293
|
if (eventLike[key] !== undefined) {
|
|
294
294
|
continue;
|
|
295
295
|
}
|
|
296
|
-
const getterOrValue = props[key];
|
|
297
296
|
// If this throws, hopefully it is handled elsewhere
|
|
298
297
|
const value =
|
|
299
298
|
typeof getterOrValue === "function" ? getterOrValue() : getterOrValue;
|
|
@@ -326,8 +325,7 @@ export class TaggedLoggerAdapter implements ITelemetryBaseLogger {
|
|
|
326
325
|
category: eventWithTagsMaybe.category,
|
|
327
326
|
eventName: eventWithTagsMaybe.eventName,
|
|
328
327
|
};
|
|
329
|
-
for (const key of Object.
|
|
330
|
-
const taggableProp = eventWithTagsMaybe[key];
|
|
328
|
+
for (const [key, taggableProp] of Object.entries(eventWithTagsMaybe)) {
|
|
331
329
|
const { value, tag } =
|
|
332
330
|
typeof taggableProp === "object"
|
|
333
331
|
? taggableProp
|
|
@@ -765,12 +763,16 @@ export class PerformanceEvent {
|
|
|
765
763
|
this.reportEvent("end");
|
|
766
764
|
}
|
|
767
765
|
this.performanceEndMark();
|
|
766
|
+
|
|
767
|
+
// To prevent the event from being reported again later
|
|
768
768
|
this.event = undefined;
|
|
769
769
|
}
|
|
770
770
|
|
|
771
771
|
public end(props?: ITelemetryPropertiesExt): void {
|
|
772
772
|
this.reportEvent("end", props);
|
|
773
773
|
this.performanceEndMark();
|
|
774
|
+
|
|
775
|
+
// To prevent the event from being reported again later
|
|
774
776
|
this.event = undefined;
|
|
775
777
|
}
|
|
776
778
|
|
|
@@ -787,6 +789,8 @@ export class PerformanceEvent {
|
|
|
787
789
|
if (this.markers.cancel !== undefined) {
|
|
788
790
|
this.reportEvent("cancel", { category: this.markers.cancel, ...props }, error);
|
|
789
791
|
}
|
|
792
|
+
|
|
793
|
+
// To prevent the event from being reported again later
|
|
790
794
|
this.event = undefined;
|
|
791
795
|
}
|
|
792
796
|
|
|
@@ -798,9 +802,8 @@ export class PerformanceEvent {
|
|
|
798
802
|
props?: ITelemetryPropertiesExt,
|
|
799
803
|
error?: unknown,
|
|
800
804
|
): void {
|
|
801
|
-
//
|
|
802
|
-
//
|
|
803
|
-
// and the caller attempts to end directly, e.g. issue #3936. Just return.
|
|
805
|
+
// If the caller invokes cancel or end directly inside the callback for timedExec[Async],
|
|
806
|
+
// then it's possible to come back through reportEvent twice. Only the first time counts.
|
|
804
807
|
if (!this.event) {
|
|
805
808
|
return;
|
|
806
809
|
}
|
|
@@ -944,7 +947,6 @@ export const tagData = <
|
|
|
944
947
|
// The ternary form is less legible in this case.
|
|
945
948
|
// eslint-disable-next-line unicorn/prefer-ternary
|
|
946
949
|
if (typeof value === "function") {
|
|
947
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
948
950
|
pv[key] = () => {
|
|
949
951
|
return { tag, value: value() };
|
|
950
952
|
};
|
package/src/mockLogger.ts
CHANGED
|
@@ -23,28 +23,7 @@ import type {
|
|
|
23
23
|
* Records events sent to it, and then can walk back over those events, searching for a set of expected events to
|
|
24
24
|
* match against the logged events.
|
|
25
25
|
*
|
|
26
|
-
* @
|
|
27
|
-
*
|
|
28
|
-
* This class is not intended for use outside of the `fluid-framework` repo, and will be removed from
|
|
29
|
-
* package exports in the near future.
|
|
30
|
-
*
|
|
31
|
-
* Please migrate usages by either creating your own mock {@link @fluidframework/core-interfaces#ITelemetryBaseLogger}
|
|
32
|
-
* implementation, or by copying this code as-is into your own repo.
|
|
33
|
-
*
|
|
34
|
-
* @privateRemarks TODO: When we are ready, this type should be made `internal`, and the deprecation notice should be removed.
|
|
35
|
-
*
|
|
36
|
-
* @deprecated
|
|
37
|
-
*
|
|
38
|
-
* This class is not intended for use outside of the `fluid-framework` repo, and will be removed from
|
|
39
|
-
* package exports in the near future.
|
|
40
|
-
*
|
|
41
|
-
* Please migrate usages by either creating your own mock {@link @fluidframework/core-interfaces#ITelemetryBaseLogger}
|
|
42
|
-
* implementation, or by copying this code as-is into your own repo.
|
|
43
|
-
*
|
|
44
|
-
* @privateRemarks TODO: When we are ready, this type should be made `internal`, and the deprecation notice should be removed.
|
|
45
|
-
*
|
|
46
|
-
* @legacy
|
|
47
|
-
* @alpha
|
|
26
|
+
* @internal
|
|
48
27
|
*/
|
|
49
28
|
export class MockLogger implements ITelemetryBaseLogger {
|
|
50
29
|
/**
|
|
@@ -327,6 +306,23 @@ ${JSON.stringify(actualEvents)}`);
|
|
|
327
306
|
}
|
|
328
307
|
return matchObjects(actual, expected);
|
|
329
308
|
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Throws if any errors were logged
|
|
312
|
+
*/
|
|
313
|
+
public assertNoErrors(message?: string, clearEventsAfterCheck: boolean = true): void {
|
|
314
|
+
const actualEvents = this.events;
|
|
315
|
+
const errors = actualEvents.filter((event) => event.category === "error");
|
|
316
|
+
if (clearEventsAfterCheck) {
|
|
317
|
+
this.clear();
|
|
318
|
+
}
|
|
319
|
+
if (errors.length > 0) {
|
|
320
|
+
throw new Error(`${message ?? "Errors found in logs"}
|
|
321
|
+
|
|
322
|
+
error logs:
|
|
323
|
+
${JSON.stringify(errors)}`);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
330
326
|
}
|
|
331
327
|
|
|
332
328
|
function matchObjects(
|
|
@@ -386,28 +382,3 @@ export function createMockLoggerExt(minLogLevel?: LogLevel): IMockLoggerExt {
|
|
|
386
382
|
});
|
|
387
383
|
return childLogger as IMockLoggerExt;
|
|
388
384
|
}
|
|
389
|
-
|
|
390
|
-
/**
|
|
391
|
-
* Temporary extension to add new functionality during breaking change freeze,
|
|
392
|
-
* since MockLogger wasn't able to be made internal yet.
|
|
393
|
-
*
|
|
394
|
-
* @internal
|
|
395
|
-
*/
|
|
396
|
-
export class MockLogger2 extends MockLogger {
|
|
397
|
-
/**
|
|
398
|
-
* Throws if any errors were logged
|
|
399
|
-
*/
|
|
400
|
-
public assertNoErrors(message?: string, clearEventsAfterCheck: boolean = true): void {
|
|
401
|
-
const actualEvents = this.events;
|
|
402
|
-
const errors = actualEvents.filter((event) => event.category === "error");
|
|
403
|
-
if (clearEventsAfterCheck) {
|
|
404
|
-
this.clear();
|
|
405
|
-
}
|
|
406
|
-
if (errors.length > 0) {
|
|
407
|
-
throw new Error(`${message ?? "Errors found in logs"}
|
|
408
|
-
|
|
409
|
-
error logs:
|
|
410
|
-
${JSON.stringify(errors)}`);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
}
|