@fluidframework/telemetry-utils 2.0.0-dev.5.2.0.169897 → 2.0.0-dev.6.4.0.191258

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.
Files changed (122) hide show
  1. package/.eslintrc.js +2 -1
  2. package/CHANGELOG.md +126 -0
  3. package/README.md +4 -3
  4. package/dist/config.d.ts +4 -2
  5. package/dist/config.d.ts.map +1 -1
  6. package/dist/config.js +36 -38
  7. package/dist/config.js.map +1 -1
  8. package/dist/error.d.ts +92 -0
  9. package/dist/error.d.ts.map +1 -0
  10. package/dist/error.js +133 -0
  11. package/dist/error.js.map +1 -0
  12. package/dist/errorLogging.d.ts +44 -19
  13. package/dist/errorLogging.d.ts.map +1 -1
  14. package/dist/errorLogging.js +70 -31
  15. package/dist/errorLogging.js.map +1 -1
  16. package/dist/eventEmitterWithErrorHandling.d.ts +3 -3
  17. package/dist/eventEmitterWithErrorHandling.d.ts.map +1 -1
  18. package/dist/eventEmitterWithErrorHandling.js +10 -3
  19. package/dist/eventEmitterWithErrorHandling.js.map +1 -1
  20. package/dist/events.d.ts +1 -1
  21. package/dist/events.d.ts.map +1 -1
  22. package/dist/events.js.map +1 -1
  23. package/dist/fluidErrorBase.d.ts +49 -16
  24. package/dist/fluidErrorBase.d.ts.map +1 -1
  25. package/dist/fluidErrorBase.js +21 -14
  26. package/dist/fluidErrorBase.js.map +1 -1
  27. package/dist/index.d.ts +5 -5
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +16 -8
  30. package/dist/index.js.map +1 -1
  31. package/dist/logger.d.ts +98 -60
  32. package/dist/logger.d.ts.map +1 -1
  33. package/dist/logger.js +193 -124
  34. package/dist/logger.js.map +1 -1
  35. package/dist/mockLogger.d.ts +17 -8
  36. package/dist/mockLogger.d.ts.map +1 -1
  37. package/dist/mockLogger.js +49 -28
  38. package/dist/mockLogger.js.map +1 -1
  39. package/dist/sampledTelemetryHelper.d.ts +9 -8
  40. package/dist/sampledTelemetryHelper.d.ts.map +1 -1
  41. package/dist/sampledTelemetryHelper.js +21 -16
  42. package/dist/sampledTelemetryHelper.js.map +1 -1
  43. package/dist/telemetryTypes.d.ts +20 -6
  44. package/dist/telemetryTypes.d.ts.map +1 -1
  45. package/dist/telemetryTypes.js.map +1 -1
  46. package/dist/thresholdCounter.d.ts.map +1 -1
  47. package/dist/thresholdCounter.js.map +1 -1
  48. package/dist/utils.d.ts +3 -3
  49. package/dist/utils.d.ts.map +1 -1
  50. package/dist/utils.js +2 -2
  51. package/dist/utils.js.map +1 -1
  52. package/lib/config.d.ts +4 -2
  53. package/lib/config.d.ts.map +1 -1
  54. package/lib/config.js +34 -37
  55. package/lib/config.js.map +1 -1
  56. package/lib/error.d.ts +92 -0
  57. package/lib/error.d.ts.map +1 -0
  58. package/lib/error.js +125 -0
  59. package/lib/error.js.map +1 -0
  60. package/lib/errorLogging.d.ts +44 -19
  61. package/lib/errorLogging.d.ts.map +1 -1
  62. package/lib/errorLogging.js +69 -31
  63. package/lib/errorLogging.js.map +1 -1
  64. package/lib/eventEmitterWithErrorHandling.d.ts +3 -3
  65. package/lib/eventEmitterWithErrorHandling.d.ts.map +1 -1
  66. package/lib/eventEmitterWithErrorHandling.js +9 -2
  67. package/lib/eventEmitterWithErrorHandling.js.map +1 -1
  68. package/lib/events.d.ts +1 -1
  69. package/lib/events.d.ts.map +1 -1
  70. package/lib/events.js.map +1 -1
  71. package/lib/fluidErrorBase.d.ts +49 -16
  72. package/lib/fluidErrorBase.d.ts.map +1 -1
  73. package/lib/fluidErrorBase.js +21 -14
  74. package/lib/fluidErrorBase.js.map +1 -1
  75. package/lib/index.d.ts +5 -5
  76. package/lib/index.d.ts.map +1 -1
  77. package/lib/index.js +4 -4
  78. package/lib/index.js.map +1 -1
  79. package/lib/logger.d.ts +98 -60
  80. package/lib/logger.d.ts.map +1 -1
  81. package/lib/logger.js +184 -119
  82. package/lib/logger.js.map +1 -1
  83. package/lib/mockLogger.d.ts +17 -8
  84. package/lib/mockLogger.d.ts.map +1 -1
  85. package/lib/mockLogger.js +50 -29
  86. package/lib/mockLogger.js.map +1 -1
  87. package/lib/sampledTelemetryHelper.d.ts +9 -8
  88. package/lib/sampledTelemetryHelper.d.ts.map +1 -1
  89. package/lib/sampledTelemetryHelper.js +19 -14
  90. package/lib/sampledTelemetryHelper.js.map +1 -1
  91. package/lib/telemetryTypes.d.ts +20 -6
  92. package/lib/telemetryTypes.d.ts.map +1 -1
  93. package/lib/telemetryTypes.js.map +1 -1
  94. package/lib/thresholdCounter.d.ts.map +1 -1
  95. package/lib/thresholdCounter.js.map +1 -1
  96. package/lib/utils.d.ts +3 -3
  97. package/lib/utils.d.ts.map +1 -1
  98. package/lib/utils.js +2 -2
  99. package/lib/utils.js.map +1 -1
  100. package/package.json +21 -44
  101. package/src/config.ts +25 -15
  102. package/src/error.ts +202 -0
  103. package/src/errorLogging.ts +102 -57
  104. package/src/eventEmitterWithErrorHandling.ts +5 -3
  105. package/src/events.ts +3 -3
  106. package/src/fluidErrorBase.ts +63 -27
  107. package/src/index.ts +17 -6
  108. package/src/logger.ts +291 -121
  109. package/src/mockLogger.ts +65 -24
  110. package/src/sampledTelemetryHelper.ts +20 -16
  111. package/src/telemetryTypes.ts +29 -6
  112. package/src/thresholdCounter.ts +2 -2
  113. package/src/utils.ts +3 -3
  114. package/dist/debugLogger.d.ts +0 -39
  115. package/dist/debugLogger.d.ts.map +0 -1
  116. package/dist/debugLogger.js +0 -112
  117. package/dist/debugLogger.js.map +0 -1
  118. package/lib/debugLogger.d.ts +0 -39
  119. package/lib/debugLogger.d.ts.map +0 -1
  120. package/lib/debugLogger.js +0 -108
  121. package/lib/debugLogger.js.map +0 -1
  122. package/src/debugLogger.ts +0 -143
package/dist/error.js ADDED
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.extractSafePropertiesFromMessage = exports.DataProcessingError = exports.DataCorruptionError = exports.UsageError = exports.GenericError = void 0;
8
+ const core_interfaces_1 = require("@fluidframework/core-interfaces");
9
+ const errorLogging_1 = require("./errorLogging");
10
+ /**
11
+ * Generic wrapper for an unrecognized/uncategorized error object
12
+ */
13
+ class GenericError extends errorLogging_1.LoggingError {
14
+ /**
15
+ * Create a new GenericError
16
+ * @param message - Error message
17
+ * @param error - inner error object
18
+ * @param props - Telemetry props to include when the error is logged
19
+ */
20
+ // TODO: Use `unknown` instead (API breaking change because error is not just an input parameter, but a public member of the class)
21
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
22
+ constructor(message, error, props) {
23
+ // Don't try to log the inner error
24
+ super(message, props, new Set(["error"]));
25
+ this.error = error;
26
+ this.errorType = core_interfaces_1.FluidErrorTypes.genericError;
27
+ }
28
+ }
29
+ exports.GenericError = GenericError;
30
+ /**
31
+ * Error indicating an API is being used improperly resulting in an invalid operation.
32
+ */
33
+ class UsageError extends errorLogging_1.LoggingError {
34
+ constructor(message, props) {
35
+ super(message, { ...props, usageError: true });
36
+ this.errorType = core_interfaces_1.FluidErrorTypes.usageError;
37
+ }
38
+ }
39
+ exports.UsageError = UsageError;
40
+ /**
41
+ * DataCorruptionError indicates that we encountered definitive evidence that the data at rest
42
+ * backing this container is corrupted, and this container would never be expected to load properly again
43
+ */
44
+ class DataCorruptionError extends errorLogging_1.LoggingError {
45
+ constructor(message, props) {
46
+ super(message, { ...props, dataProcessingError: 1 });
47
+ this.errorType = core_interfaces_1.FluidErrorTypes.dataCorruptionError;
48
+ this.canRetry = false;
49
+ }
50
+ }
51
+ exports.DataCorruptionError = DataCorruptionError;
52
+ /**
53
+ * Indicates we hit a fatal error while processing incoming data from the Fluid Service.
54
+ *
55
+ * @remarks
56
+ *
57
+ * The error will often originate in the dataStore or DDS implementation that is responding to incoming changes.
58
+ * This differs from {@link DataCorruptionError} in that this may be a transient error that will not repro in another
59
+ * client or session.
60
+ */
61
+ class DataProcessingError extends errorLogging_1.LoggingError {
62
+ constructor(errorMessage, props) {
63
+ super(errorMessage, props);
64
+ /**
65
+ * {@inheritDoc IFluidErrorBase.errorType}
66
+ */
67
+ this.errorType = core_interfaces_1.FluidErrorTypes.dataProcessingError;
68
+ this.canRetry = false;
69
+ }
70
+ /**
71
+ * Create a new `DataProcessingError` detected and raised within the Fluid Framework.
72
+ */
73
+ static create(errorMessage, dataProcessingCodepath, sequencedMessage, props = {}) {
74
+ const dataProcessingError = DataProcessingError.wrapIfUnrecognized(errorMessage, dataProcessingCodepath, sequencedMessage);
75
+ dataProcessingError.addTelemetryProperties(props);
76
+ return dataProcessingError;
77
+ }
78
+ /**
79
+ * Wrap the given error in a `DataProcessingError`, unless the error is already of a known type
80
+ * with the exception of a normalized {@link LoggingError}, which will still be wrapped.
81
+ *
82
+ * In either case, the error will have some relevant properties added for telemetry.
83
+ *
84
+ * @remarks
85
+ *
86
+ * We wrap conditionally since known error types represent well-understood failure modes, and ideally
87
+ * one day we will move away from throwing these errors but rather we'll return them.
88
+ * But an unrecognized error needs to be classified as `DataProcessingError`.
89
+ *
90
+ * @param originalError - The error to be converted.
91
+ * @param dataProcessingCodepath - Which code-path failed while processing data.
92
+ * @param messageLike - Message to include info about via telemetry props.
93
+ *
94
+ * @returns Either a new `DataProcessingError`, or (if wrapping is deemed unnecessary) the given error.
95
+ */
96
+ static wrapIfUnrecognized(originalError, dataProcessingCodepath, messageLike) {
97
+ const props = {
98
+ dataProcessingError: 1,
99
+ dataProcessingCodepath,
100
+ ...(messageLike === undefined
101
+ ? undefined
102
+ : (0, exports.extractSafePropertiesFromMessage)(messageLike)),
103
+ };
104
+ const normalizedError = (0, errorLogging_1.normalizeError)(originalError, { props });
105
+ // Note that other errors may have the NORMALIZED_ERROR_TYPE errorType,
106
+ // but if so they are still suitable to be wrapped as DataProcessingError.
107
+ if ((0, errorLogging_1.isExternalError)(normalizedError) ||
108
+ normalizedError.errorType === errorLogging_1.NORMALIZED_ERROR_TYPE) {
109
+ // Create a new DataProcessingError to wrap this external error
110
+ const dataProcessingError = (0, errorLogging_1.wrapError)(normalizedError, (message) => new DataProcessingError(message));
111
+ // Copy over the props above and any others added to this error since first being normalized
112
+ dataProcessingError.addTelemetryProperties(normalizedError.getTelemetryProperties());
113
+ return dataProcessingError;
114
+ }
115
+ return normalizedError;
116
+ }
117
+ }
118
+ exports.DataProcessingError = DataProcessingError;
119
+ /**
120
+ * Extracts specific properties from the provided message that we know are safe to log.
121
+ *
122
+ * @param messageLike - Message to include info about via telemetry props.
123
+ */
124
+ const extractSafePropertiesFromMessage = (messageLike) => ({
125
+ messageClientId: messageLike.clientId === null ? "null" : messageLike.clientId,
126
+ messageSequenceNumber: messageLike.sequenceNumber,
127
+ messageClientSequenceNumber: messageLike.clientSequenceNumber,
128
+ messageReferenceSequenceNumber: messageLike.referenceSequenceNumber,
129
+ messageMinimumSequenceNumber: messageLike.minimumSequenceNumber,
130
+ messageTimestamp: messageLike.timestamp,
131
+ });
132
+ exports.extractSafePropertiesFromMessage = extractSafePropertiesFromMessage;
133
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,qEAMyC;AAGzC,iDAMwB;AAGxB;;GAEG;AACH,MAAa,YAAa,SAAQ,2BAAY;IAG7C;;;;;OAKG;IACH,mIAAmI;IACnI,iHAAiH;IACjH,YAAY,OAAe,EAAkB,KAAW,EAAE,KAAgC;QACzF,mCAAmC;QACnC,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAFE,UAAK,GAAL,KAAK,CAAM;QAV/C,cAAS,GAAG,iCAAe,CAAC,YAAY,CAAC;IAalD,CAAC;CACD;AAfD,oCAeC;AAED;;GAEG;AACH,MAAa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AS;gBAC5B,CAAC,CAAC,SAAS;gBACX,CAAC,CAAC,IAAA,wCAAgC,EAAC,WAAW,CAAC,CAAC;SACjD,CAAC;QAEF,MAAM,eAAe,GAAG,IAAA,6BAAc,EAAC,aAAa,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QACjE,uEAAuE;QACvE,0EAA0E;QAC1E,IACC,IAAA,8BAAe,EAAC,eAAe,CAAC;YAChC,eAAe,CAAC,SAAS,KAAK,oCAAqB,EAClD;YACD,+DAA+D;YAC/D,MAAM,mBAAmB,GAAG,IAAA,wBAAS,EACpC,eAAe,EACf,CAAC,OAAe,EAAE,EAAE,CAAC,IAAI,mBAAmB,CAAC,OAAO,CAAC,CACrD,CAAC;YAEF,4FAA4F;YAC5F,mBAAmB,CAAC,sBAAsB,CAAC,eAAe,CAAC,sBAAsB,EAAE,CAAC,CAAC;YAErF,OAAO,mBAAmB,CAAC;SAC3B;QACD,OAAO,eAAe,CAAC;IACxB,CAAC;CACD;AA5FD,kDA4FC;AAED;;;;GAIG;AACI,MAAM,gCAAgC,GAAG,CAC/C,WAUC,EAQA,EAAE,CAAC,CAAC;IACL,eAAe,EAAE,WAAW,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,QAAQ;IAC9E,qBAAqB,EAAE,WAAW,CAAC,cAAc;IACjD,2BAA2B,EAAE,WAAW,CAAC,oBAAoB;IAC7D,8BAA8B,EAAE,WAAW,CAAC,uBAAuB;IACnE,4BAA4B,EAAE,WAAW,CAAC,qBAAqB;IAC/D,gBAAgB,EAAE,WAAW,CAAC,SAAS;CACvC,CAAC,CAAC;AA1BU,QAAA,gCAAgC,oCA0B1C","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tFluidErrorTypes,\n\tIGenericError,\n\tIErrorBase,\n\tITelemetryBaseProperties,\n\tIUsageError,\n} from \"@fluidframework/core-interfaces\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\n\nimport {\n\tLoggingError,\n\tNORMALIZED_ERROR_TYPE,\n\tisExternalError,\n\tnormalizeError,\n\twrapError,\n} from \"./errorLogging\";\nimport { IFluidErrorBase } from \"./fluidErrorBase\";\n\n/**\n * Generic wrapper for an unrecognized/uncategorized error object\n */\nexport class GenericError extends LoggingError implements IGenericError, IFluidErrorBase {\n\treadonly errorType = FluidErrorTypes.genericError;\n\n\t/**\n\t * Create a new GenericError\n\t * @param message - Error message\n\t * @param error - inner error object\n\t * @param props - Telemetry props to include when the error is logged\n\t */\n\t// TODO: Use `unknown` instead (API breaking change because error is not just an input parameter, but a public member of the class)\n\t// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any\n\tconstructor(message: string, public readonly error?: any, props?: ITelemetryBaseProperties) {\n\t\t// Don't try to log the inner error\n\t\tsuper(message, props, new Set([\"error\"]));\n\t}\n}\n\n/**\n * Error indicating an API is being used improperly resulting in an invalid operation.\n */\nexport class UsageError extends LoggingError implements IUsageError, IFluidErrorBase {\n\treadonly errorType = FluidErrorTypes.usageError;\n\n\tconstructor(message: string, props?: ITelemetryBaseProperties) {\n\t\tsuper(message, { ...props, usageError: true });\n\t}\n}\n\n/**\n * DataCorruptionError indicates that we encountered definitive evidence that the data at rest\n * backing this container is corrupted, and this container would never be expected to load properly again\n */\nexport class DataCorruptionError extends LoggingError implements IErrorBase, IFluidErrorBase {\n\treadonly errorType = FluidErrorTypes.dataCorruptionError;\n\treadonly canRetry = false;\n\n\tconstructor(message: string, props: ITelemetryBaseProperties) {\n\t\tsuper(message, { ...props, dataProcessingError: 1 });\n\t}\n}\n\n/**\n * Indicates we hit a fatal error while processing incoming data from the Fluid Service.\n *\n * @remarks\n *\n * The error will often originate in the dataStore or DDS implementation that is responding to incoming changes.\n * This differs from {@link DataCorruptionError} in that this may be a transient error that will not repro in another\n * client or session.\n */\nexport class DataProcessingError extends LoggingError implements IErrorBase, IFluidErrorBase {\n\t/**\n\t * {@inheritDoc IFluidErrorBase.errorType}\n\t */\n\tpublic readonly errorType = FluidErrorTypes.dataProcessingError;\n\n\tpublic readonly canRetry = false;\n\n\tprivate constructor(errorMessage: string, props?: ITelemetryBaseProperties) {\n\t\tsuper(errorMessage, props);\n\t}\n\n\t/**\n\t * Create a new `DataProcessingError` detected and raised within the Fluid Framework.\n\t */\n\tpublic static create(\n\t\terrorMessage: string,\n\t\tdataProcessingCodepath: string,\n\t\tsequencedMessage?: ISequencedDocumentMessage,\n\t\tprops: ITelemetryBaseProperties = {},\n\t): IFluidErrorBase {\n\t\tconst dataProcessingError = DataProcessingError.wrapIfUnrecognized(\n\t\t\terrorMessage,\n\t\t\tdataProcessingCodepath,\n\t\t\tsequencedMessage,\n\t\t);\n\t\tdataProcessingError.addTelemetryProperties(props);\n\n\t\treturn dataProcessingError;\n\t}\n\n\t/**\n\t * Wrap the given error in a `DataProcessingError`, unless the error is already of a known type\n\t * with the exception of a normalized {@link LoggingError}, which will still be wrapped.\n\t *\n\t * In either case, the error will have some relevant properties added for telemetry.\n\t *\n\t * @remarks\n\t *\n\t * We wrap conditionally since known error types represent well-understood failure modes, and ideally\n\t * one day we will move away from throwing these errors but rather we'll return them.\n\t * But an unrecognized error needs to be classified as `DataProcessingError`.\n\t *\n\t * @param originalError - The error to be converted.\n\t * @param dataProcessingCodepath - Which code-path failed while processing data.\n\t * @param messageLike - Message to include info about via telemetry props.\n\t *\n\t * @returns Either a new `DataProcessingError`, or (if wrapping is deemed unnecessary) the given error.\n\t */\n\tpublic static wrapIfUnrecognized(\n\t\toriginalError: unknown,\n\t\tdataProcessingCodepath: string,\n\t\tmessageLike?: Partial<\n\t\t\tPick<\n\t\t\t\tISequencedDocumentMessage,\n\t\t\t\t| \"clientId\"\n\t\t\t\t| \"sequenceNumber\"\n\t\t\t\t| \"clientSequenceNumber\"\n\t\t\t\t| \"referenceSequenceNumber\"\n\t\t\t\t| \"minimumSequenceNumber\"\n\t\t\t\t| \"timestamp\"\n\t\t\t>\n\t\t>,\n\t): IFluidErrorBase {\n\t\tconst props = {\n\t\t\tdataProcessingError: 1,\n\t\t\tdataProcessingCodepath,\n\t\t\t...(messageLike === undefined\n\t\t\t\t? undefined\n\t\t\t\t: extractSafePropertiesFromMessage(messageLike)),\n\t\t};\n\n\t\tconst normalizedError = normalizeError(originalError, { props });\n\t\t// Note that other errors may have the NORMALIZED_ERROR_TYPE errorType,\n\t\t// but if so they are still suitable to be wrapped as DataProcessingError.\n\t\tif (\n\t\t\tisExternalError(normalizedError) ||\n\t\t\tnormalizedError.errorType === NORMALIZED_ERROR_TYPE\n\t\t) {\n\t\t\t// Create a new DataProcessingError to wrap this external error\n\t\t\tconst dataProcessingError = wrapError(\n\t\t\t\tnormalizedError,\n\t\t\t\t(message: string) => new DataProcessingError(message),\n\t\t\t);\n\n\t\t\t// Copy over the props above and any others added to this error since first being normalized\n\t\t\tdataProcessingError.addTelemetryProperties(normalizedError.getTelemetryProperties());\n\n\t\t\treturn dataProcessingError;\n\t\t}\n\t\treturn normalizedError;\n\t}\n}\n\n/**\n * Extracts specific properties from the provided message that we know are safe to log.\n *\n * @param messageLike - Message to include info about via telemetry props.\n */\nexport const extractSafePropertiesFromMessage = (\n\tmessageLike: Partial<\n\t\tPick<\n\t\t\tISequencedDocumentMessage,\n\t\t\t| \"clientId\"\n\t\t\t| \"sequenceNumber\"\n\t\t\t| \"clientSequenceNumber\"\n\t\t\t| \"referenceSequenceNumber\"\n\t\t\t| \"minimumSequenceNumber\"\n\t\t\t| \"timestamp\"\n\t\t>\n\t>,\n): {\n\tmessageClientId: string | undefined;\n\tmessageSequenceNumber: number | undefined;\n\tmessageClientSequenceNumber: number | undefined;\n\tmessageReferenceSequenceNumber: number | undefined;\n\tmessageMinimumSequenceNumber: number | undefined;\n\tmessageTimestamp: number | undefined;\n} => ({\n\tmessageClientId: messageLike.clientId === null ? \"null\" : messageLike.clientId,\n\tmessageSequenceNumber: messageLike.sequenceNumber,\n\tmessageClientSequenceNumber: messageLike.clientSequenceNumber,\n\tmessageReferenceSequenceNumber: messageLike.referenceSequenceNumber,\n\tmessageMinimumSequenceNumber: messageLike.minimumSequenceNumber,\n\tmessageTimestamp: messageLike.timestamp,\n});\n"]}
@@ -2,21 +2,29 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { ILoggingError, ITaggedTelemetryPropertyType, ITelemetryProperties } from "@fluidframework/common-definitions";
5
+ import { ILoggingError, ITelemetryBaseProperties, Tagged } from "@fluidframework/core-interfaces";
6
6
  import { IFluidErrorBase } from "./fluidErrorBase";
7
- import { ITaggedTelemetryPropertyTypeExt, ITelemetryLoggerExt, TelemetryEventPropertyTypeExt } from "./telemetryTypes";
8
- /** Inspect the given error for common "safe" props and return them */
9
- export declare function extractLogSafeErrorProperties(error: any, sanitizeStack: boolean): {
7
+ import { ITelemetryLoggerExt, TelemetryEventPropertyTypeExt } from "./telemetryTypes";
8
+ /**
9
+ * Inspect the given error for common "safe" props and return them.
10
+ */
11
+ export declare function extractLogSafeErrorProperties(error: unknown, sanitizeStack: boolean): {
10
12
  message: string;
11
13
  errorType?: string | undefined;
12
14
  stack?: string | undefined;
13
15
  };
14
- /** type guard for ILoggingError interface */
15
- export declare const isILoggingError: (x: any) => x is ILoggingError;
16
- /** Metadata to annotate an error object when annotating or normalizing it */
16
+ /**
17
+ * type guard for ILoggingError interface
18
+ */
19
+ export declare const isILoggingError: (x: unknown) => x is ILoggingError;
20
+ /**
21
+ * Metadata to annotate an error object when annotating or normalizing it
22
+ */
17
23
  export interface IFluidErrorAnnotations {
18
- /** Telemetry props to log with the error */
19
- props?: ITelemetryProperties;
24
+ /**
25
+ * Telemetry props to log with the error
26
+ */
27
+ props?: ITelemetryBaseProperties;
20
28
  }
21
29
  /**
22
30
  * Normalize the given error yielding a valid Fluid Error
@@ -44,18 +52,31 @@ export declare function generateStack(): string | undefined;
44
52
  * @returns A new error object "wrapping" the given error
45
53
  */
46
54
  export declare function wrapError<T extends LoggingError>(innerError: unknown, newErrorFn: (message: string) => T): T;
47
- /** The same as wrapError, but also logs the innerError, including the wrapping error's instance id */
55
+ /**
56
+ * The same as wrapError, but also logs the innerError, including the wrapping error's instance ID.
57
+ *
58
+ * @typeParam T - The kind of wrapper error to create.
59
+ */
48
60
  export declare function wrapErrorAndLog<T extends LoggingError>(innerError: unknown, newErrorFn: (message: string) => T, logger: ITelemetryLoggerExt): T;
61
+ /**
62
+ * Attempts to overwrite the error's stack
63
+ *
64
+ * There have been reports of certain JS environments where overwriting stack will throw.
65
+ * If that happens, this adds the given stack as the telemetry property "stack2"
66
+ *
67
+ * @internal
68
+ */
69
+ export declare function overwriteStack(error: IFluidErrorBase | LoggingError, stack: string): void;
49
70
  /**
50
71
  * True for any error object that is an (optionally normalized) external error
51
72
  * False for any error we created and raised within the FF codebase via LoggingError base class,
52
73
  * or wrapped in a well-known error type
53
74
  */
54
- export declare function isExternalError(e: any): boolean;
75
+ export declare function isExternalError(error: unknown): boolean;
55
76
  /**
56
77
  * Type guard to identify if a particular telemetry property appears to be a tagged telemetry property
57
78
  */
58
- export declare function isTaggedTelemetryPropertyValue(x: ITaggedTelemetryPropertyTypeExt | TelemetryEventPropertyTypeExt): x is ITaggedTelemetryPropertyType | ITaggedTelemetryPropertyTypeExt;
79
+ export declare function isTaggedTelemetryPropertyValue(x: Tagged<TelemetryEventPropertyTypeExt> | TelemetryEventPropertyTypeExt): x is Tagged<TelemetryEventPropertyTypeExt>;
59
80
  /**
60
81
  * Borrowed from
61
82
  * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value#examples}
@@ -63,7 +84,7 @@ export declare function isTaggedTelemetryPropertyValue(x: ITaggedTelemetryProper
63
84
  * Not ideal, as will cut values that are not necessarily circular references.
64
85
  * Could be improved by implementing Node's util.inspect() for browser (minus all the coloring code)
65
86
  */
66
- export declare const getCircularReplacer: () => (key: string, value: any) => any;
87
+ export declare const getCircularReplacer: () => (key: string, value: unknown) => any;
67
88
  /**
68
89
  * Base class for "trusted" errors we create, whose properties can generally be logged to telemetry safely.
69
90
  * All properties set on the object, or passed in (via the constructor or addTelemetryProperties),
@@ -76,7 +97,9 @@ export declare class LoggingError extends Error implements ILoggingError, Omit<I
76
97
  private _errorInstanceId;
77
98
  get errorInstanceId(): string;
78
99
  overwriteErrorInstanceId(id: string): void;
79
- /** Back-compat to appease isFluidError typeguard in old code that may handle this error */
100
+ /**
101
+ * Backwards compatibility to appease {@link isFluidError} in old code that may handle this error.
102
+ */
80
103
  private readonly fluidErrorCode;
81
104
  /**
82
105
  * Create a new LoggingError
@@ -84,22 +107,24 @@ export declare class LoggingError extends Error implements ILoggingError, Omit<I
84
107
  * @param props - telemetry props to include on the error for when it's logged
85
108
  * @param omitPropsFromLogging - properties by name to omit from telemetry props
86
109
  */
87
- constructor(message: string, props?: ITelemetryProperties, omitPropsFromLogging?: Set<string>);
110
+ constructor(message: string, props?: ITelemetryBaseProperties, omitPropsFromLogging?: Set<string>);
88
111
  /**
89
112
  * Determines if a given object is an instance of a LoggingError
90
113
  * @param object - any object
91
- * @returns - true if the object is an instance of a LoggingError, false if not.
114
+ * @returns true if the object is an instance of a LoggingError, false if not.
92
115
  */
93
116
  static typeCheck(object: unknown): object is LoggingError;
94
117
  /**
95
118
  * Add additional properties to be logged
96
119
  */
97
- addTelemetryProperties(props: ITelemetryProperties): void;
120
+ addTelemetryProperties(props: ITelemetryBaseProperties): void;
98
121
  /**
99
122
  * Get all properties fit to be logged to telemetry for this error
100
123
  */
101
- getTelemetryProperties(): ITelemetryProperties;
124
+ getTelemetryProperties(): ITelemetryBaseProperties;
102
125
  }
103
- /** The Error class used when normalizing an external error */
126
+ /**
127
+ * The Error class used when normalizing an external error
128
+ */
104
129
  export declare const NORMALIZED_ERROR_TYPE = "genericError";
105
130
  //# sourceMappingURL=errorLogging.d.ts.map
@@ -1 +1 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,SAAS,OAAO,KAAK,GAWxE,CAAC;AAGF;;;;;;GAMG;AACH,qBAAa,YACZ,SAAQ,KACR,YAAW,aAAa,EAAE,IAAI,CAAC,eAAe,EAAE,WAAW,CAAC;IA0B3D,OAAO,CAAC,QAAQ,CAAC,oBAAoB;IAxBtC,OAAO,CAAC,gBAAgB,CAAU;IAClC,IAAI,eAAe,IAAI,MAAM,CAE5B;IACD,wBAAwB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAI1C;;OAEG;IAGH,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAY;IAE3C;;;;;OAKG;gBAEF,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,wBAAwB,EACf,oBAAoB,GAAE,GAAG,CAAC,MAAM,CAAa;IAa/D;;;;OAIG;WACW,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,YAAY;IAWhE;;OAEG;IACI,sBAAsB,CAAC,KAAK,EAAE,wBAAwB,GAAG,IAAI;IAIpE;;OAEG;IACI,sBAAsB,IAAI,wBAAwB;CAUzD;AAED;;GAEG;AACH,eAAO,MAAM,qBAAqB,iBAAiB,CAAC"}
@@ -4,14 +4,18 @@
4
4
  * Licensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.NORMALIZED_ERROR_TYPE = exports.LoggingError = exports.getCircularReplacer = exports.isTaggedTelemetryPropertyValue = exports.isExternalError = exports.wrapErrorAndLog = exports.wrapError = exports.generateStack = exports.generateErrorWithStack = exports.normalizeError = exports.isILoggingError = exports.extractLogSafeErrorProperties = void 0;
7
+ exports.NORMALIZED_ERROR_TYPE = exports.LoggingError = exports.getCircularReplacer = exports.isTaggedTelemetryPropertyValue = exports.isExternalError = exports.overwriteStack = exports.wrapErrorAndLog = exports.wrapError = exports.generateStack = exports.generateErrorWithStack = exports.normalizeError = exports.isILoggingError = exports.extractLogSafeErrorProperties = void 0;
8
8
  const uuid_1 = require("uuid");
9
9
  const fluidErrorBase_1 = require("./fluidErrorBase");
10
- /** @returns true if value is an object but neither null nor an array */
10
+ /**
11
+ * Determines if the provided value is an object but neither null nor an array.
12
+ */
11
13
  const isRegularObject = (value) => {
12
14
  return value !== null && !Array.isArray(value) && typeof value === "object";
13
15
  };
14
- /** Inspect the given error for common "safe" props and return them */
16
+ /**
17
+ * Inspect the given error for common "safe" props and return them.
18
+ */
15
19
  function extractLogSafeErrorProperties(error, sanitizeStack) {
16
20
  const removeMessageFromStack = (stack, errorName) => {
17
21
  if (!sanitizeStack) {
@@ -24,7 +28,9 @@ function extractLogSafeErrorProperties(error, sanitizeStack) {
24
28
  }
25
29
  return stackFrames.join("\n");
26
30
  };
27
- const message = typeof (error === null || error === void 0 ? void 0 : error.message) === "string" ? error.message : String(error);
31
+ const message = typeof error?.message === "string"
32
+ ? error.message
33
+ : String(error);
28
34
  const safeProps = {
29
35
  message,
30
36
  };
@@ -41,10 +47,14 @@ function extractLogSafeErrorProperties(error, sanitizeStack) {
41
47
  return safeProps;
42
48
  }
43
49
  exports.extractLogSafeErrorProperties = extractLogSafeErrorProperties;
44
- /** type guard for ILoggingError interface */
45
- const isILoggingError = (x) => typeof (x === null || x === void 0 ? void 0 : x.getTelemetryProperties) === "function";
50
+ /**
51
+ * type guard for ILoggingError interface
52
+ */
53
+ const isILoggingError = (x) => typeof x?.getTelemetryProperties === "function";
46
54
  exports.isILoggingError = isILoggingError;
47
- /** Copy props from source onto target, but do not overwrite an existing prop that matches */
55
+ /**
56
+ * Copy props from source onto target, but do not overwrite an existing prop that matches
57
+ */
48
58
  function copyProps(target, source) {
49
59
  for (const key of Object.keys(source)) {
50
60
  if (target[key] === undefined) {
@@ -52,8 +62,11 @@ function copyProps(target, source) {
52
62
  }
53
63
  }
54
64
  }
55
- /** For backwards compatibility with pre-errorInstanceId valid errors */
65
+ /**
66
+ * For backwards compatibility with pre-errorInstanceId valid errors
67
+ */
56
68
  function patchLegacyError(legacyError) {
69
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any
57
70
  const patchMe = legacyError;
58
71
  if (patchMe.errorInstanceId === undefined) {
59
72
  patchMe.errorInstanceId = (0, uuid_1.v4)();
@@ -66,14 +79,13 @@ function patchLegacyError(legacyError) {
66
79
  * @param annotations - Annotations to apply to the normalized error
67
80
  */
68
81
  function normalizeError(error, annotations = {}) {
69
- var _a;
70
82
  // Back-compat, while IFluidErrorBase is rolled out
71
83
  if ((0, fluidErrorBase_1.isValidLegacyError)(error)) {
72
84
  patchLegacyError(error);
73
85
  }
74
86
  if ((0, fluidErrorBase_1.isFluidError)(error)) {
75
87
  // We can simply add the telemetry props to the error and return it
76
- error.addTelemetryProperties((_a = annotations.props) !== null && _a !== void 0 ? _a : {});
88
+ error.addTelemetryProperties(annotations.props ?? {});
77
89
  return error;
78
90
  }
79
91
  // We have to construct a new Fluid Error, copying safe properties over
@@ -89,11 +101,11 @@ function normalizeError(error, annotations = {}) {
89
101
  const maybeHasRetry = error;
90
102
  let retryProps;
91
103
  if ("canRetry" in error) {
92
- retryProps !== null && retryProps !== void 0 ? retryProps : (retryProps = {});
104
+ retryProps ?? (retryProps = {});
93
105
  retryProps.canRetry = maybeHasRetry.canRetry;
94
106
  }
95
107
  if ("retryAfterSeconds" in error) {
96
- retryProps !== null && retryProps !== void 0 ? retryProps : (retryProps = {});
108
+ retryProps ?? (retryProps = {});
97
109
  retryProps.retryAfterSeconds = maybeHasRetry.retryAfterSeconds;
98
110
  }
99
111
  if (retryProps !== undefined) {
@@ -107,7 +119,10 @@ function normalizeError(error, annotations = {}) {
107
119
  const errorTelemetryProps = LoggingError.typeCheck(error)
108
120
  ? error.getTelemetryProperties()
109
121
  : { untrustedOrigin: 1 }; // This will let us filter errors that did not originate from our own codebase
110
- fluidError.addTelemetryProperties(Object.assign(Object.assign({}, errorTelemetryProps), annotations.props));
122
+ fluidError.addTelemetryProperties({
123
+ ...errorTelemetryProps,
124
+ ...annotations.props,
125
+ });
111
126
  return fluidError;
112
127
  }
113
128
  exports.normalizeError = normalizeError;
@@ -132,8 +147,8 @@ function generateErrorWithStack() {
132
147
  try {
133
148
  throw err;
134
149
  }
135
- catch (e) {
136
- return e;
150
+ catch (error) {
151
+ return error;
137
152
  }
138
153
  }
139
154
  exports.generateErrorWithStack = generateErrorWithStack;
@@ -172,7 +187,11 @@ function wrapError(innerError, newErrorFn) {
172
187
  return newError;
173
188
  }
174
189
  exports.wrapError = wrapError;
175
- /** The same as wrapError, but also logs the innerError, including the wrapping error's instance id */
190
+ /**
191
+ * The same as wrapError, but also logs the innerError, including the wrapping error's instance ID.
192
+ *
193
+ * @typeParam T - The kind of wrapper error to create.
194
+ */
176
195
  function wrapErrorAndLog(innerError, newErrorFn, logger) {
177
196
  const newError = wrapError(innerError, newErrorFn);
178
197
  // This will match innerError.errorInstanceId if present (see wrapError)
@@ -187,45 +206,52 @@ function wrapErrorAndLog(innerError, newErrorFn, logger) {
187
206
  return newError;
188
207
  }
189
208
  exports.wrapErrorAndLog = wrapErrorAndLog;
209
+ /**
210
+ * Attempts to overwrite the error's stack
211
+ *
212
+ * There have been reports of certain JS environments where overwriting stack will throw.
213
+ * If that happens, this adds the given stack as the telemetry property "stack2"
214
+ *
215
+ * @internal
216
+ */
190
217
  function overwriteStack(error, stack) {
191
- // supposedly setting stack on an Error can throw.
192
218
  try {
193
219
  Object.assign(error, { stack });
194
220
  }
195
- catch (errorSettingStack) {
221
+ catch {
196
222
  error.addTelemetryProperties({ stack2: stack });
197
223
  }
198
224
  }
225
+ exports.overwriteStack = overwriteStack;
199
226
  /**
200
227
  * True for any error object that is an (optionally normalized) external error
201
228
  * False for any error we created and raised within the FF codebase via LoggingError base class,
202
229
  * or wrapped in a well-known error type
203
230
  */
204
- function isExternalError(e) {
231
+ function isExternalError(error) {
205
232
  // LoggingErrors are an internal FF error type. However, an external error can be converted
206
233
  // into a LoggingError if it is normalized. In this case we must use the untrustedOrigin flag to
207
234
  // determine whether the original error was infact external.
208
- if (LoggingError.typeCheck(e)) {
209
- if (e.errorType === exports.NORMALIZED_ERROR_TYPE) {
210
- return e.getTelemetryProperties().untrustedOrigin === 1;
235
+ if (LoggingError.typeCheck(error)) {
236
+ if (error.errorType === exports.NORMALIZED_ERROR_TYPE) {
237
+ return error.getTelemetryProperties().untrustedOrigin === 1;
211
238
  }
212
239
  return false;
213
240
  }
214
- return !(0, fluidErrorBase_1.isValidLegacyError)(e);
241
+ return !(0, fluidErrorBase_1.isValidLegacyError)(error);
215
242
  }
216
243
  exports.isExternalError = isExternalError;
217
244
  /**
218
245
  * Type guard to identify if a particular telemetry property appears to be a tagged telemetry property
219
246
  */
220
247
  function isTaggedTelemetryPropertyValue(x) {
221
- var _a;
222
- return typeof ((_a = x) === null || _a === void 0 ? void 0 : _a.tag) === "string";
248
+ return typeof x?.tag === "string";
223
249
  }
224
250
  exports.isTaggedTelemetryPropertyValue = isTaggedTelemetryPropertyValue;
225
251
  /**
226
252
  * Filter serializable telemetry properties
227
- * @param x - any telemetry prop
228
- * @returns - as-is if x is primitive. returns stringified if x is an array of primitive.
253
+ * @param x - Any telemetry prop
254
+ * @returns As-is if x is primitive. returns stringified if x is an array of primitive.
229
255
  * otherwise returns null since this is what we support at the moment.
230
256
  */
231
257
  function filterValidTelemetryProps(x, key) {
@@ -281,6 +307,8 @@ function getValidTelemetryProps(obj, keysToOmit) {
281
307
  * Not ideal, as will cut values that are not necessarily circular references.
282
308
  * Could be improved by implementing Node's util.inspect() for browser (minus all the coloring code)
283
309
  */
310
+ // TODO: Use `unknown` instead (API breaking change)
311
+ /* eslint-disable @typescript-eslint/no-explicit-any */
284
312
  const getCircularReplacer = () => {
285
313
  const seen = new WeakSet();
286
314
  return (key, value) => {
@@ -294,6 +322,7 @@ const getCircularReplacer = () => {
294
322
  };
295
323
  };
296
324
  exports.getCircularReplacer = getCircularReplacer;
325
+ /* eslint-enable @typescript-eslint/no-explicit-any */
297
326
  /**
298
327
  * Base class for "trusted" errors we create, whose properties can generally be logged to telemetry safely.
299
328
  * All properties set on the object, or passed in (via the constructor or addTelemetryProperties),
@@ -312,8 +341,11 @@ class LoggingError extends Error {
312
341
  super(message);
313
342
  this.omitPropsFromLogging = omitPropsFromLogging;
314
343
  this._errorInstanceId = (0, uuid_1.v4)();
315
- /** Back-compat to appease isFluidError typeguard in old code that may handle this error */
344
+ /**
345
+ * Backwards compatibility to appease {@link isFluidError} in old code that may handle this error.
346
+ */
316
347
  // @ts-expect-error - This field shouldn't be referenced in the current version, but needs to exist at runtime.
348
+ // eslint-disable-next-line @typescript-eslint/prefer-as-const
317
349
  this.fluidErrorCode = "-";
318
350
  // Don't log this list itself, or the private _errorInstanceId
319
351
  omitPropsFromLogging.add("omitPropsFromLogging");
@@ -331,7 +363,7 @@ class LoggingError extends Error {
331
363
  /**
332
364
  * Determines if a given object is an instance of a LoggingError
333
365
  * @param object - any object
334
- * @returns - true if the object is an instance of a LoggingError, false if not.
366
+ * @returns true if the object is an instance of a LoggingError, false if not.
335
367
  */
336
368
  static typeCheck(object) {
337
369
  if (typeof object === "object" && object !== null) {
@@ -353,11 +385,18 @@ class LoggingError extends Error {
353
385
  getTelemetryProperties() {
354
386
  const taggableProps = getValidTelemetryProps(this, this.omitPropsFromLogging);
355
387
  // Include non-enumerable props that are not returned by getValidTelemetryProps
356
- return Object.assign(Object.assign({}, taggableProps), { stack: this.stack, message: this.message, errorInstanceId: this._errorInstanceId });
388
+ return {
389
+ ...taggableProps,
390
+ stack: this.stack,
391
+ message: this.message,
392
+ errorInstanceId: this._errorInstanceId,
393
+ };
357
394
  }
358
395
  }
359
396
  exports.LoggingError = LoggingError;
360
- /** The Error class used when normalizing an external error */
397
+ /**
398
+ * The Error class used when normalizing an external error
399
+ */
361
400
  exports.NORMALIZED_ERROR_TYPE = "genericError";
362
401
  class NormalizedLoggingError extends LoggingError {
363
402
  constructor(errorProps) {