@fluidframework/telemetry-utils 1.4.0-121020 → 2.0.0-dev-rc.1.0.0.224419
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.js +12 -13
- package/.mocharc.js +12 -0
- package/CHANGELOG.md +249 -0
- package/README.md +68 -1
- package/api-extractor-lint.json +4 -0
- package/api-extractor.json +2 -2
- package/api-report/telemetry-utils.api.md +444 -0
- package/dist/config.d.ts +47 -16
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +88 -38
- package/dist/config.js.map +1 -1
- package/dist/error.d.ts +112 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +159 -0
- package/dist/error.js.map +1 -0
- package/dist/errorLogging.d.ts +86 -20
- package/dist/errorLogging.d.ts.map +1 -1
- package/dist/errorLogging.js +190 -60
- package/dist/errorLogging.js.map +1 -1
- package/dist/eventEmitterWithErrorHandling.d.ts +9 -3
- package/dist/eventEmitterWithErrorHandling.d.ts.map +1 -1
- package/dist/eventEmitterWithErrorHandling.js +16 -3
- package/dist/eventEmitterWithErrorHandling.js.map +1 -1
- package/dist/events.d.ts +27 -3
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +26 -2
- package/dist/events.js.map +1 -1
- package/dist/fluidErrorBase.d.ts +57 -16
- package/dist/fluidErrorBase.d.ts.map +1 -1
- package/dist/fluidErrorBase.js +27 -14
- package/dist/fluidErrorBase.js.map +1 -1
- package/dist/index.d.ts +12 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +55 -21
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +267 -51
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +423 -132
- package/dist/logger.js.map +1 -1
- package/dist/mockLogger.d.ts +39 -12
- package/dist/mockLogger.d.ts.map +1 -1
- package/dist/mockLogger.js +105 -22
- package/dist/mockLogger.js.map +1 -1
- package/dist/sampledTelemetryHelper.d.ts +18 -12
- package/dist/sampledTelemetryHelper.d.ts.map +1 -1
- package/dist/sampledTelemetryHelper.js +28 -19
- package/dist/sampledTelemetryHelper.js.map +1 -1
- package/dist/telemetry-utils-alpha.d.ts +290 -0
- package/dist/telemetry-utils-beta.d.ts +264 -0
- package/dist/telemetry-utils-public.d.ts +264 -0
- package/dist/telemetry-utils-untrimmed.d.ts +1102 -0
- package/dist/telemetryTypes.d.ts +115 -0
- package/dist/telemetryTypes.d.ts.map +1 -0
- package/dist/telemetryTypes.js +7 -0
- package/dist/telemetryTypes.js.map +1 -0
- package/dist/thresholdCounter.d.ts +6 -5
- package/dist/thresholdCounter.d.ts.map +1 -1
- package/dist/thresholdCounter.js +4 -3
- package/dist/thresholdCounter.js.map +1 -1
- package/dist/tsdoc-metadata.json +11 -0
- package/dist/utils.d.ts +54 -3
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +58 -3
- package/dist/utils.js.map +1 -1
- package/lib/config.d.ts +47 -16
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +85 -36
- package/lib/config.js.map +1 -1
- package/lib/error.d.ts +112 -0
- package/lib/error.d.ts.map +1 -0
- package/lib/error.js +150 -0
- package/lib/error.js.map +1 -0
- package/lib/errorLogging.d.ts +86 -20
- package/lib/errorLogging.d.ts.map +1 -1
- package/lib/errorLogging.js +189 -60
- package/lib/errorLogging.js.map +1 -1
- package/lib/eventEmitterWithErrorHandling.d.ts +9 -3
- package/lib/eventEmitterWithErrorHandling.d.ts.map +1 -1
- package/lib/eventEmitterWithErrorHandling.js +15 -2
- package/lib/eventEmitterWithErrorHandling.js.map +1 -1
- package/lib/events.d.ts +27 -3
- package/lib/events.d.ts.map +1 -1
- package/lib/events.js +26 -2
- package/lib/events.js.map +1 -1
- package/lib/fluidErrorBase.d.ts +57 -16
- package/lib/fluidErrorBase.d.ts.map +1 -1
- package/lib/fluidErrorBase.js +27 -14
- package/lib/fluidErrorBase.js.map +1 -1
- package/lib/index.d.ts +12 -11
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +11 -11
- package/lib/index.js.map +1 -1
- package/lib/logger.d.ts +267 -51
- package/lib/logger.d.ts.map +1 -1
- package/lib/logger.js +415 -131
- package/lib/logger.js.map +1 -1
- package/lib/mockLogger.d.ts +39 -12
- package/lib/mockLogger.d.ts.map +1 -1
- package/lib/mockLogger.js +106 -23
- package/lib/mockLogger.js.map +1 -1
- package/lib/sampledTelemetryHelper.d.ts +18 -12
- package/lib/sampledTelemetryHelper.d.ts.map +1 -1
- package/lib/sampledTelemetryHelper.js +26 -17
- package/lib/sampledTelemetryHelper.js.map +1 -1
- package/lib/telemetry-utils-alpha.d.ts +290 -0
- package/lib/telemetry-utils-beta.d.ts +264 -0
- package/lib/telemetry-utils-public.d.ts +264 -0
- package/lib/telemetry-utils-untrimmed.d.ts +1102 -0
- package/lib/telemetryTypes.d.ts +115 -0
- package/lib/telemetryTypes.d.ts.map +1 -0
- package/lib/telemetryTypes.js +6 -0
- package/lib/telemetryTypes.js.map +1 -0
- package/lib/thresholdCounter.d.ts +6 -5
- package/lib/thresholdCounter.d.ts.map +1 -1
- package/lib/thresholdCounter.js +4 -3
- package/lib/thresholdCounter.js.map +1 -1
- package/lib/utils.d.ts +54 -3
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +56 -2
- package/lib/utils.js.map +1 -1
- package/package.json +86 -57
- package/prettier.config.cjs +8 -0
- package/src/config.ts +254 -189
- package/src/error.ts +235 -0
- package/src/errorLogging.ts +440 -290
- package/src/eventEmitterWithErrorHandling.ts +26 -14
- package/src/events.ts +54 -25
- package/src/fluidErrorBase.ts +94 -46
- package/src/index.ts +76 -17
- package/src/logger.ts +966 -505
- package/src/mockLogger.ts +225 -83
- package/src/sampledTelemetryHelper.ts +136 -128
- package/src/telemetryTypes.ts +140 -0
- package/src/thresholdCounter.ts +38 -37
- package/src/utils.ts +108 -17
- package/tsconfig.esnext.json +6 -6
- package/tsconfig.json +9 -13
- package/dist/debugLogger.d.ts +0 -39
- package/dist/debugLogger.d.ts.map +0 -1
- package/dist/debugLogger.js +0 -101
- package/dist/debugLogger.js.map +0 -1
- package/dist/packageVersion.d.ts +0 -9
- package/dist/packageVersion.d.ts.map +0 -1
- package/dist/packageVersion.js +0 -12
- package/dist/packageVersion.js.map +0 -1
- package/lib/debugLogger.d.ts +0 -39
- package/lib/debugLogger.d.ts.map +0 -1
- package/lib/debugLogger.js +0 -97
- package/lib/debugLogger.js.map +0 -1
- package/lib/packageVersion.d.ts +0 -9
- package/lib/packageVersion.d.ts.map +0 -1
- package/lib/packageVersion.js +0 -9
- package/lib/packageVersion.js.map +0 -1
- package/src/debugLogger.ts +0 -126
- package/src/packageVersion.ts +0 -9
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { ITelemetryBaseLogger, LogLevel, Tagged } from "@fluidframework/core-interfaces";
|
|
6
|
+
/**
|
|
7
|
+
* The categories FF uses when instrumenting the code.
|
|
8
|
+
*
|
|
9
|
+
* generic - Informational log event
|
|
10
|
+
*
|
|
11
|
+
* error - Error log event, ideally 0 of these are logged during a session
|
|
12
|
+
*
|
|
13
|
+
* performance - Includes duration, and often has _start, _end, or _cancel suffixes for activity tracking
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export type TelemetryEventCategory = "generic" | "error" | "performance";
|
|
17
|
+
/**
|
|
18
|
+
* Property types that can be logged.
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* Includes extra types beyond {@link @fluidframework/core-interfaces#TelemetryBaseEventPropertyType}, which must be
|
|
22
|
+
* converted before sending to a base logger.
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export type TelemetryEventPropertyTypeExt = string | number | boolean | undefined | (string | number | boolean)[] | {
|
|
26
|
+
[key: string]: // Flat objects can have the same properties as the event itself
|
|
27
|
+
string | number | boolean | undefined | (string | number | boolean)[];
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* A property to be logged to telemetry containing both the value and a tag. Tags are generic strings that can be used
|
|
31
|
+
* to mark pieces of information that should be organized or handled differently by loggers in various first or third
|
|
32
|
+
* party scenarios. For example, tags are used to mark personal information that should not be stored in logs.
|
|
33
|
+
*
|
|
34
|
+
* @deprecated Use {@link @fluidframework/core-interfaces#Tagged}\<{@link TelemetryEventPropertyTypeExt}\>
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
export interface ITaggedTelemetryPropertyTypeExt {
|
|
38
|
+
value: TelemetryEventPropertyTypeExt;
|
|
39
|
+
tag: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* JSON-serializable properties, which will be logged with telemetry.
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
export interface ITelemetryPropertiesExt {
|
|
46
|
+
[index: string]: TelemetryEventPropertyTypeExt | Tagged<TelemetryEventPropertyTypeExt>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Interface for logging telemetry statements.
|
|
50
|
+
* @remarks May contain any number of properties that get serialized as json payload.
|
|
51
|
+
* @param category - category of the event, like "error", "performance", "generic", etc.
|
|
52
|
+
* @param eventName - name of the event.
|
|
53
|
+
*
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
56
|
+
export interface ITelemetryEventExt extends ITelemetryPropertiesExt {
|
|
57
|
+
category: string;
|
|
58
|
+
eventName: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Informational (non-error) telemetry event
|
|
62
|
+
* @remarks Maps to category = "generic"
|
|
63
|
+
* @public
|
|
64
|
+
*/
|
|
65
|
+
export interface ITelemetryGenericEventExt extends ITelemetryPropertiesExt {
|
|
66
|
+
eventName: string;
|
|
67
|
+
category?: TelemetryEventCategory;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Error telemetry event.
|
|
71
|
+
* @remarks Maps to category = "error"
|
|
72
|
+
* @public
|
|
73
|
+
*/
|
|
74
|
+
export interface ITelemetryErrorEventExt extends ITelemetryPropertiesExt {
|
|
75
|
+
eventName: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Performance telemetry event.
|
|
79
|
+
* @remarks Maps to category = "performance"
|
|
80
|
+
* @public
|
|
81
|
+
*/
|
|
82
|
+
export interface ITelemetryPerformanceEventExt extends ITelemetryGenericEventExt {
|
|
83
|
+
duration?: number;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* An extended {@link @fluidframework/core-interfaces#ITelemetryBaseLogger} which allows for more lenient event types.
|
|
87
|
+
*
|
|
88
|
+
* @remarks
|
|
89
|
+
* This interface is meant to be used internally within the Fluid Framework,
|
|
90
|
+
* and `ITelemetryBaseLogger` should be used when loggers are passed between layers.
|
|
91
|
+
* @public
|
|
92
|
+
*/
|
|
93
|
+
export interface ITelemetryLoggerExt extends ITelemetryBaseLogger {
|
|
94
|
+
/**
|
|
95
|
+
* Send information telemetry event
|
|
96
|
+
* @param event - Event to send
|
|
97
|
+
* @param error - optional error object to log
|
|
98
|
+
* @param logLevel - optional level of the log.
|
|
99
|
+
*/
|
|
100
|
+
sendTelemetryEvent(event: ITelemetryGenericEventExt, error?: unknown, logLevel?: typeof LogLevel.verbose | typeof LogLevel.default): void;
|
|
101
|
+
/**
|
|
102
|
+
* Send error telemetry event
|
|
103
|
+
* @param event - Event to send
|
|
104
|
+
* @param error - optional error object to log
|
|
105
|
+
*/
|
|
106
|
+
sendErrorEvent(event: ITelemetryErrorEventExt, error?: unknown): void;
|
|
107
|
+
/**
|
|
108
|
+
* Send performance telemetry event
|
|
109
|
+
* @param event - Event to send
|
|
110
|
+
* @param error - optional error object to log
|
|
111
|
+
* @param logLevel - optional level of the log.
|
|
112
|
+
*/
|
|
113
|
+
sendPerformanceEvent(event: ITelemetryPerformanceEventExt, error?: unknown, logLevel?: typeof LogLevel.verbose | typeof LogLevel.default): void;
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=telemetryTypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetryTypes.d.ts","sourceRoot":"","sources":["../src/telemetryTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AAEzF;;;;;;;;;GASG;AACH,MAAM,MAAM,sBAAsB,GAAG,SAAS,GAAG,OAAO,GAAG,aAAa,CAAC;AAEzE;;;;;;;GAOG;AACH,MAAM,MAAM,6BAA6B,GACtC,MAAM,GACN,MAAM,GACN,OAAO,GACP,SAAS,GACT,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,EAAE,GAC7B;IACA,CAAC,GAAG,EAAE,MAAM,GACZ,AADe,gEAAgE;IAC/E,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC;CACrE,CAAC;AAEL;;;;;;;GAOG;AACH,MAAM,WAAW,+BAA+B;IAC/C,KAAK,EAAE,6BAA6B,CAAC;IACrC,GAAG,EAAE,MAAM,CAAC;CACZ;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACvC,CAAC,KAAK,EAAE,MAAM,GAAG,6BAA6B,GAAG,MAAM,CAAC,6BAA6B,CAAC,CAAC;CACvF;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAmB,SAAQ,uBAAuB;IAClE,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,MAAM,WAAW,yBAA0B,SAAQ,uBAAuB;IACzE,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,sBAAsB,CAAC;CAClC;AAED;;;;GAIG;AACH,MAAM,WAAW,uBAAwB,SAAQ,uBAAuB;IACvE,SAAS,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,MAAM,WAAW,6BAA8B,SAAQ,yBAAyB;IAC/E,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,mBAAoB,SAAQ,oBAAoB;IAChE;;;;;OAKG;IACH,kBAAkB,CACjB,KAAK,EAAE,yBAAyB,EAChC,KAAK,CAAC,EAAE,OAAO,EACf,QAAQ,CAAC,EAAE,OAAO,QAAQ,CAAC,OAAO,GAAG,OAAO,QAAQ,CAAC,OAAO,GAC1D,IAAI,CAAC;IAER;;;;OAIG;IACH,cAAc,CAAC,KAAK,EAAE,uBAAuB,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAEtE;;;;;OAKG;IACH,oBAAoB,CACnB,KAAK,EAAE,6BAA6B,EACpC,KAAK,CAAC,EAAE,OAAO,EACf,QAAQ,CAAC,EAAE,OAAO,QAAQ,CAAC,OAAO,GAAG,OAAO,QAAQ,CAAC,OAAO,GAC1D,IAAI,CAAC;CACR"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetryTypes.js","sourceRoot":"","sources":["../src/telemetryTypes.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryBaseLogger, LogLevel, Tagged } from \"@fluidframework/core-interfaces\";\n\n/**\n * The categories FF uses when instrumenting the code.\n *\n * generic - Informational log event\n *\n * error - Error log event, ideally 0 of these are logged during a session\n *\n * performance - Includes duration, and often has _start, _end, or _cancel suffixes for activity tracking\n * @public\n */\nexport type TelemetryEventCategory = \"generic\" | \"error\" | \"performance\";\n\n/**\n * Property types that can be logged.\n *\n * @remarks\n * Includes extra types beyond {@link @fluidframework/core-interfaces#TelemetryBaseEventPropertyType}, which must be\n * converted before sending to a base logger.\n * @public\n */\nexport type TelemetryEventPropertyTypeExt =\n\t| string\n\t| number\n\t| boolean\n\t| undefined\n\t| (string | number | boolean)[]\n\t| {\n\t\t\t[key: string]: // Flat objects can have the same properties as the event itself\n\t\t\tstring | number | boolean | undefined | (string | number | boolean)[];\n\t };\n\n/**\n * A property to be logged to telemetry containing both the value and a tag. Tags are generic strings that can be used\n * to mark pieces of information that should be organized or handled differently by loggers in various first or third\n * party scenarios. For example, tags are used to mark personal information that should not be stored in logs.\n *\n * @deprecated Use {@link @fluidframework/core-interfaces#Tagged}\\<{@link TelemetryEventPropertyTypeExt}\\>\n * @internal\n */\nexport interface ITaggedTelemetryPropertyTypeExt {\n\tvalue: TelemetryEventPropertyTypeExt;\n\ttag: string;\n}\n\n/**\n * JSON-serializable properties, which will be logged with telemetry.\n * @public\n */\nexport interface ITelemetryPropertiesExt {\n\t[index: string]: TelemetryEventPropertyTypeExt | Tagged<TelemetryEventPropertyTypeExt>;\n}\n\n/**\n * Interface for logging telemetry statements.\n * @remarks May contain any number of properties that get serialized as json payload.\n * @param category - category of the event, like \"error\", \"performance\", \"generic\", etc.\n * @param eventName - name of the event.\n *\n * @internal\n */\nexport interface ITelemetryEventExt extends ITelemetryPropertiesExt {\n\tcategory: string;\n\teventName: string;\n}\n\n/**\n * Informational (non-error) telemetry event\n * @remarks Maps to category = \"generic\"\n * @public\n */\nexport interface ITelemetryGenericEventExt extends ITelemetryPropertiesExt {\n\teventName: string;\n\tcategory?: TelemetryEventCategory;\n}\n\n/**\n * Error telemetry event.\n * @remarks Maps to category = \"error\"\n * @public\n */\nexport interface ITelemetryErrorEventExt extends ITelemetryPropertiesExt {\n\teventName: string;\n}\n\n/**\n * Performance telemetry event.\n * @remarks Maps to category = \"performance\"\n * @public\n */\nexport interface ITelemetryPerformanceEventExt extends ITelemetryGenericEventExt {\n\tduration?: number; // Duration of event (optional)\n}\n\n/**\n * An extended {@link @fluidframework/core-interfaces#ITelemetryBaseLogger} which allows for more lenient event types.\n *\n * @remarks\n * This interface is meant to be used internally within the Fluid Framework,\n * and `ITelemetryBaseLogger` should be used when loggers are passed between layers.\n * @public\n */\nexport interface ITelemetryLoggerExt extends ITelemetryBaseLogger {\n\t/**\n\t * Send information telemetry event\n\t * @param event - Event to send\n\t * @param error - optional error object to log\n\t * @param logLevel - optional level of the log.\n\t */\n\tsendTelemetryEvent(\n\t\tevent: ITelemetryGenericEventExt,\n\t\terror?: unknown,\n\t\tlogLevel?: typeof LogLevel.verbose | typeof LogLevel.default,\n\t): void;\n\n\t/**\n\t * Send error telemetry event\n\t * @param event - Event to send\n\t * @param error - optional error object to log\n\t */\n\tsendErrorEvent(event: ITelemetryErrorEventExt, error?: unknown): void;\n\n\t/**\n\t * Send performance telemetry event\n\t * @param event - Event to send\n\t * @param error - optional error object to log\n\t * @param logLevel - optional level of the log.\n\t */\n\tsendPerformanceEvent(\n\t\tevent: ITelemetryPerformanceEventExt,\n\t\terror?: unknown,\n\t\tlogLevel?: typeof LogLevel.verbose | typeof LogLevel.default,\n\t): void;\n}\n"]}
|
|
@@ -2,22 +2,23 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import { ITelemetryLoggerExt } from "./telemetryTypes";
|
|
6
6
|
/**
|
|
7
|
-
* Utility counter which will send event only if the provided value
|
|
8
|
-
*
|
|
7
|
+
* Utility counter which will send event only if the provided value is above a configured threshold.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
9
10
|
*/
|
|
10
11
|
export declare class ThresholdCounter {
|
|
11
12
|
private readonly threshold;
|
|
12
13
|
private readonly logger;
|
|
13
14
|
private thresholdMultiple;
|
|
14
|
-
constructor(threshold: number, logger:
|
|
15
|
+
constructor(threshold: number, logger: ITelemetryLoggerExt, thresholdMultiple?: number);
|
|
15
16
|
/**
|
|
16
17
|
* Sends the value if it's above the treshold.
|
|
17
18
|
*/
|
|
18
19
|
send(eventName: string, value: number): void;
|
|
19
20
|
/**
|
|
20
|
-
* Sends the value if it's above the
|
|
21
|
+
* Sends the value if it's above the threshold
|
|
21
22
|
* and a multiple of the threshold.
|
|
22
23
|
*
|
|
23
24
|
* To be used in scenarios where we'd like to record a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thresholdCounter.d.ts","sourceRoot":"","sources":["../src/thresholdCounter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,
|
|
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"}
|
package/dist/thresholdCounter.js
CHANGED
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.ThresholdCounter = void 0;
|
|
8
8
|
/**
|
|
9
|
-
* Utility counter which will send event only if the provided value
|
|
10
|
-
*
|
|
9
|
+
* Utility counter which will send event only if the provided value is above a configured threshold.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
11
12
|
*/
|
|
12
13
|
class ThresholdCounter {
|
|
13
14
|
constructor(threshold, logger, thresholdMultiple = threshold) {
|
|
@@ -28,7 +29,7 @@ class ThresholdCounter {
|
|
|
28
29
|
});
|
|
29
30
|
}
|
|
30
31
|
/**
|
|
31
|
-
* Sends the value if it's above the
|
|
32
|
+
* Sends the value if it's above the threshold
|
|
32
33
|
* and a multiple of the threshold.
|
|
33
34
|
*
|
|
34
35
|
* To be used in scenarios where we'd like to record a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thresholdCounter.js","sourceRoot":"","sources":["../src/thresholdCounter.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH
|
|
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"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
+
{
|
|
4
|
+
"tsdocVersion": "0.12",
|
|
5
|
+
"toolPackages": [
|
|
6
|
+
{
|
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
|
8
|
+
"packageVersion": "7.38.3"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|
package/dist/utils.d.ts
CHANGED
|
@@ -2,13 +2,64 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import { ITelemetryBaseLogger, ITelemetryGenericEvent } from "@fluidframework/
|
|
5
|
+
import { ITelemetryBaseLogger, ITelemetryGenericEvent } from "@fluidframework/core-interfaces";
|
|
6
|
+
import { ITelemetryLoggerExt } from "./telemetryTypes";
|
|
6
7
|
/**
|
|
7
8
|
* Like assert, but logs only if the condition is false, rather than throwing
|
|
8
9
|
* @param condition - The condition to attest too
|
|
9
10
|
* @param logger - The logger to log with
|
|
10
11
|
* @param event - The string or event to log
|
|
11
|
-
* @returns
|
|
12
|
+
* @returns The outcome of the condition
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*
|
|
16
|
+
* @deprecated
|
|
17
|
+
* This API will be removed in a future release.
|
|
18
|
+
* No replacement API is intended, but reproducing its behavior should be trivial for anyone who needs it.
|
|
12
19
|
*/
|
|
13
|
-
export declare function logIfFalse(condition:
|
|
20
|
+
export declare function logIfFalse(condition: unknown, logger: ITelemetryBaseLogger, event: string | ITelemetryGenericEvent): condition is true;
|
|
21
|
+
/**
|
|
22
|
+
* An object that contains a callback used in conjunction with the {@link createSampledLogger} utility function to provide custom logic for sampling events.
|
|
23
|
+
*
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
export interface IEventSampler {
|
|
27
|
+
/**
|
|
28
|
+
* @returns true if the event should be sampled or false if not
|
|
29
|
+
*/
|
|
30
|
+
sample: () => boolean | undefined;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A telemetry logger that has sampling capabilities
|
|
34
|
+
*
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
export interface ISampledTelemetryLogger extends ITelemetryLoggerExt {
|
|
38
|
+
/**
|
|
39
|
+
* Indicates if the feature flag to disable sampling is set.
|
|
40
|
+
*
|
|
41
|
+
* @remarks Exposed to enable some advanced scenarios where the code using the sampled logger
|
|
42
|
+
* could take advantage of skipping the execution of some logic when it can determine
|
|
43
|
+
* it won't be necessary because the telemetry event that needs it wouldn't be
|
|
44
|
+
* emitted anyway.
|
|
45
|
+
*/
|
|
46
|
+
isSamplingDisabled: boolean;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Wraps around an existing logger matching the {@link ITelemetryLoggerExt} interface and provides the ability to only log a subset of events using a sampling strategy provided by an ${@link IEventSampler}.
|
|
50
|
+
* You can chose to not provide an event sampler which is effectively a no-op, meaning that it will be treated as if the sampler always returns true.
|
|
51
|
+
*
|
|
52
|
+
* @remarks
|
|
53
|
+
* The sampling functionality uses the Fluid telemetry logging configuration along with the optionally provided event sampling callback to determine whether an event should
|
|
54
|
+
* be logged or not.
|
|
55
|
+
*
|
|
56
|
+
* Configuration object parameters:
|
|
57
|
+
* 'Fluid.Telemetry.DisableSampling': if this config value is set to true, all events will be unsampled and therefore logged.
|
|
58
|
+
* Otherwise only a sample will be logged according to the provided event sampler callback.
|
|
59
|
+
*
|
|
60
|
+
* Note that the same sampler is used for all APIs of the returned logger. If you want separate events flowing through the returned logger to be sampled separately, the {@link IEventSampler} you provide should track them separately.
|
|
61
|
+
*
|
|
62
|
+
* @internal
|
|
63
|
+
*/
|
|
64
|
+
export declare function createSampledLogger(logger: ITelemetryLoggerExt, eventSampler?: IEventSampler): ISampledTelemetryLogger;
|
|
14
65
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAEN,oBAAoB,EACpB,sBAAsB,EACtB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAA6B,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAElF;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CACzB,SAAS,EAAE,OAAO,EAClB,MAAM,EAAE,oBAAoB,EAC5B,KAAK,EAAE,MAAM,GAAG,sBAAsB,GACpC,SAAS,IAAI,IAAI,CAUnB;AAED;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC7B;;OAEG;IACH,MAAM,EAAE,MAAM,OAAO,GAAG,SAAS,CAAC;CAClC;AAED;;;;GAIG;AACH,MAAM,WAAW,uBAAwB,SAAQ,mBAAmB;IACnE;;;;;;;OAOG;IACH,kBAAkB,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mBAAmB,CAClC,MAAM,EAAE,mBAAmB,EAC3B,YAAY,CAAC,EAAE,aAAa,GAC1B,uBAAuB,CAiCzB"}
|
package/dist/utils.js
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.logIfFalse = void 0;
|
|
3
|
+
exports.createSampledLogger = exports.logIfFalse = void 0;
|
|
4
|
+
const config_1 = require("./config");
|
|
4
5
|
/**
|
|
5
6
|
* Like assert, but logs only if the condition is false, rather than throwing
|
|
6
7
|
* @param condition - The condition to attest too
|
|
7
8
|
* @param logger - The logger to log with
|
|
8
9
|
* @param event - The string or event to log
|
|
9
|
-
* @returns
|
|
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.
|
|
10
17
|
*/
|
|
11
18
|
function logIfFalse(condition, logger, event) {
|
|
12
19
|
if (condition) {
|
|
@@ -14,9 +21,57 @@ function logIfFalse(condition, logger, event) {
|
|
|
14
21
|
}
|
|
15
22
|
const newEvent = typeof event === "string"
|
|
16
23
|
? { eventName: event, category: "error" }
|
|
17
|
-
:
|
|
24
|
+
: { category: "error", ...event };
|
|
18
25
|
logger.send(newEvent);
|
|
19
26
|
return false;
|
|
20
27
|
}
|
|
21
28
|
exports.logIfFalse = logIfFalse;
|
|
29
|
+
/**
|
|
30
|
+
* 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
|
+
* 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.
|
|
32
|
+
*
|
|
33
|
+
* @remarks
|
|
34
|
+
* The sampling functionality uses the Fluid telemetry logging configuration along with the optionally provided event sampling callback to determine whether an event should
|
|
35
|
+
* be logged or not.
|
|
36
|
+
*
|
|
37
|
+
* Configuration object parameters:
|
|
38
|
+
* 'Fluid.Telemetry.DisableSampling': if this config value is set to true, all events will be unsampled and therefore logged.
|
|
39
|
+
* Otherwise only a sample will be logged according to the provided event sampler callback.
|
|
40
|
+
*
|
|
41
|
+
* 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.
|
|
42
|
+
*
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
function createSampledLogger(logger, eventSampler) {
|
|
46
|
+
const monitoringContext = (0, config_1.loggerToMonitoringContext)(logger);
|
|
47
|
+
const isSamplingDisabled = monitoringContext.config.getBoolean("Fluid.Telemetry.DisableSampling") ?? false;
|
|
48
|
+
const sampledLogger = {
|
|
49
|
+
send: (event) => {
|
|
50
|
+
// The sampler uses the following logic for sending events:
|
|
51
|
+
// 1. If isSamplingDisabled is true, then this means events should be unsampled. Therefore we send the event without any checks.
|
|
52
|
+
// 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.
|
|
53
|
+
if (isSamplingDisabled || eventSampler === undefined || eventSampler.sample()) {
|
|
54
|
+
logger.send(event);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
sendTelemetryEvent: (event) => {
|
|
58
|
+
if (isSamplingDisabled || eventSampler === undefined || eventSampler.sample()) {
|
|
59
|
+
logger.sendTelemetryEvent(event);
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
sendErrorEvent: (event) => {
|
|
63
|
+
if (isSamplingDisabled || eventSampler === undefined || eventSampler.sample()) {
|
|
64
|
+
logger.sendErrorEvent(event);
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
sendPerformanceEvent: (event) => {
|
|
68
|
+
if (isSamplingDisabled || eventSampler === undefined || eventSampler.sample()) {
|
|
69
|
+
logger.sendPerformanceEvent(event);
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
isSamplingDisabled,
|
|
73
|
+
};
|
|
74
|
+
return sampledLogger;
|
|
75
|
+
}
|
|
76
|
+
exports.createSampledLogger = createSampledLogger;
|
|
22
77
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AASA,qCAAqD;AAGrD;;;;;;;;;;;;GAYG;AACH,SAAgB,UAAU,CACzB,SAAkB,EAClB,MAA4B,EAC5B,KAAsC;IAEtC,IAAI,SAAS,EAAE;QACd,OAAO,IAAI,CAAC;KACZ;IACD,MAAM,QAAQ,GACb,OAAO,KAAK,KAAK,QAAQ;QACxB,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE;QACzC,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,KAAK,EAAE,CAAC;IACpC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACtB,OAAO,KAAK,CAAC;AACd,CAAC;AAdD,gCAcC;AA+BD;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,mBAAmB,CAClC,MAA2B,EAC3B,YAA4B;IAE5B,MAAM,iBAAiB,GAAG,IAAA,kCAAyB,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 {\n\tITelemetryBaseEvent,\n\tITelemetryBaseLogger,\n\tITelemetryGenericEvent,\n} from \"@fluidframework/core-interfaces\";\nimport { loggerToMonitoringContext } from \"./config\";\nimport { ITelemetryGenericEventExt, ITelemetryLoggerExt } from \"./telemetryTypes\";\n\n/**\n * Like assert, but logs only if the condition is false, rather than throwing\n * @param condition - The condition to attest too\n * @param logger - The logger to log with\n * @param event - The string or event to log\n * @returns The outcome of the condition\n *\n * @internal\n *\n * @deprecated\n * This API will be removed in a future release.\n * No replacement API is intended, but reproducing its behavior should be trivial for anyone who needs it.\n */\nexport function logIfFalse(\n\tcondition: unknown,\n\tlogger: ITelemetryBaseLogger,\n\tevent: string | ITelemetryGenericEvent,\n): condition is true {\n\tif (condition) {\n\t\treturn true;\n\t}\n\tconst newEvent: ITelemetryBaseEvent =\n\t\ttypeof event === \"string\"\n\t\t\t? { eventName: event, category: \"error\" }\n\t\t\t: { category: \"error\", ...event };\n\tlogger.send(newEvent);\n\treturn false;\n}\n\n/**\n * An object that contains a callback used in conjunction with the {@link createSampledLogger} utility function to provide custom logic for sampling events.\n *\n * @internal\n */\nexport interface IEventSampler {\n\t/**\n\t * @returns true if the event should be sampled or false if not\n\t */\n\tsample: () => boolean | undefined;\n}\n\n/**\n * A telemetry logger that has sampling capabilities\n *\n * @internal\n */\nexport interface ISampledTelemetryLogger extends ITelemetryLoggerExt {\n\t/**\n\t * Indicates if the feature flag to disable sampling is set.\n\t *\n\t * @remarks Exposed to enable some advanced scenarios where the code using the sampled logger\n\t * could take advantage of skipping the execution of some logic when it can determine\n\t * it won't be necessary because the telemetry event that needs it wouldn't be\n\t * emitted anyway.\n\t */\n\tisSamplingDisabled: boolean;\n}\n\n/**\n * Wraps around an existing logger matching the {@link ITelemetryLoggerExt} interface and provides the ability to only log a subset of events using a sampling strategy provided by an ${@link IEventSampler}.\n * You can chose to not provide an event sampler which is effectively a no-op, meaning that it will be treated as if the sampler always returns true.\n *\n * @remarks\n * The sampling functionality uses the Fluid telemetry logging configuration along with the optionally provided event sampling callback to determine whether an event should\n * be logged or not.\n *\n * Configuration object parameters:\n * 'Fluid.Telemetry.DisableSampling': if this config value is set to true, all events will be unsampled and therefore logged.\n * Otherwise only a sample will be logged according to the provided event sampler callback.\n *\n * Note that the same sampler is used for all APIs of the returned logger. If you want separate events flowing through the returned logger to be sampled separately, the {@link IEventSampler} you provide should track them separately.\n *\n * @internal\n */\nexport function createSampledLogger(\n\tlogger: ITelemetryLoggerExt,\n\teventSampler?: IEventSampler,\n): ISampledTelemetryLogger {\n\tconst monitoringContext = loggerToMonitoringContext(logger);\n\tconst isSamplingDisabled =\n\t\tmonitoringContext.config.getBoolean(\"Fluid.Telemetry.DisableSampling\") ?? false;\n\n\tconst sampledLogger = {\n\t\tsend: (event: ITelemetryBaseEvent): void => {\n\t\t\t// The sampler uses the following logic for sending events:\n\t\t\t// 1. If isSamplingDisabled is true, then this means events should be unsampled. Therefore we send the event without any checks.\n\t\t\t// 2. If isSamplingDisabled is false, then event should be sampled using the event sampler, if the sampler is not defined just send all events, other use the eventSampler.sample() method.\n\t\t\tif (isSamplingDisabled || eventSampler === undefined || eventSampler.sample()) {\n\t\t\t\tlogger.send(event);\n\t\t\t}\n\t\t},\n\t\tsendTelemetryEvent: (event: ITelemetryGenericEventExt): void => {\n\t\t\tif (isSamplingDisabled || eventSampler === undefined || eventSampler.sample()) {\n\t\t\t\tlogger.sendTelemetryEvent(event);\n\t\t\t}\n\t\t},\n\t\tsendErrorEvent: (event: ITelemetryGenericEventExt): void => {\n\t\t\tif (isSamplingDisabled || eventSampler === undefined || eventSampler.sample()) {\n\t\t\t\tlogger.sendErrorEvent(event);\n\t\t\t}\n\t\t},\n\t\tsendPerformanceEvent: (event: ITelemetryGenericEventExt): void => {\n\t\t\tif (isSamplingDisabled || eventSampler === undefined || eventSampler.sample()) {\n\t\t\t\tlogger.sendPerformanceEvent(event);\n\t\t\t}\n\t\t},\n\t\tisSamplingDisabled,\n\t};\n\n\treturn sampledLogger;\n}\n"]}
|
package/lib/config.d.ts
CHANGED
|
@@ -2,17 +2,14 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import { ITelemetryBaseLogger,
|
|
6
|
-
import { Lazy } from "@fluidframework/
|
|
7
|
-
|
|
5
|
+
import { ITelemetryBaseLogger, IConfigProviderBase, ConfigTypes } from "@fluidframework/core-interfaces";
|
|
6
|
+
import { Lazy } from "@fluidframework/core-utils";
|
|
7
|
+
import { createChildLogger } from "./logger";
|
|
8
|
+
import { ITelemetryLoggerExt } from "./telemetryTypes";
|
|
8
9
|
/**
|
|
9
|
-
*
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
getRawConfig(name: string): ConfigTypes;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Explicitly typed interface for reading configurations
|
|
10
|
+
* Explicitly typed interface for reading configurations.
|
|
11
|
+
*
|
|
12
|
+
* @internal
|
|
16
13
|
*/
|
|
17
14
|
export interface IConfigProvider extends IConfigProviderBase {
|
|
18
15
|
getBoolean(name: string): boolean | undefined;
|
|
@@ -26,6 +23,8 @@ export interface IConfigProvider extends IConfigProviderBase {
|
|
|
26
23
|
* Creates a base configuration provider based on `sessionStorage`
|
|
27
24
|
*
|
|
28
25
|
* @returns A lazy initialized base configuration provider with `sessionStorage` as the underlying config store
|
|
26
|
+
*
|
|
27
|
+
* @internal
|
|
29
28
|
*/
|
|
30
29
|
export declare const sessionStorageConfigProvider: Lazy<IConfigProviderBase>;
|
|
31
30
|
/**
|
|
@@ -40,9 +39,10 @@ export declare const inMemoryConfigProvider: (storage: Storage | undefined) => I
|
|
|
40
39
|
* Implementation of {@link IConfigProvider} which contains nested {@link IConfigProviderBase} instances
|
|
41
40
|
*/
|
|
42
41
|
export declare class CachedConfigProvider implements IConfigProvider {
|
|
42
|
+
private readonly logger?;
|
|
43
43
|
private readonly configCache;
|
|
44
44
|
private readonly orderedBaseProviders;
|
|
45
|
-
constructor(...orderedBaseProviders: (IConfigProviderBase | undefined)[]);
|
|
45
|
+
constructor(logger?: ITelemetryBaseLogger | undefined, ...orderedBaseProviders: (IConfigProviderBase | undefined)[]);
|
|
46
46
|
getBoolean(name: string): boolean | undefined;
|
|
47
47
|
getNumber(name: string): number | undefined;
|
|
48
48
|
getString(name: string): string | undefined;
|
|
@@ -53,13 +53,44 @@ export declare class CachedConfigProvider implements IConfigProvider {
|
|
|
53
53
|
private getCacheEntry;
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
56
|
-
* A type containing both a telemetry logger and a configuration provider
|
|
56
|
+
* A type containing both a telemetry logger and a configuration provider.
|
|
57
|
+
*
|
|
58
|
+
* @internal
|
|
57
59
|
*/
|
|
58
|
-
export interface MonitoringContext<L extends ITelemetryBaseLogger =
|
|
60
|
+
export interface MonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt> {
|
|
59
61
|
config: IConfigProvider;
|
|
60
62
|
logger: L;
|
|
61
63
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Determines whether or not the provided object is a {@link MonitoringContext}.
|
|
66
|
+
* @remarks Can be used for type-narrowing.
|
|
67
|
+
*
|
|
68
|
+
* @internal
|
|
69
|
+
*/
|
|
70
|
+
export declare function loggerIsMonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt>(obj: L): obj is L & MonitoringContext<L>;
|
|
71
|
+
/**
|
|
72
|
+
* Creates a {@link MonitoringContext} from the provided logger, if it isn't already one.
|
|
73
|
+
*
|
|
74
|
+
* @internal
|
|
75
|
+
*/
|
|
76
|
+
export declare function loggerToMonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt>(logger: L): MonitoringContext<L>;
|
|
77
|
+
/**
|
|
78
|
+
* Creates a {@link MonitoringContext} from the provided logger.
|
|
79
|
+
*
|
|
80
|
+
* @remarks
|
|
81
|
+
* Assumes that the provided logger is not itself already a {@link MonitoringContext}, and will throw an error if it is.
|
|
82
|
+
* If you are unsure, use {@link loggerToMonitoringContext} instead.
|
|
83
|
+
*
|
|
84
|
+
* @throws If the provided logger is already a {@link MonitoringContext}.
|
|
85
|
+
*
|
|
86
|
+
* @internal
|
|
87
|
+
*/
|
|
88
|
+
export declare function mixinMonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt>(logger: L, ...configs: (IConfigProviderBase | undefined)[]): MonitoringContext<L>;
|
|
89
|
+
/**
|
|
90
|
+
* Creates a child logger with a {@link MonitoringContext}.
|
|
91
|
+
*
|
|
92
|
+
* @see {@link loggerToMonitoringContext}
|
|
93
|
+
* @internal
|
|
94
|
+
*/
|
|
95
|
+
export declare function createChildMonitoringContext(props: Parameters<typeof createChildLogger>[0]): MonitoringContext;
|
|
65
96
|
//# sourceMappingURL=config.d.ts.map
|
package/lib/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"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"}
|