@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/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.keys(props)) {
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.keys(eventWithTagsMaybe)) {
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
- // There are strange sequences involving multiple Promise chains
802
- // where the event can be cancelled and then later a callback is invoked
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
- * @deprecated
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
- }