@fluidframework/telemetry-utils 1.2.6 → 1.3.0-100520
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/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/sampledTelemetryHelper.d.ts +53 -0
- package/dist/sampledTelemetryHelper.d.ts.map +1 -0
- package/dist/sampledTelemetryHelper.js +92 -0
- package/dist/sampledTelemetryHelper.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.d.ts.map +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/sampledTelemetryHelper.d.ts +53 -0
- package/lib/sampledTelemetryHelper.d.ts.map +1 -0
- package/lib/sampledTelemetryHelper.js +88 -0
- package/lib/sampledTelemetryHelper.js.map +1 -0
- package/package.json +4 -4
- package/src/index.ts +1 -0
- package/src/packageVersion.ts +1 -1
- package/src/sampledTelemetryHelper.ts +142 -0
package/dist/index.d.ts
CHANGED
|
@@ -11,5 +11,6 @@ export * from "./logger";
|
|
|
11
11
|
export * from "./mockLogger";
|
|
12
12
|
export * from "./thresholdCounter";
|
|
13
13
|
export * from "./utils";
|
|
14
|
+
export * from "./sampledTelemetryHelper";
|
|
14
15
|
export { MonitoringContext, IConfigProviderBase, sessionStorageConfigProvider, mixinMonitoringContext, IConfigProvider, ConfigTypes, loggerToMonitoringContext, } from "./config";
|
|
15
16
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iCAAiC,CAAC;AAChD,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,SAAS,CAAC;AACxB,OAAO,EACH,iBAAiB,EACjB,mBAAmB,EACnB,4BAA4B,EAC5B,sBAAsB,EACtB,eAAe,EACf,WAAW,EACX,yBAAyB,GAC5B,MAAM,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iCAAiC,CAAC;AAChD,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,SAAS,CAAC;AACxB,cAAc,0BAA0B,CAAC;AACzC,OAAO,EACH,iBAAiB,EACjB,mBAAmB,EACnB,4BAA4B,EAC5B,sBAAsB,EACtB,eAAe,EACf,WAAW,EACX,yBAAyB,GAC5B,MAAM,UAAU,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -24,6 +24,7 @@ __exportStar(require("./logger"), exports);
|
|
|
24
24
|
__exportStar(require("./mockLogger"), exports);
|
|
25
25
|
__exportStar(require("./thresholdCounter"), exports);
|
|
26
26
|
__exportStar(require("./utils"), exports);
|
|
27
|
+
__exportStar(require("./sampledTelemetryHelper"), exports);
|
|
27
28
|
var config_1 = require("./config");
|
|
28
29
|
Object.defineProperty(exports, "sessionStorageConfigProvider", { enumerable: true, get: function () { return config_1.sessionStorageConfigProvider; } });
|
|
29
30
|
Object.defineProperty(exports, "mixinMonitoringContext", { enumerable: true, get: function () { return config_1.mixinMonitoringContext; } });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA;;;GAGG;AACH,gDAA8B;AAC9B,iDAA+B;AAC/B,kEAAgD;AAChD,2CAAyB;AACzB,mDAAiC;AACjC,2CAAyB;AACzB,+CAA6B;AAC7B,qDAAmC;AACnC,0CAAwB;AACxB,mCAQkB;AALd,sHAAA,4BAA4B,OAAA;AAC5B,gHAAA,sBAAsB,OAAA;AAGtB,mHAAA,yBAAyB,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nexport * from \"./debugLogger\";\nexport * from \"./errorLogging\";\nexport * from \"./eventEmitterWithErrorHandling\";\nexport * from \"./events\";\nexport * from \"./fluidErrorBase\";\nexport * from \"./logger\";\nexport * from \"./mockLogger\";\nexport * from \"./thresholdCounter\";\nexport * from \"./utils\";\nexport {\n MonitoringContext,\n IConfigProviderBase,\n sessionStorageConfigProvider,\n mixinMonitoringContext,\n IConfigProvider,\n ConfigTypes,\n loggerToMonitoringContext,\n} from \"./config\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA;;;GAGG;AACH,gDAA8B;AAC9B,iDAA+B;AAC/B,kEAAgD;AAChD,2CAAyB;AACzB,mDAAiC;AACjC,2CAAyB;AACzB,+CAA6B;AAC7B,qDAAmC;AACnC,0CAAwB;AACxB,2DAAyC;AACzC,mCAQkB;AALd,sHAAA,4BAA4B,OAAA;AAC5B,gHAAA,sBAAsB,OAAA;AAGtB,mHAAA,yBAAyB,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nexport * from \"./debugLogger\";\nexport * from \"./errorLogging\";\nexport * from \"./eventEmitterWithErrorHandling\";\nexport * from \"./events\";\nexport * from \"./fluidErrorBase\";\nexport * from \"./logger\";\nexport * from \"./mockLogger\";\nexport * from \"./thresholdCounter\";\nexport * from \"./utils\";\nexport * from \"./sampledTelemetryHelper\";\nexport {\n MonitoringContext,\n IConfigProviderBase,\n sessionStorageConfigProvider,\n mixinMonitoringContext,\n IConfigProvider,\n ConfigTypes,\n loggerToMonitoringContext,\n} from \"./config\";\n"]}
|
package/dist/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/telemetry-utils";
|
|
8
|
-
export declare const pkgVersion = "1.
|
|
8
|
+
export declare const pkgVersion = "1.3.0-100520";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,oCAAoC,CAAC;AACzD,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,oCAAoC,CAAC;AACzD,eAAO,MAAM,UAAU,iBAAiB,CAAC"}
|
package/dist/packageVersion.js
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.pkgVersion = exports.pkgName = void 0;
|
|
10
10
|
exports.pkgName = "@fluidframework/telemetry-utils";
|
|
11
|
-
exports.pkgVersion = "1.
|
|
11
|
+
exports.pkgVersion = "1.3.0-100520";
|
|
12
12
|
//# sourceMappingURL=packageVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,iCAAiC,CAAC;AAC5C,QAAA,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,iCAAiC,CAAC;AAC5C,QAAA,UAAU,GAAG,cAAc,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/telemetry-utils\";\nexport const pkgVersion = \"1.3.0-100520\";\n"]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { IDisposable, ITelemetryGenericEvent, ITelemetryLogger, ITelemetryProperties } from "@fluidframework/common-definitions";
|
|
6
|
+
/**
|
|
7
|
+
* Helper class that executes a specified code block and writes an
|
|
8
|
+
* {@link @fluidframework/common-definitions#ITelemetryPerformanceEvent} to a specified logger every time a specified
|
|
9
|
+
* number of executions is reached (or when the class is disposed). The `duration` field in the telemetry event is
|
|
10
|
+
* the duration of the latest execution (sample) of the specified function. See the documentation of the
|
|
11
|
+
* `includeAggregateMetrics` parameter for additional details that can be included.
|
|
12
|
+
*/
|
|
13
|
+
export declare class SampledTelemetryHelper implements IDisposable {
|
|
14
|
+
private readonly eventBase;
|
|
15
|
+
private readonly logger;
|
|
16
|
+
private readonly sampleThreshold;
|
|
17
|
+
private readonly includeAggregateMetrics;
|
|
18
|
+
private readonly perBucketProperties;
|
|
19
|
+
disposed: boolean;
|
|
20
|
+
private readonly measurementsMap;
|
|
21
|
+
/**
|
|
22
|
+
* @param eventBase -
|
|
23
|
+
* Custom properties to include in the telemetry performance event when it is written.
|
|
24
|
+
* @param logger -
|
|
25
|
+
* The logger to use to write the telemetry performance event.
|
|
26
|
+
* @param sampleThreshold -
|
|
27
|
+
* Telemetry performance events will be generated every time we hit this many executions of the code block.
|
|
28
|
+
* @param includeAggregateMetrics -
|
|
29
|
+
* If set to `true`, the telemetry performance event will include aggregated metrics (total duration, min duration,
|
|
30
|
+
* max duration) for all the executions in between generated events.
|
|
31
|
+
* @param perBucketProperties -
|
|
32
|
+
* Map of strings that represent different buckets (which can be specified when calling the 'measure' method), to
|
|
33
|
+
* properties which should be added to the telemetry event for that bucket. If a bucket being measured does not
|
|
34
|
+
* have an entry in this map, no additional properties will be added to its telemetry events. The following keys are
|
|
35
|
+
* reserved for use by this class: "duration", "count", "totalDuration", "minDuration", "maxDuration". If any of
|
|
36
|
+
* them is specified as a key in one of the ITelemetryProperties objects in this map, that key-value pair will be
|
|
37
|
+
* ignored.
|
|
38
|
+
*/
|
|
39
|
+
constructor(eventBase: ITelemetryGenericEvent, logger: ITelemetryLogger, sampleThreshold: number, includeAggregateMetrics?: boolean, perBucketProperties?: Map<string, ITelemetryProperties>);
|
|
40
|
+
/**
|
|
41
|
+
* @param codeToMeasure -
|
|
42
|
+
* The code to be executed and measured.
|
|
43
|
+
* @param bucket -
|
|
44
|
+
* A key to track executions of the code block separately. Each different value of this parameter has a separate
|
|
45
|
+
* set of executions and metrics tracked by the class. If no such distinction needs to be made, do not provide a
|
|
46
|
+
* value.
|
|
47
|
+
* @returns Whatever the passed-in code block returns.
|
|
48
|
+
*/
|
|
49
|
+
measure<T>(codeToMeasure: () => T, bucket?: string): T;
|
|
50
|
+
private flushBucket;
|
|
51
|
+
dispose(error?: Error | undefined): void;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=sampledTelemetryHelper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sampledTelemetryHelper.d.ts","sourceRoot":"","sources":["../src/sampledTelemetryHelper.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,WAAW,EACX,sBAAsB,EACtB,gBAAgB,EAEhB,oBAAoB,EACvB,MAAM,oCAAoC,CAAC;AAkC5C;;;;;;GAMG;AACF,qBAAa,sBAAuB,YAAW,WAAW;IAwBnD,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,uBAAuB;IACxC,OAAO,CAAC,QAAQ,CAAC,mBAAmB;IA3BxC,QAAQ,EAAE,OAAO,CAAS;IAE1B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAmC;IAEnE;;;;;;;;;;;;;;;;;OAiBG;gBAEkB,SAAS,EAAE,sBAAsB,EACjC,MAAM,EAAE,gBAAgB,EACxB,eAAe,EAAE,MAAM,EACvB,uBAAuB,GAAE,OAAe,EACxC,mBAAmB,oCAA0C;IAGlF;;;;;;;;OAQG;IACI,OAAO,CAAC,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,MAAM,GAAE,MAAW,GAAG,CAAC;IA0BjE,OAAO,CAAC,WAAW;IAoBZ,OAAO,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,GAAG,IAAI;CAGlD"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.SampledTelemetryHelper = void 0;
|
|
8
|
+
const common_utils_1 = require("@fluidframework/common-utils");
|
|
9
|
+
/**
|
|
10
|
+
* Helper class that executes a specified code block and writes an
|
|
11
|
+
* {@link @fluidframework/common-definitions#ITelemetryPerformanceEvent} to a specified logger every time a specified
|
|
12
|
+
* number of executions is reached (or when the class is disposed). The `duration` field in the telemetry event is
|
|
13
|
+
* the duration of the latest execution (sample) of the specified function. See the documentation of the
|
|
14
|
+
* `includeAggregateMetrics` parameter for additional details that can be included.
|
|
15
|
+
*/
|
|
16
|
+
class SampledTelemetryHelper {
|
|
17
|
+
/**
|
|
18
|
+
* @param eventBase -
|
|
19
|
+
* Custom properties to include in the telemetry performance event when it is written.
|
|
20
|
+
* @param logger -
|
|
21
|
+
* The logger to use to write the telemetry performance event.
|
|
22
|
+
* @param sampleThreshold -
|
|
23
|
+
* Telemetry performance events will be generated every time we hit this many executions of the code block.
|
|
24
|
+
* @param includeAggregateMetrics -
|
|
25
|
+
* If set to `true`, the telemetry performance event will include aggregated metrics (total duration, min duration,
|
|
26
|
+
* max duration) for all the executions in between generated events.
|
|
27
|
+
* @param perBucketProperties -
|
|
28
|
+
* Map of strings that represent different buckets (which can be specified when calling the 'measure' method), to
|
|
29
|
+
* properties which should be added to the telemetry event for that bucket. If a bucket being measured does not
|
|
30
|
+
* have an entry in this map, no additional properties will be added to its telemetry events. The following keys are
|
|
31
|
+
* reserved for use by this class: "duration", "count", "totalDuration", "minDuration", "maxDuration". If any of
|
|
32
|
+
* them is specified as a key in one of the ITelemetryProperties objects in this map, that key-value pair will be
|
|
33
|
+
* ignored.
|
|
34
|
+
*/
|
|
35
|
+
constructor(eventBase, logger, sampleThreshold, includeAggregateMetrics = false, perBucketProperties = new Map()) {
|
|
36
|
+
this.eventBase = eventBase;
|
|
37
|
+
this.logger = logger;
|
|
38
|
+
this.sampleThreshold = sampleThreshold;
|
|
39
|
+
this.includeAggregateMetrics = includeAggregateMetrics;
|
|
40
|
+
this.perBucketProperties = perBucketProperties;
|
|
41
|
+
this.disposed = false;
|
|
42
|
+
this.measurementsMap = new Map();
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* @param codeToMeasure -
|
|
46
|
+
* The code to be executed and measured.
|
|
47
|
+
* @param bucket -
|
|
48
|
+
* A key to track executions of the code block separately. Each different value of this parameter has a separate
|
|
49
|
+
* set of executions and metrics tracked by the class. If no such distinction needs to be made, do not provide a
|
|
50
|
+
* value.
|
|
51
|
+
* @returns Whatever the passed-in code block returns.
|
|
52
|
+
*/
|
|
53
|
+
measure(codeToMeasure, bucket = "") {
|
|
54
|
+
var _a, _b, _c;
|
|
55
|
+
const start = common_utils_1.performance.now();
|
|
56
|
+
const returnValue = codeToMeasure();
|
|
57
|
+
const duration = common_utils_1.performance.now() - start;
|
|
58
|
+
let m = this.measurementsMap.get(bucket);
|
|
59
|
+
if (m === undefined) {
|
|
60
|
+
m = { count: 0, duration: -1 };
|
|
61
|
+
this.measurementsMap.set(bucket, m);
|
|
62
|
+
}
|
|
63
|
+
m.count++;
|
|
64
|
+
m.duration = duration;
|
|
65
|
+
if (this.includeAggregateMetrics) {
|
|
66
|
+
m.totalDuration = ((_a = m.totalDuration) !== null && _a !== void 0 ? _a : 0) + duration;
|
|
67
|
+
m.minDuration = Math.min((_b = m.minDuration) !== null && _b !== void 0 ? _b : duration, duration);
|
|
68
|
+
m.maxDuration = Math.max((_c = m.maxDuration) !== null && _c !== void 0 ? _c : 0, duration);
|
|
69
|
+
}
|
|
70
|
+
if (m.count >= this.sampleThreshold) {
|
|
71
|
+
this.flushBucket(bucket);
|
|
72
|
+
}
|
|
73
|
+
return returnValue;
|
|
74
|
+
}
|
|
75
|
+
flushBucket(bucket) {
|
|
76
|
+
const measurements = this.measurementsMap.get(bucket);
|
|
77
|
+
if (measurements === undefined) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (measurements.count !== 0) {
|
|
81
|
+
const bucketProperties = this.perBucketProperties.get(bucket);
|
|
82
|
+
const telemetryEvent = Object.assign(Object.assign(Object.assign({}, this.eventBase), bucketProperties), measurements);
|
|
83
|
+
this.logger.sendPerformanceEvent(telemetryEvent);
|
|
84
|
+
this.measurementsMap.delete(bucket);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
dispose(error) {
|
|
88
|
+
this.measurementsMap.forEach((_, k) => this.flushBucket(k));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.SampledTelemetryHelper = SampledTelemetryHelper;
|
|
92
|
+
//# sourceMappingURL=sampledTelemetryHelper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sampledTelemetryHelper.js","sourceRoot":"","sources":["../src/sampledTelemetryHelper.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AASH,+DAA2D;AAiC3D;;;;;;GAMG;AACF,MAAa,sBAAsB;IAKhC;;;;;;;;;;;;;;;;;OAiBG;IACH,YACqB,SAAiC,EACjC,MAAwB,EACxB,eAAuB,EACvB,0BAAmC,KAAK,EACxC,sBAAsB,IAAI,GAAG,EAAgC;QAJ7D,cAAS,GAAT,SAAS,CAAwB;QACjC,WAAM,GAAN,MAAM,CAAkB;QACxB,oBAAe,GAAf,eAAe,CAAQ;QACvB,4BAAuB,GAAvB,uBAAuB,CAAiB;QACxC,wBAAmB,GAAnB,mBAAmB,CAA0C;QA3BlF,aAAQ,GAAY,KAAK,CAAC;QAET,oBAAe,GAAG,IAAI,GAAG,EAAwB,CAAC;IA0BnE,CAAC;IAED;;;;;;;;OAQG;IACI,OAAO,CAAI,aAAsB,EAAE,SAAiB,EAAE;;QACzD,MAAM,KAAK,GAAG,0BAAW,CAAC,GAAG,EAAE,CAAC;QAChC,MAAM,WAAW,GAAG,aAAa,EAAE,CAAC;QACpC,MAAM,QAAQ,GAAG,0BAAW,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;QAE3C,IAAI,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACzC,IAAI,CAAC,KAAK,SAAS,EAAE;YACjB,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC;YAC/B,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;SACvC;QACD,CAAC,CAAC,KAAK,EAAE,CAAC;QACV,CAAC,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAEtB,IAAI,IAAI,CAAC,uBAAuB,EAAE;YAC9B,CAAC,CAAC,aAAa,GAAG,CAAC,MAAA,CAAC,CAAC,aAAa,mCAAI,CAAC,CAAC,GAAG,QAAQ,CAAC;YACpD,CAAC,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,MAAA,CAAC,CAAC,WAAW,mCAAI,QAAQ,EAAE,QAAQ,CAAC,CAAC;YAC9D,CAAC,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,MAAA,CAAC,CAAC,WAAW,mCAAI,CAAC,EAAE,QAAQ,CAAC,CAAC;SAC1D;QAED,IAAI,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,eAAe,EAAE;YACjC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;SAC5B;QAED,OAAO,WAAW,CAAC;IACvB,CAAC;IAEO,WAAW,CAAC,MAAc;QAC9B,MAAM,YAAY,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACtD,IAAI,YAAY,KAAK,SAAS,EAAE;YAC5B,OAAO;SACV;QAED,IAAI,YAAY,CAAC,KAAK,KAAK,CAAC,EAAE;YAC1B,MAAM,gBAAgB,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YAE9D,MAAM,cAAc,iDACb,IAAI,CAAC,SAAS,GACd,gBAAgB,GAChB,YAAY,CAClB,CAAC;YAEF,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC,cAAc,CAAC,CAAC;YACjD,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;SACvC;IACL,CAAC;IAEM,OAAO,CAAC,KAAyB;QACpC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IAChE,CAAC;CACJ;AAzFA,wDAyFA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n IDisposable,\n ITelemetryGenericEvent,\n ITelemetryLogger,\n ITelemetryPerformanceEvent,\n ITelemetryProperties,\n} from \"@fluidframework/common-definitions\";\nimport { performance } from \"@fluidframework/common-utils\";\n\ninterface Measurements {\n // The names of the properties in this interface are the ones that will get stamped in the\n // telemetry event, changes should be considered carefully. The optional properties should\n // only be populated if 'includeAggregateMetrics' is true.\n\n /**\n * The duration of the latest execution.\n */\n duration: number;\n\n /**\n * The number of executions since the last time an event was generated.\n */\n count: number;\n\n /**\n * Total duration across all the executions since the last event was generated.\n */\n totalDuration?: number;\n\n /**\n * Min duration across all the executions since the last event was generated.\n */\n minDuration?: number;\n\n /**\n * Max duration across all the executions since the last event was generated.\n */\n maxDuration?: number;\n}\n\n/**\n * Helper class that executes a specified code block and writes an\n * {@link @fluidframework/common-definitions#ITelemetryPerformanceEvent} to a specified logger every time a specified\n * number of executions is reached (or when the class is disposed). The `duration` field in the telemetry event is\n * the duration of the latest execution (sample) of the specified function. See the documentation of the\n * `includeAggregateMetrics` parameter for additional details that can be included.\n */\n export class SampledTelemetryHelper implements IDisposable {\n disposed: boolean = false;\n\n private readonly measurementsMap = new Map<string, Measurements>();\n\n /**\n * @param eventBase -\n * Custom properties to include in the telemetry performance event when it is written.\n * @param logger -\n * The logger to use to write the telemetry performance event.\n * @param sampleThreshold -\n * Telemetry performance events will be generated every time we hit this many executions of the code block.\n * @param includeAggregateMetrics -\n * If set to `true`, the telemetry performance event will include aggregated metrics (total duration, min duration,\n * max duration) for all the executions in between generated events.\n * @param perBucketProperties -\n * Map of strings that represent different buckets (which can be specified when calling the 'measure' method), to\n * properties which should be added to the telemetry event for that bucket. If a bucket being measured does not\n * have an entry in this map, no additional properties will be added to its telemetry events. The following keys are\n * reserved for use by this class: \"duration\", \"count\", \"totalDuration\", \"minDuration\", \"maxDuration\". If any of\n * them is specified as a key in one of the ITelemetryProperties objects in this map, that key-value pair will be\n * ignored.\n */\n public constructor(\n private readonly eventBase: ITelemetryGenericEvent,\n private readonly logger: ITelemetryLogger,\n private readonly sampleThreshold: number,\n private readonly includeAggregateMetrics: boolean = false,\n private readonly perBucketProperties = new Map<string, ITelemetryProperties>()) {\n }\n\n /**\n * @param codeToMeasure -\n * The code to be executed and measured.\n * @param bucket -\n * A key to track executions of the code block separately. Each different value of this parameter has a separate\n * set of executions and metrics tracked by the class. If no such distinction needs to be made, do not provide a\n * value.\n * @returns Whatever the passed-in code block returns.\n */\n public measure<T>(codeToMeasure: () => T, bucket: string = \"\"): T {\n const start = performance.now();\n const returnValue = codeToMeasure();\n const duration = performance.now() - start;\n\n let m = this.measurementsMap.get(bucket);\n if (m === undefined) {\n m = { count: 0, duration: -1 };\n this.measurementsMap.set(bucket, m);\n }\n m.count++;\n m.duration = duration;\n\n if (this.includeAggregateMetrics) {\n m.totalDuration = (m.totalDuration ?? 0) + duration;\n m.minDuration = Math.min(m.minDuration ?? duration, duration);\n m.maxDuration = Math.max(m.maxDuration ?? 0, duration);\n }\n\n if (m.count >= this.sampleThreshold) {\n this.flushBucket(bucket);\n }\n\n return returnValue;\n }\n\n private flushBucket(bucket: string) {\n const measurements = this.measurementsMap.get(bucket);\n if (measurements === undefined) {\n return;\n }\n\n if (measurements.count !== 0) {\n const bucketProperties = this.perBucketProperties.get(bucket);\n\n const telemetryEvent: ITelemetryPerformanceEvent = {\n ...this.eventBase,\n ...bucketProperties, // If the bucket doesn't exist and this is undefined, things work as expected\n ...measurements,\n };\n\n this.logger.sendPerformanceEvent(telemetryEvent);\n this.measurementsMap.delete(bucket);\n }\n }\n\n public dispose(error?: Error | undefined): void {\n this.measurementsMap.forEach((_, k) => this.flushBucket(k));\n }\n}\n"]}
|
package/lib/index.d.ts
CHANGED
|
@@ -11,5 +11,6 @@ export * from "./logger";
|
|
|
11
11
|
export * from "./mockLogger";
|
|
12
12
|
export * from "./thresholdCounter";
|
|
13
13
|
export * from "./utils";
|
|
14
|
+
export * from "./sampledTelemetryHelper";
|
|
14
15
|
export { MonitoringContext, IConfigProviderBase, sessionStorageConfigProvider, mixinMonitoringContext, IConfigProvider, ConfigTypes, loggerToMonitoringContext, } from "./config";
|
|
15
16
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iCAAiC,CAAC;AAChD,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,SAAS,CAAC;AACxB,OAAO,EACH,iBAAiB,EACjB,mBAAmB,EACnB,4BAA4B,EAC5B,sBAAsB,EACtB,eAAe,EACf,WAAW,EACX,yBAAyB,GAC5B,MAAM,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iCAAiC,CAAC;AAChD,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,SAAS,CAAC;AACxB,cAAc,0BAA0B,CAAC;AACzC,OAAO,EACH,iBAAiB,EACjB,mBAAmB,EACnB,4BAA4B,EAC5B,sBAAsB,EACtB,eAAe,EACf,WAAW,EACX,yBAAyB,GAC5B,MAAM,UAAU,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -11,5 +11,6 @@ export * from "./logger";
|
|
|
11
11
|
export * from "./mockLogger";
|
|
12
12
|
export * from "./thresholdCounter";
|
|
13
13
|
export * from "./utils";
|
|
14
|
+
export * from "./sampledTelemetryHelper";
|
|
14
15
|
export { sessionStorageConfigProvider, mixinMonitoringContext, loggerToMonitoringContext, } from "./config";
|
|
15
16
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iCAAiC,CAAC;AAChD,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,SAAS,CAAC;AACxB,OAAO,EAGH,4BAA4B,EAC5B,sBAAsB,EAGtB,yBAAyB,GAC5B,MAAM,UAAU,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nexport * from \"./debugLogger\";\nexport * from \"./errorLogging\";\nexport * from \"./eventEmitterWithErrorHandling\";\nexport * from \"./events\";\nexport * from \"./fluidErrorBase\";\nexport * from \"./logger\";\nexport * from \"./mockLogger\";\nexport * from \"./thresholdCounter\";\nexport * from \"./utils\";\nexport {\n MonitoringContext,\n IConfigProviderBase,\n sessionStorageConfigProvider,\n mixinMonitoringContext,\n IConfigProvider,\n ConfigTypes,\n loggerToMonitoringContext,\n} from \"./config\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iCAAiC,CAAC;AAChD,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,SAAS,CAAC;AACxB,cAAc,0BAA0B,CAAC;AACzC,OAAO,EAGH,4BAA4B,EAC5B,sBAAsB,EAGtB,yBAAyB,GAC5B,MAAM,UAAU,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nexport * from \"./debugLogger\";\nexport * from \"./errorLogging\";\nexport * from \"./eventEmitterWithErrorHandling\";\nexport * from \"./events\";\nexport * from \"./fluidErrorBase\";\nexport * from \"./logger\";\nexport * from \"./mockLogger\";\nexport * from \"./thresholdCounter\";\nexport * from \"./utils\";\nexport * from \"./sampledTelemetryHelper\";\nexport {\n MonitoringContext,\n IConfigProviderBase,\n sessionStorageConfigProvider,\n mixinMonitoringContext,\n IConfigProvider,\n ConfigTypes,\n loggerToMonitoringContext,\n} from \"./config\";\n"]}
|
package/lib/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/telemetry-utils";
|
|
8
|
-
export declare const pkgVersion = "1.
|
|
8
|
+
export declare const pkgVersion = "1.3.0-100520";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,oCAAoC,CAAC;AACzD,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,oCAAoC,CAAC;AACzD,eAAO,MAAM,UAAU,iBAAiB,CAAC"}
|
package/lib/packageVersion.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,iCAAiC,CAAC;AACzD,MAAM,CAAC,MAAM,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,iCAAiC,CAAC;AACzD,MAAM,CAAC,MAAM,UAAU,GAAG,cAAc,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/telemetry-utils\";\nexport const pkgVersion = \"1.3.0-100520\";\n"]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { IDisposable, ITelemetryGenericEvent, ITelemetryLogger, ITelemetryProperties } from "@fluidframework/common-definitions";
|
|
6
|
+
/**
|
|
7
|
+
* Helper class that executes a specified code block and writes an
|
|
8
|
+
* {@link @fluidframework/common-definitions#ITelemetryPerformanceEvent} to a specified logger every time a specified
|
|
9
|
+
* number of executions is reached (or when the class is disposed). The `duration` field in the telemetry event is
|
|
10
|
+
* the duration of the latest execution (sample) of the specified function. See the documentation of the
|
|
11
|
+
* `includeAggregateMetrics` parameter for additional details that can be included.
|
|
12
|
+
*/
|
|
13
|
+
export declare class SampledTelemetryHelper implements IDisposable {
|
|
14
|
+
private readonly eventBase;
|
|
15
|
+
private readonly logger;
|
|
16
|
+
private readonly sampleThreshold;
|
|
17
|
+
private readonly includeAggregateMetrics;
|
|
18
|
+
private readonly perBucketProperties;
|
|
19
|
+
disposed: boolean;
|
|
20
|
+
private readonly measurementsMap;
|
|
21
|
+
/**
|
|
22
|
+
* @param eventBase -
|
|
23
|
+
* Custom properties to include in the telemetry performance event when it is written.
|
|
24
|
+
* @param logger -
|
|
25
|
+
* The logger to use to write the telemetry performance event.
|
|
26
|
+
* @param sampleThreshold -
|
|
27
|
+
* Telemetry performance events will be generated every time we hit this many executions of the code block.
|
|
28
|
+
* @param includeAggregateMetrics -
|
|
29
|
+
* If set to `true`, the telemetry performance event will include aggregated metrics (total duration, min duration,
|
|
30
|
+
* max duration) for all the executions in between generated events.
|
|
31
|
+
* @param perBucketProperties -
|
|
32
|
+
* Map of strings that represent different buckets (which can be specified when calling the 'measure' method), to
|
|
33
|
+
* properties which should be added to the telemetry event for that bucket. If a bucket being measured does not
|
|
34
|
+
* have an entry in this map, no additional properties will be added to its telemetry events. The following keys are
|
|
35
|
+
* reserved for use by this class: "duration", "count", "totalDuration", "minDuration", "maxDuration". If any of
|
|
36
|
+
* them is specified as a key in one of the ITelemetryProperties objects in this map, that key-value pair will be
|
|
37
|
+
* ignored.
|
|
38
|
+
*/
|
|
39
|
+
constructor(eventBase: ITelemetryGenericEvent, logger: ITelemetryLogger, sampleThreshold: number, includeAggregateMetrics?: boolean, perBucketProperties?: Map<string, ITelemetryProperties>);
|
|
40
|
+
/**
|
|
41
|
+
* @param codeToMeasure -
|
|
42
|
+
* The code to be executed and measured.
|
|
43
|
+
* @param bucket -
|
|
44
|
+
* A key to track executions of the code block separately. Each different value of this parameter has a separate
|
|
45
|
+
* set of executions and metrics tracked by the class. If no such distinction needs to be made, do not provide a
|
|
46
|
+
* value.
|
|
47
|
+
* @returns Whatever the passed-in code block returns.
|
|
48
|
+
*/
|
|
49
|
+
measure<T>(codeToMeasure: () => T, bucket?: string): T;
|
|
50
|
+
private flushBucket;
|
|
51
|
+
dispose(error?: Error | undefined): void;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=sampledTelemetryHelper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sampledTelemetryHelper.d.ts","sourceRoot":"","sources":["../src/sampledTelemetryHelper.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,WAAW,EACX,sBAAsB,EACtB,gBAAgB,EAEhB,oBAAoB,EACvB,MAAM,oCAAoC,CAAC;AAkC5C;;;;;;GAMG;AACF,qBAAa,sBAAuB,YAAW,WAAW;IAwBnD,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,uBAAuB;IACxC,OAAO,CAAC,QAAQ,CAAC,mBAAmB;IA3BxC,QAAQ,EAAE,OAAO,CAAS;IAE1B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAmC;IAEnE;;;;;;;;;;;;;;;;;OAiBG;gBAEkB,SAAS,EAAE,sBAAsB,EACjC,MAAM,EAAE,gBAAgB,EACxB,eAAe,EAAE,MAAM,EACvB,uBAAuB,GAAE,OAAe,EACxC,mBAAmB,oCAA0C;IAGlF;;;;;;;;OAQG;IACI,OAAO,CAAC,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,MAAM,GAAE,MAAW,GAAG,CAAC;IA0BjE,OAAO,CAAC,WAAW;IAoBZ,OAAO,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,GAAG,IAAI;CAGlD"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { performance } from "@fluidframework/common-utils";
|
|
6
|
+
/**
|
|
7
|
+
* Helper class that executes a specified code block and writes an
|
|
8
|
+
* {@link @fluidframework/common-definitions#ITelemetryPerformanceEvent} to a specified logger every time a specified
|
|
9
|
+
* number of executions is reached (or when the class is disposed). The `duration` field in the telemetry event is
|
|
10
|
+
* the duration of the latest execution (sample) of the specified function. See the documentation of the
|
|
11
|
+
* `includeAggregateMetrics` parameter for additional details that can be included.
|
|
12
|
+
*/
|
|
13
|
+
export class SampledTelemetryHelper {
|
|
14
|
+
/**
|
|
15
|
+
* @param eventBase -
|
|
16
|
+
* Custom properties to include in the telemetry performance event when it is written.
|
|
17
|
+
* @param logger -
|
|
18
|
+
* The logger to use to write the telemetry performance event.
|
|
19
|
+
* @param sampleThreshold -
|
|
20
|
+
* Telemetry performance events will be generated every time we hit this many executions of the code block.
|
|
21
|
+
* @param includeAggregateMetrics -
|
|
22
|
+
* If set to `true`, the telemetry performance event will include aggregated metrics (total duration, min duration,
|
|
23
|
+
* max duration) for all the executions in between generated events.
|
|
24
|
+
* @param perBucketProperties -
|
|
25
|
+
* Map of strings that represent different buckets (which can be specified when calling the 'measure' method), to
|
|
26
|
+
* properties which should be added to the telemetry event for that bucket. If a bucket being measured does not
|
|
27
|
+
* have an entry in this map, no additional properties will be added to its telemetry events. The following keys are
|
|
28
|
+
* reserved for use by this class: "duration", "count", "totalDuration", "minDuration", "maxDuration". If any of
|
|
29
|
+
* them is specified as a key in one of the ITelemetryProperties objects in this map, that key-value pair will be
|
|
30
|
+
* ignored.
|
|
31
|
+
*/
|
|
32
|
+
constructor(eventBase, logger, sampleThreshold, includeAggregateMetrics = false, perBucketProperties = new Map()) {
|
|
33
|
+
this.eventBase = eventBase;
|
|
34
|
+
this.logger = logger;
|
|
35
|
+
this.sampleThreshold = sampleThreshold;
|
|
36
|
+
this.includeAggregateMetrics = includeAggregateMetrics;
|
|
37
|
+
this.perBucketProperties = perBucketProperties;
|
|
38
|
+
this.disposed = false;
|
|
39
|
+
this.measurementsMap = new Map();
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* @param codeToMeasure -
|
|
43
|
+
* The code to be executed and measured.
|
|
44
|
+
* @param bucket -
|
|
45
|
+
* A key to track executions of the code block separately. Each different value of this parameter has a separate
|
|
46
|
+
* set of executions and metrics tracked by the class. If no such distinction needs to be made, do not provide a
|
|
47
|
+
* value.
|
|
48
|
+
* @returns Whatever the passed-in code block returns.
|
|
49
|
+
*/
|
|
50
|
+
measure(codeToMeasure, bucket = "") {
|
|
51
|
+
var _a, _b, _c;
|
|
52
|
+
const start = performance.now();
|
|
53
|
+
const returnValue = codeToMeasure();
|
|
54
|
+
const duration = performance.now() - start;
|
|
55
|
+
let m = this.measurementsMap.get(bucket);
|
|
56
|
+
if (m === undefined) {
|
|
57
|
+
m = { count: 0, duration: -1 };
|
|
58
|
+
this.measurementsMap.set(bucket, m);
|
|
59
|
+
}
|
|
60
|
+
m.count++;
|
|
61
|
+
m.duration = duration;
|
|
62
|
+
if (this.includeAggregateMetrics) {
|
|
63
|
+
m.totalDuration = ((_a = m.totalDuration) !== null && _a !== void 0 ? _a : 0) + duration;
|
|
64
|
+
m.minDuration = Math.min((_b = m.minDuration) !== null && _b !== void 0 ? _b : duration, duration);
|
|
65
|
+
m.maxDuration = Math.max((_c = m.maxDuration) !== null && _c !== void 0 ? _c : 0, duration);
|
|
66
|
+
}
|
|
67
|
+
if (m.count >= this.sampleThreshold) {
|
|
68
|
+
this.flushBucket(bucket);
|
|
69
|
+
}
|
|
70
|
+
return returnValue;
|
|
71
|
+
}
|
|
72
|
+
flushBucket(bucket) {
|
|
73
|
+
const measurements = this.measurementsMap.get(bucket);
|
|
74
|
+
if (measurements === undefined) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (measurements.count !== 0) {
|
|
78
|
+
const bucketProperties = this.perBucketProperties.get(bucket);
|
|
79
|
+
const telemetryEvent = Object.assign(Object.assign(Object.assign({}, this.eventBase), bucketProperties), measurements);
|
|
80
|
+
this.logger.sendPerformanceEvent(telemetryEvent);
|
|
81
|
+
this.measurementsMap.delete(bucket);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
dispose(error) {
|
|
85
|
+
this.measurementsMap.forEach((_, k) => this.flushBucket(k));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=sampledTelemetryHelper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sampledTelemetryHelper.js","sourceRoot":"","sources":["../src/sampledTelemetryHelper.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAiC3D;;;;;;GAMG;AACF,MAAM,OAAO,sBAAsB;IAKhC;;;;;;;;;;;;;;;;;OAiBG;IACH,YACqB,SAAiC,EACjC,MAAwB,EACxB,eAAuB,EACvB,0BAAmC,KAAK,EACxC,sBAAsB,IAAI,GAAG,EAAgC;QAJ7D,cAAS,GAAT,SAAS,CAAwB;QACjC,WAAM,GAAN,MAAM,CAAkB;QACxB,oBAAe,GAAf,eAAe,CAAQ;QACvB,4BAAuB,GAAvB,uBAAuB,CAAiB;QACxC,wBAAmB,GAAnB,mBAAmB,CAA0C;QA3BlF,aAAQ,GAAY,KAAK,CAAC;QAET,oBAAe,GAAG,IAAI,GAAG,EAAwB,CAAC;IA0BnE,CAAC;IAED;;;;;;;;OAQG;IACI,OAAO,CAAI,aAAsB,EAAE,SAAiB,EAAE;;QACzD,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QAChC,MAAM,WAAW,GAAG,aAAa,EAAE,CAAC;QACpC,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;QAE3C,IAAI,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACzC,IAAI,CAAC,KAAK,SAAS,EAAE;YACjB,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC;YAC/B,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;SACvC;QACD,CAAC,CAAC,KAAK,EAAE,CAAC;QACV,CAAC,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAEtB,IAAI,IAAI,CAAC,uBAAuB,EAAE;YAC9B,CAAC,CAAC,aAAa,GAAG,CAAC,MAAA,CAAC,CAAC,aAAa,mCAAI,CAAC,CAAC,GAAG,QAAQ,CAAC;YACpD,CAAC,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,MAAA,CAAC,CAAC,WAAW,mCAAI,QAAQ,EAAE,QAAQ,CAAC,CAAC;YAC9D,CAAC,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,MAAA,CAAC,CAAC,WAAW,mCAAI,CAAC,EAAE,QAAQ,CAAC,CAAC;SAC1D;QAED,IAAI,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,eAAe,EAAE;YACjC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;SAC5B;QAED,OAAO,WAAW,CAAC;IACvB,CAAC;IAEO,WAAW,CAAC,MAAc;QAC9B,MAAM,YAAY,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACtD,IAAI,YAAY,KAAK,SAAS,EAAE;YAC5B,OAAO;SACV;QAED,IAAI,YAAY,CAAC,KAAK,KAAK,CAAC,EAAE;YAC1B,MAAM,gBAAgB,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YAE9D,MAAM,cAAc,iDACb,IAAI,CAAC,SAAS,GACd,gBAAgB,GAChB,YAAY,CAClB,CAAC;YAEF,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC,cAAc,CAAC,CAAC;YACjD,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;SACvC;IACL,CAAC;IAEM,OAAO,CAAC,KAAyB;QACpC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IAChE,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n IDisposable,\n ITelemetryGenericEvent,\n ITelemetryLogger,\n ITelemetryPerformanceEvent,\n ITelemetryProperties,\n} from \"@fluidframework/common-definitions\";\nimport { performance } from \"@fluidframework/common-utils\";\n\ninterface Measurements {\n // The names of the properties in this interface are the ones that will get stamped in the\n // telemetry event, changes should be considered carefully. The optional properties should\n // only be populated if 'includeAggregateMetrics' is true.\n\n /**\n * The duration of the latest execution.\n */\n duration: number;\n\n /**\n * The number of executions since the last time an event was generated.\n */\n count: number;\n\n /**\n * Total duration across all the executions since the last event was generated.\n */\n totalDuration?: number;\n\n /**\n * Min duration across all the executions since the last event was generated.\n */\n minDuration?: number;\n\n /**\n * Max duration across all the executions since the last event was generated.\n */\n maxDuration?: number;\n}\n\n/**\n * Helper class that executes a specified code block and writes an\n * {@link @fluidframework/common-definitions#ITelemetryPerformanceEvent} to a specified logger every time a specified\n * number of executions is reached (or when the class is disposed). The `duration` field in the telemetry event is\n * the duration of the latest execution (sample) of the specified function. See the documentation of the\n * `includeAggregateMetrics` parameter for additional details that can be included.\n */\n export class SampledTelemetryHelper implements IDisposable {\n disposed: boolean = false;\n\n private readonly measurementsMap = new Map<string, Measurements>();\n\n /**\n * @param eventBase -\n * Custom properties to include in the telemetry performance event when it is written.\n * @param logger -\n * The logger to use to write the telemetry performance event.\n * @param sampleThreshold -\n * Telemetry performance events will be generated every time we hit this many executions of the code block.\n * @param includeAggregateMetrics -\n * If set to `true`, the telemetry performance event will include aggregated metrics (total duration, min duration,\n * max duration) for all the executions in between generated events.\n * @param perBucketProperties -\n * Map of strings that represent different buckets (which can be specified when calling the 'measure' method), to\n * properties which should be added to the telemetry event for that bucket. If a bucket being measured does not\n * have an entry in this map, no additional properties will be added to its telemetry events. The following keys are\n * reserved for use by this class: \"duration\", \"count\", \"totalDuration\", \"minDuration\", \"maxDuration\". If any of\n * them is specified as a key in one of the ITelemetryProperties objects in this map, that key-value pair will be\n * ignored.\n */\n public constructor(\n private readonly eventBase: ITelemetryGenericEvent,\n private readonly logger: ITelemetryLogger,\n private readonly sampleThreshold: number,\n private readonly includeAggregateMetrics: boolean = false,\n private readonly perBucketProperties = new Map<string, ITelemetryProperties>()) {\n }\n\n /**\n * @param codeToMeasure -\n * The code to be executed and measured.\n * @param bucket -\n * A key to track executions of the code block separately. Each different value of this parameter has a separate\n * set of executions and metrics tracked by the class. If no such distinction needs to be made, do not provide a\n * value.\n * @returns Whatever the passed-in code block returns.\n */\n public measure<T>(codeToMeasure: () => T, bucket: string = \"\"): T {\n const start = performance.now();\n const returnValue = codeToMeasure();\n const duration = performance.now() - start;\n\n let m = this.measurementsMap.get(bucket);\n if (m === undefined) {\n m = { count: 0, duration: -1 };\n this.measurementsMap.set(bucket, m);\n }\n m.count++;\n m.duration = duration;\n\n if (this.includeAggregateMetrics) {\n m.totalDuration = (m.totalDuration ?? 0) + duration;\n m.minDuration = Math.min(m.minDuration ?? duration, duration);\n m.maxDuration = Math.max(m.maxDuration ?? 0, duration);\n }\n\n if (m.count >= this.sampleThreshold) {\n this.flushBucket(bucket);\n }\n\n return returnValue;\n }\n\n private flushBucket(bucket: string) {\n const measurements = this.measurementsMap.get(bucket);\n if (measurements === undefined) {\n return;\n }\n\n if (measurements.count !== 0) {\n const bucketProperties = this.perBucketProperties.get(bucket);\n\n const telemetryEvent: ITelemetryPerformanceEvent = {\n ...this.eventBase,\n ...bucketProperties, // If the bucket doesn't exist and this is undefined, things work as expected\n ...measurements,\n };\n\n this.logger.sendPerformanceEvent(telemetryEvent);\n this.measurementsMap.delete(bucket);\n }\n }\n\n public dispose(error?: Error | undefined): void {\n this.measurementsMap.forEach((_, k) => this.flushBucket(k));\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/telemetry-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0-100520",
|
|
4
4
|
"description": "Collection of telemetry relates utilities for Fluid",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -74,8 +74,8 @@
|
|
|
74
74
|
"@fluidframework/build-common": "^0.24.0",
|
|
75
75
|
"@fluidframework/build-tools": "^0.2.74327",
|
|
76
76
|
"@fluidframework/eslint-config-fluid": "^0.28.2000",
|
|
77
|
-
"@fluidframework/mocha-test-setup": "
|
|
78
|
-
"@fluidframework/telemetry-utils-previous": "npm:@fluidframework/telemetry-utils
|
|
77
|
+
"@fluidframework/mocha-test-setup": "1.3.0-100520",
|
|
78
|
+
"@fluidframework/telemetry-utils-previous": "npm:@fluidframework/telemetry-utils@^1.2.0",
|
|
79
79
|
"@microsoft/api-extractor": "^7.22.2",
|
|
80
80
|
"@rushstack/eslint-config": "^2.5.1",
|
|
81
81
|
"@types/debug": "^4.1.5",
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
"typescript": "~4.5.5"
|
|
94
94
|
},
|
|
95
95
|
"typeValidation": {
|
|
96
|
-
"version": "1.
|
|
96
|
+
"version": "1.3.0",
|
|
97
97
|
"broken": {}
|
|
98
98
|
}
|
|
99
99
|
}
|
package/src/index.ts
CHANGED
package/src/packageVersion.ts
CHANGED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
IDisposable,
|
|
8
|
+
ITelemetryGenericEvent,
|
|
9
|
+
ITelemetryLogger,
|
|
10
|
+
ITelemetryPerformanceEvent,
|
|
11
|
+
ITelemetryProperties,
|
|
12
|
+
} from "@fluidframework/common-definitions";
|
|
13
|
+
import { performance } from "@fluidframework/common-utils";
|
|
14
|
+
|
|
15
|
+
interface Measurements {
|
|
16
|
+
// The names of the properties in this interface are the ones that will get stamped in the
|
|
17
|
+
// telemetry event, changes should be considered carefully. The optional properties should
|
|
18
|
+
// only be populated if 'includeAggregateMetrics' is true.
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The duration of the latest execution.
|
|
22
|
+
*/
|
|
23
|
+
duration: number;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The number of executions since the last time an event was generated.
|
|
27
|
+
*/
|
|
28
|
+
count: number;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Total duration across all the executions since the last event was generated.
|
|
32
|
+
*/
|
|
33
|
+
totalDuration?: number;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Min duration across all the executions since the last event was generated.
|
|
37
|
+
*/
|
|
38
|
+
minDuration?: number;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Max duration across all the executions since the last event was generated.
|
|
42
|
+
*/
|
|
43
|
+
maxDuration?: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Helper class that executes a specified code block and writes an
|
|
48
|
+
* {@link @fluidframework/common-definitions#ITelemetryPerformanceEvent} to a specified logger every time a specified
|
|
49
|
+
* number of executions is reached (or when the class is disposed). The `duration` field in the telemetry event is
|
|
50
|
+
* the duration of the latest execution (sample) of the specified function. See the documentation of the
|
|
51
|
+
* `includeAggregateMetrics` parameter for additional details that can be included.
|
|
52
|
+
*/
|
|
53
|
+
export class SampledTelemetryHelper implements IDisposable {
|
|
54
|
+
disposed: boolean = false;
|
|
55
|
+
|
|
56
|
+
private readonly measurementsMap = new Map<string, Measurements>();
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @param eventBase -
|
|
60
|
+
* Custom properties to include in the telemetry performance event when it is written.
|
|
61
|
+
* @param logger -
|
|
62
|
+
* The logger to use to write the telemetry performance event.
|
|
63
|
+
* @param sampleThreshold -
|
|
64
|
+
* Telemetry performance events will be generated every time we hit this many executions of the code block.
|
|
65
|
+
* @param includeAggregateMetrics -
|
|
66
|
+
* If set to `true`, the telemetry performance event will include aggregated metrics (total duration, min duration,
|
|
67
|
+
* max duration) for all the executions in between generated events.
|
|
68
|
+
* @param perBucketProperties -
|
|
69
|
+
* Map of strings that represent different buckets (which can be specified when calling the 'measure' method), to
|
|
70
|
+
* properties which should be added to the telemetry event for that bucket. If a bucket being measured does not
|
|
71
|
+
* have an entry in this map, no additional properties will be added to its telemetry events. The following keys are
|
|
72
|
+
* reserved for use by this class: "duration", "count", "totalDuration", "minDuration", "maxDuration". If any of
|
|
73
|
+
* them is specified as a key in one of the ITelemetryProperties objects in this map, that key-value pair will be
|
|
74
|
+
* ignored.
|
|
75
|
+
*/
|
|
76
|
+
public constructor(
|
|
77
|
+
private readonly eventBase: ITelemetryGenericEvent,
|
|
78
|
+
private readonly logger: ITelemetryLogger,
|
|
79
|
+
private readonly sampleThreshold: number,
|
|
80
|
+
private readonly includeAggregateMetrics: boolean = false,
|
|
81
|
+
private readonly perBucketProperties = new Map<string, ITelemetryProperties>()) {
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @param codeToMeasure -
|
|
86
|
+
* The code to be executed and measured.
|
|
87
|
+
* @param bucket -
|
|
88
|
+
* A key to track executions of the code block separately. Each different value of this parameter has a separate
|
|
89
|
+
* set of executions and metrics tracked by the class. If no such distinction needs to be made, do not provide a
|
|
90
|
+
* value.
|
|
91
|
+
* @returns Whatever the passed-in code block returns.
|
|
92
|
+
*/
|
|
93
|
+
public measure<T>(codeToMeasure: () => T, bucket: string = ""): T {
|
|
94
|
+
const start = performance.now();
|
|
95
|
+
const returnValue = codeToMeasure();
|
|
96
|
+
const duration = performance.now() - start;
|
|
97
|
+
|
|
98
|
+
let m = this.measurementsMap.get(bucket);
|
|
99
|
+
if (m === undefined) {
|
|
100
|
+
m = { count: 0, duration: -1 };
|
|
101
|
+
this.measurementsMap.set(bucket, m);
|
|
102
|
+
}
|
|
103
|
+
m.count++;
|
|
104
|
+
m.duration = duration;
|
|
105
|
+
|
|
106
|
+
if (this.includeAggregateMetrics) {
|
|
107
|
+
m.totalDuration = (m.totalDuration ?? 0) + duration;
|
|
108
|
+
m.minDuration = Math.min(m.minDuration ?? duration, duration);
|
|
109
|
+
m.maxDuration = Math.max(m.maxDuration ?? 0, duration);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (m.count >= this.sampleThreshold) {
|
|
113
|
+
this.flushBucket(bucket);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return returnValue;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
private flushBucket(bucket: string) {
|
|
120
|
+
const measurements = this.measurementsMap.get(bucket);
|
|
121
|
+
if (measurements === undefined) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (measurements.count !== 0) {
|
|
126
|
+
const bucketProperties = this.perBucketProperties.get(bucket);
|
|
127
|
+
|
|
128
|
+
const telemetryEvent: ITelemetryPerformanceEvent = {
|
|
129
|
+
...this.eventBase,
|
|
130
|
+
...bucketProperties, // If the bucket doesn't exist and this is undefined, things work as expected
|
|
131
|
+
...measurements,
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
this.logger.sendPerformanceEvent(telemetryEvent);
|
|
135
|
+
this.measurementsMap.delete(bucket);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
public dispose(error?: Error | undefined): void {
|
|
140
|
+
this.measurementsMap.forEach((_, k) => this.flushBucket(k));
|
|
141
|
+
}
|
|
142
|
+
}
|