@fluidframework/telemetry-utils 1.4.0-121020 → 2.0.0-dev-rc.1.0.0.225277

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.
Files changed (156) hide show
  1. package/.eslintrc.js +12 -13
  2. package/.mocharc.js +12 -0
  3. package/CHANGELOG.md +249 -0
  4. package/README.md +68 -1
  5. package/api-extractor-esm.json +5 -0
  6. package/api-extractor-lint.json +4 -0
  7. package/api-extractor.json +2 -2
  8. package/api-report/telemetry-utils.api.md +444 -0
  9. package/dist/config.d.ts +47 -16
  10. package/dist/config.d.ts.map +1 -1
  11. package/dist/config.js +88 -38
  12. package/dist/config.js.map +1 -1
  13. package/dist/error.d.ts +112 -0
  14. package/dist/error.d.ts.map +1 -0
  15. package/dist/error.js +159 -0
  16. package/dist/error.js.map +1 -0
  17. package/dist/errorLogging.d.ts +86 -20
  18. package/dist/errorLogging.d.ts.map +1 -1
  19. package/dist/errorLogging.js +190 -60
  20. package/dist/errorLogging.js.map +1 -1
  21. package/dist/eventEmitterWithErrorHandling.d.ts +9 -3
  22. package/dist/eventEmitterWithErrorHandling.d.ts.map +1 -1
  23. package/dist/eventEmitterWithErrorHandling.js +16 -3
  24. package/dist/eventEmitterWithErrorHandling.js.map +1 -1
  25. package/dist/events.d.ts +27 -3
  26. package/dist/events.d.ts.map +1 -1
  27. package/dist/events.js +26 -2
  28. package/dist/events.js.map +1 -1
  29. package/dist/fluidErrorBase.d.ts +57 -16
  30. package/dist/fluidErrorBase.d.ts.map +1 -1
  31. package/dist/fluidErrorBase.js +27 -14
  32. package/dist/fluidErrorBase.js.map +1 -1
  33. package/dist/index.d.ts +12 -11
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +55 -21
  36. package/dist/index.js.map +1 -1
  37. package/dist/logger.d.ts +269 -53
  38. package/dist/logger.d.ts.map +1 -1
  39. package/dist/logger.js +423 -132
  40. package/dist/logger.js.map +1 -1
  41. package/dist/mockLogger.d.ts +39 -12
  42. package/dist/mockLogger.d.ts.map +1 -1
  43. package/dist/mockLogger.js +105 -22
  44. package/dist/mockLogger.js.map +1 -1
  45. package/dist/sampledTelemetryHelper.d.ts +18 -12
  46. package/dist/sampledTelemetryHelper.d.ts.map +1 -1
  47. package/dist/sampledTelemetryHelper.js +28 -19
  48. package/dist/sampledTelemetryHelper.js.map +1 -1
  49. package/dist/telemetry-utils-alpha.d.ts +290 -0
  50. package/dist/telemetry-utils-beta.d.ts +264 -0
  51. package/dist/telemetry-utils-public.d.ts +264 -0
  52. package/dist/telemetry-utils-untrimmed.d.ts +1102 -0
  53. package/dist/telemetryTypes.d.ts +115 -0
  54. package/dist/telemetryTypes.d.ts.map +1 -0
  55. package/dist/telemetryTypes.js +7 -0
  56. package/dist/telemetryTypes.js.map +1 -0
  57. package/dist/thresholdCounter.d.ts +6 -5
  58. package/dist/thresholdCounter.d.ts.map +1 -1
  59. package/dist/thresholdCounter.js +4 -3
  60. package/dist/thresholdCounter.js.map +1 -1
  61. package/dist/tsdoc-metadata.json +11 -0
  62. package/dist/utils.d.ts +54 -3
  63. package/dist/utils.d.ts.map +1 -1
  64. package/dist/utils.js +58 -3
  65. package/dist/utils.js.map +1 -1
  66. package/lib/config.d.ts +47 -16
  67. package/lib/config.d.ts.map +1 -1
  68. package/lib/config.js +85 -36
  69. package/lib/config.js.map +1 -1
  70. package/lib/error.d.ts +112 -0
  71. package/lib/error.d.ts.map +1 -0
  72. package/lib/error.js +150 -0
  73. package/lib/error.js.map +1 -0
  74. package/lib/errorLogging.d.ts +86 -20
  75. package/lib/errorLogging.d.ts.map +1 -1
  76. package/lib/errorLogging.js +189 -60
  77. package/lib/errorLogging.js.map +1 -1
  78. package/lib/eventEmitterWithErrorHandling.d.ts +9 -3
  79. package/lib/eventEmitterWithErrorHandling.d.ts.map +1 -1
  80. package/lib/eventEmitterWithErrorHandling.js +15 -2
  81. package/lib/eventEmitterWithErrorHandling.js.map +1 -1
  82. package/lib/events.d.ts +27 -3
  83. package/lib/events.d.ts.map +1 -1
  84. package/lib/events.js +26 -2
  85. package/lib/events.js.map +1 -1
  86. package/lib/fluidErrorBase.d.ts +57 -16
  87. package/lib/fluidErrorBase.d.ts.map +1 -1
  88. package/lib/fluidErrorBase.js +27 -14
  89. package/lib/fluidErrorBase.js.map +1 -1
  90. package/lib/index.d.ts +12 -11
  91. package/lib/index.d.ts.map +1 -1
  92. package/lib/index.js +11 -11
  93. package/lib/index.js.map +1 -1
  94. package/lib/logger.d.ts +269 -53
  95. package/lib/logger.d.ts.map +1 -1
  96. package/lib/logger.js +415 -131
  97. package/lib/logger.js.map +1 -1
  98. package/lib/mockLogger.d.ts +39 -12
  99. package/lib/mockLogger.d.ts.map +1 -1
  100. package/lib/mockLogger.js +106 -23
  101. package/lib/mockLogger.js.map +1 -1
  102. package/lib/sampledTelemetryHelper.d.ts +18 -12
  103. package/lib/sampledTelemetryHelper.d.ts.map +1 -1
  104. package/lib/sampledTelemetryHelper.js +26 -17
  105. package/lib/sampledTelemetryHelper.js.map +1 -1
  106. package/lib/telemetry-utils-alpha.d.mts +290 -0
  107. package/lib/telemetry-utils-beta.d.mts +264 -0
  108. package/lib/telemetry-utils-public.d.mts +264 -0
  109. package/lib/telemetry-utils-untrimmed.d.mts +1102 -0
  110. package/lib/telemetryTypes.d.ts +115 -0
  111. package/lib/telemetryTypes.d.ts.map +1 -0
  112. package/lib/telemetryTypes.js +6 -0
  113. package/lib/telemetryTypes.js.map +1 -0
  114. package/lib/thresholdCounter.d.ts +6 -5
  115. package/lib/thresholdCounter.d.ts.map +1 -1
  116. package/lib/thresholdCounter.js +4 -3
  117. package/lib/thresholdCounter.js.map +1 -1
  118. package/lib/utils.d.ts +54 -3
  119. package/lib/utils.d.ts.map +1 -1
  120. package/lib/utils.js +56 -2
  121. package/lib/utils.js.map +1 -1
  122. package/package.json +86 -57
  123. package/prettier.config.cjs +8 -0
  124. package/src/config.ts +254 -189
  125. package/src/error.ts +235 -0
  126. package/src/errorLogging.ts +440 -290
  127. package/src/eventEmitterWithErrorHandling.ts +26 -14
  128. package/src/events.ts +54 -25
  129. package/src/fluidErrorBase.ts +94 -46
  130. package/src/index.ts +76 -17
  131. package/src/logger.ts +972 -505
  132. package/src/mockLogger.ts +225 -83
  133. package/src/sampledTelemetryHelper.ts +136 -128
  134. package/src/telemetryTypes.ts +140 -0
  135. package/src/thresholdCounter.ts +38 -37
  136. package/src/utils.ts +108 -17
  137. package/tsconfig.esnext.json +6 -6
  138. package/tsconfig.json +9 -13
  139. package/dist/debugLogger.d.ts +0 -39
  140. package/dist/debugLogger.d.ts.map +0 -1
  141. package/dist/debugLogger.js +0 -101
  142. package/dist/debugLogger.js.map +0 -1
  143. package/dist/packageVersion.d.ts +0 -9
  144. package/dist/packageVersion.d.ts.map +0 -1
  145. package/dist/packageVersion.js +0 -12
  146. package/dist/packageVersion.js.map +0 -1
  147. package/lib/debugLogger.d.ts +0 -39
  148. package/lib/debugLogger.d.ts.map +0 -1
  149. package/lib/debugLogger.js +0 -97
  150. package/lib/debugLogger.js.map +0 -1
  151. package/lib/packageVersion.d.ts +0 -9
  152. package/lib/packageVersion.d.ts.map +0 -1
  153. package/lib/packageVersion.js +0 -9
  154. package/lib/packageVersion.js.map +0 -1
  155. package/src/debugLogger.ts +0 -126
  156. package/src/packageVersion.ts +0 -9
@@ -0,0 +1,115 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { ITelemetryBaseLogger, LogLevel, Tagged } from "@fluidframework/core-interfaces";
6
+ /**
7
+ * The categories FF uses when instrumenting the code.
8
+ *
9
+ * generic - Informational log event
10
+ *
11
+ * error - Error log event, ideally 0 of these are logged during a session
12
+ *
13
+ * performance - Includes duration, and often has _start, _end, or _cancel suffixes for activity tracking
14
+ * @public
15
+ */
16
+ export type TelemetryEventCategory = "generic" | "error" | "performance";
17
+ /**
18
+ * Property types that can be logged.
19
+ *
20
+ * @remarks
21
+ * Includes extra types beyond {@link @fluidframework/core-interfaces#TelemetryBaseEventPropertyType}, which must be
22
+ * converted before sending to a base logger.
23
+ * @public
24
+ */
25
+ export type TelemetryEventPropertyTypeExt = string | number | boolean | undefined | (string | number | boolean)[] | {
26
+ [key: string]: // Flat objects can have the same properties as the event itself
27
+ string | number | boolean | undefined | (string | number | boolean)[];
28
+ };
29
+ /**
30
+ * A property to be logged to telemetry containing both the value and a tag. Tags are generic strings that can be used
31
+ * to mark pieces of information that should be organized or handled differently by loggers in various first or third
32
+ * party scenarios. For example, tags are used to mark personal information that should not be stored in logs.
33
+ *
34
+ * @deprecated Use {@link @fluidframework/core-interfaces#Tagged}\<{@link TelemetryEventPropertyTypeExt}\>
35
+ * @internal
36
+ */
37
+ export interface ITaggedTelemetryPropertyTypeExt {
38
+ value: TelemetryEventPropertyTypeExt;
39
+ tag: string;
40
+ }
41
+ /**
42
+ * JSON-serializable properties, which will be logged with telemetry.
43
+ * @public
44
+ */
45
+ export interface ITelemetryPropertiesExt {
46
+ [index: string]: TelemetryEventPropertyTypeExt | Tagged<TelemetryEventPropertyTypeExt>;
47
+ }
48
+ /**
49
+ * Interface for logging telemetry statements.
50
+ * @remarks May contain any number of properties that get serialized as json payload.
51
+ * @param category - category of the event, like "error", "performance", "generic", etc.
52
+ * @param eventName - name of the event.
53
+ *
54
+ * @internal
55
+ */
56
+ export interface ITelemetryEventExt extends ITelemetryPropertiesExt {
57
+ category: string;
58
+ eventName: string;
59
+ }
60
+ /**
61
+ * Informational (non-error) telemetry event
62
+ * @remarks Maps to category = "generic"
63
+ * @public
64
+ */
65
+ export interface ITelemetryGenericEventExt extends ITelemetryPropertiesExt {
66
+ eventName: string;
67
+ category?: TelemetryEventCategory;
68
+ }
69
+ /**
70
+ * Error telemetry event.
71
+ * @remarks Maps to category = "error"
72
+ * @public
73
+ */
74
+ export interface ITelemetryErrorEventExt extends ITelemetryPropertiesExt {
75
+ eventName: string;
76
+ }
77
+ /**
78
+ * Performance telemetry event.
79
+ * @remarks Maps to category = "performance"
80
+ * @public
81
+ */
82
+ export interface ITelemetryPerformanceEventExt extends ITelemetryGenericEventExt {
83
+ duration?: number;
84
+ }
85
+ /**
86
+ * An extended {@link @fluidframework/core-interfaces#ITelemetryBaseLogger} which allows for more lenient event types.
87
+ *
88
+ * @remarks
89
+ * This interface is meant to be used internally within the Fluid Framework,
90
+ * and `ITelemetryBaseLogger` should be used when loggers are passed between layers.
91
+ * @public
92
+ */
93
+ export interface ITelemetryLoggerExt extends ITelemetryBaseLogger {
94
+ /**
95
+ * Send information telemetry event
96
+ * @param event - Event to send
97
+ * @param error - optional error object to log
98
+ * @param logLevel - optional level of the log.
99
+ */
100
+ sendTelemetryEvent(event: ITelemetryGenericEventExt, error?: unknown, logLevel?: typeof LogLevel.verbose | typeof LogLevel.default): void;
101
+ /**
102
+ * Send error telemetry event
103
+ * @param event - Event to send
104
+ * @param error - optional error object to log
105
+ */
106
+ sendErrorEvent(event: ITelemetryErrorEventExt, error?: unknown): void;
107
+ /**
108
+ * Send performance telemetry event
109
+ * @param event - Event to send
110
+ * @param error - optional error object to log
111
+ * @param logLevel - optional level of the log.
112
+ */
113
+ sendPerformanceEvent(event: ITelemetryPerformanceEventExt, error?: unknown, logLevel?: typeof LogLevel.verbose | typeof LogLevel.default): void;
114
+ }
115
+ //# sourceMappingURL=telemetryTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetryTypes.d.ts","sourceRoot":"","sources":["../src/telemetryTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AAEzF;;;;;;;;;GASG;AACH,MAAM,MAAM,sBAAsB,GAAG,SAAS,GAAG,OAAO,GAAG,aAAa,CAAC;AAEzE;;;;;;;GAOG;AACH,MAAM,MAAM,6BAA6B,GACtC,MAAM,GACN,MAAM,GACN,OAAO,GACP,SAAS,GACT,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,EAAE,GAC7B;IACA,CAAC,GAAG,EAAE,MAAM,GACZ,AADe,gEAAgE;IAC/E,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC;CACrE,CAAC;AAEL;;;;;;;GAOG;AACH,MAAM,WAAW,+BAA+B;IAC/C,KAAK,EAAE,6BAA6B,CAAC;IACrC,GAAG,EAAE,MAAM,CAAC;CACZ;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACvC,CAAC,KAAK,EAAE,MAAM,GAAG,6BAA6B,GAAG,MAAM,CAAC,6BAA6B,CAAC,CAAC;CACvF;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAmB,SAAQ,uBAAuB;IAClE,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,MAAM,WAAW,yBAA0B,SAAQ,uBAAuB;IACzE,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,sBAAsB,CAAC;CAClC;AAED;;;;GAIG;AACH,MAAM,WAAW,uBAAwB,SAAQ,uBAAuB;IACvE,SAAS,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,MAAM,WAAW,6BAA8B,SAAQ,yBAAyB;IAC/E,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,mBAAoB,SAAQ,oBAAoB;IAChE;;;;;OAKG;IACH,kBAAkB,CACjB,KAAK,EAAE,yBAAyB,EAChC,KAAK,CAAC,EAAE,OAAO,EACf,QAAQ,CAAC,EAAE,OAAO,QAAQ,CAAC,OAAO,GAAG,OAAO,QAAQ,CAAC,OAAO,GAC1D,IAAI,CAAC;IAER;;;;OAIG;IACH,cAAc,CAAC,KAAK,EAAE,uBAAuB,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAEtE;;;;;OAKG;IACH,oBAAoB,CACnB,KAAK,EAAE,6BAA6B,EACpC,KAAK,CAAC,EAAE,OAAO,EACf,QAAQ,CAAC,EAAE,OAAO,QAAQ,CAAC,OAAO,GAAG,OAAO,QAAQ,CAAC,OAAO,GAC1D,IAAI,CAAC;CACR"}
@@ -0,0 +1,6 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=telemetryTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetryTypes.js","sourceRoot":"","sources":["../src/telemetryTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryBaseLogger, LogLevel, Tagged } from \"@fluidframework/core-interfaces\";\n\n/**\n * The categories FF uses when instrumenting the code.\n *\n * generic - Informational log event\n *\n * error - Error log event, ideally 0 of these are logged during a session\n *\n * performance - Includes duration, and often has _start, _end, or _cancel suffixes for activity tracking\n * @public\n */\nexport type TelemetryEventCategory = \"generic\" | \"error\" | \"performance\";\n\n/**\n * Property types that can be logged.\n *\n * @remarks\n * Includes extra types beyond {@link @fluidframework/core-interfaces#TelemetryBaseEventPropertyType}, which must be\n * converted before sending to a base logger.\n * @public\n */\nexport type TelemetryEventPropertyTypeExt =\n\t| string\n\t| number\n\t| boolean\n\t| undefined\n\t| (string | number | boolean)[]\n\t| {\n\t\t\t[key: string]: // Flat objects can have the same properties as the event itself\n\t\t\tstring | number | boolean | undefined | (string | number | boolean)[];\n\t };\n\n/**\n * A property to be logged to telemetry containing both the value and a tag. Tags are generic strings that can be used\n * to mark pieces of information that should be organized or handled differently by loggers in various first or third\n * party scenarios. For example, tags are used to mark personal information that should not be stored in logs.\n *\n * @deprecated Use {@link @fluidframework/core-interfaces#Tagged}\\<{@link TelemetryEventPropertyTypeExt}\\>\n * @internal\n */\nexport interface ITaggedTelemetryPropertyTypeExt {\n\tvalue: TelemetryEventPropertyTypeExt;\n\ttag: string;\n}\n\n/**\n * JSON-serializable properties, which will be logged with telemetry.\n * @public\n */\nexport interface ITelemetryPropertiesExt {\n\t[index: string]: TelemetryEventPropertyTypeExt | Tagged<TelemetryEventPropertyTypeExt>;\n}\n\n/**\n * Interface for logging telemetry statements.\n * @remarks May contain any number of properties that get serialized as json payload.\n * @param category - category of the event, like \"error\", \"performance\", \"generic\", etc.\n * @param eventName - name of the event.\n *\n * @internal\n */\nexport interface ITelemetryEventExt extends ITelemetryPropertiesExt {\n\tcategory: string;\n\teventName: string;\n}\n\n/**\n * Informational (non-error) telemetry event\n * @remarks Maps to category = \"generic\"\n * @public\n */\nexport interface ITelemetryGenericEventExt extends ITelemetryPropertiesExt {\n\teventName: string;\n\tcategory?: TelemetryEventCategory;\n}\n\n/**\n * Error telemetry event.\n * @remarks Maps to category = \"error\"\n * @public\n */\nexport interface ITelemetryErrorEventExt extends ITelemetryPropertiesExt {\n\teventName: string;\n}\n\n/**\n * Performance telemetry event.\n * @remarks Maps to category = \"performance\"\n * @public\n */\nexport interface ITelemetryPerformanceEventExt extends ITelemetryGenericEventExt {\n\tduration?: number; // Duration of event (optional)\n}\n\n/**\n * An extended {@link @fluidframework/core-interfaces#ITelemetryBaseLogger} which allows for more lenient event types.\n *\n * @remarks\n * This interface is meant to be used internally within the Fluid Framework,\n * and `ITelemetryBaseLogger` should be used when loggers are passed between layers.\n * @public\n */\nexport interface ITelemetryLoggerExt extends ITelemetryBaseLogger {\n\t/**\n\t * Send information telemetry event\n\t * @param event - Event to send\n\t * @param error - optional error object to log\n\t * @param logLevel - optional level of the log.\n\t */\n\tsendTelemetryEvent(\n\t\tevent: ITelemetryGenericEventExt,\n\t\terror?: unknown,\n\t\tlogLevel?: typeof LogLevel.verbose | typeof LogLevel.default,\n\t): void;\n\n\t/**\n\t * Send error telemetry event\n\t * @param event - Event to send\n\t * @param error - optional error object to log\n\t */\n\tsendErrorEvent(event: ITelemetryErrorEventExt, error?: unknown): void;\n\n\t/**\n\t * Send performance telemetry event\n\t * @param event - Event to send\n\t * @param error - optional error object to log\n\t * @param logLevel - optional level of the log.\n\t */\n\tsendPerformanceEvent(\n\t\tevent: ITelemetryPerformanceEventExt,\n\t\terror?: unknown,\n\t\tlogLevel?: typeof LogLevel.verbose | typeof LogLevel.default,\n\t): void;\n}\n"]}
@@ -2,22 +2,23 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { ITelemetryLogger } from "@fluidframework/common-definitions";
5
+ import { ITelemetryLoggerExt } from "./telemetryTypes";
6
6
  /**
7
- * Utility counter which will send event only if the provided value
8
- * is above a configured threshold
7
+ * Utility counter which will send event only if the provided value is above a configured threshold.
8
+ *
9
+ * @internal
9
10
  */
10
11
  export declare class ThresholdCounter {
11
12
  private readonly threshold;
12
13
  private readonly logger;
13
14
  private thresholdMultiple;
14
- constructor(threshold: number, logger: ITelemetryLogger, thresholdMultiple?: number);
15
+ constructor(threshold: number, logger: ITelemetryLoggerExt, thresholdMultiple?: number);
15
16
  /**
16
17
  * Sends the value if it's above the treshold.
17
18
  */
18
19
  send(eventName: string, value: number): void;
19
20
  /**
20
- * Sends the value if it's above the treshold
21
+ * Sends the value if it's above the threshold
21
22
  * and a multiple of the threshold.
22
23
  *
23
24
  * To be used in scenarios where we'd like to record a
@@ -1 +1 @@
1
- {"version":3,"file":"thresholdCounter.d.ts","sourceRoot":"","sources":["../src/thresholdCounter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAEtE;;;GAGG;AACH,qBAAa,gBAAgB;IAErB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,iBAAiB;gBAFR,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,gBAAgB,EACjC,iBAAiB,SAAY;IAGzC;;OAEG;IACI,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAU5C;;;;;;OAMG;IACI,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;CAUzD"}
1
+ {"version":3,"file":"thresholdCounter.d.ts","sourceRoot":"","sources":["../src/thresholdCounter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD;;;;GAIG;AACH,qBAAa,gBAAgB;IAE3B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,iBAAiB;gBAFR,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,mBAAmB,EACpC,iBAAiB,SAAY;IAGtC;;OAEG;IACI,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAUnD;;;;;;OAMG;IACI,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;CAU7D"}
@@ -3,8 +3,9 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  /**
6
- * Utility counter which will send event only if the provided value
7
- * is above a configured threshold
6
+ * Utility counter which will send event only if the provided value is above a configured threshold.
7
+ *
8
+ * @internal
8
9
  */
9
10
  export class ThresholdCounter {
10
11
  constructor(threshold, logger, thresholdMultiple = threshold) {
@@ -25,7 +26,7 @@ export class ThresholdCounter {
25
26
  });
26
27
  }
27
28
  /**
28
- * Sends the value if it's above the treshold
29
+ * Sends the value if it's above the threshold
29
30
  * and a multiple of the threshold.
30
31
  *
31
32
  * To be used in scenarios where we'd like to record a
@@ -1 +1 @@
1
- {"version":3,"file":"thresholdCounter.js","sourceRoot":"","sources":["../src/thresholdCounter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;GAGG;AACH,MAAM,OAAO,gBAAgB;IACzB,YACqB,SAAiB,EACjB,MAAwB,EACjC,oBAAoB,SAAS;QAFpB,cAAS,GAAT,SAAS,CAAQ;QACjB,WAAM,GAAN,MAAM,CAAkB;QACjC,sBAAiB,GAAjB,iBAAiB,CAAY;IACtC,CAAC;IAEJ;;OAEG;IACI,IAAI,CAAC,SAAiB,EAAE,KAAa;QACxC,IAAI,KAAK,GAAG,IAAI,CAAC,SAAS,EAAE;YACxB,OAAO;SACV;QACD,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC;YAC7B,SAAS;YACT,KAAK;SACR,CAAC,CAAC;IACP,CAAC;IAED;;;;;;OAMG;IACI,cAAc,CAAC,SAAiB,EAAE,KAAa;QAClD,IAAI,KAAK,KAAK,IAAI,CAAC,iBAAiB,EAAE;YAClC,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC;gBAC7B,SAAS;gBACT,KAAK;aACR,CAAC,CAAC;YACH,sCAAsC;YACtC,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,iBAAiB,GAAG,CAAC,CAAC;SACvD;IACL,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\n\n/**\n * Utility counter which will send event only if the provided value\n * is above a configured threshold\n */\nexport class ThresholdCounter {\n public constructor(\n private readonly threshold: number,\n private readonly logger: ITelemetryLogger,\n private thresholdMultiple = threshold,\n ) {}\n\n /**\n * Sends the value if it's above the treshold.\n */\n public send(eventName: string, value: number) {\n if (value < this.threshold) {\n return;\n }\n this.logger.sendPerformanceEvent({\n eventName,\n value,\n });\n }\n\n /**\n * Sends the value if it's above the treshold\n * and a multiple of the threshold.\n *\n * To be used in scenarios where we'd like to record a\n * threshold violation while reducing telemetry noise.\n */\n public sendIfMultiple(eventName: string, value: number) {\n if (value === this.thresholdMultiple) {\n this.logger.sendPerformanceEvent({\n eventName,\n value,\n });\n // reduce number of \"multiple\" events.\n this.thresholdMultiple = this.thresholdMultiple * 2;\n }\n }\n}\n"]}
1
+ {"version":3,"file":"thresholdCounter.js","sourceRoot":"","sources":["../src/thresholdCounter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;;GAIG;AACH,MAAM,OAAO,gBAAgB;IAC5B,YACkB,SAAiB,EACjB,MAA2B,EACpC,oBAAoB,SAAS;QAFpB,cAAS,GAAT,SAAS,CAAQ;QACjB,WAAM,GAAN,MAAM,CAAqB;QACpC,sBAAiB,GAAjB,iBAAiB,CAAY;IACnC,CAAC;IAEJ;;OAEG;IACI,IAAI,CAAC,SAAiB,EAAE,KAAa;QAC3C,IAAI,KAAK,GAAG,IAAI,CAAC,SAAS,EAAE;YAC3B,OAAO;SACP;QACD,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC;YAChC,SAAS;YACT,KAAK;SACL,CAAC,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACI,cAAc,CAAC,SAAiB,EAAE,KAAa;QACrD,IAAI,KAAK,KAAK,IAAI,CAAC,iBAAiB,EAAE;YACrC,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC;gBAChC,SAAS;gBACT,KAAK;aACL,CAAC,CAAC;YACH,sCAAsC;YACtC,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,iBAAiB,GAAG,CAAC,CAAC;SACpD;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLoggerExt } from \"./telemetryTypes\";\n\n/**\n * Utility counter which will send event only if the provided value is above a configured threshold.\n *\n * @internal\n */\nexport class ThresholdCounter {\n\tpublic constructor(\n\t\tprivate readonly threshold: number,\n\t\tprivate readonly logger: ITelemetryLoggerExt,\n\t\tprivate thresholdMultiple = threshold,\n\t) {}\n\n\t/**\n\t * Sends the value if it's above the treshold.\n\t */\n\tpublic send(eventName: string, value: number): void {\n\t\tif (value < this.threshold) {\n\t\t\treturn;\n\t\t}\n\t\tthis.logger.sendPerformanceEvent({\n\t\t\teventName,\n\t\t\tvalue,\n\t\t});\n\t}\n\n\t/**\n\t * Sends the value if it's above the threshold\n\t * and a multiple of the threshold.\n\t *\n\t * To be used in scenarios where we'd like to record a\n\t * threshold violation while reducing telemetry noise.\n\t */\n\tpublic sendIfMultiple(eventName: string, value: number): void {\n\t\tif (value === this.thresholdMultiple) {\n\t\t\tthis.logger.sendPerformanceEvent({\n\t\t\t\teventName,\n\t\t\t\tvalue,\n\t\t\t});\n\t\t\t// reduce number of \"multiple\" events.\n\t\t\tthis.thresholdMultiple = this.thresholdMultiple * 2;\n\t\t}\n\t}\n}\n"]}
package/lib/utils.d.ts CHANGED
@@ -2,13 +2,64 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { ITelemetryBaseLogger, ITelemetryGenericEvent } from "@fluidframework/common-definitions";
5
+ import { ITelemetryBaseLogger, ITelemetryGenericEvent } from "@fluidframework/core-interfaces";
6
+ import { ITelemetryLoggerExt } from "./telemetryTypes";
6
7
  /**
7
8
  * Like assert, but logs only if the condition is false, rather than throwing
8
9
  * @param condition - The condition to attest too
9
10
  * @param logger - The logger to log with
10
11
  * @param event - The string or event to log
11
- * @returns - The outcome of the condition
12
+ * @returns The outcome of the condition
13
+ *
14
+ * @internal
15
+ *
16
+ * @deprecated
17
+ * This API will be removed in a future release.
18
+ * No replacement API is intended, but reproducing its behavior should be trivial for anyone who needs it.
12
19
  */
13
- export declare function logIfFalse(condition: any, logger: ITelemetryBaseLogger, event: string | ITelemetryGenericEvent): condition is true;
20
+ export declare function logIfFalse(condition: unknown, logger: ITelemetryBaseLogger, event: string | ITelemetryGenericEvent): condition is true;
21
+ /**
22
+ * An object that contains a callback used in conjunction with the {@link createSampledLogger} utility function to provide custom logic for sampling events.
23
+ *
24
+ * @internal
25
+ */
26
+ export interface IEventSampler {
27
+ /**
28
+ * @returns true if the event should be sampled or false if not
29
+ */
30
+ sample: () => boolean | undefined;
31
+ }
32
+ /**
33
+ * A telemetry logger that has sampling capabilities
34
+ *
35
+ * @internal
36
+ */
37
+ export interface ISampledTelemetryLogger extends ITelemetryLoggerExt {
38
+ /**
39
+ * Indicates if the feature flag to disable sampling is set.
40
+ *
41
+ * @remarks Exposed to enable some advanced scenarios where the code using the sampled logger
42
+ * could take advantage of skipping the execution of some logic when it can determine
43
+ * it won't be necessary because the telemetry event that needs it wouldn't be
44
+ * emitted anyway.
45
+ */
46
+ isSamplingDisabled: boolean;
47
+ }
48
+ /**
49
+ * Wraps around an existing logger matching the {@link ITelemetryLoggerExt} interface and provides the ability to only log a subset of events using a sampling strategy provided by an ${@link IEventSampler}.
50
+ * You can chose to not provide an event sampler which is effectively a no-op, meaning that it will be treated as if the sampler always returns true.
51
+ *
52
+ * @remarks
53
+ * The sampling functionality uses the Fluid telemetry logging configuration along with the optionally provided event sampling callback to determine whether an event should
54
+ * be logged or not.
55
+ *
56
+ * Configuration object parameters:
57
+ * 'Fluid.Telemetry.DisableSampling': if this config value is set to true, all events will be unsampled and therefore logged.
58
+ * Otherwise only a sample will be logged according to the provided event sampler callback.
59
+ *
60
+ * Note that the same sampler is used for all APIs of the returned logger. If you want separate events flowing through the returned logger to be sampled separately, the {@link IEventSampler} you provide should track them separately.
61
+ *
62
+ * @internal
63
+ */
64
+ export declare function createSampledLogger(logger: ITelemetryLoggerExt, eventSampler?: IEventSampler): ISampledTelemetryLogger;
14
65
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAEH,oBAAoB,EACpB,sBAAsB,EACzB,MAAM,oCAAoC,CAAC;AAE5C;;;;;;GAMG;AACH,wBAAgB,UAAU,CACtB,SAAS,EAAE,GAAG,EACd,MAAM,EAAE,oBAAoB,EAC5B,KAAK,EAAE,MAAM,GAAG,sBAAsB,GACvC,SAAS,IAAI,IAAI,CAUnB"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAEN,oBAAoB,EACpB,sBAAsB,EACtB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAA6B,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAElF;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CACzB,SAAS,EAAE,OAAO,EAClB,MAAM,EAAE,oBAAoB,EAC5B,KAAK,EAAE,MAAM,GAAG,sBAAsB,GACpC,SAAS,IAAI,IAAI,CAUnB;AAED;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC7B;;OAEG;IACH,MAAM,EAAE,MAAM,OAAO,GAAG,SAAS,CAAC;CAClC;AAED;;;;GAIG;AACH,MAAM,WAAW,uBAAwB,SAAQ,mBAAmB;IACnE;;;;;;;OAOG;IACH,kBAAkB,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mBAAmB,CAClC,MAAM,EAAE,mBAAmB,EAC3B,YAAY,CAAC,EAAE,aAAa,GAC1B,uBAAuB,CAiCzB"}
package/lib/utils.js CHANGED
@@ -1,9 +1,16 @@
1
+ import { loggerToMonitoringContext } from "./config";
1
2
  /**
2
3
  * Like assert, but logs only if the condition is false, rather than throwing
3
4
  * @param condition - The condition to attest too
4
5
  * @param logger - The logger to log with
5
6
  * @param event - The string or event to log
6
- * @returns - The outcome of the condition
7
+ * @returns The outcome of the condition
8
+ *
9
+ * @internal
10
+ *
11
+ * @deprecated
12
+ * This API will be removed in a future release.
13
+ * No replacement API is intended, but reproducing its behavior should be trivial for anyone who needs it.
7
14
  */
8
15
  export function logIfFalse(condition, logger, event) {
9
16
  if (condition) {
@@ -11,8 +18,55 @@ export function logIfFalse(condition, logger, event) {
11
18
  }
12
19
  const newEvent = typeof event === "string"
13
20
  ? { eventName: event, category: "error" }
14
- : Object.assign({ category: "error" }, event);
21
+ : { category: "error", ...event };
15
22
  logger.send(newEvent);
16
23
  return false;
17
24
  }
25
+ /**
26
+ * Wraps around an existing logger matching the {@link ITelemetryLoggerExt} interface and provides the ability to only log a subset of events using a sampling strategy provided by an ${@link IEventSampler}.
27
+ * You can chose to not provide an event sampler which is effectively a no-op, meaning that it will be treated as if the sampler always returns true.
28
+ *
29
+ * @remarks
30
+ * The sampling functionality uses the Fluid telemetry logging configuration along with the optionally provided event sampling callback to determine whether an event should
31
+ * be logged or not.
32
+ *
33
+ * Configuration object parameters:
34
+ * 'Fluid.Telemetry.DisableSampling': if this config value is set to true, all events will be unsampled and therefore logged.
35
+ * Otherwise only a sample will be logged according to the provided event sampler callback.
36
+ *
37
+ * Note that the same sampler is used for all APIs of the returned logger. If you want separate events flowing through the returned logger to be sampled separately, the {@link IEventSampler} you provide should track them separately.
38
+ *
39
+ * @internal
40
+ */
41
+ export function createSampledLogger(logger, eventSampler) {
42
+ const monitoringContext = loggerToMonitoringContext(logger);
43
+ const isSamplingDisabled = monitoringContext.config.getBoolean("Fluid.Telemetry.DisableSampling") ?? false;
44
+ const sampledLogger = {
45
+ send: (event) => {
46
+ // The sampler uses the following logic for sending events:
47
+ // 1. If isSamplingDisabled is true, then this means events should be unsampled. Therefore we send the event without any checks.
48
+ // 2. If isSamplingDisabled is false, then event should be sampled using the event sampler, if the sampler is not defined just send all events, other use the eventSampler.sample() method.
49
+ if (isSamplingDisabled || eventSampler === undefined || eventSampler.sample()) {
50
+ logger.send(event);
51
+ }
52
+ },
53
+ sendTelemetryEvent: (event) => {
54
+ if (isSamplingDisabled || eventSampler === undefined || eventSampler.sample()) {
55
+ logger.sendTelemetryEvent(event);
56
+ }
57
+ },
58
+ sendErrorEvent: (event) => {
59
+ if (isSamplingDisabled || eventSampler === undefined || eventSampler.sample()) {
60
+ logger.sendErrorEvent(event);
61
+ }
62
+ },
63
+ sendPerformanceEvent: (event) => {
64
+ if (isSamplingDisabled || eventSampler === undefined || eventSampler.sample()) {
65
+ logger.sendPerformanceEvent(event);
66
+ }
67
+ },
68
+ isSamplingDisabled,
69
+ };
70
+ return sampledLogger;
71
+ }
18
72
  //# sourceMappingURL=utils.js.map
package/lib/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAUA;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CACtB,SAAc,EACd,MAA4B,EAC5B,KAAsC;IAEtC,IAAI,SAAS,EAAE;QACX,OAAO,IAAI,CAAC;KACf;IACD,MAAM,QAAQ,GACV,OAAO,KAAK,KAAK,QAAQ;QACzB,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE;QACzC,CAAC,iBAAG,QAAQ,EAAE,OAAO,IAAK,KAAK,CAAE,CAAC;IACtC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACtB,OAAO,KAAK,CAAC;AACjB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport {\n ITelemetryBaseEvent,\n ITelemetryBaseLogger,\n ITelemetryGenericEvent,\n} from \"@fluidframework/common-definitions\";\n\n/**\n * Like assert, but logs only if the condition is false, rather than throwing\n * @param condition - The condition to attest too\n * @param logger - The logger to log with\n * @param event - The string or event to log\n * @returns - The outcome of the condition\n */\nexport function logIfFalse(\n condition: any,\n logger: ITelemetryBaseLogger,\n event: string | ITelemetryGenericEvent,\n): condition is true {\n if (condition) {\n return true;\n }\n const newEvent: ITelemetryBaseEvent =\n typeof event === \"string\"\n ? { eventName: event, category: \"error\" }\n : { category: \"error\", ...event };\n logger.send(newEvent);\n return false;\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAGrD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,UAAU,CACzB,SAAkB,EAClB,MAA4B,EAC5B,KAAsC;IAEtC,IAAI,SAAS,EAAE;QACd,OAAO,IAAI,CAAC;KACZ;IACD,MAAM,QAAQ,GACb,OAAO,KAAK,KAAK,QAAQ;QACxB,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE;QACzC,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,KAAK,EAAE,CAAC;IACpC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACtB,OAAO,KAAK,CAAC;AACd,CAAC;AA+BD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,mBAAmB,CAClC,MAA2B,EAC3B,YAA4B;IAE5B,MAAM,iBAAiB,GAAG,yBAAyB,CAAC,MAAM,CAAC,CAAC;IAC5D,MAAM,kBAAkB,GACvB,iBAAiB,CAAC,MAAM,CAAC,UAAU,CAAC,iCAAiC,CAAC,IAAI,KAAK,CAAC;IAEjF,MAAM,aAAa,GAAG;QACrB,IAAI,EAAE,CAAC,KAA0B,EAAQ,EAAE;YAC1C,2DAA2D;YAC3D,gIAAgI;YAChI,2LAA2L;YAC3L,IAAI,kBAAkB,IAAI,YAAY,KAAK,SAAS,IAAI,YAAY,CAAC,MAAM,EAAE,EAAE;gBAC9E,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aACnB;QACF,CAAC;QACD,kBAAkB,EAAE,CAAC,KAAgC,EAAQ,EAAE;YAC9D,IAAI,kBAAkB,IAAI,YAAY,KAAK,SAAS,IAAI,YAAY,CAAC,MAAM,EAAE,EAAE;gBAC9E,MAAM,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;aACjC;QACF,CAAC;QACD,cAAc,EAAE,CAAC,KAAgC,EAAQ,EAAE;YAC1D,IAAI,kBAAkB,IAAI,YAAY,KAAK,SAAS,IAAI,YAAY,CAAC,MAAM,EAAE,EAAE;gBAC9E,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;aAC7B;QACF,CAAC;QACD,oBAAoB,EAAE,CAAC,KAAgC,EAAQ,EAAE;YAChE,IAAI,kBAAkB,IAAI,YAAY,KAAK,SAAS,IAAI,YAAY,CAAC,MAAM,EAAE,EAAE;gBAC9E,MAAM,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC;aACnC;QACF,CAAC;QACD,kBAAkB;KAClB,CAAC;IAEF,OAAO,aAAa,CAAC;AACtB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport {\n\tITelemetryBaseEvent,\n\tITelemetryBaseLogger,\n\tITelemetryGenericEvent,\n} from \"@fluidframework/core-interfaces\";\nimport { loggerToMonitoringContext } from \"./config\";\nimport { ITelemetryGenericEventExt, ITelemetryLoggerExt } from \"./telemetryTypes\";\n\n/**\n * Like assert, but logs only if the condition is false, rather than throwing\n * @param condition - The condition to attest too\n * @param logger - The logger to log with\n * @param event - The string or event to log\n * @returns The outcome of the condition\n *\n * @internal\n *\n * @deprecated\n * This API will be removed in a future release.\n * No replacement API is intended, but reproducing its behavior should be trivial for anyone who needs it.\n */\nexport function logIfFalse(\n\tcondition: unknown,\n\tlogger: ITelemetryBaseLogger,\n\tevent: string | ITelemetryGenericEvent,\n): condition is true {\n\tif (condition) {\n\t\treturn true;\n\t}\n\tconst newEvent: ITelemetryBaseEvent =\n\t\ttypeof event === \"string\"\n\t\t\t? { eventName: event, category: \"error\" }\n\t\t\t: { category: \"error\", ...event };\n\tlogger.send(newEvent);\n\treturn false;\n}\n\n/**\n * An object that contains a callback used in conjunction with the {@link createSampledLogger} utility function to provide custom logic for sampling events.\n *\n * @internal\n */\nexport interface IEventSampler {\n\t/**\n\t * @returns true if the event should be sampled or false if not\n\t */\n\tsample: () => boolean | undefined;\n}\n\n/**\n * A telemetry logger that has sampling capabilities\n *\n * @internal\n */\nexport interface ISampledTelemetryLogger extends ITelemetryLoggerExt {\n\t/**\n\t * Indicates if the feature flag to disable sampling is set.\n\t *\n\t * @remarks Exposed to enable some advanced scenarios where the code using the sampled logger\n\t * could take advantage of skipping the execution of some logic when it can determine\n\t * it won't be necessary because the telemetry event that needs it wouldn't be\n\t * emitted anyway.\n\t */\n\tisSamplingDisabled: boolean;\n}\n\n/**\n * Wraps around an existing logger matching the {@link ITelemetryLoggerExt} interface and provides the ability to only log a subset of events using a sampling strategy provided by an ${@link IEventSampler}.\n * You can chose to not provide an event sampler which is effectively a no-op, meaning that it will be treated as if the sampler always returns true.\n *\n * @remarks\n * The sampling functionality uses the Fluid telemetry logging configuration along with the optionally provided event sampling callback to determine whether an event should\n * be logged or not.\n *\n * Configuration object parameters:\n * 'Fluid.Telemetry.DisableSampling': if this config value is set to true, all events will be unsampled and therefore logged.\n * Otherwise only a sample will be logged according to the provided event sampler callback.\n *\n * Note that the same sampler is used for all APIs of the returned logger. If you want separate events flowing through the returned logger to be sampled separately, the {@link IEventSampler} you provide should track them separately.\n *\n * @internal\n */\nexport function createSampledLogger(\n\tlogger: ITelemetryLoggerExt,\n\teventSampler?: IEventSampler,\n): ISampledTelemetryLogger {\n\tconst monitoringContext = loggerToMonitoringContext(logger);\n\tconst isSamplingDisabled =\n\t\tmonitoringContext.config.getBoolean(\"Fluid.Telemetry.DisableSampling\") ?? false;\n\n\tconst sampledLogger = {\n\t\tsend: (event: ITelemetryBaseEvent): void => {\n\t\t\t// The sampler uses the following logic for sending events:\n\t\t\t// 1. If isSamplingDisabled is true, then this means events should be unsampled. Therefore we send the event without any checks.\n\t\t\t// 2. If isSamplingDisabled is false, then event should be sampled using the event sampler, if the sampler is not defined just send all events, other use the eventSampler.sample() method.\n\t\t\tif (isSamplingDisabled || eventSampler === undefined || eventSampler.sample()) {\n\t\t\t\tlogger.send(event);\n\t\t\t}\n\t\t},\n\t\tsendTelemetryEvent: (event: ITelemetryGenericEventExt): void => {\n\t\t\tif (isSamplingDisabled || eventSampler === undefined || eventSampler.sample()) {\n\t\t\t\tlogger.sendTelemetryEvent(event);\n\t\t\t}\n\t\t},\n\t\tsendErrorEvent: (event: ITelemetryGenericEventExt): void => {\n\t\t\tif (isSamplingDisabled || eventSampler === undefined || eventSampler.sample()) {\n\t\t\t\tlogger.sendErrorEvent(event);\n\t\t\t}\n\t\t},\n\t\tsendPerformanceEvent: (event: ITelemetryGenericEventExt): void => {\n\t\t\tif (isSamplingDisabled || eventSampler === undefined || eventSampler.sample()) {\n\t\t\t\tlogger.sendPerformanceEvent(event);\n\t\t\t}\n\t\t},\n\t\tisSamplingDisabled,\n\t};\n\n\treturn sampledLogger;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/telemetry-utils",
3
- "version": "1.4.0-121020",
3
+ "version": "2.0.0-dev-rc.1.0.0.225277",
4
4
  "description": "Collection of telemetry relates utilities for Fluid",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -18,43 +18,17 @@
18
18
  "./lib/indexNode.js": "./lib/indexBrowser.js"
19
19
  },
20
20
  "types": "dist/index.d.ts",
21
- "scripts": {
22
- "build": "npm run build:genver && concurrently npm:build:compile npm:lint && npm run build:docs",
23
- "build:commonjs": "npm run tsc && npm run typetests:gen && npm run build:test",
24
- "build:compile": "concurrently npm:build:commonjs npm:build:esnext",
25
- "build:docs": "api-extractor run --local --typescript-compiler-folder ../../../node_modules/typescript && copyfiles -u 1 ./_api-extractor-temp/doc-models/* ../../../_api-extractor-temp/",
26
- "build:esnext": "tsc --project ./tsconfig.esnext.json",
27
- "build:full": "npm run build",
28
- "build:full:compile": "npm run build:compile",
29
- "build:genver": "gen-version",
30
- "build:test": "tsc --project ./src/test/tsconfig.json",
31
- "bump-version": "npm version minor --no-push --no-git-tag-version && npm run build:genver",
32
- "ci:build:docs": "api-extractor run --typescript-compiler-folder ../../../node_modules/typescript && copyfiles -u 1 ./_api-extractor-temp/* ../../../_api-extractor-temp/",
33
- "clean": "rimraf dist lib *.tsbuildinfo *.build.log",
34
- "eslint": "eslint --format stylish src",
35
- "eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
36
- "lint": "npm run eslint",
37
- "lint:fix": "npm run eslint:fix",
38
- "test": "npm run test:mocha",
39
- "test:coverage": "nyc npm run test:report",
40
- "test:mocha": "mocha --ignore 'dist/test/types/*' --recursive dist/test -r node_modules/@fluidframework/mocha-test-setup --unhandled-rejections=strict",
41
- "test:mocha:verbose": "cross-env FLUID_TEST_VERBOSE=1 npm run test:mocha",
42
- "test:report": "npm test -- -- --reporter xunit --reporter-option output=nyc/mocha-junit-report.xml",
43
- "tsc": "tsc",
44
- "typetests:gen": "flub generate typetests --generate --dir . --no-generateInName",
45
- "typetests:prepare": "flub generate typetests --prepare --dir . --pin"
46
- },
47
- "nyc": {
21
+ "c8": {
48
22
  "all": true,
49
23
  "cache-dir": "nyc/.cache",
50
24
  "exclude": [
51
- "src/test/**/*.ts",
52
- "dist/test/**/*.js"
25
+ "src/test/**/*.*ts",
26
+ "dist/test/**/*.*js"
53
27
  ],
54
28
  "exclude-after-remap": false,
55
29
  "include": [
56
- "src/**/*.ts",
57
- "dist/**/*.js"
30
+ "src/**/*.*ts",
31
+ "dist/**/*.*js"
58
32
  ],
59
33
  "report-dir": "nyc/report",
60
34
  "reporter": [
@@ -65,38 +39,93 @@
65
39
  "temp-directory": "nyc/.nyc_output"
66
40
  },
67
41
  "dependencies": {
68
- "@fluidframework/common-definitions": "^0.20.1",
69
- "@fluidframework/common-utils": "^0.32.1",
70
- "debug": "^4.1.1",
42
+ "@fluid-internal/client-utils": "2.0.0-dev-rc.1.0.0.225277",
43
+ "@fluidframework/core-interfaces": "2.0.0-dev-rc.1.0.0.225277",
44
+ "@fluidframework/core-utils": "2.0.0-dev-rc.1.0.0.225277",
45
+ "@fluidframework/protocol-definitions": "^3.1.0-223007",
46
+ "debug": "^4.3.4",
71
47
  "events": "^3.1.0",
72
- "uuid": "^8.3.1"
48
+ "uuid": "^9.0.0"
73
49
  },
74
50
  "devDependencies": {
75
- "@fluidframework/build-common": "^0.24.0",
76
- "@fluidframework/build-tools": "^0.6.0-110101",
77
- "@fluidframework/eslint-config-fluid": "^0.28.2000",
78
- "@fluidframework/mocha-test-setup": "1.4.0-121020",
79
- "@fluidframework/telemetry-utils-previous": "npm:@fluidframework/telemetry-utils@1.3.1",
80
- "@microsoft/api-extractor": "^7.22.2",
81
- "@rushstack/eslint-config": "^2.5.1",
51
+ "@arethetypeswrong/cli": "^0.13.3",
52
+ "@fluid-tools/build-cli": "0.29.0-222379",
53
+ "@fluidframework/build-common": "^2.0.3",
54
+ "@fluidframework/build-tools": "0.29.0-222379",
55
+ "@fluidframework/eslint-config-fluid": "^3.1.0",
56
+ "@fluidframework/mocha-test-setup": "2.0.0-dev-rc.1.0.0.225277",
57
+ "@fluidframework/telemetry-utils-previous": "npm:@fluidframework/telemetry-utils@2.0.0-internal.8.0.0",
58
+ "@microsoft/api-extractor": "^7.38.3",
82
59
  "@types/debug": "^4.1.5",
83
60
  "@types/events": "^3.0.0",
84
61
  "@types/mocha": "^9.1.1",
85
- "@types/node": "^14.18.0",
86
- "concurrently": "^6.2.0",
87
- "copyfiles": "^2.1.0",
88
- "cross-env": "^7.0.2",
89
- "eslint": "~8.6.0",
90
- "mocha": "^10.0.0",
91
- "nyc": "^15.0.0",
92
- "rimraf": "^2.6.2",
62
+ "@types/node": "^18.19.0",
63
+ "@types/uuid": "^9.0.2",
64
+ "c8": "^8.0.1",
65
+ "copyfiles": "^2.4.1",
66
+ "cross-env": "^7.0.3",
67
+ "eslint": "~8.50.0",
68
+ "mocha": "^10.2.0",
69
+ "mocha-json-output-reporter": "^2.0.1",
70
+ "mocha-multi-reporters": "^1.5.1",
71
+ "moment": "^2.21.0",
72
+ "prettier": "~3.0.3",
73
+ "rimraf": "^4.4.0",
93
74
  "sinon": "^7.4.2",
94
- "typescript": "~4.5.5"
75
+ "typescript": "~5.1.6"
76
+ },
77
+ "fluidBuild": {
78
+ "tasks": {
79
+ "build:docs": {
80
+ "dependsOn": [
81
+ "...",
82
+ "api-extractor:commonjs",
83
+ "api-extractor:esnext"
84
+ ],
85
+ "script": false
86
+ }
87
+ }
95
88
  },
96
89
  "typeValidation": {
97
- "version": "1.4.0",
98
- "baselineRange": "~1.3.0",
99
- "baselineVersion": "1.3.1",
100
- "broken": {}
90
+ "broken": {
91
+ "RemovedInterfaceDeclaration_IConfigProviderBase": {
92
+ "forwardCompat": false,
93
+ "backCompat": false
94
+ },
95
+ "RemovedTypeAliasDeclaration_ConfigTypes": {
96
+ "backCompat": false,
97
+ "forwardCompat": false
98
+ }
99
+ }
100
+ },
101
+ "scripts": {
102
+ "api": "fluid-build . --task api",
103
+ "api-extractor:commonjs": "api-extractor run --local",
104
+ "api-extractor:esnext": "api-extractor run --config ./api-extractor-esm.json",
105
+ "build": "fluid-build . --task build",
106
+ "build:commonjs": "fluid-build . --task commonjs",
107
+ "build:compile": "fluid-build . --task compile",
108
+ "build:docs": "fluid-build . --task api",
109
+ "build:esnext": "tsc --project ./tsconfig.esnext.json",
110
+ "build:test": "tsc --project ./src/test/tsconfig.json",
111
+ "bump-version": "npm version minor --no-push --no-git-tag-version && npm run build:genver",
112
+ "check:are-the-types-wrong": "attw --pack",
113
+ "check:release-tags": "api-extractor run --local --config ./api-extractor-lint.json",
114
+ "ci:build:docs": "api-extractor run",
115
+ "clean": "rimraf --glob dist lib \"**/*.tsbuildinfo\" \"**/*.build.log\" _api-extractor-temp nyc",
116
+ "eslint": "eslint --format stylish src",
117
+ "eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
118
+ "format": "npm run prettier:fix",
119
+ "lint": "npm run prettier && npm run check:release-tags && npm run eslint",
120
+ "lint:fix": "npm run prettier:fix && npm run eslint:fix",
121
+ "prettier": "prettier --check . --cache --ignore-path ../../../.prettierignore",
122
+ "prettier:fix": "prettier --write . --cache --ignore-path ../../../.prettierignore",
123
+ "test": "npm run test:mocha",
124
+ "test:coverage": "c8 npm test",
125
+ "test:mocha": "mocha --ignore \"dist/test/types/*\" --recursive dist/test -r node_modules/@fluidframework/mocha-test-setup",
126
+ "test:mocha:verbose": "cross-env FLUID_TEST_VERBOSE=1 npm run test:mocha",
127
+ "tsc": "tsc",
128
+ "typetests:gen": "fluid-type-test-generator",
129
+ "typetests:prepare": "flub typetests --dir . --reset --previous --normalize"
101
130
  }
102
- }
131
+ }
@@ -0,0 +1,8 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ module.exports = {
7
+ ...require("@fluidframework/build-common/prettier.config.cjs"),
8
+ };