@fluidframework/telemetry-utils 2.0.0-internal.5.4.0 → 2.0.0-internal.6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/dist/config.js +25 -31
- package/dist/config.js.map +1 -1
- package/dist/errorLogging.js +16 -10
- package/dist/errorLogging.js.map +1 -1
- package/dist/fluidErrorBase.js +7 -7
- package/dist/fluidErrorBase.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -9
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +1 -56
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +42 -129
- package/dist/logger.js.map +1 -1
- package/dist/mockLogger.d.ts +3 -5
- package/dist/mockLogger.d.ts.map +1 -1
- package/dist/mockLogger.js +6 -15
- package/dist/mockLogger.js.map +1 -1
- package/dist/sampledTelemetryHelper.js +8 -5
- package/dist/sampledTelemetryHelper.js.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +1 -1
- package/lib/config.js +25 -31
- package/lib/config.js.map +1 -1
- package/lib/errorLogging.js +16 -10
- package/lib/errorLogging.js.map +1 -1
- package/lib/fluidErrorBase.js +7 -7
- package/lib/fluidErrorBase.js.map +1 -1
- package/lib/index.d.ts +1 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -2
- package/lib/index.js.map +1 -1
- package/lib/logger.d.ts +1 -56
- package/lib/logger.d.ts.map +1 -1
- package/lib/logger.js +41 -125
- package/lib/logger.js.map +1 -1
- package/lib/mockLogger.d.ts +3 -5
- package/lib/mockLogger.d.ts.map +1 -1
- package/lib/mockLogger.js +7 -16
- package/lib/mockLogger.js.map +1 -1
- package/lib/sampledTelemetryHelper.js +8 -5
- package/lib/sampledTelemetryHelper.js.map +1 -1
- package/lib/utils.js +1 -1
- package/lib/utils.js.map +1 -1
- package/package.json +39 -6
- package/src/index.ts +0 -7
- package/src/logger.ts +11 -98
- package/src/mockLogger.ts +8 -8
- package/dist/debugLogger.d.ts +0 -39
- package/dist/debugLogger.d.ts.map +0 -1
- package/dist/debugLogger.js +0 -105
- package/dist/debugLogger.js.map +0 -1
- package/lib/debugLogger.d.ts +0 -39
- package/lib/debugLogger.d.ts.map +0 -1
- package/lib/debugLogger.js +0 -101
- package/lib/debugLogger.js.map +0 -1
- package/src/debugLogger.ts +0 -138
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @fluidframework/telemetry-utils
|
|
2
2
|
|
|
3
|
+
## 2.0.0-internal.6.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- Remove Deprecated Loggers [8abce8cdb4](https://github.com/microsoft/FluidFramework/commits/8abce8cdb4e2832fb6405fb44e393bef03d5648a)
|
|
8
|
+
|
|
9
|
+
This change removes the previously deprecated logger implementations. The following replacements are available:
|
|
10
|
+
|
|
11
|
+
- replace ChildLogger.create, new TelemetryNullLogger, and new BaseTelemetryNullLogger with createChildLogger
|
|
12
|
+
- replace new MultiSinkLogger with createMultiSinkLogger
|
|
13
|
+
- replace TelemetryUTLogger with MockLogger
|
|
14
|
+
- DebugLogger has no intended replacement
|
|
15
|
+
|
|
16
|
+
- MockLogger is no longer a TelemetryLogger [8abce8cdb4](https://github.com/microsoft/FluidFramework/commits/8abce8cdb4e2832fb6405fb44e393bef03d5648a)
|
|
17
|
+
|
|
18
|
+
TelemetryLogger was deprecated and has now been removed, so MockLogger can no longer inherit from it. MockLogger is now a ITelemetryBaseLogger, to get an ITelemetryLogger, or ITelemetryLoggerExt there is a new convenience method, `MockLogger.toTelemetryLogger()`
|
|
19
|
+
|
|
20
|
+
- Upgraded typescript transpilation target to ES2020 [8abce8cdb4](https://github.com/microsoft/FluidFramework/commits/8abce8cdb4e2832fb6405fb44e393bef03d5648a)
|
|
21
|
+
|
|
22
|
+
Upgraded typescript transpilation target to ES2020. This is done in order to decrease the bundle sizes of Fluid Framework packages. This has provided size improvements across the board for ex. Loader, Driver, Runtime etc. Reduced bundle sizes helps to load lesser code in apps and hence also helps to improve the perf.If any app wants to target any older versions of browsers with which this target version is not compatible, then they can use packages like babel to transpile to a older target.
|
|
23
|
+
|
|
3
24
|
## 2.0.0-internal.5.4.0
|
|
4
25
|
|
|
5
26
|
### Minor Changes
|
package/dist/config.js
CHANGED
|
@@ -23,11 +23,10 @@ const inMemoryConfigProvider = (storage) => {
|
|
|
23
23
|
if (storage !== undefined && storage !== null) {
|
|
24
24
|
return new CachedConfigProvider(undefined, {
|
|
25
25
|
getRawConfig: (name) => {
|
|
26
|
-
var _a, _b;
|
|
27
26
|
try {
|
|
28
|
-
return
|
|
27
|
+
return stronglyTypedParse(storage.getItem(name) ?? undefined)?.raw;
|
|
29
28
|
}
|
|
30
|
-
catch
|
|
29
|
+
catch { }
|
|
31
30
|
return undefined;
|
|
32
31
|
},
|
|
33
32
|
});
|
|
@@ -73,14 +72,14 @@ function stronglyTypedParse(input) {
|
|
|
73
72
|
// casting.
|
|
74
73
|
defaultReturn = { raw: input, string: input };
|
|
75
74
|
}
|
|
76
|
-
catch
|
|
75
|
+
catch { }
|
|
77
76
|
}
|
|
78
77
|
if (output === undefined) {
|
|
79
78
|
return defaultReturn;
|
|
80
79
|
}
|
|
81
80
|
const outputType = typeof output;
|
|
82
81
|
if (isPrimitiveType(outputType)) {
|
|
83
|
-
return
|
|
82
|
+
return { ...defaultReturn, raw: input, [outputType]: output };
|
|
84
83
|
}
|
|
85
84
|
if (Array.isArray(output)) {
|
|
86
85
|
const firstType = typeof output[0];
|
|
@@ -95,13 +94,12 @@ function stronglyTypedParse(input) {
|
|
|
95
94
|
return defaultReturn;
|
|
96
95
|
}
|
|
97
96
|
}
|
|
98
|
-
return
|
|
97
|
+
return { ...defaultReturn, raw: input, [`${firstType}[]`]: output };
|
|
99
98
|
}
|
|
100
99
|
return defaultReturn;
|
|
101
100
|
}
|
|
102
101
|
/** `sessionStorage` is undefined in some environments such as Node and web pages with session storage disabled */
|
|
103
102
|
const safeSessionStorage = () => {
|
|
104
|
-
var _a;
|
|
105
103
|
// For some configurations accessing "globalThis.sessionStorage" throws
|
|
106
104
|
// "'sessionStorage' property from 'Window': Access is denied for this document" rather than returning undefined.
|
|
107
105
|
// Therefor check for it before accessing.
|
|
@@ -109,9 +107,9 @@ const safeSessionStorage = () => {
|
|
|
109
107
|
// Using globalThis and checking for undefined is preferred over just accessing global sessionStorage
|
|
110
108
|
// since it avoids an exception when running in node.
|
|
111
109
|
// In some cases this has returned null when disabled in the browser, so ensure its undefined in that case:
|
|
112
|
-
return
|
|
110
|
+
return globalThis.sessionStorage ?? undefined;
|
|
113
111
|
}
|
|
114
|
-
catch
|
|
112
|
+
catch {
|
|
115
113
|
// For browsers which error on the above when session storage is disabled:
|
|
116
114
|
return undefined;
|
|
117
115
|
}
|
|
@@ -142,44 +140,40 @@ class CachedConfigProvider {
|
|
|
142
140
|
}
|
|
143
141
|
}
|
|
144
142
|
getBoolean(name) {
|
|
145
|
-
|
|
146
|
-
return (_a = this.getCacheEntry(name)) === null || _a === void 0 ? void 0 : _a.boolean;
|
|
143
|
+
return this.getCacheEntry(name)?.boolean;
|
|
147
144
|
}
|
|
148
145
|
getNumber(name) {
|
|
149
|
-
|
|
150
|
-
return (_a = this.getCacheEntry(name)) === null || _a === void 0 ? void 0 : _a.number;
|
|
146
|
+
return this.getCacheEntry(name)?.number;
|
|
151
147
|
}
|
|
152
148
|
getString(name) {
|
|
153
|
-
|
|
154
|
-
return (_a = this.getCacheEntry(name)) === null || _a === void 0 ? void 0 : _a.string;
|
|
149
|
+
return this.getCacheEntry(name)?.string;
|
|
155
150
|
}
|
|
156
151
|
getBooleanArray(name) {
|
|
157
|
-
|
|
158
|
-
return (_a = this.getCacheEntry(name)) === null || _a === void 0 ? void 0 : _a["boolean[]"];
|
|
152
|
+
return this.getCacheEntry(name)?.["boolean[]"];
|
|
159
153
|
}
|
|
160
154
|
getNumberArray(name) {
|
|
161
|
-
|
|
162
|
-
return (_a = this.getCacheEntry(name)) === null || _a === void 0 ? void 0 : _a["number[]"];
|
|
155
|
+
return this.getCacheEntry(name)?.["number[]"];
|
|
163
156
|
}
|
|
164
157
|
getStringArray(name) {
|
|
165
|
-
|
|
166
|
-
return (_a = this.getCacheEntry(name)) === null || _a === void 0 ? void 0 : _a["string[]"];
|
|
158
|
+
return this.getCacheEntry(name)?.["string[]"];
|
|
167
159
|
}
|
|
168
160
|
getRawConfig(name) {
|
|
169
|
-
|
|
170
|
-
return (_a = this.getCacheEntry(name)) === null || _a === void 0 ? void 0 : _a.raw;
|
|
161
|
+
return this.getCacheEntry(name)?.raw;
|
|
171
162
|
}
|
|
172
163
|
getCacheEntry(name) {
|
|
173
|
-
var _a;
|
|
174
164
|
if (!this.configCache.has(name)) {
|
|
175
165
|
for (const provider of this.orderedBaseProviders) {
|
|
176
|
-
const parsed = stronglyTypedParse(provider
|
|
166
|
+
const parsed = stronglyTypedParse(provider?.getRawConfig(name));
|
|
177
167
|
if (parsed !== undefined) {
|
|
178
168
|
this.configCache.set(name, parsed);
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
169
|
+
this.logger?.send({
|
|
170
|
+
category: "generic",
|
|
171
|
+
eventName: "ConfigRead",
|
|
172
|
+
...(0, logger_1.tagCodeArtifacts)({
|
|
173
|
+
configName: name,
|
|
174
|
+
configValue: JSON.stringify(parsed),
|
|
175
|
+
}),
|
|
176
|
+
});
|
|
183
177
|
return parsed;
|
|
184
178
|
}
|
|
185
179
|
}
|
|
@@ -192,7 +186,7 @@ class CachedConfigProvider {
|
|
|
192
186
|
exports.CachedConfigProvider = CachedConfigProvider;
|
|
193
187
|
function loggerIsMonitoringContext(obj) {
|
|
194
188
|
const maybeConfig = obj;
|
|
195
|
-
return isConfigProviderBase(maybeConfig
|
|
189
|
+
return isConfigProviderBase(maybeConfig?.config) && maybeConfig?.logger !== undefined;
|
|
196
190
|
}
|
|
197
191
|
exports.loggerIsMonitoringContext = loggerIsMonitoringContext;
|
|
198
192
|
function loggerToMonitoringContext(logger) {
|
|
@@ -222,7 +216,7 @@ function mixinMonitoringContext(logger, ...configs) {
|
|
|
222
216
|
exports.mixinMonitoringContext = mixinMonitoringContext;
|
|
223
217
|
function isConfigProviderBase(obj) {
|
|
224
218
|
const maybeConfig = obj;
|
|
225
|
-
return typeof
|
|
219
|
+
return typeof maybeConfig?.getRawConfig === "function";
|
|
226
220
|
}
|
|
227
221
|
function createChildMonitoringContext(props) {
|
|
228
222
|
return loggerToMonitoringContext((0, logger_1.createChildLogger)(props));
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;AAKA,2DAAkD;AAClD,qCAA+D;AAuB/D;;;;GAIG;AACU,QAAA,4BAA4B,GAAG,IAAI,iBAAI,CAAsB,GAAG,EAAE,CAC9E,IAAA,8BAAsB,EAAC,kBAAkB,EAAE,CAAC,CAC5C,CAAC;AAEF,MAAM,kBAAkB,GAAwB;IAC/C,YAAY,EAAE,GAAG,EAAE,CAAC,SAAS;CAC7B,CAAC;AAEF;;;;;;GAMG;AACI,MAAM,sBAAsB,GAAG,CAAC,OAA4B,EAAuB,EAAE;IAC3F,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,IAAI,EAAE;QAC9C,OAAO,IAAI,oBAAoB,CAAC,SAAS,EAAE;YAC1C,YAAY,EAAE,CAAC,IAAY,EAAE,EAAE;;gBAC9B,IAAI;oBACH,OAAO,MAAA,kBAAkB,CAAC,MAAA,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,mCAAI,SAAS,CAAC,0CAAE,GAAG,CAAC;iBACnE;gBAAC,WAAM,GAAE;gBACV,OAAO,SAAS,CAAC;YAClB,CAAC;SACD,CAAC,CAAC;KACH;IACD,OAAO,kBAAkB,CAAC;AAC3B,CAAC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,CAAC,CAAC;IACzD,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC;IACnB,OAAO,EAA0B,CAAC;AACnC,CAAC;AAnBD,wDAmBC;AAED,SAAS,oBAAoB,CAAC,GAAY;IACzC,MAAM,WAAW,GAAG,GAA+C,CAAC;IACpE,OAAO,OAAO,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,YAAY,CAAA,KAAK,UAAU,CAAC;AACxD,CAAC;AAED,SAAgB,4BAA4B,CAC3C,KAA8C;IAE9C,OAAO,yBAAyB,CAAC,IAAA,0BAAiB,EAAC,KAAK,CAAC,CAAC,CAAC;AAC5D,CAAC;AAJD,oEAIC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { Lazy } from \"@fluidframework/core-utils\";\nimport { createChildLogger, tagCodeArtifacts } from \"./logger\";\nimport { ITelemetryLoggerExt } from \"./telemetryTypes\";\n\nexport type ConfigTypes = string | number | boolean | number[] | string[] | boolean[] | undefined;\n\n/**\n * Base interface for providing configurations to enable/disable/control features\n */\nexport interface IConfigProviderBase {\n\tgetRawConfig(name: string): ConfigTypes;\n}\n\n/**\n * Explicitly typed interface for reading configurations\n */\nexport interface IConfigProvider extends IConfigProviderBase {\n\tgetBoolean(name: string): boolean | undefined;\n\tgetNumber(name: string): number | undefined;\n\tgetString(name: string): string | undefined;\n\tgetBooleanArray(name: string): boolean[] | undefined;\n\tgetNumberArray(name: string): number[] | undefined;\n\tgetStringArray(name: string): string[] | undefined;\n}\n/**\n * Creates a base configuration provider based on `sessionStorage`\n *\n * @returns A lazy initialized base configuration provider with `sessionStorage` as the underlying config store\n */\nexport const sessionStorageConfigProvider = new Lazy<IConfigProviderBase>(() =>\n\tinMemoryConfigProvider(safeSessionStorage()),\n);\n\nconst NullConfigProvider: IConfigProviderBase = {\n\tgetRawConfig: () => undefined,\n};\n\n/**\n * Creates a base configuration provider based on the supplied `Storage` instance\n *\n * @param storage - instance of `Storage` to be used as storage media for the config\n * @returns A base configuration provider with\n * the supplied `Storage` instance as the underlying config store\n */\nexport const inMemoryConfigProvider = (storage: Storage | undefined): IConfigProviderBase => {\n\tif (storage !== undefined && storage !== null) {\n\t\treturn new CachedConfigProvider(undefined, {\n\t\t\tgetRawConfig: (name: string) => {\n\t\t\t\ttry {\n\t\t\t\t\treturn stronglyTypedParse(storage.getItem(name) ?? undefined)?.raw;\n\t\t\t\t} catch {}\n\t\t\t\treturn undefined;\n\t\t\t},\n\t\t});\n\t}\n\treturn NullConfigProvider;\n};\n\ninterface ConfigTypeStringToType {\n\tnumber: number;\n\tstring: string;\n\tboolean: boolean;\n\t[\"number[]\"]: number[];\n\t[\"string[]\"]: string[];\n\t[\"boolean[]\"]: boolean[];\n}\n\ntype PrimitiveTypeStrings = \"number\" | \"string\" | \"boolean\";\n\nfunction isPrimitiveType(type: string): type is PrimitiveTypeStrings {\n\tswitch (type) {\n\t\tcase \"boolean\":\n\t\tcase \"number\":\n\t\tcase \"string\":\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\ninterface StronglyTypedValue extends Partial<ConfigTypeStringToType> {\n\traw: ConfigTypes;\n}\n/**\n * Takes any supported config type, and returns the value with a strong type. If the type of\n * the config is not a supported type undefined will be returned.\n * The user of this function should cache the result to avoid duplicated work.\n *\n * Strings will be attempted to be parsed and coerced into a strong config type.\n * if it is not possible to parsed and coerce a string to a strong config type the original string\n * will be return with a string type for the consumer to handle further if necessary.\n */\nfunction stronglyTypedParse(input: ConfigTypes): StronglyTypedValue | undefined {\n\tlet output: ConfigTypes = input;\n\tlet defaultReturn: Pick<StronglyTypedValue, \"raw\" | \"string\"> | undefined;\n\t// we do special handling for strings to try and coerce\n\t// them into a config type if we can. This makes it easy\n\t// for config sources like sessionStorage which only\n\t// holds strings\n\tif (typeof input === \"string\") {\n\t\ttry {\n\t\t\toutput = JSON.parse(input);\n\t\t\t// we succeeded in parsing, but we don't support parsing\n\t\t\t// for any object as we can't do it type safely\n\t\t\t// so in this case, the default return will be string\n\t\t\t// rather than undefined, and the consumer\n\t\t\t// can parse, as we don't want to provide\n\t\t\t// a false sense of security by just\n\t\t\t// casting.\n\t\t\tdefaultReturn = { raw: input, string: input };\n\t\t} catch {}\n\t}\n\n\tif (output === undefined) {\n\t\treturn defaultReturn;\n\t}\n\n\tconst outputType = typeof output;\n\tif (isPrimitiveType(outputType)) {\n\t\treturn { ...defaultReturn, raw: input, [outputType]: output };\n\t}\n\n\tif (Array.isArray(output)) {\n\t\tconst firstType = typeof output[0];\n\t\t// ensure the first elements is a primitive type\n\t\tif (!isPrimitiveType(firstType)) {\n\t\t\treturn defaultReturn;\n\t\t}\n\t\t// ensue all the elements types are homogeneous\n\t\t// aka they all have the same type as the first\n\t\tfor (const v of output) {\n\t\t\tif (typeof v !== firstType) {\n\t\t\t\treturn defaultReturn;\n\t\t\t}\n\t\t}\n\t\treturn { ...defaultReturn, raw: input, [`${firstType}[]`]: output };\n\t}\n\n\treturn defaultReturn;\n}\n\n/** `sessionStorage` is undefined in some environments such as Node and web pages with session storage disabled */\nconst safeSessionStorage = (): Storage | undefined => {\n\t// For some configurations accessing \"globalThis.sessionStorage\" throws\n\t// \"'sessionStorage' property from 'Window': Access is denied for this document\" rather than returning undefined.\n\t// Therefor check for it before accessing.\n\ttry {\n\t\t// Using globalThis and checking for undefined is preferred over just accessing global sessionStorage\n\t\t// since it avoids an exception when running in node.\n\t\t// In some cases this has returned null when disabled in the browser, so ensure its undefined in that case:\n\t\treturn globalThis.sessionStorage ?? undefined;\n\t} catch {\n\t\t// For browsers which error on the above when session storage is disabled:\n\t\treturn undefined;\n\t}\n};\n\n/**\n * Implementation of {@link IConfigProvider} which contains nested {@link IConfigProviderBase} instances\n */\nexport class CachedConfigProvider implements IConfigProvider {\n\tprivate readonly configCache = new Map<string, StronglyTypedValue>();\n\tprivate readonly orderedBaseProviders: (IConfigProviderBase | undefined)[];\n\n\tconstructor(\n\t\tprivate readonly logger?: ITelemetryBaseLogger,\n\t\t...orderedBaseProviders: (IConfigProviderBase | undefined)[]\n\t) {\n\t\tthis.orderedBaseProviders = [];\n\t\tconst knownProviders = new Set<IConfigProviderBase>();\n\t\tconst candidateProviders = [...orderedBaseProviders];\n\t\twhile (candidateProviders.length > 0) {\n\t\t\tconst baseProvider = candidateProviders.shift()!;\n\t\t\tif (\n\t\t\t\tbaseProvider !== undefined &&\n\t\t\t\tisConfigProviderBase(baseProvider) &&\n\t\t\t\t!knownProviders.has(baseProvider)\n\t\t\t) {\n\t\t\t\tknownProviders.add(baseProvider);\n\t\t\t\tif (baseProvider instanceof CachedConfigProvider) {\n\t\t\t\t\tcandidateProviders.push(...baseProvider.orderedBaseProviders);\n\t\t\t\t} else {\n\t\t\t\t\tthis.orderedBaseProviders.push(baseProvider);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tgetBoolean(name: string): boolean | undefined {\n\t\treturn this.getCacheEntry(name)?.boolean;\n\t}\n\tgetNumber(name: string): number | undefined {\n\t\treturn this.getCacheEntry(name)?.number;\n\t}\n\tgetString(name: string): string | undefined {\n\t\treturn this.getCacheEntry(name)?.string;\n\t}\n\tgetBooleanArray(name: string): boolean[] | undefined {\n\t\treturn this.getCacheEntry(name)?.[\"boolean[]\"];\n\t}\n\tgetNumberArray(name: string): number[] | undefined {\n\t\treturn this.getCacheEntry(name)?.[\"number[]\"];\n\t}\n\tgetStringArray(name: string): string[] | undefined {\n\t\treturn this.getCacheEntry(name)?.[\"string[]\"];\n\t}\n\n\tgetRawConfig(name: string): ConfigTypes {\n\t\treturn this.getCacheEntry(name)?.raw;\n\t}\n\n\tprivate getCacheEntry(name: string): StronglyTypedValue | undefined {\n\t\tif (!this.configCache.has(name)) {\n\t\t\tfor (const provider of this.orderedBaseProviders) {\n\t\t\t\tconst parsed = stronglyTypedParse(provider?.getRawConfig(name));\n\t\t\t\tif (parsed !== undefined) {\n\t\t\t\t\tthis.configCache.set(name, parsed);\n\t\t\t\t\tthis.logger?.send({\n\t\t\t\t\t\tcategory: \"generic\",\n\t\t\t\t\t\teventName: \"ConfigRead\",\n\t\t\t\t\t\t...tagCodeArtifacts({\n\t\t\t\t\t\t\tconfigName: name,\n\t\t\t\t\t\t\tconfigValue: JSON.stringify(parsed),\n\t\t\t\t\t\t}),\n\t\t\t\t\t});\n\t\t\t\t\treturn parsed;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// configs are immutable, if the first lookup returned no results, all lookups should\n\t\t\tthis.configCache.set(name, { raw: undefined });\n\t\t}\n\t\treturn this.configCache.get(name);\n\t}\n}\n\n/**\n * A type containing both a telemetry logger and a configuration provider\n */\nexport interface MonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt> {\n\tconfig: IConfigProvider;\n\tlogger: L;\n}\n\nexport function loggerIsMonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt>(\n\tobj: L,\n): obj is L & MonitoringContext<L> {\n\tconst maybeConfig = obj as Partial<MonitoringContext<L>> | undefined;\n\treturn isConfigProviderBase(maybeConfig?.config) && maybeConfig?.logger !== undefined;\n}\n\nexport function loggerToMonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt>(\n\tlogger: L,\n): MonitoringContext<L> {\n\tif (loggerIsMonitoringContext<L>(logger)) {\n\t\treturn logger;\n\t}\n\treturn mixinMonitoringContext<L>(logger, sessionStorageConfigProvider.value);\n}\n\nexport function mixinMonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt>(\n\tlogger: L,\n\t...configs: (IConfigProviderBase | undefined)[]\n) {\n\tif (loggerIsMonitoringContext<L>(logger)) {\n\t\tthrow new Error(\"Logger is already a monitoring context\");\n\t}\n\t/**\n\t * this is the tricky bit we use for now to smuggle monitoring context around.\n\t * To the logger we mixin both config and itself, so mc.logger === logger as it is self-referential.\n\t * We then expose it as a Monitoring context, so via types we hide the outer logger methods.\n\t * To layers that expect just a logger we can pass mc.logger, but this is still a MonitoringContext\n\t * so if a deeper layer then converts that logger to a monitoring context it can find the smuggled properties\n\t * of the MonitoringContext and get the config provider.\n\t */\n\tconst mc: L & Partial<MonitoringContext<L>> = logger;\n\tmc.config = new CachedConfigProvider(logger, ...configs);\n\tmc.logger = logger;\n\treturn mc as MonitoringContext<L>;\n}\n\nfunction isConfigProviderBase(obj: unknown): obj is IConfigProviderBase {\n\tconst maybeConfig = obj as Partial<IConfigProviderBase> | undefined;\n\treturn typeof maybeConfig?.getRawConfig === \"function\";\n}\n\nexport function createChildMonitoringContext(\n\tprops: Parameters<typeof createChildLogger>[0],\n): MonitoringContext {\n\treturn loggerToMonitoringContext(createChildLogger(props));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;AAKA,2DAAkD;AAClD,qCAA+D;AAuB/D;;;;GAIG;AACU,QAAA,4BAA4B,GAAG,IAAI,iBAAI,CAAsB,GAAG,EAAE,CAC9E,IAAA,8BAAsB,EAAC,kBAAkB,EAAE,CAAC,CAC5C,CAAC;AAEF,MAAM,kBAAkB,GAAwB;IAC/C,YAAY,EAAE,GAAG,EAAE,CAAC,SAAS;CAC7B,CAAC;AAEF;;;;;;GAMG;AACI,MAAM,sBAAsB,GAAG,CAAC,OAA4B,EAAuB,EAAE;IAC3F,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,IAAI,EAAE;QAC9C,OAAO,IAAI,oBAAoB,CAAC,SAAS,EAAE;YAC1C,YAAY,EAAE,CAAC,IAAY,EAAE,EAAE;gBAC9B,IAAI;oBACH,OAAO,kBAAkB,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,SAAS,CAAC,EAAE,GAAG,CAAC;iBACnE;gBAAC,MAAM,GAAE;gBACV,OAAO,SAAS,CAAC;YAClB,CAAC;SACD,CAAC,CAAC;KACH;IACD,OAAO,kBAAkB,CAAC;AAC3B,CAAC,CAAC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AAnBD,wDAmBC;AAED,SAAS,oBAAoB,CAAC,GAAY;IACzC,MAAM,WAAW,GAAG,GAA+C,CAAC;IACpE,OAAO,OAAO,WAAW,EAAE,YAAY,KAAK,UAAU,CAAC;AACxD,CAAC;AAED,SAAgB,4BAA4B,CAC3C,KAA8C;IAE9C,OAAO,yBAAyB,CAAC,IAAA,0BAAiB,EAAC,KAAK,CAAC,CAAC,CAAC;AAC5D,CAAC;AAJD,oEAIC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { Lazy } from \"@fluidframework/core-utils\";\nimport { createChildLogger, tagCodeArtifacts } from \"./logger\";\nimport { ITelemetryLoggerExt } from \"./telemetryTypes\";\n\nexport type ConfigTypes = string | number | boolean | number[] | string[] | boolean[] | undefined;\n\n/**\n * Base interface for providing configurations to enable/disable/control features\n */\nexport interface IConfigProviderBase {\n\tgetRawConfig(name: string): ConfigTypes;\n}\n\n/**\n * Explicitly typed interface for reading configurations\n */\nexport interface IConfigProvider extends IConfigProviderBase {\n\tgetBoolean(name: string): boolean | undefined;\n\tgetNumber(name: string): number | undefined;\n\tgetString(name: string): string | undefined;\n\tgetBooleanArray(name: string): boolean[] | undefined;\n\tgetNumberArray(name: string): number[] | undefined;\n\tgetStringArray(name: string): string[] | undefined;\n}\n/**\n * Creates a base configuration provider based on `sessionStorage`\n *\n * @returns A lazy initialized base configuration provider with `sessionStorage` as the underlying config store\n */\nexport const sessionStorageConfigProvider = new Lazy<IConfigProviderBase>(() =>\n\tinMemoryConfigProvider(safeSessionStorage()),\n);\n\nconst NullConfigProvider: IConfigProviderBase = {\n\tgetRawConfig: () => undefined,\n};\n\n/**\n * Creates a base configuration provider based on the supplied `Storage` instance\n *\n * @param storage - instance of `Storage` to be used as storage media for the config\n * @returns A base configuration provider with\n * the supplied `Storage` instance as the underlying config store\n */\nexport const inMemoryConfigProvider = (storage: Storage | undefined): IConfigProviderBase => {\n\tif (storage !== undefined && storage !== null) {\n\t\treturn new CachedConfigProvider(undefined, {\n\t\t\tgetRawConfig: (name: string) => {\n\t\t\t\ttry {\n\t\t\t\t\treturn stronglyTypedParse(storage.getItem(name) ?? undefined)?.raw;\n\t\t\t\t} catch {}\n\t\t\t\treturn undefined;\n\t\t\t},\n\t\t});\n\t}\n\treturn NullConfigProvider;\n};\n\ninterface ConfigTypeStringToType {\n\tnumber: number;\n\tstring: string;\n\tboolean: boolean;\n\t[\"number[]\"]: number[];\n\t[\"string[]\"]: string[];\n\t[\"boolean[]\"]: boolean[];\n}\n\ntype PrimitiveTypeStrings = \"number\" | \"string\" | \"boolean\";\n\nfunction isPrimitiveType(type: string): type is PrimitiveTypeStrings {\n\tswitch (type) {\n\t\tcase \"boolean\":\n\t\tcase \"number\":\n\t\tcase \"string\":\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\ninterface StronglyTypedValue extends Partial<ConfigTypeStringToType> {\n\traw: ConfigTypes;\n}\n/**\n * Takes any supported config type, and returns the value with a strong type. If the type of\n * the config is not a supported type undefined will be returned.\n * The user of this function should cache the result to avoid duplicated work.\n *\n * Strings will be attempted to be parsed and coerced into a strong config type.\n * if it is not possible to parsed and coerce a string to a strong config type the original string\n * will be return with a string type for the consumer to handle further if necessary.\n */\nfunction stronglyTypedParse(input: ConfigTypes): StronglyTypedValue | undefined {\n\tlet output: ConfigTypes = input;\n\tlet defaultReturn: Pick<StronglyTypedValue, \"raw\" | \"string\"> | undefined;\n\t// we do special handling for strings to try and coerce\n\t// them into a config type if we can. This makes it easy\n\t// for config sources like sessionStorage which only\n\t// holds strings\n\tif (typeof input === \"string\") {\n\t\ttry {\n\t\t\toutput = JSON.parse(input);\n\t\t\t// we succeeded in parsing, but we don't support parsing\n\t\t\t// for any object as we can't do it type safely\n\t\t\t// so in this case, the default return will be string\n\t\t\t// rather than undefined, and the consumer\n\t\t\t// can parse, as we don't want to provide\n\t\t\t// a false sense of security by just\n\t\t\t// casting.\n\t\t\tdefaultReturn = { raw: input, string: input };\n\t\t} catch {}\n\t}\n\n\tif (output === undefined) {\n\t\treturn defaultReturn;\n\t}\n\n\tconst outputType = typeof output;\n\tif (isPrimitiveType(outputType)) {\n\t\treturn { ...defaultReturn, raw: input, [outputType]: output };\n\t}\n\n\tif (Array.isArray(output)) {\n\t\tconst firstType = typeof output[0];\n\t\t// ensure the first elements is a primitive type\n\t\tif (!isPrimitiveType(firstType)) {\n\t\t\treturn defaultReturn;\n\t\t}\n\t\t// ensue all the elements types are homogeneous\n\t\t// aka they all have the same type as the first\n\t\tfor (const v of output) {\n\t\t\tif (typeof v !== firstType) {\n\t\t\t\treturn defaultReturn;\n\t\t\t}\n\t\t}\n\t\treturn { ...defaultReturn, raw: input, [`${firstType}[]`]: output };\n\t}\n\n\treturn defaultReturn;\n}\n\n/** `sessionStorage` is undefined in some environments such as Node and web pages with session storage disabled */\nconst safeSessionStorage = (): Storage | undefined => {\n\t// For some configurations accessing \"globalThis.sessionStorage\" throws\n\t// \"'sessionStorage' property from 'Window': Access is denied for this document\" rather than returning undefined.\n\t// Therefor check for it before accessing.\n\ttry {\n\t\t// Using globalThis and checking for undefined is preferred over just accessing global sessionStorage\n\t\t// since it avoids an exception when running in node.\n\t\t// In some cases this has returned null when disabled in the browser, so ensure its undefined in that case:\n\t\treturn globalThis.sessionStorage ?? undefined;\n\t} catch {\n\t\t// For browsers which error on the above when session storage is disabled:\n\t\treturn undefined;\n\t}\n};\n\n/**\n * Implementation of {@link IConfigProvider} which contains nested {@link IConfigProviderBase} instances\n */\nexport class CachedConfigProvider implements IConfigProvider {\n\tprivate readonly configCache = new Map<string, StronglyTypedValue>();\n\tprivate readonly orderedBaseProviders: (IConfigProviderBase | undefined)[];\n\n\tconstructor(\n\t\tprivate readonly logger?: ITelemetryBaseLogger,\n\t\t...orderedBaseProviders: (IConfigProviderBase | undefined)[]\n\t) {\n\t\tthis.orderedBaseProviders = [];\n\t\tconst knownProviders = new Set<IConfigProviderBase>();\n\t\tconst candidateProviders = [...orderedBaseProviders];\n\t\twhile (candidateProviders.length > 0) {\n\t\t\tconst baseProvider = candidateProviders.shift()!;\n\t\t\tif (\n\t\t\t\tbaseProvider !== undefined &&\n\t\t\t\tisConfigProviderBase(baseProvider) &&\n\t\t\t\t!knownProviders.has(baseProvider)\n\t\t\t) {\n\t\t\t\tknownProviders.add(baseProvider);\n\t\t\t\tif (baseProvider instanceof CachedConfigProvider) {\n\t\t\t\t\tcandidateProviders.push(...baseProvider.orderedBaseProviders);\n\t\t\t\t} else {\n\t\t\t\t\tthis.orderedBaseProviders.push(baseProvider);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tgetBoolean(name: string): boolean | undefined {\n\t\treturn this.getCacheEntry(name)?.boolean;\n\t}\n\tgetNumber(name: string): number | undefined {\n\t\treturn this.getCacheEntry(name)?.number;\n\t}\n\tgetString(name: string): string | undefined {\n\t\treturn this.getCacheEntry(name)?.string;\n\t}\n\tgetBooleanArray(name: string): boolean[] | undefined {\n\t\treturn this.getCacheEntry(name)?.[\"boolean[]\"];\n\t}\n\tgetNumberArray(name: string): number[] | undefined {\n\t\treturn this.getCacheEntry(name)?.[\"number[]\"];\n\t}\n\tgetStringArray(name: string): string[] | undefined {\n\t\treturn this.getCacheEntry(name)?.[\"string[]\"];\n\t}\n\n\tgetRawConfig(name: string): ConfigTypes {\n\t\treturn this.getCacheEntry(name)?.raw;\n\t}\n\n\tprivate getCacheEntry(name: string): StronglyTypedValue | undefined {\n\t\tif (!this.configCache.has(name)) {\n\t\t\tfor (const provider of this.orderedBaseProviders) {\n\t\t\t\tconst parsed = stronglyTypedParse(provider?.getRawConfig(name));\n\t\t\t\tif (parsed !== undefined) {\n\t\t\t\t\tthis.configCache.set(name, parsed);\n\t\t\t\t\tthis.logger?.send({\n\t\t\t\t\t\tcategory: \"generic\",\n\t\t\t\t\t\teventName: \"ConfigRead\",\n\t\t\t\t\t\t...tagCodeArtifacts({\n\t\t\t\t\t\t\tconfigName: name,\n\t\t\t\t\t\t\tconfigValue: JSON.stringify(parsed),\n\t\t\t\t\t\t}),\n\t\t\t\t\t});\n\t\t\t\t\treturn parsed;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// configs are immutable, if the first lookup returned no results, all lookups should\n\t\t\tthis.configCache.set(name, { raw: undefined });\n\t\t}\n\t\treturn this.configCache.get(name);\n\t}\n}\n\n/**\n * A type containing both a telemetry logger and a configuration provider\n */\nexport interface MonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt> {\n\tconfig: IConfigProvider;\n\tlogger: L;\n}\n\nexport function loggerIsMonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt>(\n\tobj: L,\n): obj is L & MonitoringContext<L> {\n\tconst maybeConfig = obj as Partial<MonitoringContext<L>> | undefined;\n\treturn isConfigProviderBase(maybeConfig?.config) && maybeConfig?.logger !== undefined;\n}\n\nexport function loggerToMonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt>(\n\tlogger: L,\n): MonitoringContext<L> {\n\tif (loggerIsMonitoringContext<L>(logger)) {\n\t\treturn logger;\n\t}\n\treturn mixinMonitoringContext<L>(logger, sessionStorageConfigProvider.value);\n}\n\nexport function mixinMonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt>(\n\tlogger: L,\n\t...configs: (IConfigProviderBase | undefined)[]\n) {\n\tif (loggerIsMonitoringContext<L>(logger)) {\n\t\tthrow new Error(\"Logger is already a monitoring context\");\n\t}\n\t/**\n\t * this is the tricky bit we use for now to smuggle monitoring context around.\n\t * To the logger we mixin both config and itself, so mc.logger === logger as it is self-referential.\n\t * We then expose it as a Monitoring context, so via types we hide the outer logger methods.\n\t * To layers that expect just a logger we can pass mc.logger, but this is still a MonitoringContext\n\t * so if a deeper layer then converts that logger to a monitoring context it can find the smuggled properties\n\t * of the MonitoringContext and get the config provider.\n\t */\n\tconst mc: L & Partial<MonitoringContext<L>> = logger;\n\tmc.config = new CachedConfigProvider(logger, ...configs);\n\tmc.logger = logger;\n\treturn mc as MonitoringContext<L>;\n}\n\nfunction isConfigProviderBase(obj: unknown): obj is IConfigProviderBase {\n\tconst maybeConfig = obj as Partial<IConfigProviderBase> | undefined;\n\treturn typeof maybeConfig?.getRawConfig === \"function\";\n}\n\nexport function createChildMonitoringContext(\n\tprops: Parameters<typeof createChildLogger>[0],\n): MonitoringContext {\n\treturn loggerToMonitoringContext(createChildLogger(props));\n}\n"]}
|
package/dist/errorLogging.js
CHANGED
|
@@ -24,7 +24,7 @@ function extractLogSafeErrorProperties(error, sanitizeStack) {
|
|
|
24
24
|
}
|
|
25
25
|
return stackFrames.join("\n");
|
|
26
26
|
};
|
|
27
|
-
const message = typeof
|
|
27
|
+
const message = typeof error?.message === "string" ? error.message : String(error);
|
|
28
28
|
const safeProps = {
|
|
29
29
|
message,
|
|
30
30
|
};
|
|
@@ -42,7 +42,7 @@ function extractLogSafeErrorProperties(error, sanitizeStack) {
|
|
|
42
42
|
}
|
|
43
43
|
exports.extractLogSafeErrorProperties = extractLogSafeErrorProperties;
|
|
44
44
|
/** type guard for ILoggingError interface */
|
|
45
|
-
const isILoggingError = (x) => typeof
|
|
45
|
+
const isILoggingError = (x) => typeof x?.getTelemetryProperties === "function";
|
|
46
46
|
exports.isILoggingError = isILoggingError;
|
|
47
47
|
/** Copy props from source onto target, but do not overwrite an existing prop that matches */
|
|
48
48
|
function copyProps(target, source) {
|
|
@@ -66,14 +66,13 @@ function patchLegacyError(legacyError) {
|
|
|
66
66
|
* @param annotations - Annotations to apply to the normalized error
|
|
67
67
|
*/
|
|
68
68
|
function normalizeError(error, annotations = {}) {
|
|
69
|
-
var _a;
|
|
70
69
|
// Back-compat, while IFluidErrorBase is rolled out
|
|
71
70
|
if ((0, fluidErrorBase_1.isValidLegacyError)(error)) {
|
|
72
71
|
patchLegacyError(error);
|
|
73
72
|
}
|
|
74
73
|
if ((0, fluidErrorBase_1.isFluidError)(error)) {
|
|
75
74
|
// We can simply add the telemetry props to the error and return it
|
|
76
|
-
error.addTelemetryProperties(
|
|
75
|
+
error.addTelemetryProperties(annotations.props ?? {});
|
|
77
76
|
return error;
|
|
78
77
|
}
|
|
79
78
|
// We have to construct a new Fluid Error, copying safe properties over
|
|
@@ -89,11 +88,11 @@ function normalizeError(error, annotations = {}) {
|
|
|
89
88
|
const maybeHasRetry = error;
|
|
90
89
|
let retryProps;
|
|
91
90
|
if ("canRetry" in error) {
|
|
92
|
-
retryProps
|
|
91
|
+
retryProps ?? (retryProps = {});
|
|
93
92
|
retryProps.canRetry = maybeHasRetry.canRetry;
|
|
94
93
|
}
|
|
95
94
|
if ("retryAfterSeconds" in error) {
|
|
96
|
-
retryProps
|
|
95
|
+
retryProps ?? (retryProps = {});
|
|
97
96
|
retryProps.retryAfterSeconds = maybeHasRetry.retryAfterSeconds;
|
|
98
97
|
}
|
|
99
98
|
if (retryProps !== undefined) {
|
|
@@ -107,7 +106,10 @@ function normalizeError(error, annotations = {}) {
|
|
|
107
106
|
const errorTelemetryProps = LoggingError.typeCheck(error)
|
|
108
107
|
? error.getTelemetryProperties()
|
|
109
108
|
: { untrustedOrigin: 1 }; // This will let us filter errors that did not originate from our own codebase
|
|
110
|
-
fluidError.addTelemetryProperties(
|
|
109
|
+
fluidError.addTelemetryProperties({
|
|
110
|
+
...errorTelemetryProps,
|
|
111
|
+
...annotations.props,
|
|
112
|
+
});
|
|
111
113
|
return fluidError;
|
|
112
114
|
}
|
|
113
115
|
exports.normalizeError = normalizeError;
|
|
@@ -218,8 +220,7 @@ exports.isExternalError = isExternalError;
|
|
|
218
220
|
* Type guard to identify if a particular telemetry property appears to be a tagged telemetry property
|
|
219
221
|
*/
|
|
220
222
|
function isTaggedTelemetryPropertyValue(x) {
|
|
221
|
-
|
|
222
|
-
return typeof ((_a = x) === null || _a === void 0 ? void 0 : _a.tag) === "string";
|
|
223
|
+
return typeof x?.tag === "string";
|
|
223
224
|
}
|
|
224
225
|
exports.isTaggedTelemetryPropertyValue = isTaggedTelemetryPropertyValue;
|
|
225
226
|
/**
|
|
@@ -353,7 +354,12 @@ class LoggingError extends Error {
|
|
|
353
354
|
getTelemetryProperties() {
|
|
354
355
|
const taggableProps = getValidTelemetryProps(this, this.omitPropsFromLogging);
|
|
355
356
|
// Include non-enumerable props that are not returned by getValidTelemetryProps
|
|
356
|
-
return
|
|
357
|
+
return {
|
|
358
|
+
...taggableProps,
|
|
359
|
+
stack: this.stack,
|
|
360
|
+
message: this.message,
|
|
361
|
+
errorInstanceId: this._errorInstanceId,
|
|
362
|
+
};
|
|
357
363
|
}
|
|
358
364
|
}
|
|
359
365
|
exports.LoggingError = LoggingError;
|
package/dist/errorLogging.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errorLogging.js","sourceRoot":"","sources":["../src/errorLogging.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAQH,+BAAkC;AAClC,qDAK0B;AAO1B,wEAAwE;AACxE,MAAM,eAAe,GAAG,CAAC,KAAU,EAAW,EAAE;IAC/C,OAAO,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC;AAC7E,CAAC,CAAC;AAEF,sEAAsE;AACtE,SAAgB,6BAA6B,CAAC,KAAU,EAAE,aAAsB;IAC/E,MAAM,sBAAsB,GAAG,CAAC,KAAa,EAAE,SAAkB,EAAE,EAAE;QACpE,IAAI,CAAC,aAAa,EAAE;YACnB,OAAO,KAAK,CAAC;SACb;QACD,MAAM,WAAW,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACtC,WAAW,CAAC,KAAK,EAAE,CAAC,CAAC,uCAAuC;QAC5D,IAAI,SAAS,KAAK,SAAS,EAAE;YAC5B,WAAW,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,oBAAoB;SACpD;QACD,OAAO,WAAW,C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G,sBAAsB,CAAC,IAAI,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;QAC9E,+EAA+E;QAC/E,uCACI,aAAa,KAChB,KAAK,EAAE,IAAI,CAAC,KAAK,EACjB,OAAO,EAAE,IAAI,CAAC,OAAO,EACrB,eAAe,EAAE,IAAI,CAAC,gBAAgB,IACrC;IACH,CAAC;CACD;AA1ED,oCA0EC;AAED,8DAA8D;AACjD,QAAA,qBAAqB,GAAG,cAAc,CAAC;AACpD,MAAM,sBAAuB,SAAQ,YAAY;IAKhD,YAAY,UAAsD;QACjE,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAL3B,2EAA2E;QAC3E,2EAA2E;QAC3E,cAAS,GAAG,6BAAqB,CAAC;QAKjC,IAAI,UAAU,CAAC,KAAK,KAAK,SAAS,EAAE;YACnC,cAAc,CAAC,IAAI,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC;SACvC;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tILoggingError,\n\tITaggedTelemetryPropertyType,\n\tITelemetryProperties,\n\tTelemetryEventPropertyType,\n} from \"@fluidframework/core-interfaces\";\nimport { v4 as uuid } from \"uuid\";\nimport {\n\thasErrorInstanceId,\n\tIFluidErrorBase,\n\tisFluidError,\n\tisValidLegacyError,\n} from \"./fluidErrorBase\";\nimport {\n\tITaggedTelemetryPropertyTypeExt,\n\tITelemetryLoggerExt,\n\tTelemetryEventPropertyTypeExt,\n} from \"./telemetryTypes\";\n\n/** @returns true if value is an object but neither null nor an array */\nconst isRegularObject = (value: any): boolean => {\n\treturn 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\tconst removeMessageFromStack = (stack: string, errorName?: string) => {\n\t\tif (!sanitizeStack) {\n\t\t\treturn stack;\n\t\t}\n\t\tconst stackFrames = stack.split(\"\\n\");\n\t\tstackFrames.shift(); // Remove \"[ErrorName]: [ErrorMessage]\"\n\t\tif (errorName !== undefined) {\n\t\t\tstackFrames.unshift(errorName); // Add \"[ErrorName]\"\n\t\t}\n\t\treturn stackFrames.join(\"\\n\");\n\t};\n\n\tconst message = typeof error?.message === \"string\" ? (error.message as string) : String(error);\n\n\tconst safeProps: { message: string; errorType?: string; stack?: string } = {\n\t\tmessage,\n\t};\n\n\tif (isRegularObject(error)) {\n\t\tconst { errorType, stack, name } = error;\n\n\t\tif (typeof errorType === \"string\") {\n\t\t\tsafeProps.errorType = errorType;\n\t\t}\n\n\t\tif (typeof stack === \"string\") {\n\t\t\tconst errorName = typeof name === \"string\" ? name : undefined;\n\t\t\tsafeProps.stack = removeMessageFromStack(stack, errorName);\n\t\t}\n\t}\n\n\treturn safeProps;\n}\n\n/** type guard for ILoggingError interface */\nexport const isILoggingError = (x: any): x is ILoggingError =>\n\ttypeof 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\tfor (const key of Object.keys(source)) {\n\t\tif (target[key] === undefined) {\n\t\t\ttarget[key] = source[key];\n\t\t}\n\t}\n}\n\n/** Metadata to annotate an error object when annotating or normalizing it */\nexport interface IFluidErrorAnnotations {\n\t/** Telemetry props to log with the error */\n\tprops?: ITelemetryProperties;\n}\n\n/** For backwards compatibility with pre-errorInstanceId valid errors */\nfunction patchLegacyError(\n\tlegacyError: Omit<IFluidErrorBase, \"errorInstanceId\">,\n): asserts legacyError is IFluidErrorBase {\n\tconst patchMe: { -readonly [P in \"errorInstanceId\"]?: IFluidErrorBase[P] } = legacyError as any;\n\tif (patchMe.errorInstanceId === undefined) {\n\t\tpatchMe.errorInstanceId = uuid();\n\t}\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\terror: unknown,\n\tannotations: IFluidErrorAnnotations = {},\n): IFluidErrorBase {\n\t// Back-compat, while IFluidErrorBase is rolled out\n\tif (isValidLegacyError(error)) {\n\t\tpatchLegacyError(error);\n\t}\n\n\tif (isFluidError(error)) {\n\t\t// We can simply add the telemetry props to the error and return it\n\t\terror.addTelemetryProperties(annotations.props ?? {});\n\t\treturn error;\n\t}\n\n\t// We have to construct a new Fluid Error, copying safe properties over\n\tconst { message, stack } = extractLogSafeErrorProperties(error, false /* sanitizeStack */);\n\tconst fluidError: IFluidErrorBase = new NormalizedLoggingError({\n\t\tmessage,\n\t\tstack,\n\t});\n\n\t// We need to preserve these properties which are used in a non-typesafe way throughout driver code (see #8743)\n\t// Anywhere they are set should be on a valid Fluid Error that would have been returned above,\n\t// but we can't prove it with the types, so adding this defensive measure.\n\tif (typeof error === \"object\" && error !== null) {\n\t\tconst maybeHasRetry: Partial<Record<\"canRetry\" | \"retryAfterSeconds\", unknown>> = error;\n\t\tlet retryProps: Partial<Record<\"canRetry\" | \"retryAfterSeconds\", unknown>> | undefined;\n\t\tif (\"canRetry\" in error) {\n\t\t\tretryProps ??= {};\n\t\t\tretryProps.canRetry = maybeHasRetry.canRetry;\n\t\t}\n\t\tif (\"retryAfterSeconds\" in error) {\n\t\t\tretryProps ??= {};\n\t\t\tretryProps.retryAfterSeconds = maybeHasRetry.retryAfterSeconds;\n\t\t}\n\t\tif (retryProps !== undefined) {\n\t\t\tObject.assign(fluidError, retryProps);\n\t\t}\n\t}\n\n\tif (typeof error !== \"object\") {\n\t\t// This is only interesting for non-objects\n\t\tfluidError.addTelemetryProperties({ typeofError: typeof error });\n\t}\n\n\tconst errorTelemetryProps = LoggingError.typeCheck(error)\n\t\t? error.getTelemetryProperties()\n\t\t: { untrustedOrigin: 1 }; // This will let us filter errors that did not originate from our own codebase\n\n\tfluidError.addTelemetryProperties({\n\t\t...errorTelemetryProps,\n\t\t...annotations.props,\n\t});\n\n\treturn fluidError;\n}\n\nlet stackPopulatedOnCreation: boolean | undefined;\n\n/**\n * The purpose of this function is to provide ability to capture stack context quickly.\n * Accessing new Error().stack is slow, and the slowest part is accessing stack property itself.\n * There are scenarios where we generate error with stack, but error is handled in most cases and\n * stack property is not accessed.\n * For such cases it's better to not read stack property right away, but rather delay it until / if it's needed\n * Some browsers will populate stack right away, others require throwing Error, so we do auto-detection on the fly.\n * @returns Error object that has stack populated.\n */\nexport function generateErrorWithStack(): Error {\n\tconst err = new Error(\"<<generated stack>>\");\n\n\tif (stackPopulatedOnCreation === undefined) {\n\t\tstackPopulatedOnCreation = err.stack !== undefined;\n\t}\n\n\tif (stackPopulatedOnCreation) {\n\t\treturn err;\n\t}\n\n\ttry {\n\t\tthrow err;\n\t} catch (e) {\n\t\treturn e as Error;\n\t}\n}\n\nexport function generateStack(): string | undefined {\n\treturn generateErrorWithStack().stack;\n}\n\n/**\n * Create a new error using newErrorFn, wrapping and caused by the given unknown error.\n * Copies the inner error's stack, errorInstanceId and telemetry props over to the new error if present\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 */\nexport function wrapError<T extends LoggingError>(\n\tinnerError: unknown,\n\tnewErrorFn: (message: string) => T,\n): T {\n\tconst { message, stack } = extractLogSafeErrorProperties(innerError, false /* sanitizeStack */);\n\n\tconst newError = newErrorFn(message);\n\n\tif (stack !== undefined) {\n\t\toverwriteStack(newError, stack);\n\t}\n\n\t// Mark external errors with untrustedOrigin flag\n\tif (isExternalError(innerError)) {\n\t\tnewError.addTelemetryProperties({ untrustedOrigin: 1 });\n\t}\n\n\t// Reuse errorInstanceId\n\tif (hasErrorInstanceId(innerError)) {\n\t\tnewError.overwriteErrorInstanceId(innerError.errorInstanceId);\n\n\t\t// For \"back-compat\" in the logs\n\t\tnewError.addTelemetryProperties({ innerErrorInstanceId: innerError.errorInstanceId });\n\t}\n\n\t// Lastly, copy over all other telemetry properties. Note these will not overwrite existing properties\n\t// This will include the untrustedOrigin property if the inner error itself was created from an external error\n\tif (isILoggingError(innerError)) {\n\t\tnewError.addTelemetryProperties(innerError.getTelemetryProperties());\n\t}\n\n\treturn 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 LoggingError>(\n\tinnerError: unknown,\n\tnewErrorFn: (message: string) => T,\n\tlogger: ITelemetryLoggerExt,\n) {\n\tconst newError = wrapError(innerError, newErrorFn);\n\n\t// This will match innerError.errorInstanceId if present (see wrapError)\n\tconst errorInstanceId = newError.errorInstanceId;\n\n\t// For \"back-compat\" in the logs\n\tconst wrappedByErrorInstanceId = errorInstanceId;\n\n\tlogger.sendTelemetryEvent(\n\t\t{\n\t\t\teventName: \"WrapError\",\n\t\t\terrorInstanceId,\n\t\t\twrappedByErrorInstanceId,\n\t\t},\n\t\tinnerError,\n\t);\n\n\treturn newError;\n}\n\nfunction overwriteStack(error: IFluidErrorBase | LoggingError, stack: string) {\n\t// supposedly setting stack on an Error can throw.\n\ttry {\n\t\tObject.assign(error, { stack });\n\t} catch (errorSettingStack) {\n\t\terror.addTelemetryProperties({ stack2: stack });\n\t}\n}\n\n/**\n * True for any error object that is an (optionally normalized) external error\n * False for any error we created and raised within the FF codebase via LoggingError base class,\n * or wrapped in a well-known error type\n */\nexport function isExternalError(e: any): boolean {\n\t// LoggingErrors are an internal FF error type. However, an external error can be converted\n\t// into a LoggingError if it is normalized. In this case we must use the untrustedOrigin flag to\n\t// determine whether the original error was infact external.\n\tif (LoggingError.typeCheck(e)) {\n\t\tif ((e as NormalizedLoggingError).errorType === NORMALIZED_ERROR_TYPE) {\n\t\t\treturn e.getTelemetryProperties().untrustedOrigin === 1;\n\t\t}\n\t\treturn false;\n\t}\n\treturn !isValidLegacyError(e);\n}\n\n/**\n * Type guard to identify if a particular telemetry property appears to be a tagged telemetry property\n */\nexport function isTaggedTelemetryPropertyValue(\n\tx: ITaggedTelemetryPropertyTypeExt | TelemetryEventPropertyTypeExt,\n): x is ITaggedTelemetryPropertyType | ITaggedTelemetryPropertyTypeExt {\n\treturn typeof (x as any)?.tag === \"string\";\n}\n\n/**\n * Filter serializable telemetry properties\n * @param x - any telemetry prop\n * @returns - as-is if x is primitive. returns stringified if x is an array of primitive.\n * otherwise returns null since this is what we support at the moment.\n */\nfunction filterValidTelemetryProps(x: any, key: string): TelemetryEventPropertyType {\n\tif (Array.isArray(x) && x.every((val) => isTelemetryEventPropertyValue(val))) {\n\t\treturn JSON.stringify(x);\n\t}\n\tif (isTelemetryEventPropertyValue(x)) {\n\t\treturn x;\n\t}\n\t// We don't support logging arbitrary objects\n\tconsole.error(`UnSupported Format of Logging Error Property for key ${key}:`, x);\n\treturn \"REDACTED (arbitrary object)\";\n}\n\n// checking type of x, returns false if x is null\nfunction isTelemetryEventPropertyValue(x: any): x is TelemetryEventPropertyType {\n\tswitch (typeof x) {\n\t\tcase \"string\":\n\t\tcase \"number\":\n\t\tcase \"boolean\":\n\t\tcase \"undefined\":\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\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\tconst props: ITelemetryProperties = {};\n\tfor (const key of Object.keys(obj)) {\n\t\tif (keysToOmit.has(key)) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst val = obj[key];\n\n\t\t// ensure only valid props get logged, since props of logging error could be in any shape\n\t\tif (isTaggedTelemetryPropertyValue(val)) {\n\t\t\tprops[key] = {\n\t\t\t\tvalue: filterValidTelemetryProps(val.value, key),\n\t\t\t\ttag: val.tag,\n\t\t\t};\n\t\t} else {\n\t\t\tprops[key] = filterValidTelemetryProps(val, key);\n\t\t}\n\t}\n\treturn props;\n}\n\n/**\n * Borrowed from\n * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value#examples}\n * Avoids runtime errors with circular references.\n * Not ideal, as will cut values that are not necessarily circular references.\n * Could be improved by implementing Node's util.inspect() for browser (minus all the coloring code)\n */\nexport const getCircularReplacer = () => {\n\tconst seen = new WeakSet();\n\treturn (key: string, value: any): any => {\n\t\tif (typeof value === \"object\" && value !== null) {\n\t\t\tif (seen.has(value)) {\n\t\t\t\treturn \"<removed/circular>\";\n\t\t\t}\n\t\t\tseen.add(value);\n\t\t}\n\t\treturn value;\n\t};\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 addTelemetryProperties),\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\n\textends Error\n\timplements ILoggingError, Omit<IFluidErrorBase, \"errorType\">\n{\n\tprivate _errorInstanceId = uuid();\n\tget errorInstanceId() {\n\t\treturn this._errorInstanceId;\n\t}\n\toverwriteErrorInstanceId(id: string) {\n\t\tthis._errorInstanceId = id;\n\t}\n\n\t/** Back-compat to appease isFluidError typeguard in old code that may handle this error */\n\t// @ts-expect-error - This field shouldn't be referenced in the current version, but needs to exist at runtime.\n\tprivate readonly fluidErrorCode: \"-\" = \"-\";\n\n\t/**\n\t * Create a new LoggingError\n\t * @param message - Error message to use for Error base class\n\t * @param props - telemetry props to include on the error for when it's logged\n\t * @param omitPropsFromLogging - properties by name to omit from telemetry props\n\t */\n\tconstructor(\n\t\tmessage: string,\n\t\tprops?: ITelemetryProperties,\n\t\tprivate readonly omitPropsFromLogging: Set<string> = new Set(),\n\t) {\n\t\tsuper(message);\n\n\t\t// Don't log this list itself, or the private _errorInstanceId\n\t\tomitPropsFromLogging.add(\"omitPropsFromLogging\");\n\t\tomitPropsFromLogging.add(\"_errorInstanceId\");\n\n\t\tif (props) {\n\t\t\tthis.addTelemetryProperties(props);\n\t\t}\n\t}\n\n\t/**\n\t * Determines if a given object is an instance of a LoggingError\n\t * @param object - any object\n\t * @returns - true if the object is an instance of a LoggingError, false if not.\n\t */\n\tpublic static typeCheck(object: unknown): object is LoggingError {\n\t\tif (typeof object === \"object\" && object !== null) {\n\t\t\treturn (\n\t\t\t\ttypeof (object as LoggingError).addTelemetryProperties === \"function\" &&\n\t\t\t\ttypeof (object as LoggingError).getTelemetryProperties === \"function\" &&\n\t\t\t\ttypeof (object as LoggingError).errorInstanceId === \"string\"\n\t\t\t);\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Add additional properties to be logged\n\t */\n\tpublic addTelemetryProperties(props: ITelemetryProperties) {\n\t\tcopyProps(this, props);\n\t}\n\n\t/**\n\t * Get all properties fit to be logged to telemetry for this error\n\t */\n\tpublic getTelemetryProperties(): ITelemetryProperties {\n\t\tconst taggableProps = getValidTelemetryProps(this, this.omitPropsFromLogging);\n\t\t// Include non-enumerable props that are not returned by getValidTelemetryProps\n\t\treturn {\n\t\t\t...taggableProps,\n\t\t\tstack: this.stack,\n\t\t\tmessage: this.message,\n\t\t\terrorInstanceId: this._errorInstanceId,\n\t\t};\n\t}\n}\n\n/** The Error class used when normalizing an external error */\nexport const NORMALIZED_ERROR_TYPE = \"genericError\";\nclass NormalizedLoggingError extends LoggingError {\n\t// errorType \"genericError\" is used as a default value throughout the code.\n\t// Note that this matches ContainerErrorType/DriverErrorType's genericError\n\terrorType = NORMALIZED_ERROR_TYPE;\n\n\tconstructor(errorProps: Pick<IFluidErrorBase, \"message\" | \"stack\">) {\n\t\tsuper(errorProps.message);\n\n\t\tif (errorProps.stack !== undefined) {\n\t\t\toverwriteStack(this, errorProps.stack);\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"errorLogging.js","sourceRoot":"","sources":["../src/errorLogging.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAQH,+BAAkC;AAClC,qDAK0B;AAO1B,wEAAwE;AACxE,MAAM,eAAe,GAAG,CAAC,KAAU,EAAW,EAAE;IAC/C,OAAO,KAAK,KAAK,I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OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,EAAE;YAClD,OAAO,CACN,OAAQ,MAAuB,CAAC,sBAAsB,KAAK,UAAU;gBACrE,OAAQ,MAAuB,CAAC,sBAAsB,KAAK,UAAU;gBACrE,OAAQ,MAAuB,CAAC,eAAe,KAAK,QAAQ,CAC5D,CAAC;SACF;QACD,OAAO,KAAK,CAAC;IACd,CAAC;IAED;;OAEG;IACI,sBAAsB,CAAC,KAA2B;QACxD,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACxB,CAAC;IAED;;OAEG;IACI,sBAAsB;QAC5B,MAAM,aAAa,GAAG,sBAAsB,CAAC,IAAI,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;QAC9E,+EAA+E;QAC/E,OAAO;YACN,GAAG,aAAa;YAChB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,eAAe,EAAE,IAAI,CAAC,gBAAgB;SACtC,CAAC;IACH,CAAC;CACD;AA1ED,oCA0EC;AAED,8DAA8D;AACjD,QAAA,qBAAqB,GAAG,cAAc,CAAC;AACpD,MAAM,sBAAuB,SAAQ,YAAY;IAKhD,YAAY,UAAsD;QACjE,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAL3B,2EAA2E;QAC3E,2EAA2E;QAC3E,cAAS,GAAG,6BAAqB,CAAC;QAKjC,IAAI,UAAU,CAAC,KAAK,KAAK,SAAS,EAAE;YACnC,cAAc,CAAC,IAAI,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC;SACvC;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tILoggingError,\n\tITaggedTelemetryPropertyType,\n\tITelemetryProperties,\n\tTelemetryEventPropertyType,\n} from \"@fluidframework/core-interfaces\";\nimport { v4 as uuid } from \"uuid\";\nimport {\n\thasErrorInstanceId,\n\tIFluidErrorBase,\n\tisFluidError,\n\tisValidLegacyError,\n} from \"./fluidErrorBase\";\nimport {\n\tITaggedTelemetryPropertyTypeExt,\n\tITelemetryLoggerExt,\n\tTelemetryEventPropertyTypeExt,\n} from \"./telemetryTypes\";\n\n/** @returns true if value is an object but neither null nor an array */\nconst isRegularObject = (value: any): boolean => {\n\treturn 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\tconst removeMessageFromStack = (stack: string, errorName?: string) => {\n\t\tif (!sanitizeStack) {\n\t\t\treturn stack;\n\t\t}\n\t\tconst stackFrames = stack.split(\"\\n\");\n\t\tstackFrames.shift(); // Remove \"[ErrorName]: [ErrorMessage]\"\n\t\tif (errorName !== undefined) {\n\t\t\tstackFrames.unshift(errorName); // Add \"[ErrorName]\"\n\t\t}\n\t\treturn stackFrames.join(\"\\n\");\n\t};\n\n\tconst message = typeof error?.message === \"string\" ? (error.message as string) : String(error);\n\n\tconst safeProps: { message: string; errorType?: string; stack?: string } = {\n\t\tmessage,\n\t};\n\n\tif (isRegularObject(error)) {\n\t\tconst { errorType, stack, name } = error;\n\n\t\tif (typeof errorType === \"string\") {\n\t\t\tsafeProps.errorType = errorType;\n\t\t}\n\n\t\tif (typeof stack === \"string\") {\n\t\t\tconst errorName = typeof name === \"string\" ? name : undefined;\n\t\t\tsafeProps.stack = removeMessageFromStack(stack, errorName);\n\t\t}\n\t}\n\n\treturn safeProps;\n}\n\n/** type guard for ILoggingError interface */\nexport const isILoggingError = (x: any): x is ILoggingError =>\n\ttypeof 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\tfor (const key of Object.keys(source)) {\n\t\tif (target[key] === undefined) {\n\t\t\ttarget[key] = source[key];\n\t\t}\n\t}\n}\n\n/** Metadata to annotate an error object when annotating or normalizing it */\nexport interface IFluidErrorAnnotations {\n\t/** Telemetry props to log with the error */\n\tprops?: ITelemetryProperties;\n}\n\n/** For backwards compatibility with pre-errorInstanceId valid errors */\nfunction patchLegacyError(\n\tlegacyError: Omit<IFluidErrorBase, \"errorInstanceId\">,\n): asserts legacyError is IFluidErrorBase {\n\tconst patchMe: { -readonly [P in \"errorInstanceId\"]?: IFluidErrorBase[P] } = legacyError as any;\n\tif (patchMe.errorInstanceId === undefined) {\n\t\tpatchMe.errorInstanceId = uuid();\n\t}\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\terror: unknown,\n\tannotations: IFluidErrorAnnotations = {},\n): IFluidErrorBase {\n\t// Back-compat, while IFluidErrorBase is rolled out\n\tif (isValidLegacyError(error)) {\n\t\tpatchLegacyError(error);\n\t}\n\n\tif (isFluidError(error)) {\n\t\t// We can simply add the telemetry props to the error and return it\n\t\terror.addTelemetryProperties(annotations.props ?? {});\n\t\treturn error;\n\t}\n\n\t// We have to construct a new Fluid Error, copying safe properties over\n\tconst { message, stack } = extractLogSafeErrorProperties(error, false /* sanitizeStack */);\n\tconst fluidError: IFluidErrorBase = new NormalizedLoggingError({\n\t\tmessage,\n\t\tstack,\n\t});\n\n\t// We need to preserve these properties which are used in a non-typesafe way throughout driver code (see #8743)\n\t// Anywhere they are set should be on a valid Fluid Error that would have been returned above,\n\t// but we can't prove it with the types, so adding this defensive measure.\n\tif (typeof error === \"object\" && error !== null) {\n\t\tconst maybeHasRetry: Partial<Record<\"canRetry\" | \"retryAfterSeconds\", unknown>> = error;\n\t\tlet retryProps: Partial<Record<\"canRetry\" | \"retryAfterSeconds\", unknown>> | undefined;\n\t\tif (\"canRetry\" in error) {\n\t\t\tretryProps ??= {};\n\t\t\tretryProps.canRetry = maybeHasRetry.canRetry;\n\t\t}\n\t\tif (\"retryAfterSeconds\" in error) {\n\t\t\tretryProps ??= {};\n\t\t\tretryProps.retryAfterSeconds = maybeHasRetry.retryAfterSeconds;\n\t\t}\n\t\tif (retryProps !== undefined) {\n\t\t\tObject.assign(fluidError, retryProps);\n\t\t}\n\t}\n\n\tif (typeof error !== \"object\") {\n\t\t// This is only interesting for non-objects\n\t\tfluidError.addTelemetryProperties({ typeofError: typeof error });\n\t}\n\n\tconst errorTelemetryProps = LoggingError.typeCheck(error)\n\t\t? error.getTelemetryProperties()\n\t\t: { untrustedOrigin: 1 }; // This will let us filter errors that did not originate from our own codebase\n\n\tfluidError.addTelemetryProperties({\n\t\t...errorTelemetryProps,\n\t\t...annotations.props,\n\t});\n\n\treturn fluidError;\n}\n\nlet stackPopulatedOnCreation: boolean | undefined;\n\n/**\n * The purpose of this function is to provide ability to capture stack context quickly.\n * Accessing new Error().stack is slow, and the slowest part is accessing stack property itself.\n * There are scenarios where we generate error with stack, but error is handled in most cases and\n * stack property is not accessed.\n * For such cases it's better to not read stack property right away, but rather delay it until / if it's needed\n * Some browsers will populate stack right away, others require throwing Error, so we do auto-detection on the fly.\n * @returns Error object that has stack populated.\n */\nexport function generateErrorWithStack(): Error {\n\tconst err = new Error(\"<<generated stack>>\");\n\n\tif (stackPopulatedOnCreation === undefined) {\n\t\tstackPopulatedOnCreation = err.stack !== undefined;\n\t}\n\n\tif (stackPopulatedOnCreation) {\n\t\treturn err;\n\t}\n\n\ttry {\n\t\tthrow err;\n\t} catch (e) {\n\t\treturn e as Error;\n\t}\n}\n\nexport function generateStack(): string | undefined {\n\treturn generateErrorWithStack().stack;\n}\n\n/**\n * Create a new error using newErrorFn, wrapping and caused by the given unknown error.\n * Copies the inner error's stack, errorInstanceId and telemetry props over to the new error if present\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 */\nexport function wrapError<T extends LoggingError>(\n\tinnerError: unknown,\n\tnewErrorFn: (message: string) => T,\n): T {\n\tconst { message, stack } = extractLogSafeErrorProperties(innerError, false /* sanitizeStack */);\n\n\tconst newError = newErrorFn(message);\n\n\tif (stack !== undefined) {\n\t\toverwriteStack(newError, stack);\n\t}\n\n\t// Mark external errors with untrustedOrigin flag\n\tif (isExternalError(innerError)) {\n\t\tnewError.addTelemetryProperties({ untrustedOrigin: 1 });\n\t}\n\n\t// Reuse errorInstanceId\n\tif (hasErrorInstanceId(innerError)) {\n\t\tnewError.overwriteErrorInstanceId(innerError.errorInstanceId);\n\n\t\t// For \"back-compat\" in the logs\n\t\tnewError.addTelemetryProperties({ innerErrorInstanceId: innerError.errorInstanceId });\n\t}\n\n\t// Lastly, copy over all other telemetry properties. Note these will not overwrite existing properties\n\t// This will include the untrustedOrigin property if the inner error itself was created from an external error\n\tif (isILoggingError(innerError)) {\n\t\tnewError.addTelemetryProperties(innerError.getTelemetryProperties());\n\t}\n\n\treturn 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 LoggingError>(\n\tinnerError: unknown,\n\tnewErrorFn: (message: string) => T,\n\tlogger: ITelemetryLoggerExt,\n) {\n\tconst newError = wrapError(innerError, newErrorFn);\n\n\t// This will match innerError.errorInstanceId if present (see wrapError)\n\tconst errorInstanceId = newError.errorInstanceId;\n\n\t// For \"back-compat\" in the logs\n\tconst wrappedByErrorInstanceId = errorInstanceId;\n\n\tlogger.sendTelemetryEvent(\n\t\t{\n\t\t\teventName: \"WrapError\",\n\t\t\terrorInstanceId,\n\t\t\twrappedByErrorInstanceId,\n\t\t},\n\t\tinnerError,\n\t);\n\n\treturn newError;\n}\n\nfunction overwriteStack(error: IFluidErrorBase | LoggingError, stack: string) {\n\t// supposedly setting stack on an Error can throw.\n\ttry {\n\t\tObject.assign(error, { stack });\n\t} catch (errorSettingStack) {\n\t\terror.addTelemetryProperties({ stack2: stack });\n\t}\n}\n\n/**\n * True for any error object that is an (optionally normalized) external error\n * False for any error we created and raised within the FF codebase via LoggingError base class,\n * or wrapped in a well-known error type\n */\nexport function isExternalError(e: any): boolean {\n\t// LoggingErrors are an internal FF error type. However, an external error can be converted\n\t// into a LoggingError if it is normalized. In this case we must use the untrustedOrigin flag to\n\t// determine whether the original error was infact external.\n\tif (LoggingError.typeCheck(e)) {\n\t\tif ((e as NormalizedLoggingError).errorType === NORMALIZED_ERROR_TYPE) {\n\t\t\treturn e.getTelemetryProperties().untrustedOrigin === 1;\n\t\t}\n\t\treturn false;\n\t}\n\treturn !isValidLegacyError(e);\n}\n\n/**\n * Type guard to identify if a particular telemetry property appears to be a tagged telemetry property\n */\nexport function isTaggedTelemetryPropertyValue(\n\tx: ITaggedTelemetryPropertyTypeExt | TelemetryEventPropertyTypeExt,\n): x is ITaggedTelemetryPropertyType | ITaggedTelemetryPropertyTypeExt {\n\treturn typeof (x as any)?.tag === \"string\";\n}\n\n/**\n * Filter serializable telemetry properties\n * @param x - any telemetry prop\n * @returns - as-is if x is primitive. returns stringified if x is an array of primitive.\n * otherwise returns null since this is what we support at the moment.\n */\nfunction filterValidTelemetryProps(x: any, key: string): TelemetryEventPropertyType {\n\tif (Array.isArray(x) && x.every((val) => isTelemetryEventPropertyValue(val))) {\n\t\treturn JSON.stringify(x);\n\t}\n\tif (isTelemetryEventPropertyValue(x)) {\n\t\treturn x;\n\t}\n\t// We don't support logging arbitrary objects\n\tconsole.error(`UnSupported Format of Logging Error Property for key ${key}:`, x);\n\treturn \"REDACTED (arbitrary object)\";\n}\n\n// checking type of x, returns false if x is null\nfunction isTelemetryEventPropertyValue(x: any): x is TelemetryEventPropertyType {\n\tswitch (typeof x) {\n\t\tcase \"string\":\n\t\tcase \"number\":\n\t\tcase \"boolean\":\n\t\tcase \"undefined\":\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\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\tconst props: ITelemetryProperties = {};\n\tfor (const key of Object.keys(obj)) {\n\t\tif (keysToOmit.has(key)) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst val = obj[key];\n\n\t\t// ensure only valid props get logged, since props of logging error could be in any shape\n\t\tif (isTaggedTelemetryPropertyValue(val)) {\n\t\t\tprops[key] = {\n\t\t\t\tvalue: filterValidTelemetryProps(val.value, key),\n\t\t\t\ttag: val.tag,\n\t\t\t};\n\t\t} else {\n\t\t\tprops[key] = filterValidTelemetryProps(val, key);\n\t\t}\n\t}\n\treturn props;\n}\n\n/**\n * Borrowed from\n * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value#examples}\n * Avoids runtime errors with circular references.\n * Not ideal, as will cut values that are not necessarily circular references.\n * Could be improved by implementing Node's util.inspect() for browser (minus all the coloring code)\n */\nexport const getCircularReplacer = () => {\n\tconst seen = new WeakSet();\n\treturn (key: string, value: any): any => {\n\t\tif (typeof value === \"object\" && value !== null) {\n\t\t\tif (seen.has(value)) {\n\t\t\t\treturn \"<removed/circular>\";\n\t\t\t}\n\t\t\tseen.add(value);\n\t\t}\n\t\treturn value;\n\t};\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 addTelemetryProperties),\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\n\textends Error\n\timplements ILoggingError, Omit<IFluidErrorBase, \"errorType\">\n{\n\tprivate _errorInstanceId = uuid();\n\tget errorInstanceId() {\n\t\treturn this._errorInstanceId;\n\t}\n\toverwriteErrorInstanceId(id: string) {\n\t\tthis._errorInstanceId = id;\n\t}\n\n\t/** Back-compat to appease isFluidError typeguard in old code that may handle this error */\n\t// @ts-expect-error - This field shouldn't be referenced in the current version, but needs to exist at runtime.\n\tprivate readonly fluidErrorCode: \"-\" = \"-\";\n\n\t/**\n\t * Create a new LoggingError\n\t * @param message - Error message to use for Error base class\n\t * @param props - telemetry props to include on the error for when it's logged\n\t * @param omitPropsFromLogging - properties by name to omit from telemetry props\n\t */\n\tconstructor(\n\t\tmessage: string,\n\t\tprops?: ITelemetryProperties,\n\t\tprivate readonly omitPropsFromLogging: Set<string> = new Set(),\n\t) {\n\t\tsuper(message);\n\n\t\t// Don't log this list itself, or the private _errorInstanceId\n\t\tomitPropsFromLogging.add(\"omitPropsFromLogging\");\n\t\tomitPropsFromLogging.add(\"_errorInstanceId\");\n\n\t\tif (props) {\n\t\t\tthis.addTelemetryProperties(props);\n\t\t}\n\t}\n\n\t/**\n\t * Determines if a given object is an instance of a LoggingError\n\t * @param object - any object\n\t * @returns - true if the object is an instance of a LoggingError, false if not.\n\t */\n\tpublic static typeCheck(object: unknown): object is LoggingError {\n\t\tif (typeof object === \"object\" && object !== null) {\n\t\t\treturn (\n\t\t\t\ttypeof (object as LoggingError).addTelemetryProperties === \"function\" &&\n\t\t\t\ttypeof (object as LoggingError).getTelemetryProperties === \"function\" &&\n\t\t\t\ttypeof (object as LoggingError).errorInstanceId === \"string\"\n\t\t\t);\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Add additional properties to be logged\n\t */\n\tpublic addTelemetryProperties(props: ITelemetryProperties) {\n\t\tcopyProps(this, props);\n\t}\n\n\t/**\n\t * Get all properties fit to be logged to telemetry for this error\n\t */\n\tpublic getTelemetryProperties(): ITelemetryProperties {\n\t\tconst taggableProps = getValidTelemetryProps(this, this.omitPropsFromLogging);\n\t\t// Include non-enumerable props that are not returned by getValidTelemetryProps\n\t\treturn {\n\t\t\t...taggableProps,\n\t\t\tstack: this.stack,\n\t\t\tmessage: this.message,\n\t\t\terrorInstanceId: this._errorInstanceId,\n\t\t};\n\t}\n}\n\n/** The Error class used when normalizing an external error */\nexport const NORMALIZED_ERROR_TYPE = \"genericError\";\nclass NormalizedLoggingError extends LoggingError {\n\t// errorType \"genericError\" is used as a default value throughout the code.\n\t// Note that this matches ContainerErrorType/DriverErrorType's genericError\n\terrorType = NORMALIZED_ERROR_TYPE;\n\n\tconstructor(errorProps: Pick<IFluidErrorBase, \"message\" | \"stack\">) {\n\t\tsuper(errorProps.message);\n\n\t\tif (errorProps.stack !== undefined) {\n\t\t\toverwriteStack(this, errorProps.stack);\n\t\t}\n\t}\n}\n"]}
|
package/dist/fluidErrorBase.js
CHANGED
|
@@ -5,22 +5,22 @@
|
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.isValidLegacyError = exports.isFluidError = exports.hasErrorInstanceId = void 0;
|
|
8
|
-
const hasTelemetryPropFunctions = (x) => typeof
|
|
9
|
-
typeof
|
|
10
|
-
const hasErrorInstanceId = (x) => typeof
|
|
8
|
+
const hasTelemetryPropFunctions = (x) => typeof x?.getTelemetryProperties === "function" &&
|
|
9
|
+
typeof x?.addTelemetryProperties === "function";
|
|
10
|
+
const hasErrorInstanceId = (x) => typeof x?.errorInstanceId === "string";
|
|
11
11
|
exports.hasErrorInstanceId = hasErrorInstanceId;
|
|
12
12
|
/** type guard for IFluidErrorBase interface */
|
|
13
13
|
function isFluidError(e) {
|
|
14
|
-
return (typeof
|
|
15
|
-
typeof
|
|
14
|
+
return (typeof e?.errorType === "string" &&
|
|
15
|
+
typeof e?.message === "string" &&
|
|
16
16
|
(0, exports.hasErrorInstanceId)(e) &&
|
|
17
17
|
hasTelemetryPropFunctions(e));
|
|
18
18
|
}
|
|
19
19
|
exports.isFluidError = isFluidError;
|
|
20
20
|
/** type guard for old standard of valid/known errors */
|
|
21
21
|
function isValidLegacyError(e) {
|
|
22
|
-
return (typeof
|
|
23
|
-
typeof
|
|
22
|
+
return (typeof e?.errorType === "string" &&
|
|
23
|
+
typeof e?.message === "string" &&
|
|
24
24
|
hasTelemetryPropFunctions(e));
|
|
25
25
|
}
|
|
26
26
|
exports.isValidLegacyError = isValidLegacyError;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fluidErrorBase.js","sourceRoot":"","sources":["../src/fluidErrorBase.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAuCH,MAAM,yBAAyB,GAAG,CAAC,CAAM,EAAW,EAAE,CACrD,OAAO,
|
|
1
|
+
{"version":3,"file":"fluidErrorBase.js","sourceRoot":"","sources":["../src/fluidErrorBase.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAuCH,MAAM,yBAAyB,GAAG,CAAC,CAAM,EAAW,EAAE,CACrD,OAAO,CAAC,EAAE,sBAAsB,KAAK,UAAU;IAC/C,OAAO,CAAC,EAAE,sBAAsB,KAAK,UAAU,CAAC;AAE1C,MAAM,kBAAkB,GAAG,CAAC,CAAM,EAAoC,EAAE,CAC9E,OAAO,CAAC,EAAE,eAAe,KAAK,QAAQ,CAAC;AAD3B,QAAA,kBAAkB,sBACS;AAExC,+CAA+C;AAC/C,SAAgB,YAAY,CAAC,CAAM;IAClC,OAAO,CACN,OAAO,CAAC,EAAE,SAAS,KAAK,QAAQ;QAChC,OAAO,CAAC,EAAE,OAAO,KAAK,QAAQ;QAC9B,IAAA,0BAAkB,EAAC,CAAC,CAAC;QACrB,yBAAyB,CAAC,CAAC,CAAC,CAC5B,CAAC;AACH,CAAC;AAPD,oCAOC;AAED,wDAAwD;AACxD,SAAgB,kBAAkB,CAAC,CAAM;IACxC,OAAO,CACN,OAAO,CAAC,EAAE,SAAS,KAAK,QAAQ;QAChC,OAAO,CAAC,EAAE,OAAO,KAAK,QAAQ;QAC9B,yBAAyB,CAAC,CAAC,CAAC,CAC5B,CAAC;AACH,CAAC;AAND,gDAMC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryProperties } from \"@fluidframework/core-interfaces\";\n\n/**\n * All normalized errors flowing through the Fluid Framework adhere to this readonly interface.\n * It features errorType and errorInstanceId on top of Error's members as readonly,\n * and a getter/setter for telemetry props to be included when the error is logged.\n */\nexport interface IFluidErrorBase extends Error {\n\t/** Classification of what type of error this is, used programmatically by consumers to interpret the error */\n\treadonly errorType: string;\n\n\t/**\n\t * Error's message property, made readonly.\n\t * Be specific, but also take care when including variable data to consider suitability for aggregation in telemetry\n\t * Also avoid including any data that jeopardizes the user's privacy. Add a tagged telemetry property instead.\n\t */\n\treadonly message: string;\n\n\t/** Error's stack property, made readonly */\n\treadonly stack?: string;\n\n\t/** Error's name property, made readonly */\n\treadonly name: string;\n\n\t/**\n\t * A Guid identifying this error instance.\n\t * Useful in telemetry for deduping multiple logging events arising from the same error,\n\t * or correlating an error with an inner error that caused it, in case of error wrapping.\n\t */\n\treadonly errorInstanceId: string;\n\n\t/** Get the telemetry properties stashed on this error for logging */\n\tgetTelemetryProperties(): ITelemetryProperties;\n\t/** Add telemetry properties to this error which will be logged with the error */\n\taddTelemetryProperties: (props: ITelemetryProperties) => void;\n}\n\nconst hasTelemetryPropFunctions = (x: any): boolean =>\n\ttypeof x?.getTelemetryProperties === \"function\" &&\n\ttypeof x?.addTelemetryProperties === \"function\";\n\nexport const hasErrorInstanceId = (x: any): x is { errorInstanceId: string } =>\n\ttypeof x?.errorInstanceId === \"string\";\n\n/** type guard for IFluidErrorBase interface */\nexport function isFluidError(e: any): e is IFluidErrorBase {\n\treturn (\n\t\ttypeof e?.errorType === \"string\" &&\n\t\ttypeof e?.message === \"string\" &&\n\t\thasErrorInstanceId(e) &&\n\t\thasTelemetryPropFunctions(e)\n\t);\n}\n\n/** type guard for old standard of valid/known errors */\nexport function isValidLegacyError(e: any): e is Omit<IFluidErrorBase, \"errorInstanceId\"> {\n\treturn (\n\t\ttypeof e?.errorType === \"string\" &&\n\t\ttypeof e?.message === \"string\" &&\n\t\thasTelemetryPropFunctions(e)\n\t);\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,12 +3,11 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
export { createChildMonitoringContext, MonitoringContext, IConfigProviderBase, sessionStorageConfigProvider, mixinMonitoringContext, IConfigProvider, ConfigTypes, loggerToMonitoringContext, } from "./config";
|
|
6
|
-
export { DebugLogger } from "./debugLogger";
|
|
7
6
|
export { extractLogSafeErrorProperties, generateErrorWithStack, generateStack, getCircularReplacer, IFluidErrorAnnotations, isExternalError, isILoggingError, isTaggedTelemetryPropertyValue, LoggingError, NORMALIZED_ERROR_TYPE, normalizeError, wrapError, wrapErrorAndLog, } from "./errorLogging";
|
|
8
7
|
export { EventEmitterWithErrorHandling } from "./eventEmitterWithErrorHandling";
|
|
9
8
|
export { connectedEventName, disconnectedEventName, raiseConnectedEvent, safeRaiseEvent, } from "./events";
|
|
10
9
|
export { hasErrorInstanceId, IFluidErrorBase, isFluidError, isValidLegacyError, } from "./fluidErrorBase";
|
|
11
|
-
export { eventNamespaceSeparator,
|
|
10
|
+
export { eventNamespaceSeparator, createChildLogger, createMultiSinkLogger, formatTick, IPerformanceEventMarkers, ITelemetryLoggerPropertyBag, ITelemetryLoggerPropertyBags, numberFromString, PerformanceEvent, TaggedLoggerAdapter, tagData, tagCodeArtifacts, TelemetryDataTag, TelemetryEventPropertyTypes, } from "./logger";
|
|
12
11
|
export { MockLogger } from "./mockLogger";
|
|
13
12
|
export { ThresholdCounter } from "./thresholdCounter";
|
|
14
13
|
export { SampledTelemetryHelper } from "./sampledTelemetryHelper";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACN,4BAA4B,EAC5B,iBAAiB,EACjB,mBAAmB,EACnB,4BAA4B,EAC5B,sBAAsB,EACtB,eAAe,EACf,WAAW,EACX,yBAAyB,GACzB,MAAM,UAAU,CAAC;AAClB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAC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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.logIfFalse = exports.SampledTelemetryHelper = exports.ThresholdCounter = exports.MockLogger = exports.
|
|
3
|
+
exports.logIfFalse = exports.SampledTelemetryHelper = exports.ThresholdCounter = exports.MockLogger = exports.TelemetryDataTag = exports.tagCodeArtifacts = exports.tagData = exports.TaggedLoggerAdapter = exports.PerformanceEvent = exports.numberFromString = exports.formatTick = exports.createMultiSinkLogger = exports.createChildLogger = exports.eventNamespaceSeparator = exports.isValidLegacyError = exports.isFluidError = exports.hasErrorInstanceId = exports.safeRaiseEvent = exports.raiseConnectedEvent = exports.disconnectedEventName = exports.connectedEventName = exports.EventEmitterWithErrorHandling = exports.wrapErrorAndLog = exports.wrapError = exports.normalizeError = exports.NORMALIZED_ERROR_TYPE = exports.LoggingError = exports.isTaggedTelemetryPropertyValue = exports.isILoggingError = exports.isExternalError = exports.getCircularReplacer = exports.generateStack = exports.generateErrorWithStack = exports.extractLogSafeErrorProperties = exports.loggerToMonitoringContext = exports.mixinMonitoringContext = exports.sessionStorageConfigProvider = exports.createChildMonitoringContext = void 0;
|
|
4
4
|
/*!
|
|
5
5
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
6
6
|
* Licensed under the MIT License.
|
|
@@ -10,8 +10,6 @@ Object.defineProperty(exports, "createChildMonitoringContext", { enumerable: tru
|
|
|
10
10
|
Object.defineProperty(exports, "sessionStorageConfigProvider", { enumerable: true, get: function () { return config_1.sessionStorageConfigProvider; } });
|
|
11
11
|
Object.defineProperty(exports, "mixinMonitoringContext", { enumerable: true, get: function () { return config_1.mixinMonitoringContext; } });
|
|
12
12
|
Object.defineProperty(exports, "loggerToMonitoringContext", { enumerable: true, get: function () { return config_1.loggerToMonitoringContext; } });
|
|
13
|
-
var debugLogger_1 = require("./debugLogger");
|
|
14
|
-
Object.defineProperty(exports, "DebugLogger", { enumerable: true, get: function () { return debugLogger_1.DebugLogger; } });
|
|
15
13
|
var errorLogging_1 = require("./errorLogging");
|
|
16
14
|
Object.defineProperty(exports, "extractLogSafeErrorProperties", { enumerable: true, get: function () { return errorLogging_1.extractLogSafeErrorProperties; } });
|
|
17
15
|
Object.defineProperty(exports, "generateErrorWithStack", { enumerable: true, get: function () { return errorLogging_1.generateErrorWithStack; } });
|
|
@@ -38,21 +36,15 @@ Object.defineProperty(exports, "isFluidError", { enumerable: true, get: function
|
|
|
38
36
|
Object.defineProperty(exports, "isValidLegacyError", { enumerable: true, get: function () { return fluidErrorBase_1.isValidLegacyError; } });
|
|
39
37
|
var logger_1 = require("./logger");
|
|
40
38
|
Object.defineProperty(exports, "eventNamespaceSeparator", { enumerable: true, get: function () { return logger_1.eventNamespaceSeparator; } });
|
|
41
|
-
Object.defineProperty(exports, "BaseTelemetryNullLogger", { enumerable: true, get: function () { return logger_1.BaseTelemetryNullLogger; } });
|
|
42
|
-
Object.defineProperty(exports, "ChildLogger", { enumerable: true, get: function () { return logger_1.ChildLogger; } });
|
|
43
39
|
Object.defineProperty(exports, "createChildLogger", { enumerable: true, get: function () { return logger_1.createChildLogger; } });
|
|
44
40
|
Object.defineProperty(exports, "createMultiSinkLogger", { enumerable: true, get: function () { return logger_1.createMultiSinkLogger; } });
|
|
45
41
|
Object.defineProperty(exports, "formatTick", { enumerable: true, get: function () { return logger_1.formatTick; } });
|
|
46
|
-
Object.defineProperty(exports, "MultiSinkLogger", { enumerable: true, get: function () { return logger_1.MultiSinkLogger; } });
|
|
47
42
|
Object.defineProperty(exports, "numberFromString", { enumerable: true, get: function () { return logger_1.numberFromString; } });
|
|
48
43
|
Object.defineProperty(exports, "PerformanceEvent", { enumerable: true, get: function () { return logger_1.PerformanceEvent; } });
|
|
49
44
|
Object.defineProperty(exports, "TaggedLoggerAdapter", { enumerable: true, get: function () { return logger_1.TaggedLoggerAdapter; } });
|
|
50
45
|
Object.defineProperty(exports, "tagData", { enumerable: true, get: function () { return logger_1.tagData; } });
|
|
51
46
|
Object.defineProperty(exports, "tagCodeArtifacts", { enumerable: true, get: function () { return logger_1.tagCodeArtifacts; } });
|
|
52
47
|
Object.defineProperty(exports, "TelemetryDataTag", { enumerable: true, get: function () { return logger_1.TelemetryDataTag; } });
|
|
53
|
-
Object.defineProperty(exports, "TelemetryLogger", { enumerable: true, get: function () { return logger_1.TelemetryLogger; } });
|
|
54
|
-
Object.defineProperty(exports, "TelemetryNullLogger", { enumerable: true, get: function () { return logger_1.TelemetryNullLogger; } });
|
|
55
|
-
Object.defineProperty(exports, "TelemetryUTLogger", { enumerable: true, get: function () { return logger_1.TelemetryUTLogger; } });
|
|
56
48
|
var mockLogger_1 = require("./mockLogger");
|
|
57
49
|
Object.defineProperty(exports, "MockLogger", { enumerable: true, get: function () { return mockLogger_1.MockLogger; } });
|
|
58
50
|
var thresholdCounter_1 = require("./thresholdCounter");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,mCASkB;AARjB,sHAAA,4BAA4B,OAAA;AAG5B,sHAAA,4BAA4B,OAAA;AAC5B,gHAAA,sBAAsB,OAAA;AAGtB,mHAAA,yBAAyB,OAAA;AAE1B
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,mCASkB;AARjB,sHAAA,4BAA4B,OAAA;AAG5B,sHAAA,4BAA4B,OAAA;AAC5B,gHAAA,sBAAsB,OAAA;AAGtB,mHAAA,yBAAyB,OAAA;AAE1B,+CAcwB;AAbvB,6HAAA,6BAA6B,OAAA;AAC7B,sHAAA,sBAAsB,OAAA;AACtB,6GAAA,aAAa,OAAA;AACb,mHAAA,mBAAmB,OAAA;AAEnB,+GAAA,eAAe,OAAA;AACf,+GAAA,eAAe,OAAA;AACf,8HAAA,8BAA8B,OAAA;AAC9B,4GAAA,YAAY,OAAA;AACZ,qHAAA,qBAAqB,OAAA;AACrB,8GAAA,cAAc,OAAA;AACd,yGAAA,SAAS,OAAA;AACT,+GAAA,eAAe,OAAA;AAEhB,iFAAgF;AAAvE,8IAAA,6BAA6B,OAAA;AACtC,mCAKkB;AAJjB,4GAAA,kBAAkB,OAAA;AAClB,+GAAA,qBAAqB,OAAA;AACrB,6GAAA,mBAAmB,OAAA;AACnB,wGAAA,cAAc,OAAA;AAEf,mDAK0B;AAJzB,oHAAA,kBAAkB,OAAA;AAElB,8GAAA,YAAY,OAAA;AACZ,oHAAA,kBAAkB,OAAA;AAEnB,mCAekB;AAdjB,iHAAA,uBAAuB,OAAA;AACvB,2GAAA,iBAAiB,OAAA;AACjB,+GAAA,qBAAqB,OAAA;AACrB,oGAAA,UAAU,OAAA;AAIV,0GAAA,gBAAgB,OAAA;AAChB,0GAAA,gBAAgB,OAAA;AAChB,6GAAA,mBAAmB,OAAA;AACnB,iGAAA,OAAO,OAAA;AACP,0GAAA,gBAAgB,OAAA;AAChB,0GAAA,gBAAgB,OAAA;AAGjB,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,uDAAsD;AAA7C,oHAAA,gBAAgB,OAAA;AACzB,mEAAkE;AAAzD,gIAAA,sBAAsB,OAAA;AAC/B,iCAAqC;AAA5B,mGAAA,UAAU,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nexport {\n\tcreateChildMonitoringContext,\n\tMonitoringContext,\n\tIConfigProviderBase,\n\tsessionStorageConfigProvider,\n\tmixinMonitoringContext,\n\tIConfigProvider,\n\tConfigTypes,\n\tloggerToMonitoringContext,\n} from \"./config\";\nexport {\n\textractLogSafeErrorProperties,\n\tgenerateErrorWithStack,\n\tgenerateStack,\n\tgetCircularReplacer,\n\tIFluidErrorAnnotations,\n\tisExternalError,\n\tisILoggingError,\n\tisTaggedTelemetryPropertyValue,\n\tLoggingError,\n\tNORMALIZED_ERROR_TYPE,\n\tnormalizeError,\n\twrapError,\n\twrapErrorAndLog,\n} from \"./errorLogging\";\nexport { EventEmitterWithErrorHandling } from \"./eventEmitterWithErrorHandling\";\nexport {\n\tconnectedEventName,\n\tdisconnectedEventName,\n\traiseConnectedEvent,\n\tsafeRaiseEvent,\n} from \"./events\";\nexport {\n\thasErrorInstanceId,\n\tIFluidErrorBase,\n\tisFluidError,\n\tisValidLegacyError,\n} from \"./fluidErrorBase\";\nexport {\n\teventNamespaceSeparator,\n\tcreateChildLogger,\n\tcreateMultiSinkLogger,\n\tformatTick,\n\tIPerformanceEventMarkers,\n\tITelemetryLoggerPropertyBag,\n\tITelemetryLoggerPropertyBags,\n\tnumberFromString,\n\tPerformanceEvent,\n\tTaggedLoggerAdapter,\n\ttagData,\n\ttagCodeArtifacts,\n\tTelemetryDataTag,\n\tTelemetryEventPropertyTypes,\n} from \"./logger\";\nexport { MockLogger } from \"./mockLogger\";\nexport { ThresholdCounter } from \"./thresholdCounter\";\nexport { SampledTelemetryHelper } from \"./sampledTelemetryHelper\";\nexport { logIfFalse } from \"./utils\";\nexport {\n\tTelemetryEventPropertyTypeExt,\n\tITelemetryEventExt,\n\tITelemetryGenericEventExt,\n\tITelemetryErrorEventExt,\n\tITelemetryPerformanceEventExt,\n\tITelemetryLoggerExt,\n\tITaggedTelemetryPropertyTypeExt,\n\tITelemetryPropertiesExt,\n} from \"./telemetryTypes\";\n"]}
|