@fluidframework/telemetry-utils 2.0.0-dev-rc.1.0.0.228517 → 2.0.0-dev-rc.2.0.0.245554

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 (150) hide show
  1. package/{.mocharc.js → .mocharc.cjs} +1 -1
  2. package/CHANGELOG.md +23 -0
  3. package/README.md +1 -1
  4. package/{api-extractor-esm.json → api-extractor-cjs.json} +5 -2
  5. package/api-extractor-lint.json +1 -1
  6. package/api-extractor.json +1 -1
  7. package/api-report/telemetry-utils.api.md +14 -33
  8. package/dist/config.d.ts +14 -2
  9. package/dist/config.d.ts.map +1 -1
  10. package/dist/config.js +19 -4
  11. package/dist/config.js.map +1 -1
  12. package/dist/error.d.ts +2 -2
  13. package/dist/error.d.ts.map +1 -1
  14. package/dist/error.js +9 -9
  15. package/dist/error.js.map +1 -1
  16. package/dist/errorLogging.d.ts +4 -4
  17. package/dist/errorLogging.d.ts.map +1 -1
  18. package/dist/errorLogging.js +19 -60
  19. package/dist/errorLogging.js.map +1 -1
  20. package/dist/eventEmitterWithErrorHandling.d.ts +1 -1
  21. package/dist/eventEmitterWithErrorHandling.js +1 -1
  22. package/dist/eventEmitterWithErrorHandling.js.map +1 -1
  23. package/dist/events.d.ts +2 -3
  24. package/dist/events.d.ts.map +1 -1
  25. package/dist/events.js.map +1 -1
  26. package/dist/fluidErrorBase.d.ts +4 -3
  27. package/dist/fluidErrorBase.d.ts.map +1 -1
  28. package/dist/fluidErrorBase.js.map +1 -1
  29. package/dist/index.d.ts +12 -12
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +58 -59
  32. package/dist/index.js.map +1 -1
  33. package/dist/logger.d.ts +7 -23
  34. package/dist/logger.d.ts.map +1 -1
  35. package/dist/logger.js +12 -29
  36. package/dist/logger.js.map +1 -1
  37. package/dist/mockLogger.d.ts +1 -1
  38. package/dist/mockLogger.d.ts.map +1 -1
  39. package/dist/mockLogger.js +2 -2
  40. package/dist/mockLogger.js.map +1 -1
  41. package/dist/package.json +3 -0
  42. package/dist/sampledTelemetryHelper.d.ts +4 -4
  43. package/dist/sampledTelemetryHelper.d.ts.map +1 -1
  44. package/dist/sampledTelemetryHelper.js +1 -1
  45. package/dist/sampledTelemetryHelper.js.map +1 -1
  46. package/dist/telemetry-utils-alpha.d.ts +7 -15
  47. package/dist/telemetry-utils-beta.d.ts +7 -32
  48. package/dist/telemetry-utils-public.d.ts +7 -32
  49. package/dist/telemetry-utils-untrimmed.d.ts +25 -50
  50. package/dist/thresholdCounter.d.ts +1 -1
  51. package/dist/thresholdCounter.d.ts.map +1 -1
  52. package/dist/thresholdCounter.js.map +1 -1
  53. package/dist/tsdoc-metadata.json +1 -1
  54. package/dist/utils.d.ts +1 -20
  55. package/dist/utils.d.ts.map +1 -1
  56. package/dist/utils.js +3 -27
  57. package/dist/utils.js.map +1 -1
  58. package/lib/config.d.ts +14 -2
  59. package/lib/config.d.ts.map +1 -1
  60. package/lib/config.js +15 -1
  61. package/lib/config.js.map +1 -1
  62. package/lib/error.d.ts +2 -2
  63. package/lib/error.d.ts.map +1 -1
  64. package/lib/error.js +1 -1
  65. package/lib/error.js.map +1 -1
  66. package/lib/errorLogging.d.ts +4 -4
  67. package/lib/errorLogging.d.ts.map +1 -1
  68. package/lib/errorLogging.js +15 -56
  69. package/lib/errorLogging.js.map +1 -1
  70. package/lib/eventEmitterWithErrorHandling.d.ts +1 -1
  71. package/lib/eventEmitterWithErrorHandling.js +1 -1
  72. package/lib/eventEmitterWithErrorHandling.js.map +1 -1
  73. package/lib/events.d.ts +2 -3
  74. package/lib/events.d.ts.map +1 -1
  75. package/lib/events.js.map +1 -1
  76. package/lib/fluidErrorBase.d.ts +4 -3
  77. package/lib/fluidErrorBase.d.ts.map +1 -1
  78. package/lib/fluidErrorBase.js.map +1 -1
  79. package/lib/index.d.ts +12 -12
  80. package/lib/index.d.ts.map +1 -1
  81. package/lib/index.js +11 -11
  82. package/lib/index.js.map +1 -1
  83. package/lib/logger.d.ts +7 -23
  84. package/lib/logger.d.ts.map +1 -1
  85. package/lib/logger.js +3 -19
  86. package/lib/logger.js.map +1 -1
  87. package/lib/mockLogger.d.ts +1 -1
  88. package/lib/mockLogger.d.ts.map +1 -1
  89. package/lib/mockLogger.js +1 -1
  90. package/lib/mockLogger.js.map +1 -1
  91. package/lib/sampledTelemetryHelper.d.ts +4 -4
  92. package/lib/sampledTelemetryHelper.d.ts.map +1 -1
  93. package/lib/sampledTelemetryHelper.js +1 -1
  94. package/lib/sampledTelemetryHelper.js.map +1 -1
  95. package/lib/{telemetry-utils-alpha.d.mts → telemetry-utils-alpha.d.ts} +7 -15
  96. package/lib/{telemetry-utils-beta.d.mts → telemetry-utils-beta.d.ts} +7 -32
  97. package/lib/{telemetry-utils-public.d.mts → telemetry-utils-public.d.ts} +7 -32
  98. package/lib/{telemetry-utils-untrimmed.d.mts → telemetry-utils-untrimmed.d.ts} +25 -50
  99. package/lib/test/EventEmitterWithErrorHandling.spec.js +86 -0
  100. package/lib/test/EventEmitterWithErrorHandling.spec.js.map +1 -0
  101. package/lib/test/childLogger.spec.js +233 -0
  102. package/lib/test/childLogger.spec.js.map +1 -0
  103. package/lib/test/config.spec.js +229 -0
  104. package/lib/test/config.spec.js.map +1 -0
  105. package/lib/test/error.spec.js +161 -0
  106. package/lib/test/error.spec.js.map +1 -0
  107. package/lib/test/errorLogging.spec.js +801 -0
  108. package/lib/test/errorLogging.spec.js.map +1 -0
  109. package/lib/test/errorTypeLoggingTest.spec.js +107 -0
  110. package/lib/test/errorTypeLoggingTest.spec.js.map +1 -0
  111. package/lib/test/mockLogger.spec.js +164 -0
  112. package/lib/test/mockLogger.spec.js.map +1 -0
  113. package/lib/test/multiSinkLogger.spec.js +84 -0
  114. package/lib/test/multiSinkLogger.spec.js.map +1 -0
  115. package/lib/test/performanceEvent.spec.js +86 -0
  116. package/lib/test/performanceEvent.spec.js.map +1 -0
  117. package/lib/test/sampledTelemetryHelper.spec.js +169 -0
  118. package/lib/test/sampledTelemetryHelper.spec.js.map +1 -0
  119. package/lib/test/telemetryLogger.spec.js +357 -0
  120. package/lib/test/telemetryLogger.spec.js.map +1 -0
  121. package/lib/test/thresholdCounter.spec.js +51 -0
  122. package/lib/test/thresholdCounter.spec.js.map +1 -0
  123. package/lib/test/types/validateTelemetryUtilsPrevious.generated.js +132 -0
  124. package/lib/test/types/validateTelemetryUtilsPrevious.generated.js.map +1 -0
  125. package/lib/test/utils.spec.js +284 -0
  126. package/lib/test/utils.spec.js.map +1 -0
  127. package/lib/thresholdCounter.d.ts +1 -1
  128. package/lib/thresholdCounter.d.ts.map +1 -1
  129. package/lib/thresholdCounter.js.map +1 -1
  130. package/lib/utils.d.ts +1 -20
  131. package/lib/utils.d.ts.map +1 -1
  132. package/lib/utils.js +1 -24
  133. package/lib/utils.js.map +1 -1
  134. package/package.json +75 -26
  135. package/src/config.ts +20 -2
  136. package/src/error.ts +2 -2
  137. package/src/errorLogging.ts +27 -68
  138. package/src/eventEmitterWithErrorHandling.ts +1 -1
  139. package/src/events.ts +2 -4
  140. package/src/fluidErrorBase.ts +4 -3
  141. package/src/index.ts +13 -13
  142. package/src/logger.ts +12 -28
  143. package/src/mockLogger.ts +2 -2
  144. package/src/sampledTelemetryHelper.ts +10 -11
  145. package/src/thresholdCounter.ts +1 -1
  146. package/src/utils.ts +3 -36
  147. package/tsconfig.cjs.json +7 -0
  148. package/tsconfig.json +2 -3
  149. package/tsconfig.esnext.json +0 -7
  150. /package/{.eslintrc.js → .eslintrc.cjs} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"sampledTelemetryHelper.d.ts","sourceRoot":"","sources":["../src/sampledTelemetryHelper.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,sBAAsB,EAEtB,oBAAoB,EACpB,WAAW,EACX,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAoCvD;;;;;;;;;;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,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAmC;IAEnE;;;;;;;;;;;;;;;;;OAiBG;gBAEe,SAAS,EAAE,yBAAyB,EACpC,MAAM,EAAE,mBAAmB,EAC3B,eAAe,EAAE,MAAM,EACvB,uBAAuB,GAAE,OAAe,EACxC,mBAAmB,wCAA8C;IAGnF;;;;;;;;;OASG;IACI,OAAO,CAAC,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,MAAM,GAAE,MAAW,GAAG,CAAC;IA0BjE,OAAO,CAAC,WAAW;IAoBZ,OAAO,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,GAAG,IAAI;CAG/C"}
@@ -33,7 +33,7 @@ class SampledTelemetryHelper {
33
33
  * properties which should be added to the telemetry event for that bucket. If a bucket being measured does not
34
34
  * have an entry in this map, no additional properties will be added to its telemetry events. The following keys are
35
35
  * reserved for use by this class: "duration", "count", "totalDuration", "minDuration", "maxDuration". If any of
36
- * them is specified as a key in one of the ITelemetryProperties objects in this map, that key-value pair will be
36
+ * them is specified as a key in one of the ITelemetryBaseProperties objects in this map, that key-value pair will be
37
37
  * ignored.
38
38
  */
39
39
  constructor(eventBase, logger, sampleThreshold, includeAggregateMetrics = false, perBucketProperties = new Map()) {
@@ -1 +1 @@
1
- {"version":3,"file":"sampledTelemetryHelper.js","sourceRoot":"","sources":["../src/sampledTelemetryHelper.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAQH,+DAA2D;AAqC3D;;;;;;;;;;GAUG;AACH,MAAa,sBAAsB;IAKlC;;;;;;;;;;;;;;;;;OAiBG;IACH,YACkB,SAAiC,EACjC,MAA2B,EAC3B,eAAuB,EACvB,0BAAmC,KAAK,EACxC,sBAAsB,IAAI,GAAG,EAAgC;QAJ7D,cAAS,GAAT,SAAS,CAAwB;QACjC,WAAM,GAAN,MAAM,CAAqB;QAC3B,oBAAe,GAAf,eAAe,CAAQ;QACvB,4BAAuB,GAAvB,uBAAuB,CAAiB;QACxC,wB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AC,MAAc;QACjC,MAAM,YAAY,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACtD,IAAI,YAAY,KAAK,SAAS,EAAE;YAC/B,OAAO;SACP;QAED,IAAI,YAAY,CAAC,KAAK,KAAK,CAAC,EAAE;YAC7B,MAAM,gBAAgB,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YAE9D,MAAM,cAAc,GAA+B;gBAClD,GAAG,IAAI,CAAC,SAAS;gBACjB,GAAG,gBAAgB;gBACnB,GAAG,YAAY;aACf,CAAC;YAEF,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC,cAAc,CAAC,CAAC;YACjD,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;SACpC;IACF,CAAC;IAEM,OAAO,CAAC,KAAyB;QACvC,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE;YAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IACvE,CAAC;CACD;AA1FD,wDA0FC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tITelemetryGenericEvent,\n\tITelemetryPerformanceEvent,\n\tITelemetryProperties,\n\tIDisposable,\n} from \"@fluidframework/core-interfaces\";\nimport { performance } from \"@fluid-internal/client-utils\";\nimport { ITelemetryLoggerExt } from \"./telemetryTypes\";\n\n/**\n * @privateRemarks\n *\n * The names of the properties in this interface are the ones that will get stamped in the\n * telemetry event, changes should be considered carefully. The optional properties should\n * only be populated if 'includeAggregateMetrics' is true.\n */\ninterface Measurements {\n\t/**\n\t * The duration of the latest execution.\n\t */\n\tduration: number;\n\n\t/**\n\t * The number of executions since the last time an event was generated.\n\t */\n\tcount: number;\n\n\t/**\n\t * Total duration across all the executions since the last event was generated.\n\t */\n\ttotalDuration?: number;\n\n\t/**\n\t * Min duration across all the executions since the last event was generated.\n\t */\n\tminDuration?: number;\n\n\t/**\n\t * Max duration across all the executions since the last event was generated.\n\t */\n\tmaxDuration?: number;\n}\n\n/**\n * Helper class that executes a specified code block and writes an\n * {@link @fluidframework/core-interfaces#ITelemetryPerformanceEvent} to a specified logger every time a specified\n * number of executions is reached (or when the class is disposed).\n *\n * The `duration` field in the telemetry event is the duration of the latest execution (sample) of the specified\n * function. See the documentation of the `includeAggregateMetrics` parameter for additional details that can be\n * included.\n *\n * @internal\n */\nexport class SampledTelemetryHelper implements IDisposable {\n\tdisposed: boolean = false;\n\n\tprivate readonly measurementsMap = new Map<string, Measurements>();\n\n\t/**\n\t * @param eventBase -\n\t * Custom properties to include in the telemetry performance event when it is written.\n\t * @param logger -\n\t * The logger to use to write the telemetry performance event.\n\t * @param sampleThreshold -\n\t * Telemetry performance events will be generated every time we hit this many executions of the code block.\n\t * @param includeAggregateMetrics -\n\t * If set to `true`, the telemetry performance event will include aggregated metrics (total duration, min duration,\n\t * max duration) for all the executions in between generated events.\n\t * @param perBucketProperties -\n\t * Map of strings that represent different buckets (which can be specified when calling the 'measure' method), to\n\t * properties which should be added to the telemetry event for that bucket. If a bucket being measured does not\n\t * have an entry in this map, no additional properties will be added to its telemetry events. The following keys are\n\t * reserved for use by this class: \"duration\", \"count\", \"totalDuration\", \"minDuration\", \"maxDuration\". If any of\n\t * them is specified as a key in one of the ITelemetryProperties objects in this map, that key-value pair will be\n\t * ignored.\n\t */\n\tpublic constructor(\n\t\tprivate readonly eventBase: ITelemetryGenericEvent,\n\t\tprivate readonly logger: ITelemetryLoggerExt,\n\t\tprivate readonly sampleThreshold: number,\n\t\tprivate readonly includeAggregateMetrics: boolean = false,\n\t\tprivate readonly perBucketProperties = new Map<string, ITelemetryProperties>(),\n\t) {}\n\n\t/**\n\t * Executes the specified code and keeps track of execution time statistics.\n\t * If it's been called enough times (the sampleThreshold for the class) then it generates a log message with the necessary information.\n\t *\n\t * @param codeToMeasure - The code to be executed and measured.\n\t * @param bucket - A key to track executions of the code block separately.\n\t * Each different value of this parameter has a separate set of executions and metrics tracked by the class.\n\t * If no such distinction needs to be made, do not provide a value.\n\t * @returns Whatever the passed-in code block returns.\n\t */\n\tpublic measure<T>(codeToMeasure: () => T, bucket: string = \"\"): T {\n\t\tconst start = performance.now();\n\t\tconst returnValue = codeToMeasure();\n\t\tconst duration = performance.now() - start;\n\n\t\tlet m = this.measurementsMap.get(bucket);\n\t\tif (m === undefined) {\n\t\t\tm = { count: 0, duration: -1 };\n\t\t\tthis.measurementsMap.set(bucket, m);\n\t\t}\n\t\tm.count++;\n\t\tm.duration = duration;\n\n\t\tif (this.includeAggregateMetrics) {\n\t\t\tm.totalDuration = (m.totalDuration ?? 0) + duration;\n\t\t\tm.minDuration = Math.min(m.minDuration ?? duration, duration);\n\t\t\tm.maxDuration = Math.max(m.maxDuration ?? 0, duration);\n\t\t}\n\n\t\tif (m.count >= this.sampleThreshold) {\n\t\t\tthis.flushBucket(bucket);\n\t\t}\n\n\t\treturn returnValue;\n\t}\n\n\tprivate flushBucket(bucket: string): void {\n\t\tconst measurements = this.measurementsMap.get(bucket);\n\t\tif (measurements === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (measurements.count !== 0) {\n\t\t\tconst bucketProperties = this.perBucketProperties.get(bucket);\n\n\t\t\tconst telemetryEvent: ITelemetryPerformanceEvent = {\n\t\t\t\t...this.eventBase,\n\t\t\t\t...bucketProperties, // If the bucket doesn't exist and this is undefined, things work as expected\n\t\t\t\t...measurements,\n\t\t\t};\n\n\t\t\tthis.logger.sendPerformanceEvent(telemetryEvent);\n\t\t\tthis.measurementsMap.delete(bucket);\n\t\t}\n\t}\n\n\tpublic dispose(error?: Error | undefined): void {\n\t\tfor (const [k] of this.measurementsMap.entries()) this.flushBucket(k);\n\t}\n}\n"]}
1
+ {"version":3,"file":"sampledTelemetryHelper.js","sourceRoot":"","sources":["../src/sampledTelemetryHelper.ts"],"names":[],"mappings":";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AAC,GAAG,CAAC,CAAC,CAAC,WAAW,IAAI,QAAQ,EAAE,QAAQ,CAAC,CAAC;YAC9D,CAAC,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,WAAW,IAAI,CAAC,EAAE,QAAQ,CAAC,CAAC;SACvD;QAED,IAAI,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,eAAe,EAAE;YACpC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;SACzB;QAED,OAAO,WAAW,CAAC;IACpB,CAAC;IAEO,WAAW,CAAC,MAAc;QACjC,MAAM,YAAY,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACtD,IAAI,YAAY,KAAK,SAAS,EAAE;YAC/B,OAAO;SACP;QAED,IAAI,YAAY,CAAC,KAAK,KAAK,CAAC,EAAE;YAC7B,MAAM,gBAAgB,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YAE9D,MAAM,cAAc,GAAkC;gBACrD,GAAG,IAAI,CAAC,SAAS;gBACjB,GAAG,gBAAgB;gBACnB,GAAG,YAAY;aACf,CAAC;YAEF,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC,cAAc,CAAC,CAAC;YACjD,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;SACpC;IACF,CAAC;IAEM,OAAO,CAAC,KAAyB;QACvC,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE;YAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IACvE,CAAC;CACD;AA1FD,wDA0FC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ITelemetryBaseProperties, IDisposable } from \"@fluidframework/core-interfaces\";\nimport { performance } from \"@fluid-internal/client-utils\";\nimport {\n\tITelemetryLoggerExt,\n\ttype ITelemetryGenericEventExt,\n\ttype ITelemetryPerformanceEventExt,\n} from \"./telemetryTypes.js\";\n\n/**\n * @privateRemarks\n *\n * The names of the properties in this interface are the ones that will get stamped in the\n * telemetry event, changes should be considered carefully. The optional properties should\n * only be populated if 'includeAggregateMetrics' is true.\n */\ninterface Measurements {\n\t/**\n\t * The duration of the latest execution.\n\t */\n\tduration: number;\n\n\t/**\n\t * The number of executions since the last time an event was generated.\n\t */\n\tcount: number;\n\n\t/**\n\t * Total duration across all the executions since the last event was generated.\n\t */\n\ttotalDuration?: number;\n\n\t/**\n\t * Min duration across all the executions since the last event was generated.\n\t */\n\tminDuration?: number;\n\n\t/**\n\t * Max duration across all the executions since the last event was generated.\n\t */\n\tmaxDuration?: number;\n}\n\n/**\n * Helper class that executes a specified code block and writes an\n * {@link @fluidframework/core-interfaces#ITelemetryPerformanceEvent} to a specified logger every time a specified\n * number of executions is reached (or when the class is disposed).\n *\n * The `duration` field in the telemetry event is the duration of the latest execution (sample) of the specified\n * function. See the documentation of the `includeAggregateMetrics` parameter for additional details that can be\n * included.\n *\n * @internal\n */\nexport class SampledTelemetryHelper implements IDisposable {\n\tdisposed: boolean = false;\n\n\tprivate readonly measurementsMap = new Map<string, Measurements>();\n\n\t/**\n\t * @param eventBase -\n\t * Custom properties to include in the telemetry performance event when it is written.\n\t * @param logger -\n\t * The logger to use to write the telemetry performance event.\n\t * @param sampleThreshold -\n\t * Telemetry performance events will be generated every time we hit this many executions of the code block.\n\t * @param includeAggregateMetrics -\n\t * If set to `true`, the telemetry performance event will include aggregated metrics (total duration, min duration,\n\t * max duration) for all the executions in between generated events.\n\t * @param perBucketProperties -\n\t * Map of strings that represent different buckets (which can be specified when calling the 'measure' method), to\n\t * properties which should be added to the telemetry event for that bucket. If a bucket being measured does not\n\t * have an entry in this map, no additional properties will be added to its telemetry events. The following keys are\n\t * reserved for use by this class: \"duration\", \"count\", \"totalDuration\", \"minDuration\", \"maxDuration\". If any of\n\t * them is specified as a key in one of the ITelemetryBaseProperties objects in this map, that key-value pair will be\n\t * ignored.\n\t */\n\tpublic constructor(\n\t\tprivate readonly eventBase: ITelemetryGenericEventExt,\n\t\tprivate readonly logger: ITelemetryLoggerExt,\n\t\tprivate readonly sampleThreshold: number,\n\t\tprivate readonly includeAggregateMetrics: boolean = false,\n\t\tprivate readonly perBucketProperties = new Map<string, ITelemetryBaseProperties>(),\n\t) {}\n\n\t/**\n\t * Executes the specified code and keeps track of execution time statistics.\n\t * If it's been called enough times (the sampleThreshold for the class) then it generates a log message with the necessary information.\n\t *\n\t * @param codeToMeasure - The code to be executed and measured.\n\t * @param bucket - A key to track executions of the code block separately.\n\t * Each different value of this parameter has a separate set of executions and metrics tracked by the class.\n\t * If no such distinction needs to be made, do not provide a value.\n\t * @returns Whatever the passed-in code block returns.\n\t */\n\tpublic measure<T>(codeToMeasure: () => T, bucket: string = \"\"): T {\n\t\tconst start = performance.now();\n\t\tconst returnValue = codeToMeasure();\n\t\tconst duration = performance.now() - start;\n\n\t\tlet m = this.measurementsMap.get(bucket);\n\t\tif (m === undefined) {\n\t\t\tm = { count: 0, duration: -1 };\n\t\t\tthis.measurementsMap.set(bucket, m);\n\t\t}\n\t\tm.count++;\n\t\tm.duration = duration;\n\n\t\tif (this.includeAggregateMetrics) {\n\t\t\tm.totalDuration = (m.totalDuration ?? 0) + duration;\n\t\t\tm.minDuration = Math.min(m.minDuration ?? duration, duration);\n\t\t\tm.maxDuration = Math.max(m.maxDuration ?? 0, duration);\n\t\t}\n\n\t\tif (m.count >= this.sampleThreshold) {\n\t\t\tthis.flushBucket(bucket);\n\t\t}\n\n\t\treturn returnValue;\n\t}\n\n\tprivate flushBucket(bucket: string): void {\n\t\tconst measurements = this.measurementsMap.get(bucket);\n\t\tif (measurements === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (measurements.count !== 0) {\n\t\t\tconst bucketProperties = this.perBucketProperties.get(bucket);\n\n\t\t\tconst telemetryEvent: ITelemetryPerformanceEventExt = {\n\t\t\t\t...this.eventBase,\n\t\t\t\t...bucketProperties, // If the bucket doesn't exist and this is undefined, things work as expected\n\t\t\t\t...measurements,\n\t\t\t};\n\n\t\t\tthis.logger.sendPerformanceEvent(telemetryEvent);\n\t\t\tthis.measurementsMap.delete(bucket);\n\t\t}\n\t}\n\n\tpublic dispose(error?: Error | undefined): void {\n\t\tfor (const [k] of this.measurementsMap.entries()) this.flushBucket(k);\n\t}\n}\n"]}
@@ -1,27 +1,21 @@
1
- /// <reference types="node" />
2
-
3
- import { EventEmitter } from 'events';
1
+ import { ConfigTypes } from '@fluidframework/core-interfaces';
2
+ import type { EventEmitter } from '@fluid-internal/client-utils';
4
3
  import { EventEmitterEventType } from '@fluid-internal/client-utils';
5
4
  import { IConfigProviderBase } from '@fluidframework/core-interfaces';
6
- import { IDisposable } from '@fluidframework/core-interfaces';
5
+ import type { IDisposable } from '@fluidframework/core-interfaces';
7
6
  import { IErrorBase } from '@fluidframework/core-interfaces';
8
7
  import { IEvent } from '@fluidframework/core-interfaces';
9
8
  import { IGenericError } from '@fluidframework/core-interfaces';
10
- import { ILoggingError } from '@fluidframework/core-interfaces';
9
+ import type { ILoggingError } from '@fluidframework/core-interfaces';
11
10
  import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
12
11
  import { ITelemetryBaseEvent } from '@fluidframework/core-interfaces';
13
12
  import { ITelemetryBaseLogger } from '@fluidframework/core-interfaces';
14
13
  import { ITelemetryBaseProperties } from '@fluidframework/core-interfaces';
15
- import { ITelemetryErrorEvent } from '@fluidframework/core-interfaces';
16
- import { ITelemetryGenericEvent } from '@fluidframework/core-interfaces';
17
- import { ITelemetryPerformanceEvent } from '@fluidframework/core-interfaces';
18
- import { ITelemetryProperties } from '@fluidframework/core-interfaces';
19
14
  import { IUsageError } from '@fluidframework/core-interfaces';
20
15
  import { Lazy } from '@fluidframework/core-utils';
21
16
  import { LogLevel } from '@fluidframework/core-interfaces';
22
17
  import { Tagged } from '@fluidframework/core-interfaces';
23
18
  import { TelemetryBaseEventPropertyType } from '@fluidframework/core-interfaces';
24
- import { TelemetryEventPropertyType } from '@fluidframework/core-interfaces';
25
19
  import { TypedEventEmitter } from '@fluid-internal/client-utils';
26
20
 
27
21
  /* Excluded from this release type: connectedEventName */
@@ -63,7 +57,7 @@ export declare function createChildLogger(props?: {
63
57
  * @privateRemarks
64
58
  * This probably doesn't belong in this package, as it is not telemetry-specific, and is really only intended for internal fluid-framework use.
65
59
  * We should consider moving it to the `core-utils` package.
66
- * @public
60
+ * @alpha
67
61
  */
68
62
  export declare class EventEmitterWithErrorHandling<TEvent extends IEvent = IEvent> extends TypedEventEmitter<TEvent> {
69
63
  private readonly errorHandler;
@@ -209,8 +203,6 @@ export declare interface ITelemetryPropertiesExt {
209
203
 
210
204
  /* Excluded from this release type: LoggingError */
211
205
 
212
- /* Excluded from this release type: logIfFalse */
213
-
214
206
  /* Excluded from this release type: mixinMonitoringContext */
215
207
 
216
208
  /* Excluded from this release type: MockLogger */
@@ -275,14 +267,14 @@ export declare type TelemetryEventPropertyTypeExt = string | number | boolean |
275
267
  */
276
268
  export declare type TelemetryEventPropertyTypes = ITelemetryBaseProperties[string];
277
269
 
278
- /* Excluded from this release type: TelemetryNullLogger */
279
-
280
270
  /* Excluded from this release type: ThresholdCounter */
281
271
 
282
272
  /* Excluded from this release type: UsageError */
283
273
 
284
274
  /* Excluded from this release type: validatePrecondition */
285
275
 
276
+ /* Excluded from this release type: wrapConfigProviderWithDefaults */
277
+
286
278
  /* Excluded from this release type: wrapError */
287
279
 
288
280
  /* Excluded from this release type: wrapErrorAndLog */
@@ -1,27 +1,21 @@
1
- /// <reference types="node" />
2
-
3
- import { EventEmitter } from 'events';
1
+ import { ConfigTypes } from '@fluidframework/core-interfaces';
2
+ import type { EventEmitter } from '@fluid-internal/client-utils';
4
3
  import { EventEmitterEventType } from '@fluid-internal/client-utils';
5
4
  import { IConfigProviderBase } from '@fluidframework/core-interfaces';
6
- import { IDisposable } from '@fluidframework/core-interfaces';
5
+ import type { IDisposable } from '@fluidframework/core-interfaces';
7
6
  import { IErrorBase } from '@fluidframework/core-interfaces';
8
7
  import { IEvent } from '@fluidframework/core-interfaces';
9
8
  import { IGenericError } from '@fluidframework/core-interfaces';
10
- import { ILoggingError } from '@fluidframework/core-interfaces';
9
+ import type { ILoggingError } from '@fluidframework/core-interfaces';
11
10
  import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
12
11
  import { ITelemetryBaseEvent } from '@fluidframework/core-interfaces';
13
12
  import { ITelemetryBaseLogger } from '@fluidframework/core-interfaces';
14
13
  import { ITelemetryBaseProperties } from '@fluidframework/core-interfaces';
15
- import { ITelemetryErrorEvent } from '@fluidframework/core-interfaces';
16
- import { ITelemetryGenericEvent } from '@fluidframework/core-interfaces';
17
- import { ITelemetryPerformanceEvent } from '@fluidframework/core-interfaces';
18
- import { ITelemetryProperties } from '@fluidframework/core-interfaces';
19
14
  import { IUsageError } from '@fluidframework/core-interfaces';
20
15
  import { Lazy } from '@fluidframework/core-utils';
21
16
  import { LogLevel } from '@fluidframework/core-interfaces';
22
17
  import { Tagged } from '@fluidframework/core-interfaces';
23
18
  import { TelemetryBaseEventPropertyType } from '@fluidframework/core-interfaces';
24
- import { TelemetryEventPropertyType } from '@fluidframework/core-interfaces';
25
19
  import { TypedEventEmitter } from '@fluid-internal/client-utils';
26
20
 
27
21
  /* Excluded from this release type: connectedEventName */
@@ -40,22 +34,7 @@ import { TypedEventEmitter } from '@fluid-internal/client-utils';
40
34
 
41
35
  /* Excluded from this release type: disconnectedEventName */
42
36
 
43
- /**
44
- * Event Emitter helper class
45
- *
46
- * @remarks
47
- * Any exceptions thrown by listeners will be caught and raised through "error" event.
48
- * Any exception thrown by "error" listeners will propagate to the caller.
49
- * @privateRemarks
50
- * This probably doesn't belong in this package, as it is not telemetry-specific, and is really only intended for internal fluid-framework use.
51
- * We should consider moving it to the `core-utils` package.
52
- * @public
53
- */
54
- export declare class EventEmitterWithErrorHandling<TEvent extends IEvent = IEvent> extends TypedEventEmitter<TEvent> {
55
- private readonly errorHandler;
56
- constructor(errorHandler: (eventName: EventEmitterEventType, error: any) => void);
57
- emit(event: EventEmitterEventType, ...args: unknown[]): boolean;
58
- }
37
+ /* Excluded from this release type: EventEmitterWithErrorHandling */
59
38
 
60
39
  /* Excluded from this release type: eventNamespaceSeparator */
61
40
 
@@ -184,8 +163,6 @@ export declare interface ITelemetryPropertiesExt {
184
163
 
185
164
  /* Excluded from this release type: LoggingError */
186
165
 
187
- /* Excluded from this release type: logIfFalse */
188
-
189
166
  /* Excluded from this release type: mixinMonitoringContext */
190
167
 
191
168
  /* Excluded from this release type: MockLogger */
@@ -218,8 +195,6 @@ export declare interface ITelemetryPropertiesExt {
218
195
 
219
196
  /* Excluded from this release type: TaggedLoggerAdapter */
220
197
 
221
- /* Excluded from this release type: TelemetryBaseEventPropertyType */
222
-
223
198
  /* Excluded from this release type: TelemetryDataTag */
224
199
 
225
200
  /**
@@ -249,14 +224,14 @@ export declare type TelemetryEventPropertyTypeExt = string | number | boolean |
249
224
 
250
225
  /* Excluded from this release type: TelemetryEventPropertyTypes */
251
226
 
252
- /* Excluded from this release type: TelemetryNullLogger */
253
-
254
227
  /* Excluded from this release type: ThresholdCounter */
255
228
 
256
229
  /* Excluded from this release type: UsageError */
257
230
 
258
231
  /* Excluded from this release type: validatePrecondition */
259
232
 
233
+ /* Excluded from this release type: wrapConfigProviderWithDefaults */
234
+
260
235
  /* Excluded from this release type: wrapError */
261
236
 
262
237
  /* Excluded from this release type: wrapErrorAndLog */
@@ -1,27 +1,21 @@
1
- /// <reference types="node" />
2
-
3
- import { EventEmitter } from 'events';
1
+ import { ConfigTypes } from '@fluidframework/core-interfaces';
2
+ import type { EventEmitter } from '@fluid-internal/client-utils';
4
3
  import { EventEmitterEventType } from '@fluid-internal/client-utils';
5
4
  import { IConfigProviderBase } from '@fluidframework/core-interfaces';
6
- import { IDisposable } from '@fluidframework/core-interfaces';
5
+ import type { IDisposable } from '@fluidframework/core-interfaces';
7
6
  import { IErrorBase } from '@fluidframework/core-interfaces';
8
7
  import { IEvent } from '@fluidframework/core-interfaces';
9
8
  import { IGenericError } from '@fluidframework/core-interfaces';
10
- import { ILoggingError } from '@fluidframework/core-interfaces';
9
+ import type { ILoggingError } from '@fluidframework/core-interfaces';
11
10
  import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
12
11
  import { ITelemetryBaseEvent } from '@fluidframework/core-interfaces';
13
12
  import { ITelemetryBaseLogger } from '@fluidframework/core-interfaces';
14
13
  import { ITelemetryBaseProperties } from '@fluidframework/core-interfaces';
15
- import { ITelemetryErrorEvent } from '@fluidframework/core-interfaces';
16
- import { ITelemetryGenericEvent } from '@fluidframework/core-interfaces';
17
- import { ITelemetryPerformanceEvent } from '@fluidframework/core-interfaces';
18
- import { ITelemetryProperties } from '@fluidframework/core-interfaces';
19
14
  import { IUsageError } from '@fluidframework/core-interfaces';
20
15
  import { Lazy } from '@fluidframework/core-utils';
21
16
  import { LogLevel } from '@fluidframework/core-interfaces';
22
17
  import { Tagged } from '@fluidframework/core-interfaces';
23
18
  import { TelemetryBaseEventPropertyType } from '@fluidframework/core-interfaces';
24
- import { TelemetryEventPropertyType } from '@fluidframework/core-interfaces';
25
19
  import { TypedEventEmitter } from '@fluid-internal/client-utils';
26
20
 
27
21
  /* Excluded from this release type: connectedEventName */
@@ -40,22 +34,7 @@ import { TypedEventEmitter } from '@fluid-internal/client-utils';
40
34
 
41
35
  /* Excluded from this release type: disconnectedEventName */
42
36
 
43
- /**
44
- * Event Emitter helper class
45
- *
46
- * @remarks
47
- * Any exceptions thrown by listeners will be caught and raised through "error" event.
48
- * Any exception thrown by "error" listeners will propagate to the caller.
49
- * @privateRemarks
50
- * This probably doesn't belong in this package, as it is not telemetry-specific, and is really only intended for internal fluid-framework use.
51
- * We should consider moving it to the `core-utils` package.
52
- * @public
53
- */
54
- export declare class EventEmitterWithErrorHandling<TEvent extends IEvent = IEvent> extends TypedEventEmitter<TEvent> {
55
- private readonly errorHandler;
56
- constructor(errorHandler: (eventName: EventEmitterEventType, error: any) => void);
57
- emit(event: EventEmitterEventType, ...args: unknown[]): boolean;
58
- }
37
+ /* Excluded from this release type: EventEmitterWithErrorHandling */
59
38
 
60
39
  /* Excluded from this release type: eventNamespaceSeparator */
61
40
 
@@ -184,8 +163,6 @@ export declare interface ITelemetryPropertiesExt {
184
163
 
185
164
  /* Excluded from this release type: LoggingError */
186
165
 
187
- /* Excluded from this release type: logIfFalse */
188
-
189
166
  /* Excluded from this release type: mixinMonitoringContext */
190
167
 
191
168
  /* Excluded from this release type: MockLogger */
@@ -218,8 +195,6 @@ export declare interface ITelemetryPropertiesExt {
218
195
 
219
196
  /* Excluded from this release type: TaggedLoggerAdapter */
220
197
 
221
- /* Excluded from this release type: TelemetryBaseEventPropertyType */
222
-
223
198
  /* Excluded from this release type: TelemetryDataTag */
224
199
 
225
200
  /**
@@ -249,14 +224,14 @@ export declare type TelemetryEventPropertyTypeExt = string | number | boolean |
249
224
 
250
225
  /* Excluded from this release type: TelemetryEventPropertyTypes */
251
226
 
252
- /* Excluded from this release type: TelemetryNullLogger */
253
-
254
227
  /* Excluded from this release type: ThresholdCounter */
255
228
 
256
229
  /* Excluded from this release type: UsageError */
257
230
 
258
231
  /* Excluded from this release type: validatePrecondition */
259
232
 
233
+ /* Excluded from this release type: wrapConfigProviderWithDefaults */
234
+
260
235
  /* Excluded from this release type: wrapError */
261
236
 
262
237
  /* Excluded from this release type: wrapErrorAndLog */
@@ -1,27 +1,21 @@
1
- /// <reference types="node" />
2
-
3
- import { EventEmitter } from 'events';
1
+ import { ConfigTypes } from '@fluidframework/core-interfaces';
2
+ import type { EventEmitter } from '@fluid-internal/client-utils';
4
3
  import { EventEmitterEventType } from '@fluid-internal/client-utils';
5
4
  import { IConfigProviderBase } from '@fluidframework/core-interfaces';
6
- import { IDisposable } from '@fluidframework/core-interfaces';
5
+ import type { IDisposable } from '@fluidframework/core-interfaces';
7
6
  import { IErrorBase } from '@fluidframework/core-interfaces';
8
7
  import { IEvent } from '@fluidframework/core-interfaces';
9
8
  import { IGenericError } from '@fluidframework/core-interfaces';
10
- import { ILoggingError } from '@fluidframework/core-interfaces';
9
+ import type { ILoggingError } from '@fluidframework/core-interfaces';
11
10
  import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
12
11
  import { ITelemetryBaseEvent } from '@fluidframework/core-interfaces';
13
12
  import { ITelemetryBaseLogger } from '@fluidframework/core-interfaces';
14
13
  import { ITelemetryBaseProperties } from '@fluidframework/core-interfaces';
15
- import { ITelemetryErrorEvent } from '@fluidframework/core-interfaces';
16
- import { ITelemetryGenericEvent } from '@fluidframework/core-interfaces';
17
- import { ITelemetryPerformanceEvent } from '@fluidframework/core-interfaces';
18
- import { ITelemetryProperties } from '@fluidframework/core-interfaces';
19
14
  import { IUsageError } from '@fluidframework/core-interfaces';
20
15
  import { Lazy } from '@fluidframework/core-utils';
21
16
  import { LogLevel } from '@fluidframework/core-interfaces';
22
17
  import { Tagged } from '@fluidframework/core-interfaces';
23
18
  import { TelemetryBaseEventPropertyType } from '@fluidframework/core-interfaces';
24
- import { TelemetryEventPropertyType } from '@fluidframework/core-interfaces';
25
19
  import { TypedEventEmitter } from '@fluid-internal/client-utils';
26
20
 
27
21
  /**
@@ -147,7 +141,7 @@ export declare const disconnectedEventName = "disconnected";
147
141
  * @privateRemarks
148
142
  * This probably doesn't belong in this package, as it is not telemetry-specific, and is really only intended for internal fluid-framework use.
149
143
  * We should consider moving it to the `core-utils` package.
150
- * @public
144
+ * @alpha
151
145
  */
152
146
  export declare class EventEmitterWithErrorHandling<TEvent extends IEvent = IEvent> extends TypedEventEmitter<TEvent> {
153
147
  private readonly errorHandler;
@@ -340,11 +334,11 @@ export declare interface IFluidErrorBase extends Error {
340
334
  /**
341
335
  * Get the telemetry properties stashed on this error for logging.
342
336
  */
343
- getTelemetryProperties(): ITelemetryProperties;
337
+ getTelemetryProperties(): ITelemetryBaseProperties;
344
338
  /**
345
339
  * Add telemetry properties to this error which will be logged with the error
346
340
  */
347
- addTelemetryProperties: (props: ITelemetryProperties) => void;
341
+ addTelemetryProperties: (props: ITelemetryPropertiesExt) => void;
348
342
  }
349
343
 
350
344
  /**
@@ -568,28 +562,13 @@ export declare class LoggingError extends Error implements ILoggingError, Omit<I
568
562
  /**
569
563
  * Add additional properties to be logged
570
564
  */
571
- addTelemetryProperties(props: ITelemetryBaseProperties): void;
565
+ addTelemetryProperties(props: ITelemetryPropertiesExt): void;
572
566
  /**
573
567
  * Get all properties fit to be logged to telemetry for this error
574
568
  */
575
569
  getTelemetryProperties(): ITelemetryBaseProperties;
576
570
  }
577
571
 
578
- /**
579
- * Like assert, but logs only if the condition is false, rather than throwing
580
- * @param condition - The condition to attest too
581
- * @param logger - The logger to log with
582
- * @param event - The string or event to log
583
- * @returns The outcome of the condition
584
- *
585
- * @internal
586
- *
587
- * @deprecated
588
- * This API will be removed in a future release.
589
- * No replacement API is intended, but reproducing its behavior should be trivial for anyone who needs it.
590
- */
591
- export declare function logIfFalse(condition: unknown, logger: ITelemetryBaseLogger, event: string | ITelemetryGenericEvent): condition is true;
592
-
593
572
  /**
594
573
  * Creates a {@link MonitoringContext} from the provided logger.
595
574
  *
@@ -864,10 +843,10 @@ export declare class SampledTelemetryHelper implements IDisposable {
864
843
  * properties which should be added to the telemetry event for that bucket. If a bucket being measured does not
865
844
  * have an entry in this map, no additional properties will be added to its telemetry events. The following keys are
866
845
  * reserved for use by this class: "duration", "count", "totalDuration", "minDuration", "maxDuration". If any of
867
- * them is specified as a key in one of the ITelemetryProperties objects in this map, that key-value pair will be
846
+ * them is specified as a key in one of the ITelemetryBaseProperties objects in this map, that key-value pair will be
868
847
  * ignored.
869
848
  */
870
- constructor(eventBase: ITelemetryGenericEvent, logger: ITelemetryLoggerExt, sampleThreshold: number, includeAggregateMetrics?: boolean, perBucketProperties?: Map<string, ITelemetryProperties>);
849
+ constructor(eventBase: ITelemetryGenericEventExt, logger: ITelemetryLoggerExt, sampleThreshold: number, includeAggregateMetrics?: boolean, perBucketProperties?: Map<string, ITelemetryBaseProperties>);
871
850
  /**
872
851
  * Executes the specified code and keeps track of execution time statistics.
873
852
  * If it's been called enough times (the sampleThreshold for the class) then it generates a log message with the necessary information.
@@ -915,7 +894,7 @@ export declare const sessionStorageConfigProvider: Lazy<IConfigProviderBase>;
915
894
  *
916
895
  * @internal
917
896
  */
918
- export declare const tagCodeArtifacts: <T extends Record<string, TelemetryEventPropertyType | (() => TelemetryBaseEventPropertyType)>>(values: T) => { [P in keyof T]: (T[P] extends () => TelemetryBaseEventPropertyType ? () => {
897
+ export declare const tagCodeArtifacts: <T extends Record<string, TelemetryBaseEventPropertyType | (() => TelemetryBaseEventPropertyType)>>(values: T) => { [P in keyof T]: (T[P] extends () => TelemetryBaseEventPropertyType ? () => {
919
898
  value: ReturnType<T[P]>;
920
899
  tag: TelemetryDataTag.CodeArtifact;
921
900
  } : {
@@ -945,7 +924,7 @@ export declare const tagCodeArtifacts: <T extends Record<string, TelemetryEventP
945
924
  *
946
925
  * @internal
947
926
  */
948
- export declare const tagData: <T extends TelemetryDataTag, V extends Record<string, TelemetryEventPropertyType | (() => TelemetryBaseEventPropertyType)>>(tag: T, values: V) => { [P in keyof V]: (V[P] extends () => TelemetryBaseEventPropertyType ? () => {
927
+ export declare const tagData: <T extends TelemetryDataTag, V extends Record<string, TelemetryBaseEventPropertyType | (() => TelemetryBaseEventPropertyType)>>(tag: T, values: V) => { [P in keyof V]: (V[P] extends () => TelemetryBaseEventPropertyType ? () => {
949
928
  value: ReturnType<V[P]>;
950
929
  tag: T;
951
930
  } : {
@@ -1017,23 +996,6 @@ export declare type TelemetryEventPropertyTypeExt = string | number | boolean |
1017
996
  */
1018
997
  export declare type TelemetryEventPropertyTypes = ITelemetryBaseProperties[string];
1019
998
 
1020
- /**
1021
- * Null logger that no-ops for all telemetry events passed to it.
1022
- *
1023
- * @deprecated This will be removed in a future release.
1024
- * For internal use within the FluidFramework codebase, use {@link createChildLogger} with no arguments instead.
1025
- * For external consumers we recommend writing a trivial implementation of {@link @fluidframework/core-interfaces#ITelemetryBaseLogger}
1026
- * where the send() method does nothing and using that.
1027
- *
1028
- * @internal
1029
- */
1030
- export declare class TelemetryNullLogger implements ITelemetryLoggerExt {
1031
- send(event: ITelemetryBaseEvent): void;
1032
- sendTelemetryEvent(event: ITelemetryGenericEvent, error?: unknown): void;
1033
- sendErrorEvent(event: ITelemetryErrorEvent, error?: unknown): void;
1034
- sendPerformanceEvent(event: ITelemetryPerformanceEvent, error?: unknown): void;
1035
- }
1036
-
1037
999
  /**
1038
1000
  * Utility counter which will send event only if the provided value is above a configured threshold.
1039
1001
  *
@@ -1079,6 +1041,19 @@ export declare class UsageError extends LoggingError implements IUsageError, IFl
1079
1041
  */
1080
1042
  export declare function validatePrecondition(condition: boolean, message: string, props?: ITelemetryBaseProperties): asserts condition;
1081
1043
 
1044
+ /**
1045
+ * Creates a wrapper on top of an existing config provider which allows for
1046
+ * specifying feature gates if not present in the original provider.
1047
+ *
1048
+ * @param original - the original config provider
1049
+ * @param defaults - default feature gate configs to be used if not specified by the original provider
1050
+ * @returns A config provider that looks for any requested feature gates in the original provider and falls
1051
+ * back to the values specified in the `defaults` feature gates if they're not present in the original.
1052
+ *
1053
+ * @internal
1054
+ */
1055
+ export declare const wrapConfigProviderWithDefaults: (original: IConfigProviderBase | undefined, defaults: Record<string, ConfigTypes>) => IConfigProviderBase;
1056
+
1082
1057
  /**
1083
1058
  * Create a new error using newErrorFn, wrapping and caused by the given unknown error.
1084
1059
  * Copies the inner error's stack, errorInstanceId and telemetry props over to the new error if present
@@ -2,7 +2,7 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { ITelemetryLoggerExt } from "./telemetryTypes";
5
+ import { ITelemetryLoggerExt } from "./telemetryTypes.js";
6
6
  /**
7
7
  * Utility counter which will send event only if the provided value is above a configured threshold.
8
8
  *
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"thresholdCounter.d.ts","sourceRoot":"","sources":["../src/thresholdCounter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D;;;;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"}
@@ -1 +1 @@
1
- {"version":3,"file":"thresholdCounter.js","sourceRoot":"","sources":["../src/thresholdCounter.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH;;;;GAIG;AACH,MAAa,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;AArCD,4CAqCC","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"]}
1
+ {"version":3,"file":"thresholdCounter.js","sourceRoot":"","sources":["../src/thresholdCounter.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH;;;;GAIG;AACH,MAAa,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;AArCD,4CAqCC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLoggerExt } from \"./telemetryTypes.js\";\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"]}
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.38.3"
8
+ "packageVersion": "7.42.3"
9
9
  }
10
10
  ]
11
11
  }
package/dist/utils.d.ts CHANGED
@@ -1,23 +1,4 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import { ITelemetryBaseLogger, ITelemetryGenericEvent } from "@fluidframework/core-interfaces";
6
- import { ITelemetryLoggerExt } from "./telemetryTypes";
7
- /**
8
- * Like assert, but logs only if the condition is false, rather than throwing
9
- * @param condition - The condition to attest too
10
- * @param logger - The logger to log with
11
- * @param event - The string or event to log
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.
19
- */
20
- export declare function logIfFalse(condition: unknown, logger: ITelemetryBaseLogger, event: string | ITelemetryGenericEvent): condition is true;
1
+ import { ITelemetryLoggerExt } from "./telemetryTypes.js";
21
2
  /**
22
3
  * An object that contains a callback used in conjunction with the {@link createSampledLogger} utility function to provide custom logic for sampling events.
23
4
  *
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAMA,OAAO,EAA6B,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAErF;;;;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/dist/utils.js CHANGED
@@ -1,31 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createSampledLogger = exports.logIfFalse = void 0;
4
- const config_1 = require("./config");
5
- /**
6
- * Like assert, but logs only if the condition is false, rather than throwing
7
- * @param condition - The condition to attest too
8
- * @param logger - The logger to log with
9
- * @param event - The string or event to log
10
- * @returns The outcome of the condition
11
- *
12
- * @internal
13
- *
14
- * @deprecated
15
- * This API will be removed in a future release.
16
- * No replacement API is intended, but reproducing its behavior should be trivial for anyone who needs it.
17
- */
18
- function logIfFalse(condition, logger, event) {
19
- if (condition) {
20
- return true;
21
- }
22
- const newEvent = typeof event === "string"
23
- ? { eventName: event, category: "error" }
24
- : { category: "error", ...event };
25
- logger.send(newEvent);
26
- return false;
27
- }
28
- exports.logIfFalse = logIfFalse;
3
+ exports.createSampledLogger = void 0;
4
+ const config_js_1 = require("./config.js");
29
5
  /**
30
6
  * 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}.
31
7
  * 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.
@@ -43,7 +19,7 @@ exports.logIfFalse = logIfFalse;
43
19
  * @internal
44
20
  */
45
21
  function createSampledLogger(logger, eventSampler) {
46
- const monitoringContext = (0, config_1.loggerToMonitoringContext)(logger);
22
+ const monitoringContext = (0, config_js_1.loggerToMonitoringContext)(logger);
47
23
  const isSamplingDisabled = monitoringContext.config.getBoolean("Fluid.Telemetry.DisableSampling") ?? false;
48
24
  const sampledLogger = {
49
25
  send: (event) => {
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1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AAC,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;AApCD,kDAoCC","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"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAKA,2CAAwD;AAgCxD;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,mBAAmB,CAClC,MAA2B,EAC3B,YAA4B;IAE5B,MAAM,iBAAiB,GAAG,IAAA,qCAAyB,EAAC,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;AApCD,kDAoCC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { ITelemetryBaseEvent } from \"@fluidframework/core-interfaces\";\nimport { loggerToMonitoringContext } from \"./config.js\";\nimport { ITelemetryGenericEventExt, ITelemetryLoggerExt } from \"./telemetryTypes.js\";\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"]}