@fluidframework/telemetry-utils 1.4.0-121020 → 2.0.0-dev-rc.1.0.0.225277
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +12 -13
- package/.mocharc.js +12 -0
- package/CHANGELOG.md +249 -0
- package/README.md +68 -1
- package/api-extractor-esm.json +5 -0
- package/api-extractor-lint.json +4 -0
- package/api-extractor.json +2 -2
- package/api-report/telemetry-utils.api.md +444 -0
- package/dist/config.d.ts +47 -16
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +88 -38
- package/dist/config.js.map +1 -1
- package/dist/error.d.ts +112 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +159 -0
- package/dist/error.js.map +1 -0
- package/dist/errorLogging.d.ts +86 -20
- package/dist/errorLogging.d.ts.map +1 -1
- package/dist/errorLogging.js +190 -60
- package/dist/errorLogging.js.map +1 -1
- package/dist/eventEmitterWithErrorHandling.d.ts +9 -3
- package/dist/eventEmitterWithErrorHandling.d.ts.map +1 -1
- package/dist/eventEmitterWithErrorHandling.js +16 -3
- package/dist/eventEmitterWithErrorHandling.js.map +1 -1
- package/dist/events.d.ts +27 -3
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +26 -2
- package/dist/events.js.map +1 -1
- package/dist/fluidErrorBase.d.ts +57 -16
- package/dist/fluidErrorBase.d.ts.map +1 -1
- package/dist/fluidErrorBase.js +27 -14
- package/dist/fluidErrorBase.js.map +1 -1
- package/dist/index.d.ts +12 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +55 -21
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +269 -53
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +423 -132
- package/dist/logger.js.map +1 -1
- package/dist/mockLogger.d.ts +39 -12
- package/dist/mockLogger.d.ts.map +1 -1
- package/dist/mockLogger.js +105 -22
- package/dist/mockLogger.js.map +1 -1
- package/dist/sampledTelemetryHelper.d.ts +18 -12
- package/dist/sampledTelemetryHelper.d.ts.map +1 -1
- package/dist/sampledTelemetryHelper.js +28 -19
- package/dist/sampledTelemetryHelper.js.map +1 -1
- package/dist/telemetry-utils-alpha.d.ts +290 -0
- package/dist/telemetry-utils-beta.d.ts +264 -0
- package/dist/telemetry-utils-public.d.ts +264 -0
- package/dist/telemetry-utils-untrimmed.d.ts +1102 -0
- package/dist/telemetryTypes.d.ts +115 -0
- package/dist/telemetryTypes.d.ts.map +1 -0
- package/dist/telemetryTypes.js +7 -0
- package/dist/telemetryTypes.js.map +1 -0
- package/dist/thresholdCounter.d.ts +6 -5
- package/dist/thresholdCounter.d.ts.map +1 -1
- package/dist/thresholdCounter.js +4 -3
- package/dist/thresholdCounter.js.map +1 -1
- package/dist/tsdoc-metadata.json +11 -0
- package/dist/utils.d.ts +54 -3
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +58 -3
- package/dist/utils.js.map +1 -1
- package/lib/config.d.ts +47 -16
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +85 -36
- package/lib/config.js.map +1 -1
- package/lib/error.d.ts +112 -0
- package/lib/error.d.ts.map +1 -0
- package/lib/error.js +150 -0
- package/lib/error.js.map +1 -0
- package/lib/errorLogging.d.ts +86 -20
- package/lib/errorLogging.d.ts.map +1 -1
- package/lib/errorLogging.js +189 -60
- package/lib/errorLogging.js.map +1 -1
- package/lib/eventEmitterWithErrorHandling.d.ts +9 -3
- package/lib/eventEmitterWithErrorHandling.d.ts.map +1 -1
- package/lib/eventEmitterWithErrorHandling.js +15 -2
- package/lib/eventEmitterWithErrorHandling.js.map +1 -1
- package/lib/events.d.ts +27 -3
- package/lib/events.d.ts.map +1 -1
- package/lib/events.js +26 -2
- package/lib/events.js.map +1 -1
- package/lib/fluidErrorBase.d.ts +57 -16
- package/lib/fluidErrorBase.d.ts.map +1 -1
- package/lib/fluidErrorBase.js +27 -14
- package/lib/fluidErrorBase.js.map +1 -1
- package/lib/index.d.ts +12 -11
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +11 -11
- package/lib/index.js.map +1 -1
- package/lib/logger.d.ts +269 -53
- package/lib/logger.d.ts.map +1 -1
- package/lib/logger.js +415 -131
- package/lib/logger.js.map +1 -1
- package/lib/mockLogger.d.ts +39 -12
- package/lib/mockLogger.d.ts.map +1 -1
- package/lib/mockLogger.js +106 -23
- package/lib/mockLogger.js.map +1 -1
- package/lib/sampledTelemetryHelper.d.ts +18 -12
- package/lib/sampledTelemetryHelper.d.ts.map +1 -1
- package/lib/sampledTelemetryHelper.js +26 -17
- package/lib/sampledTelemetryHelper.js.map +1 -1
- package/lib/telemetry-utils-alpha.d.mts +290 -0
- package/lib/telemetry-utils-beta.d.mts +264 -0
- package/lib/telemetry-utils-public.d.mts +264 -0
- package/lib/telemetry-utils-untrimmed.d.mts +1102 -0
- package/lib/telemetryTypes.d.ts +115 -0
- package/lib/telemetryTypes.d.ts.map +1 -0
- package/lib/telemetryTypes.js +6 -0
- package/lib/telemetryTypes.js.map +1 -0
- package/lib/thresholdCounter.d.ts +6 -5
- package/lib/thresholdCounter.d.ts.map +1 -1
- package/lib/thresholdCounter.js +4 -3
- package/lib/thresholdCounter.js.map +1 -1
- package/lib/utils.d.ts +54 -3
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +56 -2
- package/lib/utils.js.map +1 -1
- package/package.json +86 -57
- package/prettier.config.cjs +8 -0
- package/src/config.ts +254 -189
- package/src/error.ts +235 -0
- package/src/errorLogging.ts +440 -290
- package/src/eventEmitterWithErrorHandling.ts +26 -14
- package/src/events.ts +54 -25
- package/src/fluidErrorBase.ts +94 -46
- package/src/index.ts +76 -17
- package/src/logger.ts +972 -505
- package/src/mockLogger.ts +225 -83
- package/src/sampledTelemetryHelper.ts +136 -128
- package/src/telemetryTypes.ts +140 -0
- package/src/thresholdCounter.ts +38 -37
- package/src/utils.ts +108 -17
- package/tsconfig.esnext.json +6 -6
- package/tsconfig.json +9 -13
- package/dist/debugLogger.d.ts +0 -39
- package/dist/debugLogger.d.ts.map +0 -1
- package/dist/debugLogger.js +0 -101
- package/dist/debugLogger.js.map +0 -1
- package/dist/packageVersion.d.ts +0 -9
- package/dist/packageVersion.d.ts.map +0 -1
- package/dist/packageVersion.js +0 -12
- package/dist/packageVersion.js.map +0 -1
- package/lib/debugLogger.d.ts +0 -39
- package/lib/debugLogger.d.ts.map +0 -1
- package/lib/debugLogger.js +0 -97
- package/lib/debugLogger.js.map +0 -1
- package/lib/packageVersion.d.ts +0 -9
- package/lib/packageVersion.d.ts.map +0 -1
- package/lib/packageVersion.js +0 -9
- package/lib/packageVersion.js.map +0 -1
- package/src/debugLogger.ts +0 -126
- package/src/packageVersion.ts +0 -9
package/src/error.ts
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
FluidErrorTypes,
|
|
8
|
+
IGenericError,
|
|
9
|
+
IErrorBase,
|
|
10
|
+
ITelemetryBaseProperties,
|
|
11
|
+
IUsageError,
|
|
12
|
+
} from "@fluidframework/core-interfaces";
|
|
13
|
+
import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
LoggingError,
|
|
17
|
+
NORMALIZED_ERROR_TYPE,
|
|
18
|
+
isExternalError,
|
|
19
|
+
normalizeError,
|
|
20
|
+
wrapError,
|
|
21
|
+
} from "./errorLogging";
|
|
22
|
+
import { IFluidErrorBase } from "./fluidErrorBase";
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Throws a UsageError with the given message if the condition is not met.
|
|
26
|
+
* Use this API when `false` indicates a precondition is not met on a public API (for any FF layer).
|
|
27
|
+
*
|
|
28
|
+
* @param condition - The condition that should be true, if the condition is false a UsageError will be thrown.
|
|
29
|
+
* @param message - The message to include in the error when the condition does not hold.
|
|
30
|
+
* @param props - Telemetry props to include on the error when the condition does not hold.
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
export function validatePrecondition(
|
|
34
|
+
condition: boolean,
|
|
35
|
+
message: string,
|
|
36
|
+
props?: ITelemetryBaseProperties,
|
|
37
|
+
): asserts condition {
|
|
38
|
+
if (!condition) {
|
|
39
|
+
throw new UsageError(message, props);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Generic wrapper for an unrecognized/uncategorized error object
|
|
45
|
+
*
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
export class GenericError extends LoggingError implements IGenericError, IFluidErrorBase {
|
|
49
|
+
readonly errorType = FluidErrorTypes.genericError;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Create a new GenericError
|
|
53
|
+
* @param message - Error message
|
|
54
|
+
* @param error - inner error object
|
|
55
|
+
* @param props - Telemetry props to include when the error is logged
|
|
56
|
+
*/
|
|
57
|
+
constructor(
|
|
58
|
+
message: string,
|
|
59
|
+
// TODO: Use `unknown` instead (API breaking change because error is not just an input parameter, but a public member of the class)
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
|
|
61
|
+
public readonly error?: any,
|
|
62
|
+
props?: ITelemetryBaseProperties,
|
|
63
|
+
) {
|
|
64
|
+
// Don't try to log the inner error
|
|
65
|
+
super(message, props, new Set(["error"]));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Error indicating an API is being used improperly resulting in an invalid operation.
|
|
71
|
+
*
|
|
72
|
+
* @internal
|
|
73
|
+
*/
|
|
74
|
+
export class UsageError extends LoggingError implements IUsageError, IFluidErrorBase {
|
|
75
|
+
readonly errorType = FluidErrorTypes.usageError;
|
|
76
|
+
|
|
77
|
+
constructor(message: string, props?: ITelemetryBaseProperties) {
|
|
78
|
+
super(message, { ...props, usageError: true });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* DataCorruptionError indicates that we encountered definitive evidence that the data at rest
|
|
84
|
+
* backing this container is corrupted, and this container would never be expected to load properly again
|
|
85
|
+
*
|
|
86
|
+
* @internal
|
|
87
|
+
*/
|
|
88
|
+
export class DataCorruptionError extends LoggingError implements IErrorBase, IFluidErrorBase {
|
|
89
|
+
readonly errorType = FluidErrorTypes.dataCorruptionError;
|
|
90
|
+
readonly canRetry = false;
|
|
91
|
+
|
|
92
|
+
constructor(message: string, props: ITelemetryBaseProperties) {
|
|
93
|
+
super(message, { ...props, dataProcessingError: 1 });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Indicates we hit a fatal error while processing incoming data from the Fluid Service.
|
|
99
|
+
*
|
|
100
|
+
* @remarks
|
|
101
|
+
*
|
|
102
|
+
* The error will often originate in the dataStore or DDS implementation that is responding to incoming changes.
|
|
103
|
+
* This differs from {@link DataCorruptionError} in that this may be a transient error that will not repro in another
|
|
104
|
+
* client or session.
|
|
105
|
+
*
|
|
106
|
+
* @internal
|
|
107
|
+
*/
|
|
108
|
+
export class DataProcessingError extends LoggingError implements IErrorBase, IFluidErrorBase {
|
|
109
|
+
/**
|
|
110
|
+
* {@inheritDoc IFluidErrorBase.errorType}
|
|
111
|
+
*/
|
|
112
|
+
public readonly errorType = FluidErrorTypes.dataProcessingError;
|
|
113
|
+
|
|
114
|
+
public readonly canRetry = false;
|
|
115
|
+
|
|
116
|
+
private constructor(errorMessage: string, props?: ITelemetryBaseProperties) {
|
|
117
|
+
super(errorMessage, props);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Create a new `DataProcessingError` detected and raised within the Fluid Framework.
|
|
122
|
+
*/
|
|
123
|
+
public static create(
|
|
124
|
+
errorMessage: string,
|
|
125
|
+
dataProcessingCodepath: string,
|
|
126
|
+
sequencedMessage?: ISequencedDocumentMessage,
|
|
127
|
+
props: ITelemetryBaseProperties = {},
|
|
128
|
+
): IFluidErrorBase {
|
|
129
|
+
const dataProcessingError = DataProcessingError.wrapIfUnrecognized(
|
|
130
|
+
errorMessage,
|
|
131
|
+
dataProcessingCodepath,
|
|
132
|
+
sequencedMessage,
|
|
133
|
+
);
|
|
134
|
+
dataProcessingError.addTelemetryProperties(props);
|
|
135
|
+
|
|
136
|
+
return dataProcessingError;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Wrap the given error in a `DataProcessingError`, unless the error is already of a known type
|
|
141
|
+
* with the exception of a normalized {@link LoggingError}, which will still be wrapped.
|
|
142
|
+
*
|
|
143
|
+
* In either case, the error will have some relevant properties added for telemetry.
|
|
144
|
+
*
|
|
145
|
+
* @remarks
|
|
146
|
+
*
|
|
147
|
+
* We wrap conditionally since known error types represent well-understood failure modes, and ideally
|
|
148
|
+
* one day we will move away from throwing these errors but rather we'll return them.
|
|
149
|
+
* But an unrecognized error needs to be classified as `DataProcessingError`.
|
|
150
|
+
*
|
|
151
|
+
* @param originalError - The error to be converted.
|
|
152
|
+
* @param dataProcessingCodepath - Which code-path failed while processing data.
|
|
153
|
+
* @param messageLike - Message to include info about via telemetry props.
|
|
154
|
+
*
|
|
155
|
+
* @returns Either a new `DataProcessingError`, or (if wrapping is deemed unnecessary) the given error.
|
|
156
|
+
*/
|
|
157
|
+
public static wrapIfUnrecognized(
|
|
158
|
+
originalError: unknown,
|
|
159
|
+
dataProcessingCodepath: string,
|
|
160
|
+
messageLike?: Partial<
|
|
161
|
+
Pick<
|
|
162
|
+
ISequencedDocumentMessage,
|
|
163
|
+
| "clientId"
|
|
164
|
+
| "sequenceNumber"
|
|
165
|
+
| "clientSequenceNumber"
|
|
166
|
+
| "referenceSequenceNumber"
|
|
167
|
+
| "minimumSequenceNumber"
|
|
168
|
+
| "timestamp"
|
|
169
|
+
>
|
|
170
|
+
>,
|
|
171
|
+
): IFluidErrorBase {
|
|
172
|
+
const props = {
|
|
173
|
+
dataProcessingError: 1,
|
|
174
|
+
dataProcessingCodepath,
|
|
175
|
+
...(messageLike === undefined
|
|
176
|
+
? undefined
|
|
177
|
+
: extractSafePropertiesFromMessage(messageLike)),
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const normalizedError = normalizeError(originalError, { props });
|
|
181
|
+
// Note that other errors may have the NORMALIZED_ERROR_TYPE errorType,
|
|
182
|
+
// but if so they are still suitable to be wrapped as DataProcessingError.
|
|
183
|
+
if (
|
|
184
|
+
isExternalError(normalizedError) ||
|
|
185
|
+
normalizedError.errorType === NORMALIZED_ERROR_TYPE
|
|
186
|
+
) {
|
|
187
|
+
// Create a new DataProcessingError to wrap this external error
|
|
188
|
+
const dataProcessingError = wrapError(
|
|
189
|
+
normalizedError,
|
|
190
|
+
(message: string) => new DataProcessingError(message),
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
// Copy over the props above and any others added to this error since first being normalized
|
|
194
|
+
dataProcessingError.addTelemetryProperties(normalizedError.getTelemetryProperties());
|
|
195
|
+
|
|
196
|
+
return dataProcessingError;
|
|
197
|
+
}
|
|
198
|
+
return normalizedError;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Extracts specific properties from the provided message that we know are safe to log.
|
|
204
|
+
*
|
|
205
|
+
* @param messageLike - Message to include info about via telemetry props.
|
|
206
|
+
*
|
|
207
|
+
* @internal
|
|
208
|
+
*/
|
|
209
|
+
export const extractSafePropertiesFromMessage = (
|
|
210
|
+
messageLike: Partial<
|
|
211
|
+
Pick<
|
|
212
|
+
ISequencedDocumentMessage,
|
|
213
|
+
| "clientId"
|
|
214
|
+
| "sequenceNumber"
|
|
215
|
+
| "clientSequenceNumber"
|
|
216
|
+
| "referenceSequenceNumber"
|
|
217
|
+
| "minimumSequenceNumber"
|
|
218
|
+
| "timestamp"
|
|
219
|
+
>
|
|
220
|
+
>,
|
|
221
|
+
): {
|
|
222
|
+
messageClientId: string | undefined;
|
|
223
|
+
messageSequenceNumber: number | undefined;
|
|
224
|
+
messageClientSequenceNumber: number | undefined;
|
|
225
|
+
messageReferenceSequenceNumber: number | undefined;
|
|
226
|
+
messageMinimumSequenceNumber: number | undefined;
|
|
227
|
+
messageTimestamp: number | undefined;
|
|
228
|
+
} => ({
|
|
229
|
+
messageClientId: messageLike.clientId === null ? "null" : messageLike.clientId,
|
|
230
|
+
messageSequenceNumber: messageLike.sequenceNumber,
|
|
231
|
+
messageClientSequenceNumber: messageLike.clientSequenceNumber,
|
|
232
|
+
messageReferenceSequenceNumber: messageLike.referenceSequenceNumber,
|
|
233
|
+
messageMinimumSequenceNumber: messageLike.minimumSequenceNumber,
|
|
234
|
+
messageTimestamp: messageLike.timestamp,
|
|
235
|
+
});
|