@fluidframework/telemetry-utils 0.51.2 → 0.52.0-44610
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/errorLogging.js +1 -1
- package/dist/errorLogging.js.map +1 -1
- package/dist/fluidErrorBase.d.ts +7 -3
- package/dist/fluidErrorBase.d.ts.map +1 -1
- package/dist/fluidErrorBase.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/lib/errorLogging.js +1 -1
- package/lib/errorLogging.js.map +1 -1
- package/lib/fluidErrorBase.d.ts +7 -3
- package/lib/fluidErrorBase.d.ts.map +1 -1
- package/lib/fluidErrorBase.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.d.ts.map +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/package.json +2 -2
- package/src/errorLogging.ts +5 -5
- package/src/fluidErrorBase.ts +9 -3
- package/src/packageVersion.ts +1 -1
package/dist/errorLogging.js
CHANGED
|
@@ -58,11 +58,11 @@ function copyProps(target, source) {
|
|
|
58
58
|
class SimpleFluidError {
|
|
59
59
|
constructor(errorProps) {
|
|
60
60
|
this.telemetryProps = {};
|
|
61
|
+
this.name = "Error";
|
|
61
62
|
this.errorType = errorProps.errorType;
|
|
62
63
|
this.fluidErrorCode = errorProps.fluidErrorCode;
|
|
63
64
|
this.message = errorProps.message;
|
|
64
65
|
this.stack = errorProps.stack;
|
|
65
|
-
this.name = errorProps.name;
|
|
66
66
|
this.errorInstanceId = uuid_1.v4();
|
|
67
67
|
this.addTelemetryProperties(errorProps);
|
|
68
68
|
}
|
package/dist/errorLogging.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errorLogging.js","sourceRoot":"","sources":["../src/errorLogging.ts"],"names":[],"mappings":";AAAA;;;GA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a,SAAQ,KAAK;IAGnC;;;;;OAKG;IACH,YACI,OAAe,EACf,KAA4B,EACX,uBAAoC,IAAI,GAAG,EAAE;QAE9D,KAAK,CAAC,OAAO,CAAC,CAAC;QAFE,yBAAoB,GAApB,oBAAoB,CAAyB;QAXzD,oBAAe,GAAG,SAAI,EAAE,CAAC;QAe9B,oCAAoC;QACpC,oBAAoB,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;QAEjD,IAAI,KAAK,EAAE;YACP,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC;SACtC;IACL,CAAC;IAED;;OAEG;IACI,sBAAsB,CAAC,KAA2B;QACrD,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC3B,CAAC;IAED;;OAEG;IACI,sBAAsB;QACzB,MAAM,aAAa,GAAG,sBAAsB,CAAC,IAAI,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;QAC9E,oGAAoG;QACpG,uCACO,aAAa,KAChB,KAAK,EAAE,IAAI,CAAC,KAAK,EACjB,OAAO,EAAE,IAAI,CAAC,OAAO,IACvB;IACN,CAAC;CACJ;AA3CD,oCA2CC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n ILoggingError,\n ITaggedTelemetryPropertyType,\n ITelemetryLogger,\n ITelemetryProperties,\n} from \"@fluidframework/common-definitions\";\nimport { v4 as uuid } from \"uuid\";\nimport {\n hasErrorInstanceId,\n IFluidErrorBase,\n isFluidError,\n isValidLegacyError,\n} from \"./fluidErrorBase\";\n\n/** @returns true if value is an object but neither null nor an array */\nconst isRegularObject = (value: any): boolean => {\n return value !== null && !Array.isArray(value) && typeof value === \"object\";\n};\n\n/** Inspect the given error for common \"safe\" props and return them */\nexport function extractLogSafeErrorProperties(error: any, sanitizeStack: boolean) {\n const removeMessageFromStack = (stack: string, errorName?: string) => {\n if (!sanitizeStack) {\n return stack;\n }\n const stackFrames = stack.split(\"\\n\");\n stackFrames.shift(); // Remove \"[ErrorName]: [ErrorMessage]\"\n if (errorName !== undefined) {\n stackFrames.unshift(errorName); // Add \"[ErrorName]\"\n }\n return stackFrames.join(\"\\n\");\n };\n\n const message = (typeof error?.message === \"string\")\n ? error.message as string\n : String(error);\n\n const safeProps: { message: string; errorType?: string; stack?: string } = {\n message,\n };\n\n if (isRegularObject(error)) {\n const { errorType, stack, name } = error;\n\n if (typeof errorType === \"string\") {\n safeProps.errorType = errorType;\n }\n\n if (typeof stack === \"string\") {\n const errorName = (typeof name === \"string\") ? name : undefined;\n safeProps.stack = removeMessageFromStack(stack, errorName);\n }\n }\n\n return safeProps;\n}\n\n/** type guard for ILoggingError interface */\nexport const isILoggingError = (x: any): x is ILoggingError => typeof x?.getTelemetryProperties === \"function\";\n\n/** Copy props from source onto target, but do not overwrite an existing prop that matches */\nfunction copyProps(target: ITelemetryProperties | LoggingError, source: ITelemetryProperties) {\n for (const key of Object.keys(source)) {\n if (target[key] === undefined) {\n target[key] = source[key];\n }\n }\n}\n\n/** Metadata to annotate an error object when annotating or normalizing it */\nexport interface IFluidErrorAnnotations {\n /** Telemetry props to log with the error */\n props?: ITelemetryProperties;\n}\n\n/** Simplest possible implementation of IFluidErrorBase */\nclass SimpleFluidError implements IFluidErrorBase {\n private readonly telemetryProps: ITelemetryProperties = {};\n\n readonly errorType: string;\n readonly fluidErrorCode: string;\n readonly message: string;\n readonly stack?: string;\n readonly name?: string;\n readonly errorInstanceId: string;\n\n constructor(\n errorProps: Omit<IFluidErrorBase,\n \"getTelemetryProperties\" |\n \"addTelemetryProperties\" |\n \"errorInstanceId\">,\n ) {\n this.errorType = errorProps.errorType;\n this.fluidErrorCode = errorProps.fluidErrorCode;\n this.message = errorProps.message;\n this.stack = errorProps.stack;\n this.name = errorProps.name;\n this.errorInstanceId = uuid();\n\n this.addTelemetryProperties(errorProps);\n }\n\n getTelemetryProperties(): ITelemetryProperties {\n return this.telemetryProps;\n }\n\n addTelemetryProperties(props: ITelemetryProperties) {\n copyProps(this.telemetryProps, props);\n }\n}\n\n/** For backwards compatibility with pre-fluidErrorCode valid errors */\nfunction patchWithErrorCode(\n legacyError: Omit<IFluidErrorBase, \"fluidErrorCode\">,\n): asserts legacyError is IFluidErrorBase {\n const patchMe: { -readonly [P in \"fluidErrorCode\"]?: IFluidErrorBase[P] } = legacyError as any;\n if (patchMe.fluidErrorCode === undefined) {\n patchMe.fluidErrorCode = \"<error predates fluidErrorCode>\";\n }\n}\n\n/**\n * Normalize the given error yielding a valid Fluid Error\n * @returns A valid Fluid Error with any provided annotations applied\n * @param error - The error to normalize\n * @param annotations - Annotations to apply to the normalized error\n */\nexport function normalizeError(\n error: unknown,\n annotations: IFluidErrorAnnotations = {},\n): IFluidErrorBase {\n // Back-compat, while IFluidErrorBase is rolled out\n if (isValidLegacyError(error)) {\n patchWithErrorCode(error);\n }\n\n if (isFluidError(error)) {\n // We can simply add the telemetry props to the error and return it\n error.addTelemetryProperties(annotations.props ?? {});\n return error;\n }\n\n // We have to construct a new Fluid Error, copying safe properties over\n const { message, stack } = extractLogSafeErrorProperties(error, false /* sanitizeStack */);\n const fluidError: IFluidErrorBase = new SimpleFluidError({\n errorType: \"genericError\", // Match Container/Driver generic error type\n fluidErrorCode: \"\",\n message,\n stack: stack ?? generateStack(),\n });\n\n fluidError.addTelemetryProperties({\n ...annotations.props,\n untrustedOrigin: 1, // This will let us filter to errors not originated by our own code\n });\n\n if (typeof(error) !== \"object\") {\n // This is only interesting for non-objects\n fluidError.addTelemetryProperties({ typeofError: typeof(error) });\n }\n return fluidError;\n}\n\nexport function generateStack(): string | undefined {\n // Some browsers will populate stack right away, others require throwing Error\n let stack = new Error(\"<<generated stack>>\").stack;\n if (!stack) {\n try {\n throw new Error(\"<<generated stack>>\");\n } catch (e) {\n stack = e.stack;\n }\n }\n return stack;\n}\n\n/**\n * Create a new error, wrapping and caused by the given unknown error.\n * Copies the inner error's message and stack over but otherwise uses newErrorFn to define the error.\n * The inner error's instance id will also be logged for telemetry analysis.\n * @param innerError - An error from untrusted/unknown origins\n * @param newErrorFn - callback that will create a new error given the original error's message\n * @returns A new error object \"wrapping\" the given error\n */\n export function wrapError<T extends IFluidErrorBase>(\n innerError: unknown,\n newErrorFn: (message: string) => T,\n): T {\n const {\n message,\n stack,\n } = extractLogSafeErrorProperties(innerError, false /* sanitizeStack */);\n\n const newError = newErrorFn(message);\n\n if (stack !== undefined) {\n // supposedly setting stack on an Error can throw.\n try {\n Object.assign(newError, { stack });\n } catch (errorSettingStack) {\n newError.addTelemetryProperties({ stack2: stack });\n }\n }\n\n if (hasErrorInstanceId(innerError)) {\n newError.addTelemetryProperties({ innerErrorInstanceId: innerError.errorInstanceId });\n }\n\n return newError;\n}\n\n/** The same as wrapError, but also logs the innerError, including the wrapping error's instance id */\nexport function wrapErrorAndLog<T extends IFluidErrorBase>(\n innerError: unknown,\n newErrorFn: (message: string) => T,\n logger: ITelemetryLogger,\n) {\n const newError = wrapError(innerError, newErrorFn);\n const wrappedByErrorInstanceId = hasErrorInstanceId(newError)\n ? newError.errorInstanceId\n : undefined;\n\n logger.sendTelemetryEvent({\n eventName: \"WrapError\",\n wrappedByErrorInstanceId,\n }, innerError);\n\n return newError;\n}\n\n/**\n * Type guard to identify if a particular value (loosely) appears to be a tagged telemetry property\n */\nexport function isTaggedTelemetryPropertyValue(x: any): x is ITaggedTelemetryPropertyType {\n return (typeof(x?.value) !== \"object\" && typeof(x?.tag) === \"string\");\n}\n\n/**\n * Walk an object's enumerable properties to find those fit for telemetry.\n */\nfunction getValidTelemetryProps(obj: any, keysToOmit: Set<string>): ITelemetryProperties {\n const props: ITelemetryProperties = {};\n for (const key of Object.keys(obj)) {\n if (keysToOmit.has(key)) {\n continue;\n }\n const val = obj[key];\n switch (typeof val) {\n case \"string\":\n case \"number\":\n case \"boolean\":\n case \"undefined\":\n props[key] = val;\n break;\n default: {\n if (isTaggedTelemetryPropertyValue(val)) {\n props[key] = val;\n } else {\n // We don't support logging arbitrary objects\n props[key] = \"REDACTED (arbitrary object)\";\n }\n break;\n }\n }\n }\n return props;\n}\n\n/**\n * Base class for \"trusted\" errors we create, whose properties can generally be logged to telemetry safely.\n * All properties set on the object, or passed in (via the constructor or getTelemetryProperties),\n * will be logged in accordance with their tag, if present.\n *\n * PLEASE take care to avoid setting sensitive data on this object without proper tagging!\n */\nexport class LoggingError extends Error implements ILoggingError, Pick<IFluidErrorBase, \"errorInstanceId\"> {\n readonly errorInstanceId = uuid();\n\n /**\n * Create a new LoggingError\n * @param message - Error message to use for Error base class\n * @param props - telemetry props to include on the error for when it's logged\n * @param omitPropsFromLogging - properties by name to omit from telemetry props\n */\n constructor(\n message: string,\n props?: ITelemetryProperties,\n private readonly omitPropsFromLogging: Set<string> = new Set(),\n ) {\n super(message);\n\n // Don't log this list itself either\n omitPropsFromLogging.add(\"omitPropsFromLogging\");\n\n if (props) {\n this.addTelemetryProperties(props);\n }\n }\n\n /**\n * Add additional properties to be logged\n */\n public addTelemetryProperties(props: ITelemetryProperties) {\n copyProps(this, props);\n }\n\n /**\n * Get all properties fit to be logged to telemetry for this error\n */\n public getTelemetryProperties(): ITelemetryProperties {\n const taggableProps = getValidTelemetryProps(this, this.omitPropsFromLogging);\n // Include non-enumerable props inherited from Error that are not returned by getValidTelemetryProps\n return {\n ...taggableProps,\n stack: this.stack,\n message: this.message,\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"errorLogging.js","sourceRoot":"","sources":["../src/errorLogging.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAQH,+BAAkC;AAClC,qDAK0B;AAE1B,wEAAwE;AACxE,MAAM,eAAe,GAAG,CAAC,KAAU,EAAW,EAAE;IAC5C,OAAO,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC;AAChF,CAAC,CAAC;AAEF,sEAAsE;AACtE,SAAgB,6BAA6B,CAAC,KAAU,EA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,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC;SACtC;IACL,CAAC;IAED;;OAEG;IACI,sBAAsB,CAAC,KAA2B;QACrD,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC3B,CAAC;IAED;;OAEG;IACI,sBAAsB;QACzB,MAAM,aAAa,GAAG,sBAAsB,CAAC,IAAI,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;QAC9E,oGAAoG;QACpG,uCACO,aAAa,KAChB,KAAK,EAAE,IAAI,CAAC,KAAK,EACjB,OAAO,EAAE,IAAI,CAAC,OAAO,IACvB;IACN,CAAC;CACJ;AA3CD,oCA2CC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n ILoggingError,\n ITaggedTelemetryPropertyType,\n ITelemetryLogger,\n ITelemetryProperties,\n} from \"@fluidframework/common-definitions\";\nimport { v4 as uuid } from \"uuid\";\nimport {\n hasErrorInstanceId,\n IFluidErrorBase,\n isFluidError,\n isValidLegacyError,\n} from \"./fluidErrorBase\";\n\n/** @returns true if value is an object but neither null nor an array */\nconst isRegularObject = (value: any): boolean => {\n return value !== null && !Array.isArray(value) && typeof value === \"object\";\n};\n\n/** Inspect the given error for common \"safe\" props and return them */\nexport function extractLogSafeErrorProperties(error: any, sanitizeStack: boolean) {\n const removeMessageFromStack = (stack: string, errorName?: string) => {\n if (!sanitizeStack) {\n return stack;\n }\n const stackFrames = stack.split(\"\\n\");\n stackFrames.shift(); // Remove \"[ErrorName]: [ErrorMessage]\"\n if (errorName !== undefined) {\n stackFrames.unshift(errorName); // Add \"[ErrorName]\"\n }\n return stackFrames.join(\"\\n\");\n };\n\n const message = (typeof error?.message === \"string\")\n ? error.message as string\n : String(error);\n\n const safeProps: { message: string; errorType?: string; stack?: string } = {\n message,\n };\n\n if (isRegularObject(error)) {\n const { errorType, stack, name } = error;\n\n if (typeof errorType === \"string\") {\n safeProps.errorType = errorType;\n }\n\n if (typeof stack === \"string\") {\n const errorName = (typeof name === \"string\") ? name : undefined;\n safeProps.stack = removeMessageFromStack(stack, errorName);\n }\n }\n\n return safeProps;\n}\n\n/** type guard for ILoggingError interface */\nexport const isILoggingError = (x: any): x is ILoggingError => typeof x?.getTelemetryProperties === \"function\";\n\n/** Copy props from source onto target, but do not overwrite an existing prop that matches */\nfunction copyProps(target: ITelemetryProperties | LoggingError, source: ITelemetryProperties) {\n for (const key of Object.keys(source)) {\n if (target[key] === undefined) {\n target[key] = source[key];\n }\n }\n}\n\n/** Metadata to annotate an error object when annotating or normalizing it */\nexport interface IFluidErrorAnnotations {\n /** Telemetry props to log with the error */\n props?: ITelemetryProperties;\n}\n\n/** Simplest possible implementation of IFluidErrorBase */\nclass SimpleFluidError implements IFluidErrorBase {\n private readonly telemetryProps: ITelemetryProperties = {};\n\n readonly errorType: string;\n readonly fluidErrorCode: string;\n readonly message: string;\n readonly stack?: string;\n readonly name: string = \"Error\";\n readonly errorInstanceId: string;\n\n constructor(\n errorProps: Omit<IFluidErrorBase,\n | \"getTelemetryProperties\"\n | \"addTelemetryProperties\"\n | \"errorInstanceId\"\n | \"name\">,\n ) {\n this.errorType = errorProps.errorType;\n this.fluidErrorCode = errorProps.fluidErrorCode;\n this.message = errorProps.message;\n this.stack = errorProps.stack;\n this.errorInstanceId = uuid();\n\n this.addTelemetryProperties(errorProps);\n }\n\n getTelemetryProperties(): ITelemetryProperties {\n return this.telemetryProps;\n }\n\n addTelemetryProperties(props: ITelemetryProperties) {\n copyProps(this.telemetryProps, props);\n }\n}\n\n/** For backwards compatibility with pre-fluidErrorCode valid errors */\nfunction patchWithErrorCode(\n legacyError: Omit<IFluidErrorBase, \"fluidErrorCode\">,\n): asserts legacyError is IFluidErrorBase {\n const patchMe: { -readonly [P in \"fluidErrorCode\"]?: IFluidErrorBase[P] } = legacyError as any;\n if (patchMe.fluidErrorCode === undefined) {\n patchMe.fluidErrorCode = \"<error predates fluidErrorCode>\";\n }\n}\n\n/**\n * Normalize the given error yielding a valid Fluid Error\n * @returns A valid Fluid Error with any provided annotations applied\n * @param error - The error to normalize\n * @param annotations - Annotations to apply to the normalized error\n */\nexport function normalizeError(\n error: unknown,\n annotations: IFluidErrorAnnotations = {},\n): IFluidErrorBase {\n // Back-compat, while IFluidErrorBase is rolled out\n if (isValidLegacyError(error)) {\n patchWithErrorCode(error);\n }\n\n if (isFluidError(error)) {\n // We can simply add the telemetry props to the error and return it\n error.addTelemetryProperties(annotations.props ?? {});\n return error;\n }\n\n // We have to construct a new Fluid Error, copying safe properties over\n const { message, stack } = extractLogSafeErrorProperties(error, false /* sanitizeStack */);\n const fluidError: IFluidErrorBase = new SimpleFluidError({\n errorType: \"genericError\", // Match Container/Driver generic error type\n fluidErrorCode: \"\",\n message,\n stack: stack ?? generateStack(),\n });\n\n fluidError.addTelemetryProperties({\n ...annotations.props,\n untrustedOrigin: 1, // This will let us filter to errors not originated by our own code\n });\n\n if (typeof(error) !== \"object\") {\n // This is only interesting for non-objects\n fluidError.addTelemetryProperties({ typeofError: typeof(error) });\n }\n return fluidError;\n}\n\nexport function generateStack(): string | undefined {\n // Some browsers will populate stack right away, others require throwing Error\n let stack = new Error(\"<<generated stack>>\").stack;\n if (!stack) {\n try {\n throw new Error(\"<<generated stack>>\");\n } catch (e) {\n stack = e.stack;\n }\n }\n return stack;\n}\n\n/**\n * Create a new error, wrapping and caused by the given unknown error.\n * Copies the inner error's message and stack over but otherwise uses newErrorFn to define the error.\n * The inner error's instance id will also be logged for telemetry analysis.\n * @param innerError - An error from untrusted/unknown origins\n * @param newErrorFn - callback that will create a new error given the original error's message\n * @returns A new error object \"wrapping\" the given error\n */\n export function wrapError<T extends IFluidErrorBase>(\n innerError: unknown,\n newErrorFn: (message: string) => T,\n): T {\n const {\n message,\n stack,\n } = extractLogSafeErrorProperties(innerError, false /* sanitizeStack */);\n\n const newError = newErrorFn(message);\n\n if (stack !== undefined) {\n // supposedly setting stack on an Error can throw.\n try {\n Object.assign(newError, { stack });\n } catch (errorSettingStack) {\n newError.addTelemetryProperties({ stack2: stack });\n }\n }\n\n if (hasErrorInstanceId(innerError)) {\n newError.addTelemetryProperties({ innerErrorInstanceId: innerError.errorInstanceId });\n }\n\n return newError;\n}\n\n/** The same as wrapError, but also logs the innerError, including the wrapping error's instance id */\nexport function wrapErrorAndLog<T extends IFluidErrorBase>(\n innerError: unknown,\n newErrorFn: (message: string) => T,\n logger: ITelemetryLogger,\n) {\n const newError = wrapError(innerError, newErrorFn);\n const wrappedByErrorInstanceId = hasErrorInstanceId(newError)\n ? newError.errorInstanceId\n : undefined;\n\n logger.sendTelemetryEvent({\n eventName: \"WrapError\",\n wrappedByErrorInstanceId,\n }, innerError);\n\n return newError;\n}\n\n/**\n * Type guard to identify if a particular value (loosely) appears to be a tagged telemetry property\n */\nexport function isTaggedTelemetryPropertyValue(x: any): x is ITaggedTelemetryPropertyType {\n return (typeof(x?.value) !== \"object\" && typeof(x?.tag) === \"string\");\n}\n\n/**\n * Walk an object's enumerable properties to find those fit for telemetry.\n */\nfunction getValidTelemetryProps(obj: any, keysToOmit: Set<string>): ITelemetryProperties {\n const props: ITelemetryProperties = {};\n for (const key of Object.keys(obj)) {\n if (keysToOmit.has(key)) {\n continue;\n }\n const val = obj[key];\n switch (typeof val) {\n case \"string\":\n case \"number\":\n case \"boolean\":\n case \"undefined\":\n props[key] = val;\n break;\n default: {\n if (isTaggedTelemetryPropertyValue(val)) {\n props[key] = val;\n } else {\n // We don't support logging arbitrary objects\n props[key] = \"REDACTED (arbitrary object)\";\n }\n break;\n }\n }\n }\n return props;\n}\n\n/**\n * Base class for \"trusted\" errors we create, whose properties can generally be logged to telemetry safely.\n * All properties set on the object, or passed in (via the constructor or getTelemetryProperties),\n * will be logged in accordance with their tag, if present.\n *\n * PLEASE take care to avoid setting sensitive data on this object without proper tagging!\n */\nexport class LoggingError extends Error implements ILoggingError, Pick<IFluidErrorBase, \"errorInstanceId\"> {\n readonly errorInstanceId = uuid();\n\n /**\n * Create a new LoggingError\n * @param message - Error message to use for Error base class\n * @param props - telemetry props to include on the error for when it's logged\n * @param omitPropsFromLogging - properties by name to omit from telemetry props\n */\n constructor(\n message: string,\n props?: ITelemetryProperties,\n private readonly omitPropsFromLogging: Set<string> = new Set(),\n ) {\n super(message);\n\n // Don't log this list itself either\n omitPropsFromLogging.add(\"omitPropsFromLogging\");\n\n if (props) {\n this.addTelemetryProperties(props);\n }\n }\n\n /**\n * Add additional properties to be logged\n */\n public addTelemetryProperties(props: ITelemetryProperties) {\n copyProps(this, props);\n }\n\n /**\n * Get all properties fit to be logged to telemetry for this error\n */\n public getTelemetryProperties(): ITelemetryProperties {\n const taggableProps = getValidTelemetryProps(this, this.omitPropsFromLogging);\n // Include non-enumerable props inherited from Error that are not returned by getValidTelemetryProps\n return {\n ...taggableProps,\n stack: this.stack,\n message: this.message,\n };\n }\n}\n"]}
|
package/dist/fluidErrorBase.d.ts
CHANGED
|
@@ -8,16 +8,20 @@ import { ITelemetryProperties } from "@fluidframework/common-definitions";
|
|
|
8
8
|
* It features errorType, fluidErrorCode, and message strings, plus Error's members as optional
|
|
9
9
|
* and a getter/setter for telemetry props to be included when the error is logged.
|
|
10
10
|
*/
|
|
11
|
-
export interface IFluidErrorBase extends
|
|
12
|
-
/**
|
|
11
|
+
export interface IFluidErrorBase extends Error {
|
|
12
|
+
/** Classification of what type of error this is, used programmatically by consumers to interpret the error */
|
|
13
13
|
readonly errorType: string;
|
|
14
14
|
/**
|
|
15
|
-
* Indicates a point in code where this error
|
|
15
|
+
* Indicates a point in code where this error originated.
|
|
16
16
|
* Avoid crafting these via string format or otherwise including variable data, so they're easy to find the code.
|
|
17
17
|
*/
|
|
18
18
|
readonly fluidErrorCode: string;
|
|
19
19
|
/** The free-form error message */
|
|
20
20
|
readonly message: string;
|
|
21
|
+
/** Error's stack property, made readonly */
|
|
22
|
+
readonly stack?: string;
|
|
23
|
+
/** Error's name property, made readonly */
|
|
24
|
+
readonly name: string;
|
|
21
25
|
/**
|
|
22
26
|
* A Guid identifying this error instance.
|
|
23
27
|
* Useful in telemetry for deduping multiple logging events arising from the same error,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fluidErrorBase.d.ts","sourceRoot":"","sources":["../src/fluidErrorBase.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAE1E;;;;GAIG;AACH,MAAM,WAAW,eAAgB,SAAQ,
|
|
1
|
+
{"version":3,"file":"fluidErrorBase.d.ts","sourceRoot":"","sources":["../src/fluidErrorBase.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAE1E;;;;GAIG;AACH,MAAM,WAAW,eAAgB,SAAQ,KAAK;IAC1C,8GAA8G;IAC9G,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B;;;OAGG;IACH,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAEhC,kCAAkC;IAClC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,4CAA4C;IAC5C,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAExB,2CAA2C;IAC3C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;;OAIG;IACH,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IAEjC,qEAAqE;IACrE,sBAAsB,IAAI,oBAAoB,CAAC;IAC/C,iFAAiF;IACjF,sBAAsB,EAAE,CAAC,KAAK,EAAE,oBAAoB,KAAK,IAAI,CAAC;CACjE;AAMD,eAAO,MAAM,kBAAkB,MAAO,GAAG;qBAA2B,MAAM;CAChC,CAAC;AAE3C,+CAA+C;AAC/C,wBAAgB,YAAY,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,IAAI,eAAe,CAMzD;AAED,wDAAwD;AACxD,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,IAAI,IAAI,CAAC,eAAe,EAAE,gBAAgB,CAAC,CAIvF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fluidErrorBase.js","sourceRoot":"","sources":["../src/fluidErrorBase.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;
|
|
1
|
+
{"version":3,"file":"fluidErrorBase.js","sourceRoot":"","sources":["../src/fluidErrorBase.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAyCH,MAAM,yBAAyB,GAAG,CAAC,CAAM,EAAW,EAAE,CAClD,QAAO,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,sBAAsB,CAAA,KAAK,UAAU;IAC/C,QAAO,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,sBAAsB,CAAA,KAAK,UAAU,CAAC;AAE7C,MAAM,kBAAkB,GAAG,CAAC,CAAM,EAAoC,EAAE,CAC3E,QAAO,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,eAAe,CAAA,KAAK,QAAQ,CAAC;AAD9B,QAAA,kBAAkB,sBACY;AAE3C,+CAA+C;AAC/C,SAAgB,YAAY,CAAC,CAAM;IAC/B,OAAO,QAAO,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,SAAS,CAAA,KAAK,QAAQ;QACnC,QAAO,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,cAAc,CAAA,KAAK,QAAQ;QACrC,QAAO,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,OAAO,CAAA,KAAK,QAAQ;QAC9B,QAAO,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,eAAe,CAAA,KAAK,QAAQ;QACtC,yBAAyB,CAAC,CAAC,CAAC,CAAC;AACrC,CAAC;AAND,oCAMC;AAED,wDAAwD;AACxD,SAAgB,kBAAkB,CAAC,CAAM;IACrC,OAAO,QAAO,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,SAAS,CAAA,KAAK,QAAQ;QACnC,QAAO,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,OAAO,CAAA,KAAK,QAAQ;QAC9B,yBAAyB,CAAC,CAAC,CAAC,CAAC;AACrC,CAAC;AAJD,gDAIC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryProperties } from \"@fluidframework/common-definitions\";\n\n/**\n * All normalized errors flowing through the Fluid Framework adhere to this readonly interface.\n * It features errorType, fluidErrorCode, and message strings, plus Error's members as optional\n * and a getter/setter for telemetry props to be included when the error is logged.\n */\nexport interface IFluidErrorBase extends Error {\n /** Classification of what type of error this is, used programmatically by consumers to interpret the error */\n readonly errorType: string;\n\n /**\n * Indicates a point in code where this error originated.\n * Avoid crafting these via string format or otherwise including variable data, so they're easy to find the code.\n */\n readonly fluidErrorCode: string;\n\n /** The free-form error message */\n readonly message: string;\n\n /** Error's stack property, made readonly */\n readonly stack?: string;\n\n /** Error's name property, made readonly */\n readonly name: string;\n\n /**\n * A Guid identifying this error instance.\n * Useful in telemetry for deduping multiple logging events arising from the same error,\n * or correlating an error with an inner error that caused it, in case of error wrapping.\n */\n readonly errorInstanceId: string;\n\n /** Get the telemetry properties stashed on this error for logging */\n getTelemetryProperties(): ITelemetryProperties;\n /** Add telemetry properties to this error which will be logged with the error */\n addTelemetryProperties: (props: ITelemetryProperties) => void;\n}\n\nconst hasTelemetryPropFunctions = (x: any): boolean =>\n typeof x?.getTelemetryProperties === \"function\" &&\n typeof x?.addTelemetryProperties === \"function\";\n\nexport const hasErrorInstanceId = (x: any): x is { errorInstanceId: string } =>\n typeof x?.errorInstanceId === \"string\";\n\n/** type guard for IFluidErrorBase interface */\nexport function isFluidError(e: any): e is IFluidErrorBase {\n return typeof e?.errorType === \"string\" &&\n typeof e?.fluidErrorCode === \"string\" &&\n typeof e?.message === \"string\" &&\n typeof e?.errorInstanceId === \"string\" &&\n hasTelemetryPropFunctions(e);\n}\n\n/** type guard for old standard of valid/known errors */\nexport function isValidLegacyError(e: any): e is Omit<IFluidErrorBase, \"fluidErrorCode\"> {\n return typeof e?.errorType === \"string\" &&\n typeof e?.message === \"string\" &&\n hasTelemetryPropFunctions(e);\n}\n"]}
|
package/dist/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/telemetry-utils";
|
|
8
|
-
export declare const pkgVersion = "0.
|
|
8
|
+
export declare const pkgVersion = "0.52.0-44610";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,oCAAoC,CAAC;AACzD,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,oCAAoC,CAAC;AACzD,eAAO,MAAM,UAAU,iBAAiB,CAAC"}
|
package/dist/packageVersion.js
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.pkgVersion = exports.pkgName = void 0;
|
|
10
10
|
exports.pkgName = "@fluidframework/telemetry-utils";
|
|
11
|
-
exports.pkgVersion = "0.
|
|
11
|
+
exports.pkgVersion = "0.52.0-44610";
|
|
12
12
|
//# sourceMappingURL=packageVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,iCAAiC,CAAC;AAC5C,QAAA,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,iCAAiC,CAAC;AAC5C,QAAA,UAAU,GAAG,cAAc,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/telemetry-utils\";\nexport const pkgVersion = \"0.52.0-44610\";\n"]}
|
package/lib/errorLogging.js
CHANGED
|
@@ -53,11 +53,11 @@ function copyProps(target, source) {
|
|
|
53
53
|
class SimpleFluidError {
|
|
54
54
|
constructor(errorProps) {
|
|
55
55
|
this.telemetryProps = {};
|
|
56
|
+
this.name = "Error";
|
|
56
57
|
this.errorType = errorProps.errorType;
|
|
57
58
|
this.fluidErrorCode = errorProps.fluidErrorCode;
|
|
58
59
|
this.message = errorProps.message;
|
|
59
60
|
this.stack = errorProps.stack;
|
|
60
|
-
this.name = errorProps.name;
|
|
61
61
|
this.errorInstanceId = uuid();
|
|
62
62
|
this.addTelemetryProperties(errorProps);
|
|
63
63
|
}
|
package/lib/errorLogging.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errorLogging.js","sourceRoot":"","sources":["../src/errorLogging.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EACH,kBAAkB,EAElB,YAAY,EACZ,kBAAkB,GACrB,MAAM,kBAAkB,CAAC;AAE1B,wEAAwE;AACxE,MAAM,eAAe,GAAG,CAAC,KAAU,EAAW,EAAE;IAC5C,OAAO,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,CAA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AI,KAAK,EAAE;YACP,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC;SACtC;IACL,CAAC;IAED;;OAEG;IACI,sBAAsB,CAAC,KAA2B;QACrD,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC3B,CAAC;IAED;;OAEG;IACI,sBAAsB;QACzB,MAAM,aAAa,GAAG,sBAAsB,CAAC,IAAI,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;QAC9E,oGAAoG;QACpG,uCACO,aAAa,KAChB,KAAK,EAAE,IAAI,CAAC,KAAK,EACjB,OAAO,EAAE,IAAI,CAAC,OAAO,IACvB;IACN,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n ILoggingError,\n ITaggedTelemetryPropertyType,\n ITelemetryLogger,\n ITelemetryProperties,\n} from \"@fluidframework/common-definitions\";\nimport { v4 as uuid } from \"uuid\";\nimport {\n hasErrorInstanceId,\n IFluidErrorBase,\n isFluidError,\n isValidLegacyError,\n} from \"./fluidErrorBase\";\n\n/** @returns true if value is an object but neither null nor an array */\nconst isRegularObject = (value: any): boolean => {\n return value !== null && !Array.isArray(value) && typeof value === \"object\";\n};\n\n/** Inspect the given error for common \"safe\" props and return them */\nexport function extractLogSafeErrorProperties(error: any, sanitizeStack: boolean) {\n const removeMessageFromStack = (stack: string, errorName?: string) => {\n if (!sanitizeStack) {\n return stack;\n }\n const stackFrames = stack.split(\"\\n\");\n stackFrames.shift(); // Remove \"[ErrorName]: [ErrorMessage]\"\n if (errorName !== undefined) {\n stackFrames.unshift(errorName); // Add \"[ErrorName]\"\n }\n return stackFrames.join(\"\\n\");\n };\n\n const message = (typeof error?.message === \"string\")\n ? error.message as string\n : String(error);\n\n const safeProps: { message: string; errorType?: string; stack?: string } = {\n message,\n };\n\n if (isRegularObject(error)) {\n const { errorType, stack, name } = error;\n\n if (typeof errorType === \"string\") {\n safeProps.errorType = errorType;\n }\n\n if (typeof stack === \"string\") {\n const errorName = (typeof name === \"string\") ? name : undefined;\n safeProps.stack = removeMessageFromStack(stack, errorName);\n }\n }\n\n return safeProps;\n}\n\n/** type guard for ILoggingError interface */\nexport const isILoggingError = (x: any): x is ILoggingError => typeof x?.getTelemetryProperties === \"function\";\n\n/** Copy props from source onto target, but do not overwrite an existing prop that matches */\nfunction copyProps(target: ITelemetryProperties | LoggingError, source: ITelemetryProperties) {\n for (const key of Object.keys(source)) {\n if (target[key] === undefined) {\n target[key] = source[key];\n }\n }\n}\n\n/** Metadata to annotate an error object when annotating or normalizing it */\nexport interface IFluidErrorAnnotations {\n /** Telemetry props to log with the error */\n props?: ITelemetryProperties;\n}\n\n/** Simplest possible implementation of IFluidErrorBase */\nclass SimpleFluidError implements IFluidErrorBase {\n private readonly telemetryProps: ITelemetryProperties = {};\n\n readonly errorType: string;\n readonly fluidErrorCode: string;\n readonly message: string;\n readonly stack?: string;\n readonly name?: string;\n readonly errorInstanceId: string;\n\n constructor(\n errorProps: Omit<IFluidErrorBase,\n \"getTelemetryProperties\" |\n \"addTelemetryProperties\" |\n \"errorInstanceId\">,\n ) {\n this.errorType = errorProps.errorType;\n this.fluidErrorCode = errorProps.fluidErrorCode;\n this.message = errorProps.message;\n this.stack = errorProps.stack;\n this.name = errorProps.name;\n this.errorInstanceId = uuid();\n\n this.addTelemetryProperties(errorProps);\n }\n\n getTelemetryProperties(): ITelemetryProperties {\n return this.telemetryProps;\n }\n\n addTelemetryProperties(props: ITelemetryProperties) {\n copyProps(this.telemetryProps, props);\n }\n}\n\n/** For backwards compatibility with pre-fluidErrorCode valid errors */\nfunction patchWithErrorCode(\n legacyError: Omit<IFluidErrorBase, \"fluidErrorCode\">,\n): asserts legacyError is IFluidErrorBase {\n const patchMe: { -readonly [P in \"fluidErrorCode\"]?: IFluidErrorBase[P] } = legacyError as any;\n if (patchMe.fluidErrorCode === undefined) {\n patchMe.fluidErrorCode = \"<error predates fluidErrorCode>\";\n }\n}\n\n/**\n * Normalize the given error yielding a valid Fluid Error\n * @returns A valid Fluid Error with any provided annotations applied\n * @param error - The error to normalize\n * @param annotations - Annotations to apply to the normalized error\n */\nexport function normalizeError(\n error: unknown,\n annotations: IFluidErrorAnnotations = {},\n): IFluidErrorBase {\n // Back-compat, while IFluidErrorBase is rolled out\n if (isValidLegacyError(error)) {\n patchWithErrorCode(error);\n }\n\n if (isFluidError(error)) {\n // We can simply add the telemetry props to the error and return it\n error.addTelemetryProperties(annotations.props ?? {});\n return error;\n }\n\n // We have to construct a new Fluid Error, copying safe properties over\n const { message, stack } = extractLogSafeErrorProperties(error, false /* sanitizeStack */);\n const fluidError: IFluidErrorBase = new SimpleFluidError({\n errorType: \"genericError\", // Match Container/Driver generic error type\n fluidErrorCode: \"\",\n message,\n stack: stack ?? generateStack(),\n });\n\n fluidError.addTelemetryProperties({\n ...annotations.props,\n untrustedOrigin: 1, // This will let us filter to errors not originated by our own code\n });\n\n if (typeof(error) !== \"object\") {\n // This is only interesting for non-objects\n fluidError.addTelemetryProperties({ typeofError: typeof(error) });\n }\n return fluidError;\n}\n\nexport function generateStack(): string | undefined {\n // Some browsers will populate stack right away, others require throwing Error\n let stack = new Error(\"<<generated stack>>\").stack;\n if (!stack) {\n try {\n throw new Error(\"<<generated stack>>\");\n } catch (e) {\n stack = e.stack;\n }\n }\n return stack;\n}\n\n/**\n * Create a new error, wrapping and caused by the given unknown error.\n * Copies the inner error's message and stack over but otherwise uses newErrorFn to define the error.\n * The inner error's instance id will also be logged for telemetry analysis.\n * @param innerError - An error from untrusted/unknown origins\n * @param newErrorFn - callback that will create a new error given the original error's message\n * @returns A new error object \"wrapping\" the given error\n */\n export function wrapError<T extends IFluidErrorBase>(\n innerError: unknown,\n newErrorFn: (message: string) => T,\n): T {\n const {\n message,\n stack,\n } = extractLogSafeErrorProperties(innerError, false /* sanitizeStack */);\n\n const newError = newErrorFn(message);\n\n if (stack !== undefined) {\n // supposedly setting stack on an Error can throw.\n try {\n Object.assign(newError, { stack });\n } catch (errorSettingStack) {\n newError.addTelemetryProperties({ stack2: stack });\n }\n }\n\n if (hasErrorInstanceId(innerError)) {\n newError.addTelemetryProperties({ innerErrorInstanceId: innerError.errorInstanceId });\n }\n\n return newError;\n}\n\n/** The same as wrapError, but also logs the innerError, including the wrapping error's instance id */\nexport function wrapErrorAndLog<T extends IFluidErrorBase>(\n innerError: unknown,\n newErrorFn: (message: string) => T,\n logger: ITelemetryLogger,\n) {\n const newError = wrapError(innerError, newErrorFn);\n const wrappedByErrorInstanceId = hasErrorInstanceId(newError)\n ? newError.errorInstanceId\n : undefined;\n\n logger.sendTelemetryEvent({\n eventName: \"WrapError\",\n wrappedByErrorInstanceId,\n }, innerError);\n\n return newError;\n}\n\n/**\n * Type guard to identify if a particular value (loosely) appears to be a tagged telemetry property\n */\nexport function isTaggedTelemetryPropertyValue(x: any): x is ITaggedTelemetryPropertyType {\n return (typeof(x?.value) !== \"object\" && typeof(x?.tag) === \"string\");\n}\n\n/**\n * Walk an object's enumerable properties to find those fit for telemetry.\n */\nfunction getValidTelemetryProps(obj: any, keysToOmit: Set<string>): ITelemetryProperties {\n const props: ITelemetryProperties = {};\n for (const key of Object.keys(obj)) {\n if (keysToOmit.has(key)) {\n continue;\n }\n const val = obj[key];\n switch (typeof val) {\n case \"string\":\n case \"number\":\n case \"boolean\":\n case \"undefined\":\n props[key] = val;\n break;\n default: {\n if (isTaggedTelemetryPropertyValue(val)) {\n props[key] = val;\n } else {\n // We don't support logging arbitrary objects\n props[key] = \"REDACTED (arbitrary object)\";\n }\n break;\n }\n }\n }\n return props;\n}\n\n/**\n * Base class for \"trusted\" errors we create, whose properties can generally be logged to telemetry safely.\n * All properties set on the object, or passed in (via the constructor or getTelemetryProperties),\n * will be logged in accordance with their tag, if present.\n *\n * PLEASE take care to avoid setting sensitive data on this object without proper tagging!\n */\nexport class LoggingError extends Error implements ILoggingError, Pick<IFluidErrorBase, \"errorInstanceId\"> {\n readonly errorInstanceId = uuid();\n\n /**\n * Create a new LoggingError\n * @param message - Error message to use for Error base class\n * @param props - telemetry props to include on the error for when it's logged\n * @param omitPropsFromLogging - properties by name to omit from telemetry props\n */\n constructor(\n message: string,\n props?: ITelemetryProperties,\n private readonly omitPropsFromLogging: Set<string> = new Set(),\n ) {\n super(message);\n\n // Don't log this list itself either\n omitPropsFromLogging.add(\"omitPropsFromLogging\");\n\n if (props) {\n this.addTelemetryProperties(props);\n }\n }\n\n /**\n * Add additional properties to be logged\n */\n public addTelemetryProperties(props: ITelemetryProperties) {\n copyProps(this, props);\n }\n\n /**\n * Get all properties fit to be logged to telemetry for this error\n */\n public getTelemetryProperties(): ITelemetryProperties {\n const taggableProps = getValidTelemetryProps(this, this.omitPropsFromLogging);\n // Include non-enumerable props inherited from Error that are not returned by getValidTelemetryProps\n return {\n ...taggableProps,\n stack: this.stack,\n message: this.message,\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"errorLogging.js","sourceRoot":"","sources":["../src/errorLogging.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EACH,kBAAkB,EAElB,YAAY,EACZ,kBAAkB,GACrB,MAAM,kBAAkB,CAAC;AAE1B,wEAAwE;AACxE,MAAM,eAAe,GAAG,CAAC,KAAU,EAAW,EAAE;IAC5C,OAAO,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC;AAChF,CAAC,CAAC;AAEF,sEAAsE;AACtE,MAAM,UAAU,6BAA6B,CAAC,KAAU,EAAE,aAAsB;IAC5E,MAAM,sBAAsB,GAAG,CAAC,KAAa,EAAE,SAAkB,EAAE,EAAE;QACjE,IAAI,CAAC,aAAa,EAAE;YAChB,OAAO,KAAK,CAAC;SAChB;QACD,MAAM,WAAW,GAAG,KAAK,CAAC,KAAK,CAAC,IAA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AC;QAC9E,oGAAoG;QACpG,uCACO,aAAa,KAChB,KAAK,EAAE,IAAI,CAAC,KAAK,EACjB,OAAO,EAAE,IAAI,CAAC,OAAO,IACvB;IACN,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n ILoggingError,\n ITaggedTelemetryPropertyType,\n ITelemetryLogger,\n ITelemetryProperties,\n} from \"@fluidframework/common-definitions\";\nimport { v4 as uuid } from \"uuid\";\nimport {\n hasErrorInstanceId,\n IFluidErrorBase,\n isFluidError,\n isValidLegacyError,\n} from \"./fluidErrorBase\";\n\n/** @returns true if value is an object but neither null nor an array */\nconst isRegularObject = (value: any): boolean => {\n return value !== null && !Array.isArray(value) && typeof value === \"object\";\n};\n\n/** Inspect the given error for common \"safe\" props and return them */\nexport function extractLogSafeErrorProperties(error: any, sanitizeStack: boolean) {\n const removeMessageFromStack = (stack: string, errorName?: string) => {\n if (!sanitizeStack) {\n return stack;\n }\n const stackFrames = stack.split(\"\\n\");\n stackFrames.shift(); // Remove \"[ErrorName]: [ErrorMessage]\"\n if (errorName !== undefined) {\n stackFrames.unshift(errorName); // Add \"[ErrorName]\"\n }\n return stackFrames.join(\"\\n\");\n };\n\n const message = (typeof error?.message === \"string\")\n ? error.message as string\n : String(error);\n\n const safeProps: { message: string; errorType?: string; stack?: string } = {\n message,\n };\n\n if (isRegularObject(error)) {\n const { errorType, stack, name } = error;\n\n if (typeof errorType === \"string\") {\n safeProps.errorType = errorType;\n }\n\n if (typeof stack === \"string\") {\n const errorName = (typeof name === \"string\") ? name : undefined;\n safeProps.stack = removeMessageFromStack(stack, errorName);\n }\n }\n\n return safeProps;\n}\n\n/** type guard for ILoggingError interface */\nexport const isILoggingError = (x: any): x is ILoggingError => typeof x?.getTelemetryProperties === \"function\";\n\n/** Copy props from source onto target, but do not overwrite an existing prop that matches */\nfunction copyProps(target: ITelemetryProperties | LoggingError, source: ITelemetryProperties) {\n for (const key of Object.keys(source)) {\n if (target[key] === undefined) {\n target[key] = source[key];\n }\n }\n}\n\n/** Metadata to annotate an error object when annotating or normalizing it */\nexport interface IFluidErrorAnnotations {\n /** Telemetry props to log with the error */\n props?: ITelemetryProperties;\n}\n\n/** Simplest possible implementation of IFluidErrorBase */\nclass SimpleFluidError implements IFluidErrorBase {\n private readonly telemetryProps: ITelemetryProperties = {};\n\n readonly errorType: string;\n readonly fluidErrorCode: string;\n readonly message: string;\n readonly stack?: string;\n readonly name: string = \"Error\";\n readonly errorInstanceId: string;\n\n constructor(\n errorProps: Omit<IFluidErrorBase,\n | \"getTelemetryProperties\"\n | \"addTelemetryProperties\"\n | \"errorInstanceId\"\n | \"name\">,\n ) {\n this.errorType = errorProps.errorType;\n this.fluidErrorCode = errorProps.fluidErrorCode;\n this.message = errorProps.message;\n this.stack = errorProps.stack;\n this.errorInstanceId = uuid();\n\n this.addTelemetryProperties(errorProps);\n }\n\n getTelemetryProperties(): ITelemetryProperties {\n return this.telemetryProps;\n }\n\n addTelemetryProperties(props: ITelemetryProperties) {\n copyProps(this.telemetryProps, props);\n }\n}\n\n/** For backwards compatibility with pre-fluidErrorCode valid errors */\nfunction patchWithErrorCode(\n legacyError: Omit<IFluidErrorBase, \"fluidErrorCode\">,\n): asserts legacyError is IFluidErrorBase {\n const patchMe: { -readonly [P in \"fluidErrorCode\"]?: IFluidErrorBase[P] } = legacyError as any;\n if (patchMe.fluidErrorCode === undefined) {\n patchMe.fluidErrorCode = \"<error predates fluidErrorCode>\";\n }\n}\n\n/**\n * Normalize the given error yielding a valid Fluid Error\n * @returns A valid Fluid Error with any provided annotations applied\n * @param error - The error to normalize\n * @param annotations - Annotations to apply to the normalized error\n */\nexport function normalizeError(\n error: unknown,\n annotations: IFluidErrorAnnotations = {},\n): IFluidErrorBase {\n // Back-compat, while IFluidErrorBase is rolled out\n if (isValidLegacyError(error)) {\n patchWithErrorCode(error);\n }\n\n if (isFluidError(error)) {\n // We can simply add the telemetry props to the error and return it\n error.addTelemetryProperties(annotations.props ?? {});\n return error;\n }\n\n // We have to construct a new Fluid Error, copying safe properties over\n const { message, stack } = extractLogSafeErrorProperties(error, false /* sanitizeStack */);\n const fluidError: IFluidErrorBase = new SimpleFluidError({\n errorType: \"genericError\", // Match Container/Driver generic error type\n fluidErrorCode: \"\",\n message,\n stack: stack ?? generateStack(),\n });\n\n fluidError.addTelemetryProperties({\n ...annotations.props,\n untrustedOrigin: 1, // This will let us filter to errors not originated by our own code\n });\n\n if (typeof(error) !== \"object\") {\n // This is only interesting for non-objects\n fluidError.addTelemetryProperties({ typeofError: typeof(error) });\n }\n return fluidError;\n}\n\nexport function generateStack(): string | undefined {\n // Some browsers will populate stack right away, others require throwing Error\n let stack = new Error(\"<<generated stack>>\").stack;\n if (!stack) {\n try {\n throw new Error(\"<<generated stack>>\");\n } catch (e) {\n stack = e.stack;\n }\n }\n return stack;\n}\n\n/**\n * Create a new error, wrapping and caused by the given unknown error.\n * Copies the inner error's message and stack over but otherwise uses newErrorFn to define the error.\n * The inner error's instance id will also be logged for telemetry analysis.\n * @param innerError - An error from untrusted/unknown origins\n * @param newErrorFn - callback that will create a new error given the original error's message\n * @returns A new error object \"wrapping\" the given error\n */\n export function wrapError<T extends IFluidErrorBase>(\n innerError: unknown,\n newErrorFn: (message: string) => T,\n): T {\n const {\n message,\n stack,\n } = extractLogSafeErrorProperties(innerError, false /* sanitizeStack */);\n\n const newError = newErrorFn(message);\n\n if (stack !== undefined) {\n // supposedly setting stack on an Error can throw.\n try {\n Object.assign(newError, { stack });\n } catch (errorSettingStack) {\n newError.addTelemetryProperties({ stack2: stack });\n }\n }\n\n if (hasErrorInstanceId(innerError)) {\n newError.addTelemetryProperties({ innerErrorInstanceId: innerError.errorInstanceId });\n }\n\n return newError;\n}\n\n/** The same as wrapError, but also logs the innerError, including the wrapping error's instance id */\nexport function wrapErrorAndLog<T extends IFluidErrorBase>(\n innerError: unknown,\n newErrorFn: (message: string) => T,\n logger: ITelemetryLogger,\n) {\n const newError = wrapError(innerError, newErrorFn);\n const wrappedByErrorInstanceId = hasErrorInstanceId(newError)\n ? newError.errorInstanceId\n : undefined;\n\n logger.sendTelemetryEvent({\n eventName: \"WrapError\",\n wrappedByErrorInstanceId,\n }, innerError);\n\n return newError;\n}\n\n/**\n * Type guard to identify if a particular value (loosely) appears to be a tagged telemetry property\n */\nexport function isTaggedTelemetryPropertyValue(x: any): x is ITaggedTelemetryPropertyType {\n return (typeof(x?.value) !== \"object\" && typeof(x?.tag) === \"string\");\n}\n\n/**\n * Walk an object's enumerable properties to find those fit for telemetry.\n */\nfunction getValidTelemetryProps(obj: any, keysToOmit: Set<string>): ITelemetryProperties {\n const props: ITelemetryProperties = {};\n for (const key of Object.keys(obj)) {\n if (keysToOmit.has(key)) {\n continue;\n }\n const val = obj[key];\n switch (typeof val) {\n case \"string\":\n case \"number\":\n case \"boolean\":\n case \"undefined\":\n props[key] = val;\n break;\n default: {\n if (isTaggedTelemetryPropertyValue(val)) {\n props[key] = val;\n } else {\n // We don't support logging arbitrary objects\n props[key] = \"REDACTED (arbitrary object)\";\n }\n break;\n }\n }\n }\n return props;\n}\n\n/**\n * Base class for \"trusted\" errors we create, whose properties can generally be logged to telemetry safely.\n * All properties set on the object, or passed in (via the constructor or getTelemetryProperties),\n * will be logged in accordance with their tag, if present.\n *\n * PLEASE take care to avoid setting sensitive data on this object without proper tagging!\n */\nexport class LoggingError extends Error implements ILoggingError, Pick<IFluidErrorBase, \"errorInstanceId\"> {\n readonly errorInstanceId = uuid();\n\n /**\n * Create a new LoggingError\n * @param message - Error message to use for Error base class\n * @param props - telemetry props to include on the error for when it's logged\n * @param omitPropsFromLogging - properties by name to omit from telemetry props\n */\n constructor(\n message: string,\n props?: ITelemetryProperties,\n private readonly omitPropsFromLogging: Set<string> = new Set(),\n ) {\n super(message);\n\n // Don't log this list itself either\n omitPropsFromLogging.add(\"omitPropsFromLogging\");\n\n if (props) {\n this.addTelemetryProperties(props);\n }\n }\n\n /**\n * Add additional properties to be logged\n */\n public addTelemetryProperties(props: ITelemetryProperties) {\n copyProps(this, props);\n }\n\n /**\n * Get all properties fit to be logged to telemetry for this error\n */\n public getTelemetryProperties(): ITelemetryProperties {\n const taggableProps = getValidTelemetryProps(this, this.omitPropsFromLogging);\n // Include non-enumerable props inherited from Error that are not returned by getValidTelemetryProps\n return {\n ...taggableProps,\n stack: this.stack,\n message: this.message,\n };\n }\n}\n"]}
|
package/lib/fluidErrorBase.d.ts
CHANGED
|
@@ -8,16 +8,20 @@ import { ITelemetryProperties } from "@fluidframework/common-definitions";
|
|
|
8
8
|
* It features errorType, fluidErrorCode, and message strings, plus Error's members as optional
|
|
9
9
|
* and a getter/setter for telemetry props to be included when the error is logged.
|
|
10
10
|
*/
|
|
11
|
-
export interface IFluidErrorBase extends
|
|
12
|
-
/**
|
|
11
|
+
export interface IFluidErrorBase extends Error {
|
|
12
|
+
/** Classification of what type of error this is, used programmatically by consumers to interpret the error */
|
|
13
13
|
readonly errorType: string;
|
|
14
14
|
/**
|
|
15
|
-
* Indicates a point in code where this error
|
|
15
|
+
* Indicates a point in code where this error originated.
|
|
16
16
|
* Avoid crafting these via string format or otherwise including variable data, so they're easy to find the code.
|
|
17
17
|
*/
|
|
18
18
|
readonly fluidErrorCode: string;
|
|
19
19
|
/** The free-form error message */
|
|
20
20
|
readonly message: string;
|
|
21
|
+
/** Error's stack property, made readonly */
|
|
22
|
+
readonly stack?: string;
|
|
23
|
+
/** Error's name property, made readonly */
|
|
24
|
+
readonly name: string;
|
|
21
25
|
/**
|
|
22
26
|
* A Guid identifying this error instance.
|
|
23
27
|
* Useful in telemetry for deduping multiple logging events arising from the same error,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fluidErrorBase.d.ts","sourceRoot":"","sources":["../src/fluidErrorBase.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAE1E;;;;GAIG;AACH,MAAM,WAAW,eAAgB,SAAQ,
|
|
1
|
+
{"version":3,"file":"fluidErrorBase.d.ts","sourceRoot":"","sources":["../src/fluidErrorBase.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAE1E;;;;GAIG;AACH,MAAM,WAAW,eAAgB,SAAQ,KAAK;IAC1C,8GAA8G;IAC9G,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B;;;OAGG;IACH,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAEhC,kCAAkC;IAClC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,4CAA4C;IAC5C,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAExB,2CAA2C;IAC3C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;;OAIG;IACH,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IAEjC,qEAAqE;IACrE,sBAAsB,IAAI,oBAAoB,CAAC;IAC/C,iFAAiF;IACjF,sBAAsB,EAAE,CAAC,KAAK,EAAE,oBAAoB,KAAK,IAAI,CAAC;CACjE;AAMD,eAAO,MAAM,kBAAkB,MAAO,GAAG;qBAA2B,MAAM;CAChC,CAAC;AAE3C,+CAA+C;AAC/C,wBAAgB,YAAY,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,IAAI,eAAe,CAMzD;AAED,wDAAwD;AACxD,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,IAAI,IAAI,CAAC,eAAe,EAAE,gBAAgB,CAAC,CAIvF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fluidErrorBase.js","sourceRoot":"","sources":["../src/fluidErrorBase.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"fluidErrorBase.js","sourceRoot":"","sources":["../src/fluidErrorBase.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAyCH,MAAM,yBAAyB,GAAG,CAAC,CAAM,EAAW,EAAE,CAClD,QAAO,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,sBAAsB,CAAA,KAAK,UAAU;IAC/C,QAAO,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,sBAAsB,CAAA,KAAK,UAAU,CAAC;AAEpD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAM,EAAoC,EAAE,CAC3E,QAAO,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,eAAe,CAAA,KAAK,QAAQ,CAAC;AAE3C,+CAA+C;AAC/C,MAAM,UAAU,YAAY,CAAC,CAAM;IAC/B,OAAO,QAAO,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,SAAS,CAAA,KAAK,QAAQ;QACnC,QAAO,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,cAAc,CAAA,KAAK,QAAQ;QACrC,QAAO,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,OAAO,CAAA,KAAK,QAAQ;QAC9B,QAAO,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,eAAe,CAAA,KAAK,QAAQ;QACtC,yBAAyB,CAAC,CAAC,CAAC,CAAC;AACrC,CAAC;AAED,wDAAwD;AACxD,MAAM,UAAU,kBAAkB,CAAC,CAAM;IACrC,OAAO,QAAO,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,SAAS,CAAA,KAAK,QAAQ;QACnC,QAAO,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,OAAO,CAAA,KAAK,QAAQ;QAC9B,yBAAyB,CAAC,CAAC,CAAC,CAAC;AACrC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryProperties } from \"@fluidframework/common-definitions\";\n\n/**\n * All normalized errors flowing through the Fluid Framework adhere to this readonly interface.\n * It features errorType, fluidErrorCode, and message strings, plus Error's members as optional\n * and a getter/setter for telemetry props to be included when the error is logged.\n */\nexport interface IFluidErrorBase extends Error {\n /** Classification of what type of error this is, used programmatically by consumers to interpret the error */\n readonly errorType: string;\n\n /**\n * Indicates a point in code where this error originated.\n * Avoid crafting these via string format or otherwise including variable data, so they're easy to find the code.\n */\n readonly fluidErrorCode: string;\n\n /** The free-form error message */\n readonly message: string;\n\n /** Error's stack property, made readonly */\n readonly stack?: string;\n\n /** Error's name property, made readonly */\n readonly name: string;\n\n /**\n * A Guid identifying this error instance.\n * Useful in telemetry for deduping multiple logging events arising from the same error,\n * or correlating an error with an inner error that caused it, in case of error wrapping.\n */\n readonly errorInstanceId: string;\n\n /** Get the telemetry properties stashed on this error for logging */\n getTelemetryProperties(): ITelemetryProperties;\n /** Add telemetry properties to this error which will be logged with the error */\n addTelemetryProperties: (props: ITelemetryProperties) => void;\n}\n\nconst hasTelemetryPropFunctions = (x: any): boolean =>\n typeof x?.getTelemetryProperties === \"function\" &&\n typeof x?.addTelemetryProperties === \"function\";\n\nexport const hasErrorInstanceId = (x: any): x is { errorInstanceId: string } =>\n typeof x?.errorInstanceId === \"string\";\n\n/** type guard for IFluidErrorBase interface */\nexport function isFluidError(e: any): e is IFluidErrorBase {\n return typeof e?.errorType === \"string\" &&\n typeof e?.fluidErrorCode === \"string\" &&\n typeof e?.message === \"string\" &&\n typeof e?.errorInstanceId === \"string\" &&\n hasTelemetryPropFunctions(e);\n}\n\n/** type guard for old standard of valid/known errors */\nexport function isValidLegacyError(e: any): e is Omit<IFluidErrorBase, \"fluidErrorCode\"> {\n return typeof e?.errorType === \"string\" &&\n typeof e?.message === \"string\" &&\n hasTelemetryPropFunctions(e);\n}\n"]}
|
package/lib/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/telemetry-utils";
|
|
8
|
-
export declare const pkgVersion = "0.
|
|
8
|
+
export declare const pkgVersion = "0.52.0-44610";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,oCAAoC,CAAC;AACzD,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,oCAAoC,CAAC;AACzD,eAAO,MAAM,UAAU,iBAAiB,CAAC"}
|
package/lib/packageVersion.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,iCAAiC,CAAC;AACzD,MAAM,CAAC,MAAM,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,iCAAiC,CAAC;AACzD,MAAM,CAAC,MAAM,UAAU,GAAG,cAAc,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/telemetry-utils\";\nexport const pkgVersion = \"0.52.0-44610\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/telemetry-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.52.0-44610",
|
|
4
4
|
"description": "Collection of telemetry relates utilities for Fluid",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": "https://github.com/microsoft/FluidFramework",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@fluidframework/build-common": "^0.23.0",
|
|
70
70
|
"@fluidframework/eslint-config-fluid": "^0.24.0",
|
|
71
|
-
"@fluidframework/mocha-test-setup": "
|
|
71
|
+
"@fluidframework/mocha-test-setup": "0.52.0-44610",
|
|
72
72
|
"@microsoft/api-extractor": "^7.16.1",
|
|
73
73
|
"@types/debug": "^4.1.5",
|
|
74
74
|
"@types/events": "^3.0.0",
|
package/src/errorLogging.ts
CHANGED
|
@@ -86,20 +86,20 @@ class SimpleFluidError implements IFluidErrorBase {
|
|
|
86
86
|
readonly fluidErrorCode: string;
|
|
87
87
|
readonly message: string;
|
|
88
88
|
readonly stack?: string;
|
|
89
|
-
readonly name
|
|
89
|
+
readonly name: string = "Error";
|
|
90
90
|
readonly errorInstanceId: string;
|
|
91
91
|
|
|
92
92
|
constructor(
|
|
93
93
|
errorProps: Omit<IFluidErrorBase,
|
|
94
|
-
"getTelemetryProperties"
|
|
95
|
-
"addTelemetryProperties"
|
|
96
|
-
"errorInstanceId"
|
|
94
|
+
| "getTelemetryProperties"
|
|
95
|
+
| "addTelemetryProperties"
|
|
96
|
+
| "errorInstanceId"
|
|
97
|
+
| "name">,
|
|
97
98
|
) {
|
|
98
99
|
this.errorType = errorProps.errorType;
|
|
99
100
|
this.fluidErrorCode = errorProps.fluidErrorCode;
|
|
100
101
|
this.message = errorProps.message;
|
|
101
102
|
this.stack = errorProps.stack;
|
|
102
|
-
this.name = errorProps.name;
|
|
103
103
|
this.errorInstanceId = uuid();
|
|
104
104
|
|
|
105
105
|
this.addTelemetryProperties(errorProps);
|
package/src/fluidErrorBase.ts
CHANGED
|
@@ -10,12 +10,12 @@ import { ITelemetryProperties } from "@fluidframework/common-definitions";
|
|
|
10
10
|
* It features errorType, fluidErrorCode, and message strings, plus Error's members as optional
|
|
11
11
|
* and a getter/setter for telemetry props to be included when the error is logged.
|
|
12
12
|
*/
|
|
13
|
-
export interface IFluidErrorBase extends
|
|
14
|
-
/**
|
|
13
|
+
export interface IFluidErrorBase extends Error {
|
|
14
|
+
/** Classification of what type of error this is, used programmatically by consumers to interpret the error */
|
|
15
15
|
readonly errorType: string;
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* Indicates a point in code where this error
|
|
18
|
+
* Indicates a point in code where this error originated.
|
|
19
19
|
* Avoid crafting these via string format or otherwise including variable data, so they're easy to find the code.
|
|
20
20
|
*/
|
|
21
21
|
readonly fluidErrorCode: string;
|
|
@@ -23,6 +23,12 @@ export interface IFluidErrorBase extends Readonly<Partial<Error>> {
|
|
|
23
23
|
/** The free-form error message */
|
|
24
24
|
readonly message: string;
|
|
25
25
|
|
|
26
|
+
/** Error's stack property, made readonly */
|
|
27
|
+
readonly stack?: string;
|
|
28
|
+
|
|
29
|
+
/** Error's name property, made readonly */
|
|
30
|
+
readonly name: string;
|
|
31
|
+
|
|
26
32
|
/**
|
|
27
33
|
* A Guid identifying this error instance.
|
|
28
34
|
* Useful in telemetry for deduping multiple logging events arising from the same error,
|
package/src/packageVersion.ts
CHANGED