@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.
Files changed (58) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/config.js +25 -31
  3. package/dist/config.js.map +1 -1
  4. package/dist/errorLogging.js +16 -10
  5. package/dist/errorLogging.js.map +1 -1
  6. package/dist/fluidErrorBase.js +7 -7
  7. package/dist/fluidErrorBase.js.map +1 -1
  8. package/dist/index.d.ts +1 -2
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +1 -9
  11. package/dist/index.js.map +1 -1
  12. package/dist/logger.d.ts +1 -56
  13. package/dist/logger.d.ts.map +1 -1
  14. package/dist/logger.js +42 -129
  15. package/dist/logger.js.map +1 -1
  16. package/dist/mockLogger.d.ts +3 -5
  17. package/dist/mockLogger.d.ts.map +1 -1
  18. package/dist/mockLogger.js +6 -15
  19. package/dist/mockLogger.js.map +1 -1
  20. package/dist/sampledTelemetryHelper.js +8 -5
  21. package/dist/sampledTelemetryHelper.js.map +1 -1
  22. package/dist/utils.js +1 -1
  23. package/dist/utils.js.map +1 -1
  24. package/lib/config.js +25 -31
  25. package/lib/config.js.map +1 -1
  26. package/lib/errorLogging.js +16 -10
  27. package/lib/errorLogging.js.map +1 -1
  28. package/lib/fluidErrorBase.js +7 -7
  29. package/lib/fluidErrorBase.js.map +1 -1
  30. package/lib/index.d.ts +1 -2
  31. package/lib/index.d.ts.map +1 -1
  32. package/lib/index.js +1 -2
  33. package/lib/index.js.map +1 -1
  34. package/lib/logger.d.ts +1 -56
  35. package/lib/logger.d.ts.map +1 -1
  36. package/lib/logger.js +41 -125
  37. package/lib/logger.js.map +1 -1
  38. package/lib/mockLogger.d.ts +3 -5
  39. package/lib/mockLogger.d.ts.map +1 -1
  40. package/lib/mockLogger.js +7 -16
  41. package/lib/mockLogger.js.map +1 -1
  42. package/lib/sampledTelemetryHelper.js +8 -5
  43. package/lib/sampledTelemetryHelper.js.map +1 -1
  44. package/lib/utils.js +1 -1
  45. package/lib/utils.js.map +1 -1
  46. package/package.json +39 -6
  47. package/src/index.ts +0 -7
  48. package/src/logger.ts +11 -98
  49. package/src/mockLogger.ts +8 -8
  50. package/dist/debugLogger.d.ts +0 -39
  51. package/dist/debugLogger.d.ts.map +0 -1
  52. package/dist/debugLogger.js +0 -105
  53. package/dist/debugLogger.js.map +0 -1
  54. package/lib/debugLogger.d.ts +0 -39
  55. package/lib/debugLogger.d.ts.map +0 -1
  56. package/lib/debugLogger.js +0 -101
  57. package/lib/debugLogger.js.map +0 -1
  58. package/src/debugLogger.ts +0 -138
@@ -1,39 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import { ITelemetryBaseEvent, ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
6
- import { IDebugger } from "debug";
7
- import { TelemetryLogger, ITelemetryLoggerPropertyBags } from "./logger";
8
- /**
9
- * Implementation of debug logger
10
- * @deprecated - DebugLogger is internal and will no longer be exported.
11
- */
12
- export declare class DebugLogger extends TelemetryLogger {
13
- private readonly debug;
14
- private readonly debugErr;
15
- /**
16
- * Create debug logger - all events are output to debug npm library
17
- * @param namespace - Telemetry event name prefix to add to all events
18
- * @param properties - Base properties to add to all events
19
- * @param propertyGetters - Getters to add additional properties to all events
20
- */
21
- static create(namespace: string, properties?: ITelemetryLoggerPropertyBags): TelemetryLogger;
22
- /**
23
- * Mix in debug logger with another logger.
24
- * Returned logger will output events to both newly created debug logger, as well as base logger
25
- * @param namespace - Telemetry event name prefix to add to all events
26
- * @param properties - Base properties to add to all events
27
- * @param propertyGetters - Getters to add additional properties to all events
28
- * @param logger - Base logger to output events (in addition to debug logger being created). Can be undefined.
29
- */
30
- static mixinDebugLogger(namespace: string, logger?: ITelemetryBaseLogger, properties?: ITelemetryLoggerPropertyBags): TelemetryLogger;
31
- constructor(debug: IDebugger, debugErr: IDebugger, properties?: ITelemetryLoggerPropertyBags);
32
- /**
33
- * Send an event to debug loggers
34
- *
35
- * @param event - the event to send
36
- */
37
- send(event: ITelemetryBaseEvent): void;
38
- }
39
- //# sourceMappingURL=debugLogger.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"debugLogger.d.ts","sourceRoot":"","sources":["../src/debugLogger.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,mBAAmB,EACnB,oBAAoB,EAEpB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAA0B,SAAS,EAAE,MAAM,OAAO,CAAC;AAC1D,OAAO,EACN,eAAe,EAEf,4BAA4B,EAG5B,MAAM,UAAU,CAAC;AAClB;;;GAGG;AACH,qBAAa,WAAY,SAAQ,eAAe;IA2D9C,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IA3D1B;;;;;OAKG;WACW,MAAM,CACnB,SAAS,EAAE,MAAM,EACjB,UAAU,CAAC,EAAE,4BAA4B,GACvC,eAAe;IAqBlB;;;;;;;OAOG;WACW,gBAAgB,CAC7B,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,oBAAoB,EAC7B,UAAU,CAAC,EAAE,4BAA4B,GACvC,eAAe;gBAgBA,KAAK,EAAE,SAAS,EAChB,QAAQ,EAAE,SAAS,EACpC,UAAU,CAAC,EAAE,4BAA4B;IAK1C;;;;OAIG;IACI,IAAI,CAAC,KAAK,EAAE,mBAAmB,GAAG,IAAI;CA2C7C"}
@@ -1,101 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import { performance } from "@fluidframework/common-utils";
6
- import { debug as registerDebug } from "debug";
7
- import { TelemetryLogger, MultiSinkLogger, formatTick, createChildLogger, } from "./logger";
8
- /**
9
- * Implementation of debug logger
10
- * @deprecated - DebugLogger is internal and will no longer be exported.
11
- */
12
- export class DebugLogger extends TelemetryLogger {
13
- constructor(debug, debugErr, properties) {
14
- super(undefined, properties);
15
- this.debug = debug;
16
- this.debugErr = debugErr;
17
- }
18
- /**
19
- * Create debug logger - all events are output to debug npm library
20
- * @param namespace - Telemetry event name prefix to add to all events
21
- * @param properties - Base properties to add to all events
22
- * @param propertyGetters - Getters to add additional properties to all events
23
- */
24
- static create(namespace, properties) {
25
- // Setup base logger upfront, such that host can disable it (if needed)
26
- const debug = registerDebug(namespace);
27
- // Create one for errors that is always enabled
28
- // It can be silenced by replacing console.error if the debug namespace is not enabled.
29
- const debugErr = registerDebug(namespace);
30
- debugErr.log = function () {
31
- if (debug.enabled) {
32
- // if the namespace is enabled, just use the default logger
33
- registerDebug.log(...arguments);
34
- }
35
- else {
36
- // other wise, use the console logger (which could be replaced and silenced)
37
- console.error(...arguments);
38
- }
39
- };
40
- debugErr.enabled = true;
41
- return new DebugLogger(debug, debugErr, properties);
42
- }
43
- /**
44
- * Mix in debug logger with another logger.
45
- * Returned logger will output events to both newly created debug logger, as well as base logger
46
- * @param namespace - Telemetry event name prefix to add to all events
47
- * @param properties - Base properties to add to all events
48
- * @param propertyGetters - Getters to add additional properties to all events
49
- * @param logger - Base logger to output events (in addition to debug logger being created). Can be undefined.
50
- */
51
- static mixinDebugLogger(namespace, logger, properties) {
52
- if (!logger) {
53
- return DebugLogger.create(namespace, properties);
54
- }
55
- const multiSinkLogger = new MultiSinkLogger(undefined, properties, [createChildLogger({ logger, namespace }), DebugLogger.create(namespace)], true);
56
- return multiSinkLogger;
57
- }
58
- /**
59
- * Send an event to debug loggers
60
- *
61
- * @param event - the event to send
62
- */
63
- send(event) {
64
- const newEvent = this.prepareEvent(event);
65
- const isError = newEvent.category === "error";
66
- let logger = isError ? this.debugErr : this.debug;
67
- // Use debug's coloring schema for base of the event
68
- const index = event.eventName.lastIndexOf(TelemetryLogger.eventNamespaceSeparator);
69
- const name = event.eventName.substring(index + 1);
70
- if (index > 0) {
71
- logger = logger.extend(event.eventName.substring(0, index));
72
- }
73
- newEvent.eventName = undefined;
74
- let tick = "";
75
- tick = `tick=${formatTick(performance.now())}`;
76
- // Extract stack to put it last, but also to avoid escaping '\n' in it by JSON.stringify below
77
- const stack = newEvent.stack ? newEvent.stack : "";
78
- newEvent.stack = undefined;
79
- // Watch out for circular references - they can come from two sources
80
- // 1) error object - we do not control it and should remove it and retry
81
- // 2) properties supplied by telemetry caller - that's a bug that should be addressed!
82
- let payload;
83
- try {
84
- payload = JSON.stringify(newEvent);
85
- }
86
- catch (error) {
87
- newEvent.error = undefined;
88
- payload = JSON.stringify(newEvent);
89
- }
90
- if (payload === "{}") {
91
- payload = "";
92
- }
93
- // Force errors out, to help with diagnostics
94
- if (isError) {
95
- logger.enabled = true;
96
- }
97
- // Print multi-line.
98
- logger(`${name} ${payload} ${tick} ${stack}`);
99
- }
100
- }
101
- //# sourceMappingURL=debugLogger.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"debugLogger.js","sourceRoot":"","sources":["../src/debugLogger.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,KAAK,IAAI,aAAa,EAAa,MAAM,OAAO,CAAC;AAC1D,OAAO,EACN,eAAe,EACf,eAAe,EAEf,UAAU,EACV,iBAAiB,GACjB,MAAM,UAAU,CAAC;AAClB;;;GAGG;AACH,MAAM,OAAO,WAAY,SAAQ,eAAe;IA0D/C,YACkB,KAAgB,EAChB,QAAmB,EACpC,UAAyC;QAEzC,KAAK,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QAJZ,UAAK,GAAL,KAAK,CAAW;QAChB,aAAQ,GAAR,QAAQ,CAAW;IAIrC,CAAC;IA/DD;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CACnB,SAAiB,EACjB,UAAyC;QAEzC,uEAAuE;QACvE,MAAM,KAAK,GAAG,aAAa,CAAC,SAAS,CAAC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the MIT License.\n */\n\nimport {\n\tITelemetryBaseEvent,\n\tITelemetryBaseLogger,\n\tITelemetryProperties,\n} from \"@fluidframework/core-interfaces\";\nimport { performance } from \"@fluidframework/common-utils\";\nimport { debug as registerDebug, IDebugger } from \"debug\";\nimport {\n\tTelemetryLogger,\n\tMultiSinkLogger,\n\tITelemetryLoggerPropertyBags,\n\tformatTick,\n\tcreateChildLogger,\n} from \"./logger\";\n/**\n * Implementation of debug logger\n * @deprecated - DebugLogger is internal and will no longer be exported.\n */\nexport class DebugLogger extends TelemetryLogger {\n\t/**\n\t * Create debug logger - all events are output to debug npm library\n\t * @param namespace - Telemetry event name prefix to add to all events\n\t * @param properties - Base properties to add to all events\n\t * @param propertyGetters - Getters to add additional properties to all events\n\t */\n\tpublic static create(\n\t\tnamespace: string,\n\t\tproperties?: ITelemetryLoggerPropertyBags,\n\t): TelemetryLogger {\n\t\t// Setup base logger upfront, such that host can disable it (if needed)\n\t\tconst debug = registerDebug(namespace);\n\n\t\t// Create one for errors that is always enabled\n\t\t// It can be silenced by replacing console.error if the debug namespace is not enabled.\n\t\tconst debugErr = registerDebug(namespace);\n\t\tdebugErr.log = function () {\n\t\t\tif (debug.enabled) {\n\t\t\t\t// if the namespace is enabled, just use the default logger\n\t\t\t\tregisterDebug.log(...arguments);\n\t\t\t} else {\n\t\t\t\t// other wise, use the console logger (which could be replaced and silenced)\n\t\t\t\tconsole.error(...arguments);\n\t\t\t}\n\t\t};\n\t\tdebugErr.enabled = true;\n\n\t\treturn new DebugLogger(debug, debugErr, properties);\n\t}\n\n\t/**\n\t * Mix in debug logger with another logger.\n\t * Returned logger will output events to both newly created debug logger, as well as base logger\n\t * @param namespace - Telemetry event name prefix to add to all events\n\t * @param properties - Base properties to add to all events\n\t * @param propertyGetters - Getters to add additional properties to all events\n\t * @param logger - Base logger to output events (in addition to debug logger being created). Can be undefined.\n\t */\n\tpublic static mixinDebugLogger(\n\t\tnamespace: string,\n\t\tlogger?: ITelemetryBaseLogger,\n\t\tproperties?: ITelemetryLoggerPropertyBags,\n\t): TelemetryLogger {\n\t\tif (!logger) {\n\t\t\treturn DebugLogger.create(namespace, properties);\n\t\t}\n\n\t\tconst multiSinkLogger = new MultiSinkLogger(\n\t\t\tundefined,\n\t\t\tproperties,\n\t\t\t[createChildLogger({ logger, namespace }), DebugLogger.create(namespace)],\n\t\t\ttrue,\n\t\t);\n\n\t\treturn multiSinkLogger;\n\t}\n\n\tconstructor(\n\t\tprivate readonly debug: IDebugger,\n\t\tprivate readonly debugErr: IDebugger,\n\t\tproperties?: ITelemetryLoggerPropertyBags,\n\t) {\n\t\tsuper(undefined, properties);\n\t}\n\n\t/**\n\t * Send an event to debug loggers\n\t *\n\t * @param event - the event to send\n\t */\n\tpublic send(event: ITelemetryBaseEvent): void {\n\t\tconst newEvent: ITelemetryProperties = this.prepareEvent(event);\n\t\tconst isError = newEvent.category === \"error\";\n\t\tlet logger = isError ? this.debugErr : this.debug;\n\n\t\t// Use debug's coloring schema for base of the event\n\t\tconst index = event.eventName.lastIndexOf(TelemetryLogger.eventNamespaceSeparator);\n\t\tconst name = event.eventName.substring(index + 1);\n\t\tif (index > 0) {\n\t\t\tlogger = logger.extend(event.eventName.substring(0, index));\n\t\t}\n\t\tnewEvent.eventName = undefined;\n\n\t\tlet tick = \"\";\n\t\ttick = `tick=${formatTick(performance.now())}`;\n\n\t\t// Extract stack to put it last, but also to avoid escaping '\\n' in it by JSON.stringify below\n\t\tconst stack = newEvent.stack ? newEvent.stack : \"\";\n\t\tnewEvent.stack = undefined;\n\n\t\t// Watch out for circular references - they can come from two sources\n\t\t// 1) error object - we do not control it and should remove it and retry\n\t\t// 2) properties supplied by telemetry caller - that's a bug that should be addressed!\n\t\tlet payload: string;\n\t\ttry {\n\t\t\tpayload = JSON.stringify(newEvent);\n\t\t} catch (error) {\n\t\t\tnewEvent.error = undefined;\n\t\t\tpayload = JSON.stringify(newEvent);\n\t\t}\n\n\t\tif (payload === \"{}\") {\n\t\t\tpayload = \"\";\n\t\t}\n\n\t\t// Force errors out, to help with diagnostics\n\t\tif (isError) {\n\t\t\tlogger.enabled = true;\n\t\t}\n\n\t\t// Print multi-line.\n\t\tlogger(`${name} ${payload} ${tick} ${stack}`);\n\t}\n}\n"]}
@@ -1,138 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import {
7
- ITelemetryBaseEvent,
8
- ITelemetryBaseLogger,
9
- ITelemetryProperties,
10
- } from "@fluidframework/core-interfaces";
11
- import { performance } from "@fluidframework/common-utils";
12
- import { debug as registerDebug, IDebugger } from "debug";
13
- import {
14
- TelemetryLogger,
15
- MultiSinkLogger,
16
- ITelemetryLoggerPropertyBags,
17
- formatTick,
18
- createChildLogger,
19
- } from "./logger";
20
- /**
21
- * Implementation of debug logger
22
- * @deprecated - DebugLogger is internal and will no longer be exported.
23
- */
24
- export class DebugLogger extends TelemetryLogger {
25
- /**
26
- * Create debug logger - all events are output to debug npm library
27
- * @param namespace - Telemetry event name prefix to add to all events
28
- * @param properties - Base properties to add to all events
29
- * @param propertyGetters - Getters to add additional properties to all events
30
- */
31
- public static create(
32
- namespace: string,
33
- properties?: ITelemetryLoggerPropertyBags,
34
- ): TelemetryLogger {
35
- // Setup base logger upfront, such that host can disable it (if needed)
36
- const debug = registerDebug(namespace);
37
-
38
- // Create one for errors that is always enabled
39
- // It can be silenced by replacing console.error if the debug namespace is not enabled.
40
- const debugErr = registerDebug(namespace);
41
- debugErr.log = function () {
42
- if (debug.enabled) {
43
- // if the namespace is enabled, just use the default logger
44
- registerDebug.log(...arguments);
45
- } else {
46
- // other wise, use the console logger (which could be replaced and silenced)
47
- console.error(...arguments);
48
- }
49
- };
50
- debugErr.enabled = true;
51
-
52
- return new DebugLogger(debug, debugErr, properties);
53
- }
54
-
55
- /**
56
- * Mix in debug logger with another logger.
57
- * Returned logger will output events to both newly created debug logger, as well as base logger
58
- * @param namespace - Telemetry event name prefix to add to all events
59
- * @param properties - Base properties to add to all events
60
- * @param propertyGetters - Getters to add additional properties to all events
61
- * @param logger - Base logger to output events (in addition to debug logger being created). Can be undefined.
62
- */
63
- public static mixinDebugLogger(
64
- namespace: string,
65
- logger?: ITelemetryBaseLogger,
66
- properties?: ITelemetryLoggerPropertyBags,
67
- ): TelemetryLogger {
68
- if (!logger) {
69
- return DebugLogger.create(namespace, properties);
70
- }
71
-
72
- const multiSinkLogger = new MultiSinkLogger(
73
- undefined,
74
- properties,
75
- [createChildLogger({ logger, namespace }), DebugLogger.create(namespace)],
76
- true,
77
- );
78
-
79
- return multiSinkLogger;
80
- }
81
-
82
- constructor(
83
- private readonly debug: IDebugger,
84
- private readonly debugErr: IDebugger,
85
- properties?: ITelemetryLoggerPropertyBags,
86
- ) {
87
- super(undefined, properties);
88
- }
89
-
90
- /**
91
- * Send an event to debug loggers
92
- *
93
- * @param event - the event to send
94
- */
95
- public send(event: ITelemetryBaseEvent): void {
96
- const newEvent: ITelemetryProperties = this.prepareEvent(event);
97
- const isError = newEvent.category === "error";
98
- let logger = isError ? this.debugErr : this.debug;
99
-
100
- // Use debug's coloring schema for base of the event
101
- const index = event.eventName.lastIndexOf(TelemetryLogger.eventNamespaceSeparator);
102
- const name = event.eventName.substring(index + 1);
103
- if (index > 0) {
104
- logger = logger.extend(event.eventName.substring(0, index));
105
- }
106
- newEvent.eventName = undefined;
107
-
108
- let tick = "";
109
- tick = `tick=${formatTick(performance.now())}`;
110
-
111
- // Extract stack to put it last, but also to avoid escaping '\n' in it by JSON.stringify below
112
- const stack = newEvent.stack ? newEvent.stack : "";
113
- newEvent.stack = undefined;
114
-
115
- // Watch out for circular references - they can come from two sources
116
- // 1) error object - we do not control it and should remove it and retry
117
- // 2) properties supplied by telemetry caller - that's a bug that should be addressed!
118
- let payload: string;
119
- try {
120
- payload = JSON.stringify(newEvent);
121
- } catch (error) {
122
- newEvent.error = undefined;
123
- payload = JSON.stringify(newEvent);
124
- }
125
-
126
- if (payload === "{}") {
127
- payload = "";
128
- }
129
-
130
- // Force errors out, to help with diagnostics
131
- if (isError) {
132
- logger.enabled = true;
133
- }
134
-
135
- // Print multi-line.
136
- logger(`${name} ${payload} ${tick} ${stack}`);
137
- }
138
- }