@fluidframework/telemetry-utils 0.59.4001 → 1.1.0-75972

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.
@@ -88,10 +88,6 @@ function patchLegacyError(
88
88
  }
89
89
  }
90
90
 
91
- // errorType "genericError" is used as a default value throughout the code.
92
- // Note that this matches ContainerErrorType/DriverErrorType's genericError
93
- const defaultErrorTypeForNormalize = "genericError";
94
-
95
91
  /**
96
92
  * Normalize the given error yielding a valid Fluid Error
97
93
  * @returns A valid Fluid Error with any provided annotations applied
@@ -115,17 +111,11 @@ export function normalizeError(
115
111
 
116
112
  // We have to construct a new Fluid Error, copying safe properties over
117
113
  const { message, stack } = extractLogSafeErrorProperties(error, false /* sanitizeStack */);
118
- const fluidError: IFluidErrorBase = new SimpleFluidError({
119
- errorType: defaultErrorTypeForNormalize,
114
+ const fluidError: IFluidErrorBase = new NormalizedExternalError({
120
115
  message,
121
116
  stack,
122
117
  });
123
118
 
124
- fluidError.addTelemetryProperties({
125
- ...annotations.props,
126
- untrustedOrigin: 1, // This will let us filter to errors not originated by our own code
127
- });
128
-
129
119
  // We need to preserve these properties which are used in a non-typesafe way throughout driver code (see #8743)
130
120
  // Anywhere they are set should be on a valid Fluid Error that would have been returned above,
131
121
  // but we can't prove it with the types, so adding this defensive measure.
@@ -138,6 +128,14 @@ export function normalizeError(
138
128
  // This is only interesting for non-objects
139
129
  fluidError.addTelemetryProperties({ typeofError: typeof (error) });
140
130
  }
131
+
132
+ const originalErrorTelemetryProps = isILoggingError(error) ? error.getTelemetryProperties() : {};
133
+ fluidError.addTelemetryProperties({
134
+ ...originalErrorTelemetryProps,
135
+ ...annotations.props,
136
+ untrustedOrigin: 1, // This will let us filter to errors not originated by our own code
137
+ });
138
+
141
139
  return fluidError;
142
140
  }
143
141
 
@@ -175,9 +173,8 @@ export function generateStack(): string | undefined {
175
173
  }
176
174
 
177
175
  /**
178
- * Create a new error, wrapping and caused by the given unknown error.
179
- * Copies the inner error's message and stack over but otherwise uses newErrorFn to define the error.
180
- * The inner error's instance id will also be logged for telemetry analysis.
176
+ * Create a new error using newErrorFn, wrapping and caused by the given unknown error.
177
+ * Copies the inner error's stack, errorInstanceId and telemetry props over to the new error if present
181
178
  * @param innerError - An error from untrusted/unknown origins
182
179
  * @param newErrorFn - callback that will create a new error given the original error's message
183
180
  * @returns A new error object "wrapping" the given error
@@ -198,7 +195,7 @@ export function wrapError<T extends LoggingError>(
198
195
  }
199
196
 
200
197
  // Mark external errors with untrustedOrigin flag
201
- if (originatedAsExternalError(innerError)) {
198
+ if (isExternalError(innerError)) {
202
199
  newError.addTelemetryProperties({ untrustedOrigin: 1 });
203
200
  }
204
201
 
@@ -210,6 +207,12 @@ export function wrapError<T extends LoggingError>(
210
207
  newError.addTelemetryProperties({ innerErrorInstanceId: innerError.errorInstanceId });
211
208
  }
212
209
 
210
+ // Lastly, copy over all other telemetry properties. Note these will not overwrite existing properties
211
+ // This will include the untrustedOrigin property if the inner error itself was created from an external error
212
+ if (isILoggingError(innerError)) {
213
+ newError.addTelemetryProperties(innerError.getTelemetryProperties());
214
+ }
215
+
213
216
  return newError;
214
217
  }
215
218
 
@@ -245,14 +248,6 @@ function overwriteStack(error: IFluidErrorBase | LoggingError, stack: string) {
245
248
  }
246
249
  }
247
250
 
248
- /**
249
- * True for any error object that is either external itself or is a wrapped/normalized external error
250
- * False for any error we created and raised within the FF codebase.
251
- */
252
- export function originatedAsExternalError(e: any): boolean {
253
- return !isValidLegacyError(e) || (e.getTelemetryProperties().untrustedOrigin === 1);
254
- }
255
-
256
251
  /**
257
252
  * True for any error object that is an (optionally normalized) external error
258
253
  * False for any error we created and raised within the FF codebase, or wrapped in a well-known error type
@@ -260,7 +255,7 @@ export function originatedAsExternalError(e: any): boolean {
260
255
  export function isExternalError(e: any): boolean {
261
256
  return !isValidLegacyError(e) ||
262
257
  (e.getTelemetryProperties().untrustedOrigin === 1 &&
263
- e.errorType === defaultErrorTypeForNormalize);
258
+ e.errorType === NormalizedExternalError.normalizedErrorType);
264
259
  }
265
260
 
266
261
  /**
@@ -316,19 +311,18 @@ export const getCircularReplacer = () => {
316
311
  }
317
312
  seen.add(value);
318
313
  }
319
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
320
314
  return value;
321
315
  };
322
316
  };
323
317
 
324
318
  /**
325
319
  * Base class for "trusted" errors we create, whose properties can generally be logged to telemetry safely.
326
- * All properties set on the object, or passed in (via the constructor or getTelemetryProperties),
320
+ * All properties set on the object, or passed in (via the constructor or addTelemetryProperties),
327
321
  * will be logged in accordance with their tag, if present.
328
322
  *
329
323
  * PLEASE take care to avoid setting sensitive data on this object without proper tagging!
330
324
  */
331
- export class LoggingError extends Error implements ILoggingError, Pick<IFluidErrorBase, "errorInstanceId"> {
325
+ export class LoggingError extends Error implements ILoggingError, Omit<IFluidErrorBase, "errorType"> {
332
326
  private _errorInstanceId = uuid();
333
327
  get errorInstanceId() { return this._errorInstanceId; }
334
328
  overwriteErrorInstanceId(id: string) { this._errorInstanceId = id; }
@@ -381,19 +375,22 @@ export class LoggingError extends Error implements ILoggingError, Pick<IFluidErr
381
375
  }
382
376
  }
383
377
 
384
- /** Simple implementation of IFluidErrorBase, extending LoggingError */
385
- class SimpleFluidError extends LoggingError implements IFluidErrorBase {
386
- readonly errorType: string;
378
+ /** The Error class used when normalizing an external error */
379
+ class NormalizedExternalError extends LoggingError {
380
+ // errorType "genericError" is used as a default value throughout the code.
381
+ // Note that this matches ContainerErrorType/DriverErrorType's genericError
382
+ static readonly normalizedErrorType = "genericError";
383
+
384
+ errorType = NormalizedExternalError.normalizedErrorType;
387
385
 
388
386
  constructor(
389
387
  errorProps: Pick<IFluidErrorBase,
390
388
  | "message"
391
389
  | "stack"
392
- | "errorType"
393
390
  >,
394
391
  ) {
395
392
  super(errorProps.message);
396
- this.errorType = errorProps.errorType;
393
+
397
394
  if (errorProps.stack !== undefined) {
398
395
  overwriteStack(this, errorProps.stack);
399
396
  }
package/src/logger.ts CHANGED
@@ -31,9 +31,14 @@ import {
31
31
  * Broad classifications to be applied to individual properties as they're prepared to be logged to telemetry.
32
32
  * Please do not modify existing entries for backwards compatibility.
33
33
  */
34
- export enum TelemetryDataTag {
35
- /** Data containing terms from code packages that may have been dynamically loaded */
34
+ export enum TelemetryDataTag {
35
+ /**
36
+ * Data containing terms from code packages that may have been dynamically loaded
37
+ * @deprecated 1.0, will be removed in next release (see issue #6603). Use `TelemetryDataTag.CodeArtifact` instead.
38
+ */
36
39
  PackageData = "PackageData",
40
+ /** Data containing terms or IDs from code packages that may have been dynamically loaded */
41
+ CodeArtifact = "CodeArtifact",
37
42
  /** Personal data of a variety of classifications that pertains to the user */
38
43
  UserData = "UserData",
39
44
  }
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/telemetry-utils";
9
- export const pkgVersion = "0.59.4001";
9
+ export const pkgVersion = "1.1.0-75972";