@fluidframework/telemetry-utils 2.0.0-internal.5.3.2 → 2.0.0-internal.6.0.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/CHANGELOG.md +36 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +27 -34
- package/dist/config.js.map +1 -1
- package/dist/errorLogging.js +16 -10
- package/dist/errorLogging.js.map +1 -1
- package/dist/fluidErrorBase.js +7 -7
- package/dist/fluidErrorBase.js.map +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -9
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +47 -48
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +111 -117
- package/dist/logger.js.map +1 -1
- package/dist/mockLogger.d.ts +3 -5
- package/dist/mockLogger.d.ts.map +1 -1
- package/dist/mockLogger.js +27 -19
- package/dist/mockLogger.js.map +1 -1
- package/dist/sampledTelemetryHelper.js +8 -5
- package/dist/sampledTelemetryHelper.js.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +1 -1
- package/lib/config.d.ts +2 -0
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +26 -34
- package/lib/config.js.map +1 -1
- package/lib/errorLogging.js +16 -10
- package/lib/errorLogging.js.map +1 -1
- package/lib/fluidErrorBase.js +7 -7
- package/lib/fluidErrorBase.js.map +1 -1
- package/lib/index.d.ts +2 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -3
- package/lib/index.js.map +1 -1
- package/lib/logger.d.ts +47 -48
- package/lib/logger.d.ts.map +1 -1
- package/lib/logger.js +104 -113
- package/lib/logger.js.map +1 -1
- package/lib/mockLogger.d.ts +3 -5
- package/lib/mockLogger.d.ts.map +1 -1
- package/lib/mockLogger.js +28 -20
- package/lib/mockLogger.js.map +1 -1
- package/lib/sampledTelemetryHelper.js +8 -5
- package/lib/sampledTelemetryHelper.js.map +1 -1
- package/lib/utils.js +1 -1
- package/lib/utils.js.map +1 -1
- package/package.json +41 -8
- package/src/config.ts +11 -6
- package/src/index.ts +8 -7
- package/src/logger.ts +125 -94
- package/src/mockLogger.ts +37 -13
- package/dist/debugLogger.d.ts +0 -39
- package/dist/debugLogger.d.ts.map +0 -1
- package/dist/debugLogger.js +0 -112
- package/dist/debugLogger.js.map +0 -1
- package/lib/debugLogger.d.ts +0 -39
- package/lib/debugLogger.d.ts.map +0 -1
- package/lib/debugLogger.js +0 -108
- package/lib/debugLogger.js.map +0 -1
- package/src/debugLogger.ts +0 -143
package/dist/index.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.logIfFalse = exports.SampledTelemetryHelper = exports.ThresholdCounter = exports.MockLogger = exports.
|
|
3
|
+
exports.logIfFalse = exports.SampledTelemetryHelper = exports.ThresholdCounter = exports.MockLogger = exports.TelemetryDataTag = exports.tagCodeArtifacts = exports.tagData = exports.TaggedLoggerAdapter = exports.PerformanceEvent = exports.numberFromString = exports.formatTick = exports.createMultiSinkLogger = exports.createChildLogger = exports.eventNamespaceSeparator = exports.isValidLegacyError = exports.isFluidError = exports.hasErrorInstanceId = exports.safeRaiseEvent = exports.raiseConnectedEvent = exports.disconnectedEventName = exports.connectedEventName = exports.EventEmitterWithErrorHandling = exports.wrapErrorAndLog = exports.wrapError = exports.normalizeError = exports.NORMALIZED_ERROR_TYPE = exports.LoggingError = exports.isTaggedTelemetryPropertyValue = exports.isILoggingError = exports.isExternalError = exports.getCircularReplacer = exports.generateStack = exports.generateErrorWithStack = exports.extractLogSafeErrorProperties = exports.loggerToMonitoringContext = exports.mixinMonitoringContext = exports.sessionStorageConfigProvider = exports.createChildMonitoringContext = void 0;
|
|
4
4
|
/*!
|
|
5
5
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
6
6
|
* Licensed under the MIT License.
|
|
7
7
|
*/
|
|
8
8
|
var config_1 = require("./config");
|
|
9
|
+
Object.defineProperty(exports, "createChildMonitoringContext", { enumerable: true, get: function () { return config_1.createChildMonitoringContext; } });
|
|
9
10
|
Object.defineProperty(exports, "sessionStorageConfigProvider", { enumerable: true, get: function () { return config_1.sessionStorageConfigProvider; } });
|
|
10
11
|
Object.defineProperty(exports, "mixinMonitoringContext", { enumerable: true, get: function () { return config_1.mixinMonitoringContext; } });
|
|
11
12
|
Object.defineProperty(exports, "loggerToMonitoringContext", { enumerable: true, get: function () { return config_1.loggerToMonitoringContext; } });
|
|
12
|
-
var debugLogger_1 = require("./debugLogger");
|
|
13
|
-
Object.defineProperty(exports, "DebugLogger", { enumerable: true, get: function () { return debugLogger_1.DebugLogger; } });
|
|
14
13
|
var errorLogging_1 = require("./errorLogging");
|
|
15
14
|
Object.defineProperty(exports, "extractLogSafeErrorProperties", { enumerable: true, get: function () { return errorLogging_1.extractLogSafeErrorProperties; } });
|
|
16
15
|
Object.defineProperty(exports, "generateErrorWithStack", { enumerable: true, get: function () { return errorLogging_1.generateErrorWithStack; } });
|
|
@@ -36,15 +35,16 @@ Object.defineProperty(exports, "hasErrorInstanceId", { enumerable: true, get: fu
|
|
|
36
35
|
Object.defineProperty(exports, "isFluidError", { enumerable: true, get: function () { return fluidErrorBase_1.isFluidError; } });
|
|
37
36
|
Object.defineProperty(exports, "isValidLegacyError", { enumerable: true, get: function () { return fluidErrorBase_1.isValidLegacyError; } });
|
|
38
37
|
var logger_1 = require("./logger");
|
|
39
|
-
Object.defineProperty(exports, "
|
|
40
|
-
Object.defineProperty(exports, "
|
|
41
|
-
Object.defineProperty(exports, "
|
|
38
|
+
Object.defineProperty(exports, "eventNamespaceSeparator", { enumerable: true, get: function () { return logger_1.eventNamespaceSeparator; } });
|
|
39
|
+
Object.defineProperty(exports, "createChildLogger", { enumerable: true, get: function () { return logger_1.createChildLogger; } });
|
|
40
|
+
Object.defineProperty(exports, "createMultiSinkLogger", { enumerable: true, get: function () { return logger_1.createMultiSinkLogger; } });
|
|
41
|
+
Object.defineProperty(exports, "formatTick", { enumerable: true, get: function () { return logger_1.formatTick; } });
|
|
42
|
+
Object.defineProperty(exports, "numberFromString", { enumerable: true, get: function () { return logger_1.numberFromString; } });
|
|
42
43
|
Object.defineProperty(exports, "PerformanceEvent", { enumerable: true, get: function () { return logger_1.PerformanceEvent; } });
|
|
43
44
|
Object.defineProperty(exports, "TaggedLoggerAdapter", { enumerable: true, get: function () { return logger_1.TaggedLoggerAdapter; } });
|
|
45
|
+
Object.defineProperty(exports, "tagData", { enumerable: true, get: function () { return logger_1.tagData; } });
|
|
46
|
+
Object.defineProperty(exports, "tagCodeArtifacts", { enumerable: true, get: function () { return logger_1.tagCodeArtifacts; } });
|
|
44
47
|
Object.defineProperty(exports, "TelemetryDataTag", { enumerable: true, get: function () { return logger_1.TelemetryDataTag; } });
|
|
45
|
-
Object.defineProperty(exports, "TelemetryLogger", { enumerable: true, get: function () { return logger_1.TelemetryLogger; } });
|
|
46
|
-
Object.defineProperty(exports, "TelemetryNullLogger", { enumerable: true, get: function () { return logger_1.TelemetryNullLogger; } });
|
|
47
|
-
Object.defineProperty(exports, "TelemetryUTLogger", { enumerable: true, get: function () { return logger_1.TelemetryUTLogger; } });
|
|
48
48
|
var mockLogger_1 = require("./mockLogger");
|
|
49
49
|
Object.defineProperty(exports, "MockLogger", { enumerable: true, get: function () { return mockLogger_1.MockLogger; } });
|
|
50
50
|
var thresholdCounter_1 = require("./thresholdCounter");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,mCASkB;AARjB,sHAAA,4BAA4B,OAAA;AAG5B,sHAAA,4BAA4B,OAAA;AAC5B,gHAAA,sBAAsB,OAAA;AAGtB,mHAAA,yBAAyB,OAAA;AAE1B,+CAcwB;AAbvB,6HAAA,6BAA6B,OAAA;AAC7B,sHAAA,sBAAsB,OAAA;AACtB,6GAAA,aAAa,OAAA;AACb,mHAAA,mBAAmB,OAAA;AAEnB,+GAAA,eAAe,OAAA;AACf,+GAAA,eAAe,OAAA;AACf,8HAAA,8BAA8B,OAAA;AAC9B,4GAAA,YAAY,OAAA;AACZ,qHAAA,qBAAqB,OAAA;AACrB,8GAAA,cAAc,OAAA;AACd,yGAAA,SAAS,OAAA;AACT,+GAAA,eAAe,OAAA;AAEhB,iFAAgF;AAAvE,8IAAA,6BAA6B,OAAA;AACtC,mCAKkB;AAJjB,4GAAA,kBAAkB,OAAA;AAClB,+GAAA,qBAAqB,OAAA;AACrB,6GAAA,mBAAmB,OAAA;AACnB,wGAAA,cAAc,OAAA;AAEf,mDAK0B;AAJzB,oHAAA,kBAAkB,OAAA;AAElB,8GAAA,YAAY,OAAA;AACZ,oHAAA,kBAAkB,OAAA;AAEnB,mCAekB;AAdjB,iHAAA,uBAAuB,OAAA;AACvB,2GAAA,iBAAiB,OAAA;AACjB,+GAAA,qBAAqB,OAAA;AACrB,oGAAA,UAAU,OAAA;AAIV,0GAAA,gBAAgB,OAAA;AAChB,0GAAA,gBAAgB,OAAA;AAChB,6GAAA,mBAAmB,OAAA;AACnB,iGAAA,OAAO,OAAA;AACP,0GAAA,gBAAgB,OAAA;AAChB,0GAAA,gBAAgB,OAAA;AAGjB,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,uDAAsD;AAA7C,oHAAA,gBAAgB,OAAA;AACzB,mEAAkE;AAAzD,gIAAA,sBAAsB,OAAA;AAC/B,iCAAqC;AAA5B,mGAAA,UAAU,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nexport {\n\tcreateChildMonitoringContext,\n\tMonitoringContext,\n\tIConfigProviderBase,\n\tsessionStorageConfigProvider,\n\tmixinMonitoringContext,\n\tIConfigProvider,\n\tConfigTypes,\n\tloggerToMonitoringContext,\n} from \"./config\";\nexport {\n\textractLogSafeErrorProperties,\n\tgenerateErrorWithStack,\n\tgenerateStack,\n\tgetCircularReplacer,\n\tIFluidErrorAnnotations,\n\tisExternalError,\n\tisILoggingError,\n\tisTaggedTelemetryPropertyValue,\n\tLoggingError,\n\tNORMALIZED_ERROR_TYPE,\n\tnormalizeError,\n\twrapError,\n\twrapErrorAndLog,\n} from \"./errorLogging\";\nexport { EventEmitterWithErrorHandling } from \"./eventEmitterWithErrorHandling\";\nexport {\n\tconnectedEventName,\n\tdisconnectedEventName,\n\traiseConnectedEvent,\n\tsafeRaiseEvent,\n} from \"./events\";\nexport {\n\thasErrorInstanceId,\n\tIFluidErrorBase,\n\tisFluidError,\n\tisValidLegacyError,\n} from \"./fluidErrorBase\";\nexport {\n\teventNamespaceSeparator,\n\tcreateChildLogger,\n\tcreateMultiSinkLogger,\n\tformatTick,\n\tIPerformanceEventMarkers,\n\tITelemetryLoggerPropertyBag,\n\tITelemetryLoggerPropertyBags,\n\tnumberFromString,\n\tPerformanceEvent,\n\tTaggedLoggerAdapter,\n\ttagData,\n\ttagCodeArtifacts,\n\tTelemetryDataTag,\n\tTelemetryEventPropertyTypes,\n} from \"./logger\";\nexport { MockLogger } from \"./mockLogger\";\nexport { ThresholdCounter } from \"./thresholdCounter\";\nexport { SampledTelemetryHelper } from \"./sampledTelemetryHelper\";\nexport { logIfFalse } from \"./utils\";\nexport {\n\tTelemetryEventPropertyTypeExt,\n\tITelemetryEventExt,\n\tITelemetryGenericEventExt,\n\tITelemetryErrorEventExt,\n\tITelemetryPerformanceEventExt,\n\tITelemetryLoggerExt,\n\tITaggedTelemetryPropertyTypeExt,\n\tITelemetryPropertiesExt,\n} from \"./telemetryTypes\";\n"]}
|
package/dist/logger.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import { ITelemetryBaseEvent, ITelemetryBaseLogger, ITelemetryErrorEvent, ITelemetryGenericEvent,
|
|
5
|
+
import { ITelemetryBaseEvent, ITelemetryBaseLogger, ITelemetryErrorEvent, ITelemetryGenericEvent, ITelemetryProperties, TelemetryEventPropertyType, ITaggedTelemetryPropertyType, TelemetryEventCategory } from "@fluidframework/core-interfaces";
|
|
6
6
|
import { IsomorphicPerformance } from "@fluidframework/common-utils";
|
|
7
7
|
import { ITaggedTelemetryPropertyTypeExt, ITelemetryGenericEventExt, ITelemetryLoggerExt, ITelemetryPerformanceEventExt, TelemetryEventPropertyTypeExt } from "./telemetryTypes";
|
|
8
8
|
export interface Memory {
|
|
@@ -29,23 +29,25 @@ export interface ITelemetryLoggerPropertyBags {
|
|
|
29
29
|
all?: ITelemetryLoggerPropertyBag;
|
|
30
30
|
error?: ITelemetryLoggerPropertyBag;
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Attempts to parse number from string.
|
|
34
|
+
* If fails,returns original string.
|
|
35
|
+
* Used to make telemetry data typed (and support math operations, like comparison),
|
|
36
|
+
* in places where we do expect numbers (like contentsize/duration property in http header)
|
|
37
|
+
*/
|
|
38
|
+
export declare function numberFromString(str: string | null | undefined): string | number | undefined;
|
|
39
|
+
export declare function formatTick(tick: number): number;
|
|
40
|
+
export declare const eventNamespaceSeparator: ":";
|
|
32
41
|
/**
|
|
33
42
|
* TelemetryLogger class contains various helper telemetry methods,
|
|
34
43
|
* encoding in one place schemas for various types of Fluid telemetry events.
|
|
35
44
|
* Creates sub-logger that appends properties to all events
|
|
45
|
+
*
|
|
36
46
|
*/
|
|
37
47
|
export declare abstract class TelemetryLogger implements ITelemetryLoggerExt {
|
|
38
48
|
protected readonly namespace?: string | undefined;
|
|
39
49
|
protected readonly properties?: ITelemetryLoggerPropertyBags | undefined;
|
|
40
|
-
static readonly eventNamespaceSeparator
|
|
41
|
-
static formatTick(tick: number): number;
|
|
42
|
-
/**
|
|
43
|
-
* Attempts to parse number from string.
|
|
44
|
-
* If fails,returns original string.
|
|
45
|
-
* Used to make telemetry data typed (and support math operations, like comparison),
|
|
46
|
-
* in places where we do expect numbers (like contentsize/duration property in http header)
|
|
47
|
-
*/
|
|
48
|
-
static numberFromString(str: string | null | undefined): string | number | undefined;
|
|
50
|
+
static readonly eventNamespaceSeparator: ":";
|
|
49
51
|
static sanitizePkgName(name: string): string;
|
|
50
52
|
/**
|
|
51
53
|
* Take an unknown error object and add the appropriate info from it to the event. Message and stack will be copied
|
|
@@ -93,6 +95,7 @@ export declare abstract class TelemetryLogger implements ITelemetryLoggerExt {
|
|
|
93
95
|
*/
|
|
94
96
|
sendPerformanceEvent(event: ITelemetryPerformanceEventExt, error?: any): void;
|
|
95
97
|
protected prepareEvent(event: ITelemetryBaseEvent): ITelemetryBaseEvent;
|
|
98
|
+
private extendProperties;
|
|
96
99
|
}
|
|
97
100
|
/**
|
|
98
101
|
* @deprecated 0.56, remove TaggedLoggerAdapter once its usage is removed from
|
|
@@ -104,6 +107,18 @@ export declare class TaggedLoggerAdapter implements ITelemetryBaseLogger {
|
|
|
104
107
|
constructor(logger: ITelemetryBaseLogger);
|
|
105
108
|
send(eventWithTagsMaybe: ITelemetryBaseEvent): void;
|
|
106
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Create a child logger based on the provided props object
|
|
112
|
+
* @param props - logger is the base logger the child will log to after it's processing, namespace will be prefixed to all event names, properties are default properties that will be applied events.
|
|
113
|
+
*
|
|
114
|
+
* @remarks
|
|
115
|
+
* Passing in no props object (i.e. undefined) will return a logger that is effectively a no-op.
|
|
116
|
+
*/
|
|
117
|
+
export declare function createChildLogger(props?: {
|
|
118
|
+
logger?: ITelemetryBaseLogger;
|
|
119
|
+
namespace?: string;
|
|
120
|
+
properties?: ITelemetryLoggerPropertyBags;
|
|
121
|
+
}): ITelemetryLoggerExt;
|
|
107
122
|
/**
|
|
108
123
|
* ChildLogger class contains various helper telemetry methods,
|
|
109
124
|
* encoding in one place schemas for various types of Fluid telemetry events.
|
|
@@ -127,6 +142,17 @@ export declare class ChildLogger extends TelemetryLogger {
|
|
|
127
142
|
*/
|
|
128
143
|
send(event: ITelemetryBaseEvent): void;
|
|
129
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Create a logger which logs to multiple other loggers based on the provided props object
|
|
147
|
+
* @param props - loggers are the base loggers that will logged to after it's processing, namespace will be prefixed to all event names, properties are default properties that will be applied events.
|
|
148
|
+
* tryInheritProperties will attempted to copy those loggers properties to this loggers if they are of a known type e.g. one from this package
|
|
149
|
+
*/
|
|
150
|
+
export declare function createMultiSinkLogger(props: {
|
|
151
|
+
namespace?: string;
|
|
152
|
+
properties?: ITelemetryLoggerPropertyBags;
|
|
153
|
+
loggers?: (ITelemetryBaseLogger | undefined)[];
|
|
154
|
+
tryInheritProperties?: true;
|
|
155
|
+
}): ITelemetryLoggerExt;
|
|
130
156
|
/**
|
|
131
157
|
* Multi-sink logger
|
|
132
158
|
* Takes multiple ITelemetryBaseLogger objects (sinks) and logs all events into each sink
|
|
@@ -137,8 +163,10 @@ export declare class MultiSinkLogger extends TelemetryLogger {
|
|
|
137
163
|
* Create multiple sink logger (i.e. logger that sends events to multiple sinks)
|
|
138
164
|
* @param namespace - Telemetry event name prefix to add to all events
|
|
139
165
|
* @param properties - Base properties to add to all events
|
|
166
|
+
* @param loggers - The list of loggers to use as sinks
|
|
167
|
+
* @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
|
|
140
168
|
*/
|
|
141
|
-
constructor(namespace?: string, properties?: ITelemetryLoggerPropertyBags);
|
|
169
|
+
constructor(namespace?: string, properties?: ITelemetryLoggerPropertyBags, loggers?: ITelemetryBaseLogger[], tryInheritProperties?: true);
|
|
142
170
|
/**
|
|
143
171
|
* Add logger to send all events to
|
|
144
172
|
* @param logger - Logger to add
|
|
@@ -188,43 +216,6 @@ export declare class PerformanceEvent {
|
|
|
188
216
|
*/
|
|
189
217
|
reportEvent(eventNameSuffix: string, props?: ITelemetryProperties, error?: any): void;
|
|
190
218
|
}
|
|
191
|
-
/**
|
|
192
|
-
* Logger that is useful for UT
|
|
193
|
-
* It can be used in places where logger instance is required, but events should be not send over.
|
|
194
|
-
*/
|
|
195
|
-
export declare class TelemetryUTLogger implements ITelemetryLoggerExt {
|
|
196
|
-
send(event: ITelemetryBaseEvent): void;
|
|
197
|
-
sendTelemetryEvent(event: ITelemetryGenericEvent, error?: any): void;
|
|
198
|
-
sendErrorEvent(event: ITelemetryErrorEvent, error?: any): void;
|
|
199
|
-
sendPerformanceEvent(event: ITelemetryPerformanceEvent, error?: any): void;
|
|
200
|
-
logGenericError(eventName: string, error: any): void;
|
|
201
|
-
logException(event: ITelemetryErrorEvent, exception: any): void;
|
|
202
|
-
debugAssert(condition: boolean, event?: ITelemetryErrorEvent): void;
|
|
203
|
-
shipAssert(condition: boolean, event?: ITelemetryErrorEvent): void;
|
|
204
|
-
private reportError;
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Null logger
|
|
208
|
-
* It can be used in places where logger instance is required, but events should be not send over.
|
|
209
|
-
*/
|
|
210
|
-
export declare class BaseTelemetryNullLogger implements ITelemetryBaseLogger {
|
|
211
|
-
/**
|
|
212
|
-
* Send an event with the logger
|
|
213
|
-
*
|
|
214
|
-
* @param event - the event to send
|
|
215
|
-
*/
|
|
216
|
-
send(event: ITelemetryBaseEvent): void;
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Null logger
|
|
220
|
-
* It can be used in places where logger instance is required, but events should be not send over.
|
|
221
|
-
*/
|
|
222
|
-
export declare class TelemetryNullLogger implements ITelemetryLoggerExt {
|
|
223
|
-
send(event: ITelemetryBaseEvent): void;
|
|
224
|
-
sendTelemetryEvent(event: ITelemetryGenericEvent, error?: any): void;
|
|
225
|
-
sendErrorEvent(event: ITelemetryErrorEvent, error?: any): void;
|
|
226
|
-
sendPerformanceEvent(event: ITelemetryPerformanceEvent, error?: any): void;
|
|
227
|
-
}
|
|
228
219
|
/**
|
|
229
220
|
* Takes in value, and does one of 4 things.
|
|
230
221
|
* if value is of primitive type - returns the original value.
|
|
@@ -235,4 +226,12 @@ export declare class TelemetryNullLogger implements ITelemetryLoggerExt {
|
|
|
235
226
|
* @param x - value passed in to convert to a base property type
|
|
236
227
|
*/
|
|
237
228
|
export declare function convertToBasePropertyType(x: TelemetryEventPropertyTypeExt | ITaggedTelemetryPropertyTypeExt): TelemetryEventPropertyType | ITaggedTelemetryPropertyType;
|
|
229
|
+
export declare const tagData: <T extends TelemetryDataTag, V extends Record<string, TelemetryEventPropertyTypeExt>>(tag: T, values: V) => { [P in keyof V]: {
|
|
230
|
+
value: Exclude<V[P], undefined>;
|
|
231
|
+
tag: T;
|
|
232
|
+
} | (V[P] extends undefined ? undefined : never); };
|
|
233
|
+
export declare const tagCodeArtifacts: <T extends Record<string, TelemetryEventPropertyTypeExt>>(values: T) => { [P in keyof T]: {
|
|
234
|
+
value: Exclude<T[P], undefined>;
|
|
235
|
+
tag: TelemetryDataTag.CodeArtifact;
|
|
236
|
+
} | (T[P] extends undefined ? undefined : never); };
|
|
238
237
|
//# sourceMappingURL=logger.d.ts.map
|
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,
|
|
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,EAEtB,oBAAoB,EACpB,0BAA0B,EAC1B,4BAA4B,EAC5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;AAuBD,eAAO,MAAM,OAAO;;;mDAgBL,CAAC;AAEhB,eAAO,MAAM,gBAAgB;;;mDAEsB,CAAC"}
|
package/dist/logger.js
CHANGED
|
@@ -3,19 +3,8 @@
|
|
|
3
3
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
4
|
* Licensed under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
7
|
-
var t = {};
|
|
8
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
9
|
-
t[p] = s[p];
|
|
10
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
11
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
12
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
13
|
-
t[p[i]] = s[p[i]];
|
|
14
|
-
}
|
|
15
|
-
return t;
|
|
16
|
-
};
|
|
17
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.
|
|
7
|
+
exports.tagCodeArtifacts = exports.tagData = exports.convertToBasePropertyType = exports.PerformanceEvent = exports.MultiSinkLogger = exports.createMultiSinkLogger = exports.ChildLogger = exports.createChildLogger = exports.TaggedLoggerAdapter = exports.TelemetryLogger = exports.eventNamespaceSeparator = exports.formatTick = exports.numberFromString = exports.TelemetryDataTag = void 0;
|
|
19
8
|
const common_utils_1 = require("@fluidframework/common-utils");
|
|
20
9
|
const config_1 = require("./config");
|
|
21
10
|
const errorLogging_1 = require("./errorLogging");
|
|
@@ -30,32 +19,36 @@ var TelemetryDataTag;
|
|
|
30
19
|
/** Personal data of a variety of classifications that pertains to the user */
|
|
31
20
|
TelemetryDataTag["UserData"] = "UserData";
|
|
32
21
|
})(TelemetryDataTag = exports.TelemetryDataTag || (exports.TelemetryDataTag = {}));
|
|
22
|
+
/**
|
|
23
|
+
* Attempts to parse number from string.
|
|
24
|
+
* If fails,returns original string.
|
|
25
|
+
* Used to make telemetry data typed (and support math operations, like comparison),
|
|
26
|
+
* in places where we do expect numbers (like contentsize/duration property in http header)
|
|
27
|
+
*/
|
|
28
|
+
function numberFromString(str) {
|
|
29
|
+
if (str === undefined || str === null) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
const num = Number(str);
|
|
33
|
+
return Number.isNaN(num) ? str : num;
|
|
34
|
+
}
|
|
35
|
+
exports.numberFromString = numberFromString;
|
|
36
|
+
function formatTick(tick) {
|
|
37
|
+
return Math.floor(tick);
|
|
38
|
+
}
|
|
39
|
+
exports.formatTick = formatTick;
|
|
40
|
+
exports.eventNamespaceSeparator = ":";
|
|
33
41
|
/**
|
|
34
42
|
* TelemetryLogger class contains various helper telemetry methods,
|
|
35
43
|
* encoding in one place schemas for various types of Fluid telemetry events.
|
|
36
44
|
* Creates sub-logger that appends properties to all events
|
|
45
|
+
*
|
|
37
46
|
*/
|
|
38
47
|
class TelemetryLogger {
|
|
39
48
|
constructor(namespace, properties) {
|
|
40
49
|
this.namespace = namespace;
|
|
41
50
|
this.properties = properties;
|
|
42
51
|
}
|
|
43
|
-
static formatTick(tick) {
|
|
44
|
-
return Math.floor(tick);
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Attempts to parse number from string.
|
|
48
|
-
* If fails,returns original string.
|
|
49
|
-
* Used to make telemetry data typed (and support math operations, like comparison),
|
|
50
|
-
* in places where we do expect numbers (like contentsize/duration property in http header)
|
|
51
|
-
*/
|
|
52
|
-
static numberFromString(str) {
|
|
53
|
-
if (str === undefined || str === null) {
|
|
54
|
-
return undefined;
|
|
55
|
-
}
|
|
56
|
-
const num = Number(str);
|
|
57
|
-
return Number.isNaN(num) ? str : num;
|
|
58
|
-
}
|
|
59
52
|
static sanitizePkgName(name) {
|
|
60
53
|
return name.replace("@", "").replace("/", "-");
|
|
61
54
|
}
|
|
@@ -95,8 +88,7 @@ class TelemetryLogger {
|
|
|
95
88
|
* @param error - optional error object to log
|
|
96
89
|
*/
|
|
97
90
|
sendTelemetryEvent(event, error) {
|
|
98
|
-
|
|
99
|
-
this.sendTelemetryEventCore(Object.assign(Object.assign({}, event), { category: (_a = event.category) !== null && _a !== void 0 ? _a : "generic" }), error);
|
|
91
|
+
this.sendTelemetryEventCore({ ...event, category: event.category ?? "generic" }, error);
|
|
100
92
|
}
|
|
101
93
|
/**
|
|
102
94
|
* Send a telemetry event with the logger
|
|
@@ -111,7 +103,7 @@ class TelemetryLogger {
|
|
|
111
103
|
}
|
|
112
104
|
// Will include Nan & Infinity, but probably we do not care
|
|
113
105
|
if (typeof newEvent.duration === "number") {
|
|
114
|
-
newEvent.duration =
|
|
106
|
+
newEvent.duration = formatTick(newEvent.duration);
|
|
115
107
|
}
|
|
116
108
|
this.send(newEvent);
|
|
117
109
|
}
|
|
@@ -122,10 +114,13 @@ class TelemetryLogger {
|
|
|
122
114
|
* @param error - optional error object to log
|
|
123
115
|
*/
|
|
124
116
|
sendErrorEvent(event, error) {
|
|
125
|
-
this.sendTelemetryEventCore(
|
|
117
|
+
this.sendTelemetryEventCore({
|
|
126
118
|
// ensure the error field has some value,
|
|
127
119
|
// this can and will be overridden by event, or error
|
|
128
|
-
error: event.eventName
|
|
120
|
+
error: event.eventName,
|
|
121
|
+
...event,
|
|
122
|
+
category: "error",
|
|
123
|
+
}, error);
|
|
129
124
|
}
|
|
130
125
|
/**
|
|
131
126
|
* Send a performance telemetry event with the logger
|
|
@@ -134,16 +129,24 @@ class TelemetryLogger {
|
|
|
134
129
|
* @param error - optional error object to log
|
|
135
130
|
*/
|
|
136
131
|
sendPerformanceEvent(event, error) {
|
|
137
|
-
|
|
138
|
-
|
|
132
|
+
const perfEvent = {
|
|
133
|
+
...event,
|
|
134
|
+
category: event.category ?? "performance",
|
|
135
|
+
};
|
|
139
136
|
this.sendTelemetryEventCore(perfEvent, error);
|
|
140
137
|
}
|
|
141
138
|
prepareEvent(event) {
|
|
142
139
|
const includeErrorProps = event.category === "error" || event.error !== undefined;
|
|
143
|
-
const newEvent =
|
|
140
|
+
const newEvent = {
|
|
141
|
+
...event,
|
|
142
|
+
};
|
|
144
143
|
if (this.namespace !== undefined) {
|
|
145
144
|
newEvent.eventName = `${this.namespace}${TelemetryLogger.eventNamespaceSeparator}${newEvent.eventName}`;
|
|
146
145
|
}
|
|
146
|
+
return this.extendProperties(newEvent, includeErrorProps);
|
|
147
|
+
}
|
|
148
|
+
extendProperties(toExtend, includeErrorProps) {
|
|
149
|
+
const eventLike = toExtend;
|
|
147
150
|
if (this.properties) {
|
|
148
151
|
const properties = [];
|
|
149
152
|
properties.push(this.properties.all);
|
|
@@ -153,24 +156,24 @@ class TelemetryLogger {
|
|
|
153
156
|
for (const props of properties) {
|
|
154
157
|
if (props !== undefined) {
|
|
155
158
|
for (const key of Object.keys(props)) {
|
|
156
|
-
if (
|
|
159
|
+
if (eventLike[key] !== undefined) {
|
|
157
160
|
continue;
|
|
158
161
|
}
|
|
159
162
|
const getterOrValue = props[key];
|
|
160
163
|
// If this throws, hopefully it is handled elsewhere
|
|
161
164
|
const value = typeof getterOrValue === "function" ? getterOrValue() : getterOrValue;
|
|
162
165
|
if (value !== undefined) {
|
|
163
|
-
|
|
166
|
+
eventLike[key] = value;
|
|
164
167
|
}
|
|
165
168
|
}
|
|
166
169
|
}
|
|
167
170
|
}
|
|
168
171
|
}
|
|
169
|
-
return
|
|
172
|
+
return toExtend;
|
|
170
173
|
}
|
|
171
174
|
}
|
|
172
175
|
exports.TelemetryLogger = TelemetryLogger;
|
|
173
|
-
TelemetryLogger.eventNamespaceSeparator =
|
|
176
|
+
TelemetryLogger.eventNamespaceSeparator = exports.eventNamespaceSeparator;
|
|
174
177
|
/**
|
|
175
178
|
* @deprecated 0.56, remove TaggedLoggerAdapter once its usage is removed from
|
|
176
179
|
* container-runtime. Issue: #8191
|
|
@@ -217,6 +220,17 @@ class TaggedLoggerAdapter {
|
|
|
217
220
|
}
|
|
218
221
|
}
|
|
219
222
|
exports.TaggedLoggerAdapter = TaggedLoggerAdapter;
|
|
223
|
+
/**
|
|
224
|
+
* Create a child logger based on the provided props object
|
|
225
|
+
* @param props - logger is the base logger the child will log to after it's processing, namespace will be prefixed to all event names, properties are default properties that will be applied events.
|
|
226
|
+
*
|
|
227
|
+
* @remarks
|
|
228
|
+
* Passing in no props object (i.e. undefined) will return a logger that is effectively a no-op.
|
|
229
|
+
*/
|
|
230
|
+
function createChildLogger(props) {
|
|
231
|
+
return ChildLogger.create(props?.logger, props?.namespace, props?.properties);
|
|
232
|
+
}
|
|
233
|
+
exports.createChildLogger = createChildLogger;
|
|
220
234
|
/**
|
|
221
235
|
* ChildLogger class contains various helper telemetry methods,
|
|
222
236
|
* encoding in one place schemas for various types of Fluid telemetry events.
|
|
@@ -246,10 +260,16 @@ class ChildLogger extends TelemetryLogger {
|
|
|
246
260
|
for (const extendedProps of [baseLogger.properties, properties]) {
|
|
247
261
|
if (extendedProps !== undefined) {
|
|
248
262
|
if (extendedProps.all !== undefined) {
|
|
249
|
-
combinedProperties.all =
|
|
263
|
+
combinedProperties.all = {
|
|
264
|
+
...combinedProperties.all,
|
|
265
|
+
...extendedProps.all,
|
|
266
|
+
};
|
|
250
267
|
}
|
|
251
268
|
if (extendedProps.error !== undefined) {
|
|
252
|
-
combinedProperties.error =
|
|
269
|
+
combinedProperties.error = {
|
|
270
|
+
...combinedProperties.error,
|
|
271
|
+
...extendedProps.error,
|
|
272
|
+
};
|
|
253
273
|
}
|
|
254
274
|
}
|
|
255
275
|
}
|
|
@@ -258,9 +278,13 @@ class ChildLogger extends TelemetryLogger {
|
|
|
258
278
|
: namespace === undefined
|
|
259
279
|
? baseLogger.namespace
|
|
260
280
|
: `${baseLogger.namespace}${TelemetryLogger.eventNamespaceSeparator}${namespace}`;
|
|
261
|
-
|
|
281
|
+
const child = new ChildLogger(baseLogger.baseLogger, combinedNamespace, combinedProperties);
|
|
282
|
+
if (!(0, config_1.loggerIsMonitoringContext)(child) && (0, config_1.loggerIsMonitoringContext)(baseLogger)) {
|
|
283
|
+
(0, config_1.mixinMonitoringContext)(child, baseLogger.config);
|
|
284
|
+
}
|
|
285
|
+
return child;
|
|
262
286
|
}
|
|
263
|
-
return new ChildLogger(baseLogger ? baseLogger :
|
|
287
|
+
return new ChildLogger(baseLogger ? baseLogger : { send() { } }, namespace, properties);
|
|
264
288
|
}
|
|
265
289
|
/**
|
|
266
290
|
* Send an event with the logger
|
|
@@ -272,6 +296,15 @@ class ChildLogger extends TelemetryLogger {
|
|
|
272
296
|
}
|
|
273
297
|
}
|
|
274
298
|
exports.ChildLogger = ChildLogger;
|
|
299
|
+
/**
|
|
300
|
+
* Create a logger which logs to multiple other loggers based on the provided props object
|
|
301
|
+
* @param props - loggers are the base loggers that will logged to after it's processing, namespace will be prefixed to all event names, properties are default properties that will be applied events.
|
|
302
|
+
* tryInheritProperties will attempted to copy those loggers properties to this loggers if they are of a known type e.g. one from this package
|
|
303
|
+
*/
|
|
304
|
+
function createMultiSinkLogger(props) {
|
|
305
|
+
return new MultiSinkLogger(props.namespace, props.properties, props.loggers?.filter((l) => l !== undefined), props.tryInheritProperties);
|
|
306
|
+
}
|
|
307
|
+
exports.createMultiSinkLogger = createMultiSinkLogger;
|
|
275
308
|
/**
|
|
276
309
|
* Multi-sink logger
|
|
277
310
|
* Takes multiple ITelemetryBaseLogger objects (sinks) and logs all events into each sink
|
|
@@ -281,10 +314,24 @@ class MultiSinkLogger extends TelemetryLogger {
|
|
|
281
314
|
* Create multiple sink logger (i.e. logger that sends events to multiple sinks)
|
|
282
315
|
* @param namespace - Telemetry event name prefix to add to all events
|
|
283
316
|
* @param properties - Base properties to add to all events
|
|
317
|
+
* @param loggers - The list of loggers to use as sinks
|
|
318
|
+
* @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
|
|
284
319
|
*/
|
|
285
|
-
constructor(namespace, properties) {
|
|
286
|
-
|
|
287
|
-
|
|
320
|
+
constructor(namespace, properties, loggers = [], tryInheritProperties) {
|
|
321
|
+
let realProperties = properties !== undefined ? { ...properties } : undefined;
|
|
322
|
+
if (tryInheritProperties === true) {
|
|
323
|
+
const merge = (realProperties ?? (realProperties = {}));
|
|
324
|
+
loggers
|
|
325
|
+
.filter((l) => l instanceof TelemetryLogger)
|
|
326
|
+
.map((l) => l.properties ?? {})
|
|
327
|
+
.forEach((cv) => {
|
|
328
|
+
Object.keys(cv).forEach((k) => {
|
|
329
|
+
merge[k] = { ...cv[k], ...merge?.[k] };
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
super(namespace, realProperties);
|
|
334
|
+
this.loggers = loggers;
|
|
288
335
|
}
|
|
289
336
|
/**
|
|
290
337
|
* Add logger to send all events to
|
|
@@ -313,17 +360,16 @@ exports.MultiSinkLogger = MultiSinkLogger;
|
|
|
313
360
|
*/
|
|
314
361
|
class PerformanceEvent {
|
|
315
362
|
constructor(logger, event, markers = { end: true, cancel: "generic" }, recordHeapSize = false) {
|
|
316
|
-
var _a;
|
|
317
363
|
this.logger = logger;
|
|
318
364
|
this.markers = markers;
|
|
319
365
|
this.recordHeapSize = recordHeapSize;
|
|
320
366
|
this.startTime = common_utils_1.performance.now();
|
|
321
367
|
this.startMemoryCollection = 0;
|
|
322
|
-
this.event =
|
|
368
|
+
this.event = { ...event };
|
|
323
369
|
if (this.markers.start) {
|
|
324
370
|
this.reportEvent("start");
|
|
325
371
|
}
|
|
326
|
-
if (typeof window === "object" && window != null &&
|
|
372
|
+
if (typeof window === "object" && window != null && window.performance?.mark) {
|
|
327
373
|
this.startMark = `${event.eventName}-start`;
|
|
328
374
|
window.performance.mark(this.startMark);
|
|
329
375
|
}
|
|
@@ -384,7 +430,7 @@ class PerformanceEvent {
|
|
|
384
430
|
}
|
|
385
431
|
cancel(props, error) {
|
|
386
432
|
if (this.markers.cancel !== undefined) {
|
|
387
|
-
this.reportEvent("cancel",
|
|
433
|
+
this.reportEvent("cancel", { category: this.markers.cancel, ...props }, error);
|
|
388
434
|
}
|
|
389
435
|
this.event = undefined;
|
|
390
436
|
}
|
|
@@ -392,19 +438,19 @@ class PerformanceEvent {
|
|
|
392
438
|
* Report the event, if it hasn't already been reported.
|
|
393
439
|
*/
|
|
394
440
|
reportEvent(eventNameSuffix, props, error) {
|
|
395
|
-
var _a, _b, _c, _d;
|
|
396
441
|
// There are strange sequences involving multiple Promise chains
|
|
397
442
|
// where the event can be cancelled and then later a callback is invoked
|
|
398
443
|
// and the caller attempts to end directly, e.g. issue #3936. Just return.
|
|
399
444
|
if (!this.event) {
|
|
400
445
|
return;
|
|
401
446
|
}
|
|
402
|
-
const event =
|
|
447
|
+
const event = { ...this.event, ...props };
|
|
403
448
|
event.eventName = `${event.eventName}_${eventNameSuffix}`;
|
|
404
449
|
if (eventNameSuffix !== "start") {
|
|
405
450
|
event.duration = this.duration;
|
|
406
451
|
if (this.startMemoryCollection) {
|
|
407
|
-
const currentMemory =
|
|
452
|
+
const currentMemory = common_utils_1.performance?.memory
|
|
453
|
+
?.usedJSHeapSize;
|
|
408
454
|
const differenceInKBytes = Math.floor((currentMemory - this.startMemoryCollection) / 1024);
|
|
409
455
|
if (differenceInKBytes > 0) {
|
|
410
456
|
event.usedJSHeapSize = differenceInKBytes;
|
|
@@ -412,79 +458,18 @@ class PerformanceEvent {
|
|
|
412
458
|
}
|
|
413
459
|
}
|
|
414
460
|
else if (this.recordHeapSize) {
|
|
415
|
-
this.startMemoryCollection =
|
|
461
|
+
this.startMemoryCollection = common_utils_1.performance?.memory?.usedJSHeapSize;
|
|
416
462
|
}
|
|
417
463
|
this.logger.sendPerformanceEvent(event, error);
|
|
418
464
|
}
|
|
419
465
|
}
|
|
420
466
|
exports.PerformanceEvent = PerformanceEvent;
|
|
421
|
-
/**
|
|
422
|
-
* Logger that is useful for UT
|
|
423
|
-
* It can be used in places where logger instance is required, but events should be not send over.
|
|
424
|
-
*/
|
|
425
|
-
class TelemetryUTLogger {
|
|
426
|
-
send(event) { }
|
|
427
|
-
sendTelemetryEvent(event, error) { }
|
|
428
|
-
sendErrorEvent(event, error) {
|
|
429
|
-
this.reportError("errorEvent in UT logger!", event, error);
|
|
430
|
-
}
|
|
431
|
-
sendPerformanceEvent(event, error) { }
|
|
432
|
-
logGenericError(eventName, error) {
|
|
433
|
-
this.reportError(`genericError in UT logger!`, { eventName }, error);
|
|
434
|
-
}
|
|
435
|
-
logException(event, exception) {
|
|
436
|
-
this.reportError("exception in UT logger!", event, exception);
|
|
437
|
-
}
|
|
438
|
-
debugAssert(condition, event) {
|
|
439
|
-
this.reportError("debugAssert in UT logger!");
|
|
440
|
-
}
|
|
441
|
-
shipAssert(condition, event) {
|
|
442
|
-
this.reportError("shipAssert in UT logger!");
|
|
443
|
-
}
|
|
444
|
-
reportError(message, event, err) {
|
|
445
|
-
const error = new Error(message);
|
|
446
|
-
error.error = error;
|
|
447
|
-
error.event = event;
|
|
448
|
-
// report to console as exception can be eaten
|
|
449
|
-
console.error(message);
|
|
450
|
-
console.error(error);
|
|
451
|
-
throw error;
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
exports.TelemetryUTLogger = TelemetryUTLogger;
|
|
455
|
-
/**
|
|
456
|
-
* Null logger
|
|
457
|
-
* It can be used in places where logger instance is required, but events should be not send over.
|
|
458
|
-
*/
|
|
459
|
-
class BaseTelemetryNullLogger {
|
|
460
|
-
/**
|
|
461
|
-
* Send an event with the logger
|
|
462
|
-
*
|
|
463
|
-
* @param event - the event to send
|
|
464
|
-
*/
|
|
465
|
-
send(event) {
|
|
466
|
-
return;
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
exports.BaseTelemetryNullLogger = BaseTelemetryNullLogger;
|
|
470
|
-
/**
|
|
471
|
-
* Null logger
|
|
472
|
-
* It can be used in places where logger instance is required, but events should be not send over.
|
|
473
|
-
*/
|
|
474
|
-
class TelemetryNullLogger {
|
|
475
|
-
send(event) { }
|
|
476
|
-
sendTelemetryEvent(event, error) { }
|
|
477
|
-
sendErrorEvent(event, error) { }
|
|
478
|
-
sendPerformanceEvent(event, error) { }
|
|
479
|
-
}
|
|
480
|
-
exports.TelemetryNullLogger = TelemetryNullLogger;
|
|
481
467
|
/**
|
|
482
468
|
* Takes in an event object, and converts all of its values to a basePropertyType.
|
|
483
469
|
* In the case of an invalid property type, the value will be converted to an error string.
|
|
484
470
|
* @param event - Event with fields you want to stringify.
|
|
485
471
|
*/
|
|
486
|
-
function convertToBaseEvent(
|
|
487
|
-
var { category, eventName } = _a, props = __rest(_a, ["category", "eventName"]);
|
|
472
|
+
function convertToBaseEvent({ category, eventName, ...props }) {
|
|
488
473
|
const newEvent = { category, eventName };
|
|
489
474
|
for (const key of Object.keys(props)) {
|
|
490
475
|
newEvent[key] = convertToBasePropertyType(props[key]);
|
|
@@ -525,4 +510,13 @@ function convertToBasePropertyTypeUntagged(x) {
|
|
|
525
510
|
return `INVALID PROPERTY (typed as ${typeof x})`;
|
|
526
511
|
}
|
|
527
512
|
}
|
|
513
|
+
const tagData = (tag, values) => Object.entries(values)
|
|
514
|
+
.filter((e) => e[1] !== undefined)
|
|
515
|
+
.reduce((pv, cv) => {
|
|
516
|
+
pv[cv[0]] = { tag, value: cv[1] };
|
|
517
|
+
return pv;
|
|
518
|
+
}, {});
|
|
519
|
+
exports.tagData = tagData;
|
|
520
|
+
const tagCodeArtifacts = (values) => (0, exports.tagData)(TelemetryDataTag.CodeArtifact, values);
|
|
521
|
+
exports.tagCodeArtifacts = tagCodeArtifacts;
|
|
528
522
|
//# sourceMappingURL=logger.js.map
|