@fluidframework/telemetry-utils 2.0.0-internal.6.1.1 → 2.0.0-internal.6.3.0
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 +2 -1
- package/CHANGELOG.md +59 -0
- package/README.md +4 -3
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +9 -4
- package/dist/config.js.map +1 -1
- package/dist/error.d.ts +92 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +133 -0
- package/dist/error.js.map +1 -0
- package/dist/errorLogging.d.ts +34 -18
- package/dist/errorLogging.d.ts.map +1 -1
- package/dist/errorLogging.js +42 -17
- package/dist/errorLogging.js.map +1 -1
- package/dist/eventEmitterWithErrorHandling.d.ts +3 -3
- package/dist/eventEmitterWithErrorHandling.d.ts.map +1 -1
- package/dist/eventEmitterWithErrorHandling.js +10 -3
- package/dist/eventEmitterWithErrorHandling.js.map +1 -1
- package/dist/events.d.ts +1 -1
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js.map +1 -1
- package/dist/fluidErrorBase.d.ts +48 -15
- package/dist/fluidErrorBase.d.ts.map +1 -1
- package/dist/fluidErrorBase.js +18 -11
- package/dist/fluidErrorBase.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +38 -22
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +68 -21
- package/dist/logger.js.map +1 -1
- package/dist/mockLogger.d.ts +17 -6
- package/dist/mockLogger.d.ts.map +1 -1
- package/dist/mockLogger.js +22 -9
- package/dist/mockLogger.js.map +1 -1
- package/dist/sampledTelemetryHelper.d.ts +8 -7
- package/dist/sampledTelemetryHelper.d.ts.map +1 -1
- package/dist/sampledTelemetryHelper.js +13 -11
- package/dist/sampledTelemetryHelper.js.map +1 -1
- package/dist/telemetryTypes.d.ts +20 -6
- package/dist/telemetryTypes.d.ts.map +1 -1
- package/dist/telemetryTypes.js.map +1 -1
- package/dist/thresholdCounter.d.ts.map +1 -1
- package/dist/thresholdCounter.js.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js.map +1 -1
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +9 -4
- package/lib/config.js.map +1 -1
- package/lib/error.d.ts +92 -0
- package/lib/error.d.ts.map +1 -0
- package/lib/error.js +125 -0
- package/lib/error.js.map +1 -0
- package/lib/errorLogging.d.ts +34 -18
- package/lib/errorLogging.d.ts.map +1 -1
- package/lib/errorLogging.js +42 -17
- package/lib/errorLogging.js.map +1 -1
- package/lib/eventEmitterWithErrorHandling.d.ts +3 -3
- package/lib/eventEmitterWithErrorHandling.d.ts.map +1 -1
- package/lib/eventEmitterWithErrorHandling.js +9 -2
- package/lib/eventEmitterWithErrorHandling.js.map +1 -1
- package/lib/events.d.ts +1 -1
- package/lib/events.d.ts.map +1 -1
- package/lib/events.js.map +1 -1
- package/lib/fluidErrorBase.d.ts +48 -15
- package/lib/fluidErrorBase.d.ts.map +1 -1
- package/lib/fluidErrorBase.js +18 -11
- package/lib/fluidErrorBase.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/logger.d.ts +38 -22
- package/lib/logger.d.ts.map +1 -1
- package/lib/logger.js +64 -17
- package/lib/logger.js.map +1 -1
- package/lib/mockLogger.d.ts +17 -6
- package/lib/mockLogger.d.ts.map +1 -1
- package/lib/mockLogger.js +22 -9
- package/lib/mockLogger.js.map +1 -1
- package/lib/sampledTelemetryHelper.d.ts +8 -7
- package/lib/sampledTelemetryHelper.d.ts.map +1 -1
- package/lib/sampledTelemetryHelper.js +11 -9
- package/lib/sampledTelemetryHelper.js.map +1 -1
- package/lib/telemetryTypes.d.ts +20 -6
- package/lib/telemetryTypes.d.ts.map +1 -1
- package/lib/telemetryTypes.js.map +1 -1
- package/lib/thresholdCounter.d.ts.map +1 -1
- package/lib/thresholdCounter.js.map +1 -1
- package/lib/utils.d.ts +1 -1
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js.map +1 -1
- package/package.json +15 -18
- package/src/config.ts +12 -7
- package/src/error.ts +202 -0
- package/src/errorLogging.ts +90 -52
- package/src/eventEmitterWithErrorHandling.ts +5 -3
- package/src/events.ts +3 -3
- package/src/fluidErrorBase.ts +62 -26
- package/src/index.ts +8 -0
- package/src/logger.ts +143 -45
- package/src/mockLogger.ts +33 -16
- package/src/sampledTelemetryHelper.ts +18 -14
- package/src/telemetryTypes.ts +29 -6
- package/src/thresholdCounter.ts +2 -2
- package/src/utils.ts +1 -1
package/dist/logger.d.ts
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import { ITelemetryBaseEvent, ITelemetryBaseLogger, ITelemetryErrorEvent, ITelemetryGenericEvent, ITelemetryPerformanceEvent, ITelemetryProperties, TelemetryEventPropertyType,
|
|
6
|
-
import { IsomorphicPerformance } from "@
|
|
7
|
-
import {
|
|
5
|
+
import { ITelemetryBaseEvent, ITelemetryBaseLogger, ITelemetryErrorEvent, ITelemetryGenericEvent, ITelemetryPerformanceEvent, ITelemetryProperties, TelemetryBaseEventPropertyType as TelemetryEventPropertyType, LogLevel, Tagged, ITelemetryBaseProperties } from "@fluidframework/core-interfaces";
|
|
6
|
+
import { IsomorphicPerformance } from "@fluid-internal/client-utils";
|
|
7
|
+
import { ITelemetryGenericEventExt, ITelemetryLoggerExt, ITelemetryPerformanceEventExt, TelemetryEventPropertyTypeExt, TelemetryEventCategory } from "./telemetryTypes";
|
|
8
8
|
export interface Memory {
|
|
9
9
|
usedJSHeapSize: number;
|
|
10
10
|
}
|
|
@@ -16,12 +16,16 @@ export interface PerformanceWithMemory extends IsomorphicPerformance {
|
|
|
16
16
|
* Please do not modify existing entries for backwards compatibility.
|
|
17
17
|
*/
|
|
18
18
|
export declare enum TelemetryDataTag {
|
|
19
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Data containing terms or IDs from code packages that may have been dynamically loaded
|
|
21
|
+
*/
|
|
20
22
|
CodeArtifact = "CodeArtifact",
|
|
21
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* Personal data of a variety of classifications that pertains to the user
|
|
25
|
+
*/
|
|
22
26
|
UserData = "UserData"
|
|
23
27
|
}
|
|
24
|
-
export declare type TelemetryEventPropertyTypes =
|
|
28
|
+
export declare type TelemetryEventPropertyTypes = ITelemetryBaseProperties[string];
|
|
25
29
|
export interface ITelemetryLoggerPropertyBag {
|
|
26
30
|
[index: string]: TelemetryEventPropertyTypes | (() => TelemetryEventPropertyTypes);
|
|
27
31
|
}
|
|
@@ -42,7 +46,6 @@ export declare const eventNamespaceSeparator: ":";
|
|
|
42
46
|
* TelemetryLogger class contains various helper telemetry methods,
|
|
43
47
|
* encoding in one place schemas for various types of Fluid telemetry events.
|
|
44
48
|
* Creates sub-logger that appends properties to all events
|
|
45
|
-
*
|
|
46
49
|
*/
|
|
47
50
|
export declare abstract class TelemetryLogger implements ITelemetryLoggerExt {
|
|
48
51
|
protected readonly namespace?: string | undefined;
|
|
@@ -56,44 +59,49 @@ export declare abstract class TelemetryLogger implements ITelemetryLoggerExt {
|
|
|
56
59
|
* @param error - Error to extract info from
|
|
57
60
|
* @param fetchStack - Whether to fetch the current callstack if error.stack is undefined
|
|
58
61
|
*/
|
|
59
|
-
static prepareErrorObject(event: ITelemetryBaseEvent, error:
|
|
62
|
+
static prepareErrorObject(event: ITelemetryBaseEvent, error: unknown, fetchStack: boolean): void;
|
|
60
63
|
constructor(namespace?: string | undefined, properties?: ITelemetryLoggerPropertyBags | undefined);
|
|
61
64
|
/**
|
|
62
65
|
* Send an event with the logger
|
|
63
66
|
*
|
|
64
67
|
* @param event - the event to send
|
|
65
68
|
*/
|
|
66
|
-
abstract send(event: ITelemetryBaseEvent): void;
|
|
69
|
+
abstract send(event: ITelemetryBaseEvent, logLevel?: LogLevel): void;
|
|
67
70
|
/**
|
|
68
71
|
* Send a telemetry event with the logger
|
|
69
72
|
*
|
|
70
73
|
* @param event - the event to send
|
|
71
74
|
* @param error - optional error object to log
|
|
75
|
+
* @param logLevel - optional level of the log. It category of event is set as error,
|
|
76
|
+
* then the logLevel will be upgraded to be an error.
|
|
72
77
|
*/
|
|
73
|
-
sendTelemetryEvent(event: ITelemetryGenericEventExt, error?:
|
|
78
|
+
sendTelemetryEvent(event: ITelemetryGenericEventExt, error?: unknown, logLevel?: typeof LogLevel.verbose | typeof LogLevel.default): void;
|
|
74
79
|
/**
|
|
75
80
|
* Send a telemetry event with the logger
|
|
76
81
|
*
|
|
77
82
|
* @param event - the event to send
|
|
78
83
|
* @param error - optional error object to log
|
|
84
|
+
* @param logLevel - optional level of the log.
|
|
79
85
|
*/
|
|
80
86
|
protected sendTelemetryEventCore(event: ITelemetryGenericEventExt & {
|
|
81
87
|
category: TelemetryEventCategory;
|
|
82
|
-
}, error?:
|
|
88
|
+
}, error?: unknown, logLevel?: LogLevel): void;
|
|
83
89
|
/**
|
|
84
90
|
* Send an error telemetry event with the logger
|
|
85
91
|
*
|
|
86
92
|
* @param event - the event to send
|
|
87
93
|
* @param error - optional error object to log
|
|
88
94
|
*/
|
|
89
|
-
sendErrorEvent(event: ITelemetryErrorEvent, error?:
|
|
95
|
+
sendErrorEvent(event: ITelemetryErrorEvent, error?: unknown): void;
|
|
90
96
|
/**
|
|
91
97
|
* Send a performance telemetry event with the logger
|
|
92
98
|
*
|
|
93
99
|
* @param event - Event to send
|
|
94
100
|
* @param error - optional error object to log
|
|
101
|
+
* @param logLevel - optional level of the log. It category of event is set as error,
|
|
102
|
+
* then the logLevel will be upgraded to be an error.
|
|
95
103
|
*/
|
|
96
|
-
sendPerformanceEvent(event: ITelemetryPerformanceEventExt, error?:
|
|
104
|
+
sendPerformanceEvent(event: ITelemetryPerformanceEventExt, error?: unknown, logLevel?: typeof LogLevel.verbose | typeof LogLevel.default): void;
|
|
97
105
|
protected prepareEvent(event: ITelemetryBaseEvent): ITelemetryBaseEvent;
|
|
98
106
|
private extendProperties;
|
|
99
107
|
}
|
|
@@ -105,6 +113,9 @@ export declare abstract class TelemetryLogger implements ITelemetryLoggerExt {
|
|
|
105
113
|
export declare class TaggedLoggerAdapter implements ITelemetryBaseLogger {
|
|
106
114
|
private readonly logger;
|
|
107
115
|
constructor(logger: ITelemetryBaseLogger);
|
|
116
|
+
/**
|
|
117
|
+
* {@inheritDoc @fluidframework/core-interfaces#ITelemetryBaseLogger.send}
|
|
118
|
+
*/
|
|
108
119
|
send(eventWithTagsMaybe: ITelemetryBaseEvent): void;
|
|
109
120
|
}
|
|
110
121
|
/**
|
|
@@ -135,12 +146,14 @@ export declare class ChildLogger extends TelemetryLogger {
|
|
|
135
146
|
*/
|
|
136
147
|
static create(baseLogger?: ITelemetryBaseLogger, namespace?: string, properties?: ITelemetryLoggerPropertyBags): TelemetryLogger;
|
|
137
148
|
private constructor();
|
|
149
|
+
get minLogLevel(): LogLevel | undefined;
|
|
150
|
+
private shouldFilterOutEvent;
|
|
138
151
|
/**
|
|
139
152
|
* Send an event with the logger
|
|
140
153
|
*
|
|
141
154
|
* @param event - the event to send
|
|
142
155
|
*/
|
|
143
|
-
send(event: ITelemetryBaseEvent): void;
|
|
156
|
+
send(event: ITelemetryBaseEvent, logLevel?: LogLevel): void;
|
|
144
157
|
}
|
|
145
158
|
/**
|
|
146
159
|
* Create a logger which logs to multiple other loggers based on the provided props object
|
|
@@ -159,6 +172,7 @@ export declare function createMultiSinkLogger(props: {
|
|
|
159
172
|
*/
|
|
160
173
|
export declare class MultiSinkLogger extends TelemetryLogger {
|
|
161
174
|
protected loggers: ITelemetryBaseLogger[];
|
|
175
|
+
private _minLogLevelOfAllLoggers;
|
|
162
176
|
/**
|
|
163
177
|
* Create multiple sink logger (i.e. logger that sends events to multiple sinks)
|
|
164
178
|
* @param namespace - Telemetry event name prefix to add to all events
|
|
@@ -167,6 +181,8 @@ export declare class MultiSinkLogger extends TelemetryLogger {
|
|
|
167
181
|
* @param tryInheritProperties - Will attempted to copy those loggers properties to this loggers if they are of a known type e.g. one from this package
|
|
168
182
|
*/
|
|
169
183
|
constructor(namespace?: string, properties?: ITelemetryLoggerPropertyBags, loggers?: ITelemetryBaseLogger[], tryInheritProperties?: true);
|
|
184
|
+
get minLogLevel(): LogLevel;
|
|
185
|
+
private calculateMinLogLevel;
|
|
170
186
|
/**
|
|
171
187
|
* Add logger to send all events to
|
|
172
188
|
* @param logger - Logger to add
|
|
@@ -210,11 +226,11 @@ export declare class PerformanceEvent {
|
|
|
210
226
|
private autoEnd;
|
|
211
227
|
end(props?: ITelemetryProperties): void;
|
|
212
228
|
private performanceEndMark;
|
|
213
|
-
cancel(props?: ITelemetryProperties, error?:
|
|
229
|
+
cancel(props?: ITelemetryProperties, error?: unknown): void;
|
|
214
230
|
/**
|
|
215
231
|
* Report the event, if it hasn't already been reported.
|
|
216
232
|
*/
|
|
217
|
-
reportEvent(eventNameSuffix: string, props?: ITelemetryProperties, error?:
|
|
233
|
+
reportEvent(eventNameSuffix: string, props?: ITelemetryProperties, error?: unknown): void;
|
|
218
234
|
}
|
|
219
235
|
/**
|
|
220
236
|
* Null logger that no-ops for all telemetry events passed to it.
|
|
@@ -225,20 +241,20 @@ export declare class PerformanceEvent {
|
|
|
225
241
|
*/
|
|
226
242
|
export declare class TelemetryNullLogger implements ITelemetryLoggerExt {
|
|
227
243
|
send(event: ITelemetryBaseEvent): void;
|
|
228
|
-
sendTelemetryEvent(event: ITelemetryGenericEvent, error?:
|
|
229
|
-
sendErrorEvent(event: ITelemetryErrorEvent, error?:
|
|
230
|
-
sendPerformanceEvent(event: ITelemetryPerformanceEvent, error?:
|
|
244
|
+
sendTelemetryEvent(event: ITelemetryGenericEvent, error?: unknown): void;
|
|
245
|
+
sendErrorEvent(event: ITelemetryErrorEvent, error?: unknown): void;
|
|
246
|
+
sendPerformanceEvent(event: ITelemetryPerformanceEvent, error?: unknown): void;
|
|
231
247
|
}
|
|
232
248
|
/**
|
|
233
249
|
* Takes in value, and does one of 4 things.
|
|
234
250
|
* if value is of primitive type - returns the original value.
|
|
235
|
-
* If the value is
|
|
236
|
-
* If the value is an object of type
|
|
251
|
+
* If the value is a flat array or object - returns a stringified version of the array/object.
|
|
252
|
+
* If the value is an object of type Tagged<TelemetryEventPropertyType> - returns the object
|
|
237
253
|
* with its values recursively converted to base property Type.
|
|
238
254
|
* If none of these cases are reached - returns an error string
|
|
239
255
|
* @param x - value passed in to convert to a base property type
|
|
240
256
|
*/
|
|
241
|
-
export declare function convertToBasePropertyType(x: TelemetryEventPropertyTypeExt |
|
|
257
|
+
export declare function convertToBasePropertyType(x: TelemetryEventPropertyTypeExt | Tagged<TelemetryEventPropertyTypeExt>): TelemetryEventPropertyType | Tagged<TelemetryEventPropertyType>;
|
|
242
258
|
export declare const tagData: <T extends TelemetryDataTag, V extends Record<string, TelemetryEventPropertyTypeExt>>(tag: T, values: V) => { [P in keyof V]: {
|
|
243
259
|
value: Exclude<V[P], undefined>;
|
|
244
260
|
tag: T;
|
package/dist/logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,EACtB,0BAA0B,EAC1B,oBAAoB,EACpB,0BAA0B,
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,EACtB,0BAA0B,EAC1B,oBAAoB,EACpB,8BAA8B,IAAI,0BAA0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: true });
|
|
7
7
|
exports.tagCodeArtifacts = exports.tagData = exports.convertToBasePropertyType = exports.TelemetryNullLogger = exports.PerformanceEvent = exports.MultiSinkLogger = exports.createMultiSinkLogger = exports.ChildLogger = exports.createChildLogger = exports.TaggedLoggerAdapter = exports.TelemetryLogger = exports.eventNamespaceSeparator = exports.formatTick = exports.numberFromString = exports.TelemetryDataTag = void 0;
|
|
8
|
-
const
|
|
8
|
+
const core_interfaces_1 = require("@fluidframework/core-interfaces");
|
|
9
|
+
const client_utils_1 = require("@fluid-internal/client-utils");
|
|
9
10
|
const config_1 = require("./config");
|
|
10
11
|
const errorLogging_1 = require("./errorLogging");
|
|
11
12
|
/**
|
|
@@ -14,9 +15,13 @@ const errorLogging_1 = require("./errorLogging");
|
|
|
14
15
|
*/
|
|
15
16
|
var TelemetryDataTag;
|
|
16
17
|
(function (TelemetryDataTag) {
|
|
17
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Data containing terms or IDs from code packages that may have been dynamically loaded
|
|
20
|
+
*/
|
|
18
21
|
TelemetryDataTag["CodeArtifact"] = "CodeArtifact";
|
|
19
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* Personal data of a variety of classifications that pertains to the user
|
|
24
|
+
*/
|
|
20
25
|
TelemetryDataTag["UserData"] = "UserData";
|
|
21
26
|
})(TelemetryDataTag = exports.TelemetryDataTag || (exports.TelemetryDataTag = {}));
|
|
22
27
|
/**
|
|
@@ -25,6 +30,7 @@ var TelemetryDataTag;
|
|
|
25
30
|
* Used to make telemetry data typed (and support math operations, like comparison),
|
|
26
31
|
* in places where we do expect numbers (like contentsize/duration property in http header)
|
|
27
32
|
*/
|
|
33
|
+
// eslint-disable-next-line @rushstack/no-new-null
|
|
28
34
|
function numberFromString(str) {
|
|
29
35
|
if (str === undefined || str === null) {
|
|
30
36
|
return undefined;
|
|
@@ -42,7 +48,6 @@ exports.eventNamespaceSeparator = ":";
|
|
|
42
48
|
* TelemetryLogger class contains various helper telemetry methods,
|
|
43
49
|
* encoding in one place schemas for various types of Fluid telemetry events.
|
|
44
50
|
* Creates sub-logger that appends properties to all events
|
|
45
|
-
*
|
|
46
51
|
*/
|
|
47
52
|
class TelemetryLogger {
|
|
48
53
|
constructor(namespace, properties) {
|
|
@@ -86,17 +91,20 @@ class TelemetryLogger {
|
|
|
86
91
|
*
|
|
87
92
|
* @param event - the event to send
|
|
88
93
|
* @param error - optional error object to log
|
|
94
|
+
* @param logLevel - optional level of the log. It category of event is set as error,
|
|
95
|
+
* then the logLevel will be upgraded to be an error.
|
|
89
96
|
*/
|
|
90
|
-
sendTelemetryEvent(event, error) {
|
|
91
|
-
this.sendTelemetryEventCore({ ...event, category: event.category ?? "generic" }, error);
|
|
97
|
+
sendTelemetryEvent(event, error, logLevel = core_interfaces_1.LogLevel.default) {
|
|
98
|
+
this.sendTelemetryEventCore({ ...event, category: event.category ?? "generic" }, error, event.category === "error" ? core_interfaces_1.LogLevel.error : logLevel);
|
|
92
99
|
}
|
|
93
100
|
/**
|
|
94
101
|
* Send a telemetry event with the logger
|
|
95
102
|
*
|
|
96
103
|
* @param event - the event to send
|
|
97
104
|
* @param error - optional error object to log
|
|
105
|
+
* @param logLevel - optional level of the log.
|
|
98
106
|
*/
|
|
99
|
-
sendTelemetryEventCore(event, error) {
|
|
107
|
+
sendTelemetryEventCore(event, error, logLevel) {
|
|
100
108
|
const newEvent = convertToBaseEvent(event);
|
|
101
109
|
if (error !== undefined) {
|
|
102
110
|
TelemetryLogger.prepareErrorObject(newEvent, error, false);
|
|
@@ -105,7 +113,7 @@ class TelemetryLogger {
|
|
|
105
113
|
if (typeof newEvent.duration === "number") {
|
|
106
114
|
newEvent.duration = formatTick(newEvent.duration);
|
|
107
115
|
}
|
|
108
|
-
this.send(newEvent);
|
|
116
|
+
this.send(newEvent, logLevel);
|
|
109
117
|
}
|
|
110
118
|
/**
|
|
111
119
|
* Send an error telemetry event with the logger
|
|
@@ -120,20 +128,22 @@ class TelemetryLogger {
|
|
|
120
128
|
error: event.eventName,
|
|
121
129
|
...event,
|
|
122
130
|
category: "error",
|
|
123
|
-
}, error);
|
|
131
|
+
}, error, core_interfaces_1.LogLevel.error);
|
|
124
132
|
}
|
|
125
133
|
/**
|
|
126
134
|
* Send a performance telemetry event with the logger
|
|
127
135
|
*
|
|
128
136
|
* @param event - Event to send
|
|
129
137
|
* @param error - optional error object to log
|
|
138
|
+
* @param logLevel - optional level of the log. It category of event is set as error,
|
|
139
|
+
* then the logLevel will be upgraded to be an error.
|
|
130
140
|
*/
|
|
131
|
-
sendPerformanceEvent(event, error) {
|
|
141
|
+
sendPerformanceEvent(event, error, logLevel = core_interfaces_1.LogLevel.default) {
|
|
132
142
|
const perfEvent = {
|
|
133
143
|
...event,
|
|
134
144
|
category: event.category ?? "performance",
|
|
135
145
|
};
|
|
136
|
-
this.sendTelemetryEventCore(perfEvent, error);
|
|
146
|
+
this.sendTelemetryEventCore(perfEvent, error, perfEvent.category === "error" ? core_interfaces_1.LogLevel.error : logLevel);
|
|
137
147
|
}
|
|
138
148
|
prepareEvent(event) {
|
|
139
149
|
const includeErrorProps = event.category === "error" || event.error !== undefined;
|
|
@@ -183,6 +193,9 @@ class TaggedLoggerAdapter {
|
|
|
183
193
|
constructor(logger) {
|
|
184
194
|
this.logger = logger;
|
|
185
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* {@inheritDoc @fluidframework/core-interfaces#ITelemetryBaseLogger.send}
|
|
198
|
+
*/
|
|
186
199
|
send(eventWithTagsMaybe) {
|
|
187
200
|
const newEvent = {
|
|
188
201
|
category: eventWithTagsMaybe.category,
|
|
@@ -286,13 +299,25 @@ class ChildLogger extends TelemetryLogger {
|
|
|
286
299
|
}
|
|
287
300
|
return new ChildLogger(baseLogger ? baseLogger : { send() { } }, namespace, properties);
|
|
288
301
|
}
|
|
302
|
+
get minLogLevel() {
|
|
303
|
+
return this.baseLogger.minLogLevel;
|
|
304
|
+
}
|
|
305
|
+
shouldFilterOutEvent(event, logLevel) {
|
|
306
|
+
const eventLogLevel = logLevel ?? core_interfaces_1.LogLevel.default;
|
|
307
|
+
const configLogLevel = this.baseLogger.minLogLevel ?? core_interfaces_1.LogLevel.default;
|
|
308
|
+
// Filter out in case event log level is below what is wanted in config.
|
|
309
|
+
return eventLogLevel < configLogLevel;
|
|
310
|
+
}
|
|
289
311
|
/**
|
|
290
312
|
* Send an event with the logger
|
|
291
313
|
*
|
|
292
314
|
* @param event - the event to send
|
|
293
315
|
*/
|
|
294
|
-
send(event) {
|
|
295
|
-
|
|
316
|
+
send(event, logLevel) {
|
|
317
|
+
if (this.shouldFilterOutEvent(event, logLevel)) {
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
this.baseLogger.send(this.prepareEvent(event), logLevel);
|
|
296
321
|
}
|
|
297
322
|
}
|
|
298
323
|
exports.ChildLogger = ChildLogger;
|
|
@@ -324,14 +349,31 @@ class MultiSinkLogger extends TelemetryLogger {
|
|
|
324
349
|
loggers
|
|
325
350
|
.filter((l) => l instanceof TelemetryLogger)
|
|
326
351
|
.map((l) => l.properties ?? {})
|
|
352
|
+
// eslint-disable-next-line unicorn/no-array-for-each
|
|
327
353
|
.forEach((cv) => {
|
|
354
|
+
// eslint-disable-next-line unicorn/no-array-for-each
|
|
328
355
|
Object.keys(cv).forEach((k) => {
|
|
356
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
329
357
|
merge[k] = { ...cv[k], ...merge?.[k] };
|
|
330
358
|
});
|
|
331
359
|
});
|
|
332
360
|
}
|
|
333
361
|
super(namespace, realProperties);
|
|
334
362
|
this.loggers = loggers;
|
|
363
|
+
this._minLogLevelOfAllLoggers = core_interfaces_1.LogLevel.default;
|
|
364
|
+
this.calculateMinLogLevel();
|
|
365
|
+
}
|
|
366
|
+
get minLogLevel() {
|
|
367
|
+
return this._minLogLevelOfAllLoggers;
|
|
368
|
+
}
|
|
369
|
+
calculateMinLogLevel() {
|
|
370
|
+
if (this.loggers.length > 0) {
|
|
371
|
+
const logLevels = [];
|
|
372
|
+
for (const logger of this.loggers) {
|
|
373
|
+
logLevels.push(logger.minLogLevel ?? core_interfaces_1.LogLevel.default);
|
|
374
|
+
}
|
|
375
|
+
this._minLogLevelOfAllLoggers = Math.min(...logLevels);
|
|
376
|
+
}
|
|
335
377
|
}
|
|
336
378
|
/**
|
|
337
379
|
* Add logger to send all events to
|
|
@@ -340,6 +382,8 @@ class MultiSinkLogger extends TelemetryLogger {
|
|
|
340
382
|
addLogger(logger) {
|
|
341
383
|
if (logger !== undefined && logger !== null) {
|
|
342
384
|
this.loggers.push(logger);
|
|
385
|
+
// Update in case the logLevel of added logger is less than the current.
|
|
386
|
+
this.calculateMinLogLevel();
|
|
343
387
|
}
|
|
344
388
|
}
|
|
345
389
|
/**
|
|
@@ -349,9 +393,9 @@ class MultiSinkLogger extends TelemetryLogger {
|
|
|
349
393
|
*/
|
|
350
394
|
send(event) {
|
|
351
395
|
const newEvent = this.prepareEvent(event);
|
|
352
|
-
this.loggers
|
|
396
|
+
for (const logger of this.loggers) {
|
|
353
397
|
logger.send(newEvent);
|
|
354
|
-
}
|
|
398
|
+
}
|
|
355
399
|
}
|
|
356
400
|
}
|
|
357
401
|
exports.MultiSinkLogger = MultiSinkLogger;
|
|
@@ -363,12 +407,13 @@ class PerformanceEvent {
|
|
|
363
407
|
this.logger = logger;
|
|
364
408
|
this.markers = markers;
|
|
365
409
|
this.recordHeapSize = recordHeapSize;
|
|
366
|
-
this.startTime =
|
|
410
|
+
this.startTime = client_utils_1.performance.now();
|
|
367
411
|
this.startMemoryCollection = 0;
|
|
368
412
|
this.event = { ...event };
|
|
369
413
|
if (this.markers.start) {
|
|
370
414
|
this.reportEvent("start");
|
|
371
415
|
}
|
|
416
|
+
// eslint-disable-next-line unicorn/no-null
|
|
372
417
|
if (typeof window === "object" && window != null && window.performance?.mark) {
|
|
373
418
|
this.startMark = `${event.eventName}-start`;
|
|
374
419
|
window.performance.mark(this.startMark);
|
|
@@ -402,7 +447,7 @@ class PerformanceEvent {
|
|
|
402
447
|
}
|
|
403
448
|
}
|
|
404
449
|
get duration() {
|
|
405
|
-
return
|
|
450
|
+
return client_utils_1.performance.now() - this.startTime;
|
|
406
451
|
}
|
|
407
452
|
reportProgress(props, eventNameSuffix = "update") {
|
|
408
453
|
this.reportEvent(eventNameSuffix, props);
|
|
@@ -449,7 +494,7 @@ class PerformanceEvent {
|
|
|
449
494
|
if (eventNameSuffix !== "start") {
|
|
450
495
|
event.duration = this.duration;
|
|
451
496
|
if (this.startMemoryCollection) {
|
|
452
|
-
const currentMemory =
|
|
497
|
+
const currentMemory = client_utils_1.performance?.memory
|
|
453
498
|
?.usedJSHeapSize;
|
|
454
499
|
const differenceInKBytes = Math.floor((currentMemory - this.startMemoryCollection) / 1024);
|
|
455
500
|
if (differenceInKBytes > 0) {
|
|
@@ -458,7 +503,7 @@ class PerformanceEvent {
|
|
|
458
503
|
}
|
|
459
504
|
}
|
|
460
505
|
else if (this.recordHeapSize) {
|
|
461
|
-
this.startMemoryCollection =
|
|
506
|
+
this.startMemoryCollection = client_utils_1.performance?.memory?.usedJSHeapSize;
|
|
462
507
|
}
|
|
463
508
|
this.logger.sendPerformanceEvent(event, error);
|
|
464
509
|
}
|
|
@@ -493,8 +538,8 @@ function convertToBaseEvent({ category, eventName, ...props }) {
|
|
|
493
538
|
/**
|
|
494
539
|
* Takes in value, and does one of 4 things.
|
|
495
540
|
* if value is of primitive type - returns the original value.
|
|
496
|
-
* If the value is
|
|
497
|
-
* If the value is an object of type
|
|
541
|
+
* If the value is a flat array or object - returns a stringified version of the array/object.
|
|
542
|
+
* If the value is an object of type Tagged<TelemetryEventPropertyType> - returns the object
|
|
498
543
|
* with its values recursively converted to base property Type.
|
|
499
544
|
* If none of these cases are reached - returns an error string
|
|
500
545
|
* @param x - value passed in to convert to a base property type
|
|
@@ -526,9 +571,11 @@ function convertToBasePropertyTypeUntagged(x) {
|
|
|
526
571
|
}
|
|
527
572
|
const tagData = (tag, values) => Object.entries(values)
|
|
528
573
|
.filter((e) => e[1] !== undefined)
|
|
574
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
529
575
|
.reduce((pv, cv) => {
|
|
530
576
|
pv[cv[0]] = { tag, value: cv[1] };
|
|
531
577
|
return pv;
|
|
578
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
|
|
532
579
|
}, {});
|
|
533
580
|
exports.tagData = tagData;
|
|
534
581
|
const tagCodeArtifacts = (values) => (0, exports.tagData)(TelemetryDataTag.CodeArtifact, values);
|