@fluidframework/telemetry-utils 2.0.0-internal.7.0.1 → 2.0.0-internal.7.1.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/CHANGELOG.md +4 -0
- package/api-extractor.json +9 -1
- package/api-report/telemetry-utils.api.md +444 -0
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +2 -1
- package/dist/error.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +48 -4
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +62 -8
- package/dist/logger.js.map +1 -1
- package/dist/telemetry-utils-alpha.d.ts +668 -0
- package/dist/telemetry-utils-beta.d.ts +668 -0
- package/dist/telemetry-utils-public.d.ts +668 -0
- package/dist/telemetry-utils.d.ts +909 -0
- package/dist/tsdoc-metadata.json +1 -1
- package/dist/utils.d.ts +45 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +50 -1
- package/dist/utils.js.map +1 -1
- package/lib/error.d.ts.map +1 -1
- package/lib/error.js +2 -1
- package/lib/error.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/logger.d.ts +48 -4
- package/lib/logger.d.ts.map +1 -1
- package/lib/logger.js +62 -8
- package/lib/logger.js.map +1 -1
- package/lib/utils.d.ts +45 -0
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +48 -0
- package/lib/utils.js.map +1 -1
- package/package.json +14 -14
- package/src/error.ts +7 -3
- package/src/index.ts +1 -1
- package/src/logger.ts +74 -6
- package/src/utils.ts +85 -0
package/src/utils.ts
CHANGED
|
@@ -7,6 +7,8 @@ import {
|
|
|
7
7
|
ITelemetryBaseLogger,
|
|
8
8
|
ITelemetryGenericEvent,
|
|
9
9
|
} from "@fluidframework/core-interfaces";
|
|
10
|
+
import { loggerToMonitoringContext } from "./config";
|
|
11
|
+
import { ITelemetryGenericEventExt, ITelemetryLoggerExt } from "./telemetryTypes";
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
14
|
* Like assert, but logs only if the condition is false, rather than throwing
|
|
@@ -30,3 +32,86 @@ export function logIfFalse(
|
|
|
30
32
|
logger.send(newEvent);
|
|
31
33
|
return false;
|
|
32
34
|
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* An object that contains a callback used in conjunction with the {@link createSampledLogger} utility function to provide custom logic for sampling events.
|
|
38
|
+
*
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
export interface IEventSampler {
|
|
42
|
+
/**
|
|
43
|
+
* @returns true if the event should be sampled or false if not
|
|
44
|
+
*/
|
|
45
|
+
sample: () => boolean | undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* A telemetry logger that has sampling capabilities
|
|
50
|
+
*
|
|
51
|
+
* @internal
|
|
52
|
+
*/
|
|
53
|
+
export interface ISampledTelemetryLogger extends ITelemetryLoggerExt {
|
|
54
|
+
/**
|
|
55
|
+
* Indicates if the feature flag to disable sampling is set.
|
|
56
|
+
*
|
|
57
|
+
* @remarks Exposed to enable some advanced scenarios where the code using the sampled logger
|
|
58
|
+
* could take advantage of skipping the execution of some logic when it can determine
|
|
59
|
+
* it won't be necessary because the telemetry event that needs it wouldn't be
|
|
60
|
+
* emitted anyway.
|
|
61
|
+
*/
|
|
62
|
+
isSamplingDisabled: boolean;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 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}.
|
|
67
|
+
* 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.
|
|
68
|
+
*
|
|
69
|
+
* @remarks
|
|
70
|
+
* The sampling functionality uses the Fluid telemetry logging configuration along with the optionally provided event sampling callback to determine whether an event should
|
|
71
|
+
* be logged or not.
|
|
72
|
+
*
|
|
73
|
+
* Configuration object parameters:
|
|
74
|
+
* 'Fluid.Telemetry.DisableSampling': if this config value is set to true, all events will be unsampled and therefore logged.
|
|
75
|
+
* Otherwise only a sample will be logged according to the provided event sampler callback.
|
|
76
|
+
*
|
|
77
|
+
* 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.
|
|
78
|
+
*
|
|
79
|
+
* @internal
|
|
80
|
+
*/
|
|
81
|
+
export function createSampledLogger(
|
|
82
|
+
logger: ITelemetryLoggerExt,
|
|
83
|
+
eventSampler?: IEventSampler,
|
|
84
|
+
): ISampledTelemetryLogger {
|
|
85
|
+
const monitoringContext = loggerToMonitoringContext(logger);
|
|
86
|
+
const isSamplingDisabled =
|
|
87
|
+
monitoringContext.config.getBoolean("Fluid.Telemetry.DisableSampling") ?? false;
|
|
88
|
+
|
|
89
|
+
const sampledLogger = {
|
|
90
|
+
send: (event: ITelemetryBaseEvent): void => {
|
|
91
|
+
// The sampler uses the following logic for sending events:
|
|
92
|
+
// 1. If isSamplingDisabled is true, then this means events should be unsampled. Therefore we send the event without any checks.
|
|
93
|
+
// 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.
|
|
94
|
+
if (isSamplingDisabled || eventSampler === undefined || eventSampler.sample()) {
|
|
95
|
+
logger.send(event);
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
sendTelemetryEvent: (event: ITelemetryGenericEventExt): void => {
|
|
99
|
+
if (isSamplingDisabled || eventSampler === undefined || eventSampler.sample()) {
|
|
100
|
+
logger.sendTelemetryEvent(event);
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
sendErrorEvent: (event: ITelemetryGenericEventExt): void => {
|
|
104
|
+
if (isSamplingDisabled || eventSampler === undefined || eventSampler.sample()) {
|
|
105
|
+
logger.sendErrorEvent(event);
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
sendPerformanceEvent: (event: ITelemetryGenericEventExt): void => {
|
|
109
|
+
if (isSamplingDisabled || eventSampler === undefined || eventSampler.sample()) {
|
|
110
|
+
logger.sendPerformanceEvent(event);
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
isSamplingDisabled,
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
return sampledLogger;
|
|
117
|
+
}
|