@fluidframework/telemetry-utils 2.0.0-rc.4.0.6 → 2.0.0-rc.5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.cjs +1 -1
- package/CHANGELOG.md +27 -0
- package/api-extractor/api-extractor-lint-bundle.json +5 -0
- package/api-extractor/api-extractor-lint-legacy.cjs.json +5 -0
- package/api-extractor/api-extractor-lint-legacy.esm.json +5 -0
- package/api-extractor/api-extractor-lint-public.cjs.json +5 -0
- package/api-extractor/api-extractor-lint-public.esm.json +5 -0
- package/api-extractor.json +1 -1
- package/api-report/telemetry-utils.alpha.api.md +107 -0
- package/api-report/telemetry-utils.beta.api.md +29 -0
- package/api-report/telemetry-utils.public.api.md +29 -0
- package/biome.jsonc +4 -0
- package/dist/config.d.ts +2 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/error.d.ts +5 -5
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js.map +1 -1
- package/dist/errorLogging.d.ts +2 -6
- package/dist/errorLogging.d.ts.map +1 -1
- package/dist/errorLogging.js +22 -29
- package/dist/errorLogging.js.map +1 -1
- package/dist/eventEmitterWithErrorHandling.d.ts +2 -2
- package/dist/eventEmitterWithErrorHandling.d.ts.map +1 -1
- package/dist/eventEmitterWithErrorHandling.js.map +1 -1
- package/dist/events.js.map +1 -1
- package/dist/fluidErrorBase.d.ts +0 -6
- package/dist/fluidErrorBase.d.ts.map +1 -1
- package/dist/fluidErrorBase.js +1 -12
- package/dist/fluidErrorBase.js.map +1 -1
- package/dist/index.d.ts +8 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +3 -5
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js.map +1 -1
- package/dist/mathTools.d.ts +13 -0
- package/dist/mathTools.d.ts.map +1 -0
- package/dist/mathTools.js +20 -0
- package/dist/mathTools.js.map +1 -0
- package/dist/mockLogger.d.ts +99 -19
- package/dist/mockLogger.d.ts.map +1 -1
- package/dist/mockLogger.js +120 -33
- package/dist/mockLogger.js.map +1 -1
- package/dist/sampledTelemetryHelper.d.ts +6 -2
- package/dist/sampledTelemetryHelper.d.ts.map +1 -1
- package/dist/sampledTelemetryHelper.js +11 -3
- package/dist/sampledTelemetryHelper.js.map +1 -1
- package/dist/telemetryEventBatcher.d.ts +64 -0
- package/dist/telemetryEventBatcher.d.ts.map +1 -0
- package/dist/telemetryEventBatcher.js +86 -0
- package/dist/telemetryEventBatcher.js.map +1 -0
- package/dist/telemetryTypes.d.ts +32 -18
- package/dist/telemetryTypes.d.ts.map +1 -1
- package/dist/telemetryTypes.js.map +1 -1
- package/dist/thresholdCounter.d.ts +1 -1
- package/dist/thresholdCounter.d.ts.map +1 -1
- package/dist/thresholdCounter.js.map +1 -1
- package/dist/utils.d.ts +14 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +30 -2
- package/dist/utils.js.map +1 -1
- package/lib/config.d.ts +2 -2
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js.map +1 -1
- package/lib/error.d.ts +5 -5
- package/lib/error.d.ts.map +1 -1
- package/lib/error.js.map +1 -1
- package/lib/errorLogging.d.ts +2 -6
- package/lib/errorLogging.d.ts.map +1 -1
- package/lib/errorLogging.js +23 -30
- package/lib/errorLogging.js.map +1 -1
- package/lib/eventEmitterWithErrorHandling.d.ts +2 -2
- package/lib/eventEmitterWithErrorHandling.d.ts.map +1 -1
- package/lib/eventEmitterWithErrorHandling.js.map +1 -1
- package/lib/events.js.map +1 -1
- package/lib/fluidErrorBase.d.ts +0 -6
- package/lib/fluidErrorBase.d.ts.map +1 -1
- package/lib/fluidErrorBase.js +0 -10
- package/lib/fluidErrorBase.js.map +1 -1
- package/lib/index.d.ts +8 -7
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -3
- package/lib/index.js.map +1 -1
- package/lib/logger.d.ts +3 -5
- package/lib/logger.d.ts.map +1 -1
- package/lib/logger.js.map +1 -1
- package/lib/mathTools.d.ts +13 -0
- package/lib/mathTools.d.ts.map +1 -0
- package/lib/mathTools.js +16 -0
- package/lib/mathTools.js.map +1 -0
- package/lib/mockLogger.d.ts +99 -19
- package/lib/mockLogger.d.ts.map +1 -1
- package/lib/mockLogger.js +118 -32
- package/lib/mockLogger.js.map +1 -1
- package/lib/sampledTelemetryHelper.d.ts +6 -2
- package/lib/sampledTelemetryHelper.d.ts.map +1 -1
- package/lib/sampledTelemetryHelper.js +11 -3
- package/lib/sampledTelemetryHelper.js.map +1 -1
- package/lib/telemetryEventBatcher.d.ts +64 -0
- package/lib/telemetryEventBatcher.d.ts.map +1 -0
- package/lib/telemetryEventBatcher.js +82 -0
- package/lib/telemetryEventBatcher.js.map +1 -0
- package/lib/telemetryTypes.d.ts +32 -18
- package/lib/telemetryTypes.d.ts.map +1 -1
- package/lib/telemetryTypes.js.map +1 -1
- package/lib/thresholdCounter.d.ts +1 -1
- package/lib/thresholdCounter.d.ts.map +1 -1
- package/lib/thresholdCounter.js.map +1 -1
- package/lib/tsdoc-metadata.json +1 -1
- package/lib/utils.d.ts +14 -2
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +28 -1
- package/lib/utils.js.map +1 -1
- package/package.json +30 -16
- package/src/config.ts +16 -16
- package/src/error.ts +13 -13
- package/src/errorLogging.ts +32 -46
- package/src/eventEmitterWithErrorHandling.ts +3 -3
- package/src/fluidErrorBase.ts +0 -15
- package/src/index.ts +17 -16
- package/src/logger.ts +21 -21
- package/src/mathTools.ts +16 -0
- package/src/mockLogger.ts +165 -35
- package/src/sampledTelemetryHelper.ts +15 -5
- package/src/telemetryEventBatcher.ts +103 -0
- package/src/telemetryTypes.ts +38 -19
- package/src/thresholdCounter.ts +1 -1
- package/src/utils.ts +31 -2
- package/tsconfig.json +2 -0
- package/tsdoc.json +4 -0
- package/api-report/telemetry-utils.api.md +0 -425
package/lib/telemetryTypes.d.ts
CHANGED
|
@@ -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 { ITelemetryBaseLogger, LogLevel, Tagged } from "@fluidframework/core-interfaces";
|
|
5
|
+
import type { ITelemetryBaseLogger, LogLevel, Tagged } from "@fluidframework/core-interfaces";
|
|
6
6
|
/**
|
|
7
7
|
* The categories FF uses when instrumenting the code.
|
|
8
8
|
*
|
|
@@ -22,10 +22,7 @@ export type TelemetryEventCategory = "generic" | "error" | "performance";
|
|
|
22
22
|
* converted before sending to a base logger.
|
|
23
23
|
* @alpha
|
|
24
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
|
-
};
|
|
25
|
+
export type TelemetryEventPropertyTypeExt = string | number | boolean | undefined | (string | number | boolean)[] | Record<string, string | number | boolean | undefined | (string | number | boolean)[]>;
|
|
29
26
|
/**
|
|
30
27
|
* A property to be logged to telemetry containing both the value and a tag. Tags are generic strings that can be used
|
|
31
28
|
* to mark pieces of information that should be organized or handled differently by loggers in various first or third
|
|
@@ -42,9 +39,7 @@ export interface ITaggedTelemetryPropertyTypeExt {
|
|
|
42
39
|
* JSON-serializable properties, which will be logged with telemetry.
|
|
43
40
|
* @alpha
|
|
44
41
|
*/
|
|
45
|
-
export
|
|
46
|
-
[index: string]: TelemetryEventPropertyTypeExt | Tagged<TelemetryEventPropertyTypeExt>;
|
|
47
|
-
}
|
|
42
|
+
export type ITelemetryPropertiesExt = Record<string, TelemetryEventPropertyTypeExt | Tagged<TelemetryEventPropertyTypeExt>>;
|
|
48
43
|
/**
|
|
49
44
|
* Interface for logging telemetry statements.
|
|
50
45
|
* @remarks May contain any number of properties that get serialized as json payload.
|
|
@@ -54,7 +49,13 @@ export interface ITelemetryPropertiesExt {
|
|
|
54
49
|
* @internal
|
|
55
50
|
*/
|
|
56
51
|
export interface ITelemetryEventExt extends ITelemetryPropertiesExt {
|
|
52
|
+
/**
|
|
53
|
+
* {@inheritDoc @fluidframework/core-interfaces#ITelemetryBaseEvent.category}
|
|
54
|
+
*/
|
|
57
55
|
category: string;
|
|
56
|
+
/**
|
|
57
|
+
* {@inheritDoc @fluidframework/core-interfaces#ITelemetryBaseEvent.eventName}
|
|
58
|
+
*/
|
|
58
59
|
eventName: string;
|
|
59
60
|
}
|
|
60
61
|
/**
|
|
@@ -63,7 +64,14 @@ export interface ITelemetryEventExt extends ITelemetryPropertiesExt {
|
|
|
63
64
|
* @alpha
|
|
64
65
|
*/
|
|
65
66
|
export interface ITelemetryGenericEventExt extends ITelemetryPropertiesExt {
|
|
67
|
+
/**
|
|
68
|
+
* {@inheritDoc @fluidframework/core-interfaces#ITelemetryBaseEvent.eventName}
|
|
69
|
+
*/
|
|
66
70
|
eventName: string;
|
|
71
|
+
/**
|
|
72
|
+
* Optional event {@link @fluidframework/core-interfaces#ITelemetryBaseEvent.category}.
|
|
73
|
+
* @defaultValue "generic"
|
|
74
|
+
*/
|
|
67
75
|
category?: TelemetryEventCategory;
|
|
68
76
|
}
|
|
69
77
|
/**
|
|
@@ -72,6 +80,9 @@ export interface ITelemetryGenericEventExt extends ITelemetryPropertiesExt {
|
|
|
72
80
|
* @alpha
|
|
73
81
|
*/
|
|
74
82
|
export interface ITelemetryErrorEventExt extends ITelemetryPropertiesExt {
|
|
83
|
+
/**
|
|
84
|
+
* {@inheritDoc @fluidframework/core-interfaces#ITelemetryBaseEvent.eventName}
|
|
85
|
+
*/
|
|
75
86
|
eventName: string;
|
|
76
87
|
}
|
|
77
88
|
/**
|
|
@@ -80,6 +91,9 @@ export interface ITelemetryErrorEventExt extends ITelemetryPropertiesExt {
|
|
|
80
91
|
* @alpha
|
|
81
92
|
*/
|
|
82
93
|
export interface ITelemetryPerformanceEventExt extends ITelemetryGenericEventExt {
|
|
94
|
+
/**
|
|
95
|
+
* Duration of event (optional)
|
|
96
|
+
*/
|
|
83
97
|
duration?: number;
|
|
84
98
|
}
|
|
85
99
|
/**
|
|
@@ -92,23 +106,23 @@ export interface ITelemetryPerformanceEventExt extends ITelemetryGenericEventExt
|
|
|
92
106
|
*/
|
|
93
107
|
export interface ITelemetryLoggerExt extends ITelemetryBaseLogger {
|
|
94
108
|
/**
|
|
95
|
-
* Send information telemetry event
|
|
96
|
-
* @param event - Event to send
|
|
97
|
-
* @param error -
|
|
98
|
-
* @param logLevel -
|
|
109
|
+
* Send an information telemetry event.
|
|
110
|
+
* @param event - Event to send.
|
|
111
|
+
* @param error - Optional error object to log.
|
|
112
|
+
* @param logLevel - Optional level of the log. Default: {@link @fluidframework/core-interfaces#LogLevel.default}.
|
|
99
113
|
*/
|
|
100
114
|
sendTelemetryEvent(event: ITelemetryGenericEventExt, error?: unknown, logLevel?: typeof LogLevel.verbose | typeof LogLevel.default): void;
|
|
101
115
|
/**
|
|
102
|
-
* Send error telemetry event
|
|
103
|
-
* @param event - Event to send
|
|
104
|
-
* @param error -
|
|
116
|
+
* Send an error telemetry event.
|
|
117
|
+
* @param event - Event to send.
|
|
118
|
+
* @param error - Optional error object to log.
|
|
105
119
|
*/
|
|
106
120
|
sendErrorEvent(event: ITelemetryErrorEventExt, error?: unknown): void;
|
|
107
121
|
/**
|
|
108
|
-
* Send performance telemetry event
|
|
122
|
+
* Send a performance telemetry event.
|
|
109
123
|
* @param event - Event to send
|
|
110
|
-
* @param error -
|
|
111
|
-
* @param logLevel -
|
|
124
|
+
* @param error - Optional error object to log.
|
|
125
|
+
* @param logLevel - Optional level of the log. Default: {@link @fluidframework/core-interfaces#LogLevel.default}.
|
|
112
126
|
*/
|
|
113
127
|
sendPerformanceEvent(event: ITelemetryPerformanceEventExt, error?: unknown, logLevel?: typeof LogLevel.verbose | typeof LogLevel.default): void;
|
|
114
128
|
}
|
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"file":"telemetryTypes.d.ts","sourceRoot":"","sources":["../src/telemetryTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AAE9F;;;;;;;;;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,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC,CAAC;AAEzF;;;;;;;GAOG;AACH,MAAM,WAAW,+BAA+B;IAC/C,KAAK,EAAE,6BAA6B,CAAC;IACrC,GAAG,EAAE,MAAM,CAAC;CACZ;AAED;;;GAGG;AACH,MAAM,MAAM,uBAAuB,GAAG,MAAM,CAC3C,MAAM,EACN,6BAA6B,GAAG,MAAM,CAAC,6BAA6B,CAAC,CACrE,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAmB,SAAQ,uBAAuB;IAClE;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,MAAM,WAAW,yBAA0B,SAAQ,uBAAuB;IACzE;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,QAAQ,CAAC,EAAE,sBAAsB,CAAC;CAClC;AAED;;;;GAIG;AACH,MAAM,WAAW,uBAAwB,SAAQ,uBAAuB;IACvE;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,MAAM,WAAW,6BAA8B,SAAQ,yBAAyB;IAC/E;;OAEG;IACH,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"}
|
|
@@ -1 +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 * @alpha\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 * @alpha\n */\nexport type TelemetryEventPropertyTypeExt =\n\t| string\n\t| number\n\t| boolean\n\t| undefined\n\t| (string | number | boolean)[]\n\t|
|
|
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 type { 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 * @alpha\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 * @alpha\n */\nexport type TelemetryEventPropertyTypeExt =\n\t| string\n\t| number\n\t| boolean\n\t| undefined\n\t| (string | number | boolean)[]\n\t| Record<string, string | number | boolean | undefined | (string | number | boolean)[]>;\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 * @alpha\n */\nexport type ITelemetryPropertiesExt = Record<\n\tstring,\n\tTelemetryEventPropertyTypeExt | 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\t/**\n\t * {@inheritDoc @fluidframework/core-interfaces#ITelemetryBaseEvent.category}\n\t */\n\tcategory: string;\n\n\t/**\n\t * {@inheritDoc @fluidframework/core-interfaces#ITelemetryBaseEvent.eventName}\n\t */\n\teventName: string;\n}\n\n/**\n * Informational (non-error) telemetry event\n * @remarks Maps to category = \"generic\"\n * @alpha\n */\nexport interface ITelemetryGenericEventExt extends ITelemetryPropertiesExt {\n\t/**\n\t * {@inheritDoc @fluidframework/core-interfaces#ITelemetryBaseEvent.eventName}\n\t */\n\teventName: string;\n\n\t/**\n\t * Optional event {@link @fluidframework/core-interfaces#ITelemetryBaseEvent.category}.\n\t * @defaultValue \"generic\"\n\t */\n\tcategory?: TelemetryEventCategory;\n}\n\n/**\n * Error telemetry event.\n * @remarks Maps to category = \"error\"\n * @alpha\n */\nexport interface ITelemetryErrorEventExt extends ITelemetryPropertiesExt {\n\t/**\n\t * {@inheritDoc @fluidframework/core-interfaces#ITelemetryBaseEvent.eventName}\n\t */\n\teventName: string;\n}\n\n/**\n * Performance telemetry event.\n * @remarks Maps to category = \"performance\"\n * @alpha\n */\nexport interface ITelemetryPerformanceEventExt extends ITelemetryGenericEventExt {\n\t/**\n\t * Duration of event (optional)\n\t */\n\tduration?: number;\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 * @alpha\n */\nexport interface ITelemetryLoggerExt extends ITelemetryBaseLogger {\n\t/**\n\t * Send an 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. Default: {@link @fluidframework/core-interfaces#LogLevel.default}.\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 an 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 a 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. Default: {@link @fluidframework/core-interfaces#LogLevel.default}.\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,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.js";
|
|
5
|
+
import type { 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,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"thresholdCounter.d.ts","sourceRoot":"","sources":["../src/thresholdCounter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE/D;;;;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,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;
|
|
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,CAAC;YAC5B,OAAO;QACR,CAAC;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,CAAC;YACtC,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;QACrD,CAAC;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { 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"]}
|
package/lib/tsdoc-metadata.json
CHANGED
package/lib/utils.d.ts
CHANGED
|
@@ -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.js";
|
|
5
|
+
import type { ITelemetryLoggerExt } from "./telemetryTypes.js";
|
|
6
6
|
/**
|
|
7
7
|
* An object that contains a callback used in conjunction with the {@link createSampledLogger} utility function to provide custom logic for sampling events.
|
|
8
8
|
*
|
|
@@ -46,5 +46,17 @@ export interface ISampledTelemetryLogger extends ITelemetryLoggerExt {
|
|
|
46
46
|
*
|
|
47
47
|
* @internal
|
|
48
48
|
*/
|
|
49
|
-
export declare function createSampledLogger(logger: ITelemetryLoggerExt, eventSampler?: IEventSampler): ISampledTelemetryLogger;
|
|
49
|
+
export declare function createSampledLogger(logger: ITelemetryLoggerExt, eventSampler?: IEventSampler, skipLoggingWhenSamplingIsDisabled?: boolean): ISampledTelemetryLogger;
|
|
50
|
+
/**
|
|
51
|
+
* Runs the specified function and returns an object with the time it took to run as well as any output from it.
|
|
52
|
+
* @remarks Useful in conjunction with {@link TelemetryEventBatcher}.
|
|
53
|
+
*
|
|
54
|
+
* @param codeToMeasure - The code to be executed and measured.
|
|
55
|
+
* @returns The total duration of the code execution and whatever the passed-in code block returns.
|
|
56
|
+
* @internal
|
|
57
|
+
*/
|
|
58
|
+
export declare function measure<T>(codeToMeasure: () => T): {
|
|
59
|
+
duration: number;
|
|
60
|
+
output: T;
|
|
61
|
+
};
|
|
50
62
|
//# sourceMappingURL=utils.d.ts.map
|
package/lib/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAA6B,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAA6B,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1F;;;;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,EAC5B,iCAAiC,CAAC,EAAE,OAAO,GACzC,uBAAuB,CA8CzB;AAED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,CAAC,CAAA;CAAE,CAKlF"}
|
package/lib/utils.js
CHANGED
|
@@ -19,7 +19,7 @@ import { loggerToMonitoringContext } from "./config.js";
|
|
|
19
19
|
*
|
|
20
20
|
* @internal
|
|
21
21
|
*/
|
|
22
|
-
export function createSampledLogger(logger, eventSampler) {
|
|
22
|
+
export function createSampledLogger(logger, eventSampler, skipLoggingWhenSamplingIsDisabled) {
|
|
23
23
|
const monitoringContext = loggerToMonitoringContext(logger);
|
|
24
24
|
const isSamplingDisabled = monitoringContext.config.getBoolean("Fluid.Telemetry.DisableSampling") ?? false;
|
|
25
25
|
const sampledLogger = {
|
|
@@ -27,22 +27,35 @@ export function createSampledLogger(logger, eventSampler) {
|
|
|
27
27
|
// The sampler uses the following logic for sending events:
|
|
28
28
|
// 1. If isSamplingDisabled is true, then this means events should be unsampled. Therefore we send the event without any checks.
|
|
29
29
|
// 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.
|
|
30
|
+
// 3. If skipLoggingWhenSamplingIsDisabled is true, then no event is sent.
|
|
30
31
|
if (isSamplingDisabled || eventSampler === undefined || eventSampler.sample()) {
|
|
32
|
+
if (isSamplingDisabled && skipLoggingWhenSamplingIsDisabled) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
31
35
|
logger.send(event);
|
|
32
36
|
}
|
|
33
37
|
},
|
|
34
38
|
sendTelemetryEvent: (event) => {
|
|
35
39
|
if (isSamplingDisabled || eventSampler === undefined || eventSampler.sample()) {
|
|
40
|
+
if (isSamplingDisabled && skipLoggingWhenSamplingIsDisabled) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
36
43
|
logger.sendTelemetryEvent(event);
|
|
37
44
|
}
|
|
38
45
|
},
|
|
39
46
|
sendErrorEvent: (event) => {
|
|
40
47
|
if (isSamplingDisabled || eventSampler === undefined || eventSampler.sample()) {
|
|
48
|
+
if (isSamplingDisabled && skipLoggingWhenSamplingIsDisabled) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
41
51
|
logger.sendErrorEvent(event);
|
|
42
52
|
}
|
|
43
53
|
},
|
|
44
54
|
sendPerformanceEvent: (event) => {
|
|
45
55
|
if (isSamplingDisabled || eventSampler === undefined || eventSampler.sample()) {
|
|
56
|
+
if (isSamplingDisabled && skipLoggingWhenSamplingIsDisabled) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
46
59
|
logger.sendPerformanceEvent(event);
|
|
47
60
|
}
|
|
48
61
|
},
|
|
@@ -50,4 +63,18 @@ export function createSampledLogger(logger, eventSampler) {
|
|
|
50
63
|
};
|
|
51
64
|
return sampledLogger;
|
|
52
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Runs the specified function and returns an object with the time it took to run as well as any output from it.
|
|
68
|
+
* @remarks Useful in conjunction with {@link TelemetryEventBatcher}.
|
|
69
|
+
*
|
|
70
|
+
* @param codeToMeasure - The code to be executed and measured.
|
|
71
|
+
* @returns The total duration of the code execution and whatever the passed-in code block returns.
|
|
72
|
+
* @internal
|
|
73
|
+
*/
|
|
74
|
+
export function measure(codeToMeasure) {
|
|
75
|
+
const start = performance.now();
|
|
76
|
+
const output = codeToMeasure();
|
|
77
|
+
const duration = performance.now() - start;
|
|
78
|
+
return { duration, output };
|
|
79
|
+
}
|
|
53
80
|
//# 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":"AAAA;;;GAGG;AAIH,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAgCxD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,mBAAmB,CAClC,MAA2B,EAC3B,YAA4B;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAgCxD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,mBAAmB,CAClC,MAA2B,EAC3B,YAA4B,EAC5B,iCAA2C;IAE3C,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,0EAA0E;YAC1E,IAAI,kBAAkB,IAAI,YAAY,KAAK,SAAS,IAAI,YAAY,CAAC,MAAM,EAAE,EAAE,CAAC;gBAC/E,IAAI,kBAAkB,IAAI,iCAAiC,EAAE,CAAC;oBAC7D,OAAO;gBACR,CAAC;gBACD,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACpB,CAAC;QACF,CAAC;QACD,kBAAkB,EAAE,CAAC,KAAgC,EAAQ,EAAE;YAC9D,IAAI,kBAAkB,IAAI,YAAY,KAAK,SAAS,IAAI,YAAY,CAAC,MAAM,EAAE,EAAE,CAAC;gBAC/E,IAAI,kBAAkB,IAAI,iCAAiC,EAAE,CAAC;oBAC7D,OAAO;gBACR,CAAC;gBACD,MAAM,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;YAClC,CAAC;QACF,CAAC;QACD,cAAc,EAAE,CAAC,KAAgC,EAAQ,EAAE;YAC1D,IAAI,kBAAkB,IAAI,YAAY,KAAK,SAAS,IAAI,YAAY,CAAC,MAAM,EAAE,EAAE,CAAC;gBAC/E,IAAI,kBAAkB,IAAI,iCAAiC,EAAE,CAAC;oBAC7D,OAAO;gBACR,CAAC;gBACD,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;YAC9B,CAAC;QACF,CAAC;QACD,oBAAoB,EAAE,CAAC,KAAgC,EAAQ,EAAE;YAChE,IAAI,kBAAkB,IAAI,YAAY,KAAK,SAAS,IAAI,YAAY,CAAC,MAAM,EAAE,EAAE,CAAC;gBAC/E,IAAI,kBAAkB,IAAI,iCAAiC,EAAE,CAAC;oBAC7D,OAAO;gBACR,CAAC;gBACD,MAAM,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC;YACpC,CAAC;QACF,CAAC;QACD,kBAAkB;KAClB,CAAC;IAEF,OAAO,aAAa,CAAC;AACtB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,OAAO,CAAI,aAAsB;IAChD,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IAChC,MAAM,MAAM,GAAG,aAAa,EAAE,CAAC;IAC/B,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;IAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAC7B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ITelemetryBaseEvent } from \"@fluidframework/core-interfaces\";\n\nimport { loggerToMonitoringContext } from \"./config.js\";\nimport type { 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\tskipLoggingWhenSamplingIsDisabled?: boolean,\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\t// 3. If skipLoggingWhenSamplingIsDisabled is true, then no event is sent.\n\t\t\tif (isSamplingDisabled || eventSampler === undefined || eventSampler.sample()) {\n\t\t\t\tif (isSamplingDisabled && skipLoggingWhenSamplingIsDisabled) {\n\t\t\t\t\treturn;\n\t\t\t\t}\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\tif (isSamplingDisabled && skipLoggingWhenSamplingIsDisabled) {\n\t\t\t\t\treturn;\n\t\t\t\t}\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\tif (isSamplingDisabled && skipLoggingWhenSamplingIsDisabled) {\n\t\t\t\t\treturn;\n\t\t\t\t}\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\tif (isSamplingDisabled && skipLoggingWhenSamplingIsDisabled) {\n\t\t\t\t\treturn;\n\t\t\t\t}\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\n/**\n * Runs the specified function and returns an object with the time it took to run as well as any output from it.\n * @remarks Useful in conjunction with {@link TelemetryEventBatcher}.\n *\n * @param codeToMeasure - The code to be executed and measured.\n * @returns The total duration of the code execution and whatever the passed-in code block returns.\n * @internal\n */\nexport function measure<T>(codeToMeasure: () => T): { duration: number; output: T } {\n\tconst start = performance.now();\n\tconst output = codeToMeasure();\n\tconst duration = performance.now() - start;\n\treturn { duration, output };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/telemetry-utils",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.5.0.1",
|
|
4
4
|
"description": "Collection of telemetry relates utilities for Fluid",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -67,29 +67,30 @@
|
|
|
67
67
|
"temp-directory": "nyc/.nyc_output"
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@fluid-internal/client-utils": ">=2.0.0-rc.
|
|
71
|
-
"@fluidframework/core-interfaces": ">=2.0.0-rc.
|
|
72
|
-
"@fluidframework/core-utils": ">=2.0.0-rc.
|
|
73
|
-
"@fluidframework/
|
|
70
|
+
"@fluid-internal/client-utils": ">=2.0.0-rc.5.0.1 <2.0.0-rc.5.1.0",
|
|
71
|
+
"@fluidframework/core-interfaces": ">=2.0.0-rc.5.0.1 <2.0.0-rc.5.1.0",
|
|
72
|
+
"@fluidframework/core-utils": ">=2.0.0-rc.5.0.1 <2.0.0-rc.5.1.0",
|
|
73
|
+
"@fluidframework/driver-definitions": ">=2.0.0-rc.5.0.1 <2.0.0-rc.5.1.0",
|
|
74
74
|
"debug": "^4.3.4",
|
|
75
75
|
"uuid": "^9.0.0"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@arethetypeswrong/cli": "^0.15.2",
|
|
79
|
-
"@biomejs/biome": "^1.
|
|
80
|
-
"@fluid-internal/mocha-test-setup": ">=2.0.0-rc.
|
|
81
|
-
"@fluid-tools/build-cli": "^0.
|
|
79
|
+
"@biomejs/biome": "^1.7.3",
|
|
80
|
+
"@fluid-internal/mocha-test-setup": ">=2.0.0-rc.5.0.1 <2.0.0-rc.5.1.0",
|
|
81
|
+
"@fluid-tools/build-cli": "^0.39.0",
|
|
82
82
|
"@fluidframework/build-common": "^2.0.3",
|
|
83
|
-
"@fluidframework/build-tools": "^0.
|
|
84
|
-
"@fluidframework/eslint-config-fluid": "^5.
|
|
85
|
-
"@fluidframework/telemetry-utils-previous": "npm:@fluidframework/telemetry-utils@2.0.0-rc.
|
|
86
|
-
"@microsoft/api-extractor": "^7.
|
|
83
|
+
"@fluidframework/build-tools": "^0.39.0",
|
|
84
|
+
"@fluidframework/eslint-config-fluid": "^5.3.0",
|
|
85
|
+
"@fluidframework/telemetry-utils-previous": "npm:@fluidframework/telemetry-utils@2.0.0-rc.4.0.0",
|
|
86
|
+
"@microsoft/api-extractor": "^7.45.1",
|
|
87
87
|
"@types/debug": "^4.1.5",
|
|
88
88
|
"@types/mocha": "^9.1.1",
|
|
89
89
|
"@types/node": "^18.19.0",
|
|
90
90
|
"@types/sinon": "^17.0.3",
|
|
91
91
|
"@types/uuid": "^9.0.2",
|
|
92
92
|
"c8": "^8.0.1",
|
|
93
|
+
"concurrently": "^8.2.1",
|
|
93
94
|
"copyfiles": "^2.4.1",
|
|
94
95
|
"cross-env": "^7.0.3",
|
|
95
96
|
"eslint": "~8.55.0",
|
|
@@ -100,11 +101,16 @@
|
|
|
100
101
|
"prettier": "~3.0.3",
|
|
101
102
|
"rimraf": "^4.4.0",
|
|
102
103
|
"sinon": "^17.0.1",
|
|
103
|
-
"typescript": "~5.
|
|
104
|
+
"typescript": "~5.4.5"
|
|
104
105
|
},
|
|
105
106
|
"typeValidation": {
|
|
106
107
|
"broken": {
|
|
107
|
-
"
|
|
108
|
+
"ClassDeclaration_MockLogger": {
|
|
109
|
+
"backCompat": false,
|
|
110
|
+
"forwardCompat": false
|
|
111
|
+
},
|
|
112
|
+
"RemovedFunctionDeclaration_isValidLegacyError": {
|
|
113
|
+
"forwardCompat": false,
|
|
108
114
|
"backCompat": false
|
|
109
115
|
}
|
|
110
116
|
}
|
|
@@ -123,13 +129,21 @@
|
|
|
123
129
|
"build:test:esm": "tsc --project ./src/test/tsconfig.json",
|
|
124
130
|
"bump-version": "npm version minor --no-push --no-git-tag-version && npm run build:genver",
|
|
125
131
|
"check:are-the-types-wrong": "attw --pack .",
|
|
132
|
+
"check:biome": "biome check . --formatter-enabled=true",
|
|
133
|
+
"check:exports": "concurrently \"npm:check:exports:*\"",
|
|
134
|
+
"check:exports:bundle-release-tags": "api-extractor run --config api-extractor/api-extractor-lint-bundle.json",
|
|
135
|
+
"check:exports:cjs:legacy": "api-extractor run --config api-extractor/api-extractor-lint-legacy.cjs.json",
|
|
136
|
+
"check:exports:cjs:public": "api-extractor run --config api-extractor/api-extractor-lint-public.cjs.json",
|
|
137
|
+
"check:exports:esm:legacy": "api-extractor run --config api-extractor/api-extractor-lint-legacy.esm.json",
|
|
138
|
+
"check:exports:esm:public": "api-extractor run --config api-extractor/api-extractor-lint-public.esm.json",
|
|
139
|
+
"check:format": "npm run check:biome",
|
|
126
140
|
"check:prettier": "prettier --check . --cache --ignore-path ../../../.prettierignore",
|
|
127
|
-
"check:release-tags": "api-extractor run --local --config ./api-extractor-lint.json",
|
|
128
141
|
"ci:build:docs": "api-extractor run",
|
|
129
142
|
"clean": "rimraf --glob dist lib \"*.d.ts\" \"**/*.tsbuildinfo\" \"**/*.build.log\" _api-extractor-temp nyc",
|
|
130
143
|
"eslint": "eslint --format stylish src",
|
|
131
144
|
"eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
|
|
132
|
-
"format": "
|
|
145
|
+
"format": "npm run format:biome",
|
|
146
|
+
"format:biome": "biome check . --formatter-enabled=true --apply",
|
|
133
147
|
"format:prettier": "prettier --write . --cache --ignore-path ../../../.prettierignore",
|
|
134
148
|
"lint": "fluid-build . --task lint",
|
|
135
149
|
"lint:fix": "fluid-build . --task eslint:fix --task format",
|
package/src/config.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import type {
|
|
7
7
|
ConfigTypes,
|
|
8
8
|
IConfigProviderBase,
|
|
9
9
|
ITelemetryBaseLogger,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
import { Lazy } from "@fluidframework/core-utils/internal";
|
|
12
12
|
|
|
13
13
|
import { createChildLogger, tagCodeArtifacts } from "./logger.js";
|
|
14
|
-
import { ITelemetryLoggerExt } from "./telemetryTypes.js";
|
|
14
|
+
import type { ITelemetryLoggerExt } from "./telemetryTypes.js";
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Explicitly typed interface for reading configurations.
|
|
@@ -193,7 +193,7 @@ export class CachedConfigProvider implements IConfigProvider {
|
|
|
193
193
|
private readonly configCache = new Map<string, StronglyTypedValue>();
|
|
194
194
|
private readonly orderedBaseProviders: (IConfigProviderBase | undefined)[];
|
|
195
195
|
|
|
196
|
-
constructor(
|
|
196
|
+
public constructor(
|
|
197
197
|
private readonly logger?: ITelemetryBaseLogger,
|
|
198
198
|
...orderedBaseProviders: (IConfigProviderBase | undefined)[]
|
|
199
199
|
) {
|
|
@@ -216,26 +216,26 @@ export class CachedConfigProvider implements IConfigProvider {
|
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
|
-
getBoolean(name: string): boolean | undefined {
|
|
219
|
+
public getBoolean(name: string): boolean | undefined {
|
|
220
220
|
return this.getCacheEntry(name)?.boolean;
|
|
221
221
|
}
|
|
222
|
-
getNumber(name: string): number | undefined {
|
|
222
|
+
public getNumber(name: string): number | undefined {
|
|
223
223
|
return this.getCacheEntry(name)?.number;
|
|
224
224
|
}
|
|
225
|
-
getString(name: string): string | undefined {
|
|
225
|
+
public getString(name: string): string | undefined {
|
|
226
226
|
return this.getCacheEntry(name)?.string;
|
|
227
227
|
}
|
|
228
|
-
getBooleanArray(name: string): boolean[] | undefined {
|
|
228
|
+
public getBooleanArray(name: string): boolean[] | undefined {
|
|
229
229
|
return this.getCacheEntry(name)?.["boolean[]"];
|
|
230
230
|
}
|
|
231
|
-
getNumberArray(name: string): number[] | undefined {
|
|
231
|
+
public getNumberArray(name: string): number[] | undefined {
|
|
232
232
|
return this.getCacheEntry(name)?.["number[]"];
|
|
233
233
|
}
|
|
234
|
-
getStringArray(name: string): string[] | undefined {
|
|
234
|
+
public getStringArray(name: string): string[] | undefined {
|
|
235
235
|
return this.getCacheEntry(name)?.["string[]"];
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
-
getRawConfig(name: string): ConfigTypes {
|
|
238
|
+
public getRawConfig(name: string): ConfigTypes {
|
|
239
239
|
return this.getCacheEntry(name)?.raw;
|
|
240
240
|
}
|
|
241
241
|
|
|
@@ -279,9 +279,9 @@ export interface MonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLo
|
|
|
279
279
|
*
|
|
280
280
|
* @internal
|
|
281
281
|
*/
|
|
282
|
-
export function loggerIsMonitoringContext<
|
|
283
|
-
|
|
284
|
-
): obj is L & MonitoringContext<L> {
|
|
282
|
+
export function loggerIsMonitoringContext<
|
|
283
|
+
L extends ITelemetryBaseLogger = ITelemetryLoggerExt,
|
|
284
|
+
>(obj: L): obj is L & MonitoringContext<L> {
|
|
285
285
|
const maybeConfig = obj as Partial<MonitoringContext<L>> | undefined;
|
|
286
286
|
return isConfigProviderBase(maybeConfig?.config) && maybeConfig?.logger !== undefined;
|
|
287
287
|
}
|
|
@@ -291,9 +291,9 @@ export function loggerIsMonitoringContext<L extends ITelemetryBaseLogger = ITele
|
|
|
291
291
|
*
|
|
292
292
|
* @internal
|
|
293
293
|
*/
|
|
294
|
-
export function loggerToMonitoringContext<
|
|
295
|
-
|
|
296
|
-
): MonitoringContext<L> {
|
|
294
|
+
export function loggerToMonitoringContext<
|
|
295
|
+
L extends ITelemetryBaseLogger = ITelemetryLoggerExt,
|
|
296
|
+
>(logger: L): MonitoringContext<L> {
|
|
297
297
|
if (loggerIsMonitoringContext<L>(logger)) {
|
|
298
298
|
return logger;
|
|
299
299
|
}
|
package/src/error.ts
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { IErrorBase, ITelemetryBaseProperties } from "@fluidframework/core-interfaces";
|
|
6
|
+
import type { IErrorBase, ITelemetryBaseProperties } from "@fluidframework/core-interfaces";
|
|
7
7
|
import {
|
|
8
8
|
FluidErrorTypes,
|
|
9
|
-
IGenericError,
|
|
10
|
-
IUsageError,
|
|
9
|
+
type IGenericError,
|
|
10
|
+
type IUsageError,
|
|
11
11
|
} from "@fluidframework/core-interfaces/internal";
|
|
12
|
-
import { ISequencedDocumentMessage } from "@fluidframework/
|
|
12
|
+
import type { ISequencedDocumentMessage } from "@fluidframework/driver-definitions/internal";
|
|
13
13
|
|
|
14
14
|
import {
|
|
15
15
|
LoggingError,
|
|
@@ -18,8 +18,8 @@ import {
|
|
|
18
18
|
normalizeError,
|
|
19
19
|
wrapError,
|
|
20
20
|
} from "./errorLogging.js";
|
|
21
|
-
import { IFluidErrorBase } from "./fluidErrorBase.js";
|
|
22
|
-
import { ITelemetryPropertiesExt } from "./telemetryTypes.js";
|
|
21
|
+
import type { IFluidErrorBase } from "./fluidErrorBase.js";
|
|
22
|
+
import type { ITelemetryPropertiesExt } from "./telemetryTypes.js";
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* Throws a UsageError with the given message if the condition is not met.
|
|
@@ -46,7 +46,7 @@ export function validatePrecondition(
|
|
|
46
46
|
* @internal
|
|
47
47
|
*/
|
|
48
48
|
export class GenericError extends LoggingError implements IGenericError, IFluidErrorBase {
|
|
49
|
-
readonly errorType = FluidErrorTypes.genericError;
|
|
49
|
+
public readonly errorType = FluidErrorTypes.genericError;
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
52
|
* Create a new GenericError
|
|
@@ -54,7 +54,7 @@ export class GenericError extends LoggingError implements IGenericError, IFluidE
|
|
|
54
54
|
* @param error - inner error object
|
|
55
55
|
* @param props - Telemetry props to include when the error is logged
|
|
56
56
|
*/
|
|
57
|
-
constructor(
|
|
57
|
+
public constructor(
|
|
58
58
|
message: string,
|
|
59
59
|
// TODO: Use `unknown` instead (API breaking change because error is not just an input parameter, but a public member of the class)
|
|
60
60
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
|
|
@@ -72,9 +72,9 @@ export class GenericError extends LoggingError implements IGenericError, IFluidE
|
|
|
72
72
|
* @internal
|
|
73
73
|
*/
|
|
74
74
|
export class UsageError extends LoggingError implements IUsageError, IFluidErrorBase {
|
|
75
|
-
readonly errorType = FluidErrorTypes.usageError;
|
|
75
|
+
public readonly errorType = FluidErrorTypes.usageError;
|
|
76
76
|
|
|
77
|
-
constructor(message: string, props?: ITelemetryBaseProperties) {
|
|
77
|
+
public constructor(message: string, props?: ITelemetryBaseProperties) {
|
|
78
78
|
super(message, { ...props, usageError: true });
|
|
79
79
|
}
|
|
80
80
|
}
|
|
@@ -86,10 +86,10 @@ export class UsageError extends LoggingError implements IUsageError, IFluidError
|
|
|
86
86
|
* @internal
|
|
87
87
|
*/
|
|
88
88
|
export class DataCorruptionError extends LoggingError implements IErrorBase, IFluidErrorBase {
|
|
89
|
-
readonly errorType = FluidErrorTypes.dataCorruptionError;
|
|
90
|
-
readonly canRetry = false;
|
|
89
|
+
public readonly errorType = FluidErrorTypes.dataCorruptionError;
|
|
90
|
+
public readonly canRetry = false;
|
|
91
91
|
|
|
92
|
-
constructor(message: string, props: ITelemetryBaseProperties) {
|
|
92
|
+
public constructor(message: string, props: ITelemetryBaseProperties) {
|
|
93
93
|
super(message, { ...props, dataProcessingError: 1 });
|
|
94
94
|
}
|
|
95
95
|
}
|