@fluidframework/telemetry-utils 2.0.0-dev.5.3.2.178189 → 2.0.0-dev.6.4.0.191457

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/.eslintrc.js +2 -1
  2. package/CHANGELOG.md +108 -0
  3. package/README.md +4 -3
  4. package/dist/config.d.ts +2 -0
  5. package/dist/config.d.ts.map +1 -1
  6. package/dist/config.js +34 -36
  7. package/dist/config.js.map +1 -1
  8. package/dist/error.d.ts +92 -0
  9. package/dist/error.d.ts.map +1 -0
  10. package/dist/error.js +133 -0
  11. package/dist/error.js.map +1 -0
  12. package/dist/errorLogging.d.ts +44 -19
  13. package/dist/errorLogging.d.ts.map +1 -1
  14. package/dist/errorLogging.js +70 -31
  15. package/dist/errorLogging.js.map +1 -1
  16. package/dist/eventEmitterWithErrorHandling.d.ts +3 -3
  17. package/dist/eventEmitterWithErrorHandling.d.ts.map +1 -1
  18. package/dist/eventEmitterWithErrorHandling.js +10 -3
  19. package/dist/eventEmitterWithErrorHandling.js.map +1 -1
  20. package/dist/events.d.ts +1 -1
  21. package/dist/events.d.ts.map +1 -1
  22. package/dist/events.js.map +1 -1
  23. package/dist/fluidErrorBase.d.ts +48 -15
  24. package/dist/fluidErrorBase.d.ts.map +1 -1
  25. package/dist/fluidErrorBase.js +21 -14
  26. package/dist/fluidErrorBase.js.map +1 -1
  27. package/dist/index.d.ts +5 -5
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +16 -8
  30. package/dist/index.js.map +1 -1
  31. package/dist/logger.d.ts +98 -60
  32. package/dist/logger.d.ts.map +1 -1
  33. package/dist/logger.js +193 -124
  34. package/dist/logger.js.map +1 -1
  35. package/dist/mockLogger.d.ts +17 -8
  36. package/dist/mockLogger.d.ts.map +1 -1
  37. package/dist/mockLogger.js +49 -28
  38. package/dist/mockLogger.js.map +1 -1
  39. package/dist/sampledTelemetryHelper.d.ts +8 -7
  40. package/dist/sampledTelemetryHelper.d.ts.map +1 -1
  41. package/dist/sampledTelemetryHelper.js +21 -16
  42. package/dist/sampledTelemetryHelper.js.map +1 -1
  43. package/dist/telemetryTypes.d.ts +20 -6
  44. package/dist/telemetryTypes.d.ts.map +1 -1
  45. package/dist/telemetryTypes.js.map +1 -1
  46. package/dist/thresholdCounter.d.ts.map +1 -1
  47. package/dist/thresholdCounter.js.map +1 -1
  48. package/dist/utils.d.ts +2 -2
  49. package/dist/utils.d.ts.map +1 -1
  50. package/dist/utils.js +2 -2
  51. package/dist/utils.js.map +1 -1
  52. package/lib/config.d.ts +2 -0
  53. package/lib/config.d.ts.map +1 -1
  54. package/lib/config.js +33 -36
  55. package/lib/config.js.map +1 -1
  56. package/lib/error.d.ts +92 -0
  57. package/lib/error.d.ts.map +1 -0
  58. package/lib/error.js +125 -0
  59. package/lib/error.js.map +1 -0
  60. package/lib/errorLogging.d.ts +44 -19
  61. package/lib/errorLogging.d.ts.map +1 -1
  62. package/lib/errorLogging.js +69 -31
  63. package/lib/errorLogging.js.map +1 -1
  64. package/lib/eventEmitterWithErrorHandling.d.ts +3 -3
  65. package/lib/eventEmitterWithErrorHandling.d.ts.map +1 -1
  66. package/lib/eventEmitterWithErrorHandling.js +9 -2
  67. package/lib/eventEmitterWithErrorHandling.js.map +1 -1
  68. package/lib/events.d.ts +1 -1
  69. package/lib/events.d.ts.map +1 -1
  70. package/lib/events.js.map +1 -1
  71. package/lib/fluidErrorBase.d.ts +48 -15
  72. package/lib/fluidErrorBase.d.ts.map +1 -1
  73. package/lib/fluidErrorBase.js +21 -14
  74. package/lib/fluidErrorBase.js.map +1 -1
  75. package/lib/index.d.ts +5 -5
  76. package/lib/index.d.ts.map +1 -1
  77. package/lib/index.js +4 -4
  78. package/lib/index.js.map +1 -1
  79. package/lib/logger.d.ts +98 -60
  80. package/lib/logger.d.ts.map +1 -1
  81. package/lib/logger.js +184 -119
  82. package/lib/logger.js.map +1 -1
  83. package/lib/mockLogger.d.ts +17 -8
  84. package/lib/mockLogger.d.ts.map +1 -1
  85. package/lib/mockLogger.js +50 -29
  86. package/lib/mockLogger.js.map +1 -1
  87. package/lib/sampledTelemetryHelper.d.ts +8 -7
  88. package/lib/sampledTelemetryHelper.d.ts.map +1 -1
  89. package/lib/sampledTelemetryHelper.js +19 -14
  90. package/lib/sampledTelemetryHelper.js.map +1 -1
  91. package/lib/telemetryTypes.d.ts +20 -6
  92. package/lib/telemetryTypes.d.ts.map +1 -1
  93. package/lib/telemetryTypes.js.map +1 -1
  94. package/lib/thresholdCounter.d.ts.map +1 -1
  95. package/lib/thresholdCounter.js.map +1 -1
  96. package/lib/utils.d.ts +2 -2
  97. package/lib/utils.d.ts.map +1 -1
  98. package/lib/utils.js +2 -2
  99. package/lib/utils.js.map +1 -1
  100. package/package.json +19 -22
  101. package/src/config.ts +23 -13
  102. package/src/error.ts +202 -0
  103. package/src/errorLogging.ts +101 -56
  104. package/src/eventEmitterWithErrorHandling.ts +5 -3
  105. package/src/events.ts +3 -3
  106. package/src/fluidErrorBase.ts +62 -26
  107. package/src/index.ts +17 -6
  108. package/src/logger.ts +290 -120
  109. package/src/mockLogger.ts +65 -24
  110. package/src/sampledTelemetryHelper.ts +18 -14
  111. package/src/telemetryTypes.ts +29 -6
  112. package/src/thresholdCounter.ts +2 -2
  113. package/src/utils.ts +2 -2
  114. package/dist/debugLogger.d.ts +0 -39
  115. package/dist/debugLogger.d.ts.map +0 -1
  116. package/dist/debugLogger.js +0 -112
  117. package/dist/debugLogger.js.map +0 -1
  118. package/lib/debugLogger.d.ts +0 -39
  119. package/lib/debugLogger.d.ts.map +0 -1
  120. package/lib/debugLogger.js +0 -108
  121. package/lib/debugLogger.js.map +0 -1
  122. package/src/debugLogger.ts +0 -143
package/src/mockLogger.ts CHANGED
@@ -3,26 +3,32 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { ITelemetryBaseEvent } from "@fluidframework/core-interfaces";
7
- import { assert } from "@fluidframework/common-utils";
8
- import { TelemetryLogger } from "./logger";
9
- import { ITelemetryLoggerExt } from "./telemetryTypes";
6
+ import {
7
+ ITelemetryBaseEvent,
8
+ ITelemetryBaseLogger,
9
+ LogLevel,
10
+ } from "@fluidframework/core-interfaces";
11
+ import { assert } from "@fluidframework/core-utils";
12
+ import { ITelemetryLoggerExt, ITelemetryPropertiesExt } from "./telemetryTypes";
13
+ import { createChildLogger } from "./logger";
10
14
 
11
15
  /**
12
16
  * The MockLogger records events sent to it, and then can walk back over those events
13
17
  * searching for a set of expected events to match against the logged events.
14
18
  */
15
- export class MockLogger extends TelemetryLogger implements ITelemetryLoggerExt {
19
+ export class MockLogger implements ITelemetryBaseLogger {
16
20
  events: ITelemetryBaseEvent[] = [];
17
21
 
18
- constructor() {
19
- super();
20
- }
22
+ constructor(public readonly minLogLevel?: LogLevel) {}
21
23
 
22
- clear() {
24
+ clear(): void {
23
25
  this.events = [];
24
26
  }
25
27
 
28
+ toTelemetryLogger(): ITelemetryLoggerExt {
29
+ return createChildLogger({ logger: this });
30
+ }
31
+
26
32
  send(event: ITelemetryBaseEvent): void {
27
33
  this.events.push(event);
28
34
  }
@@ -48,12 +54,14 @@ export class MockLogger extends TelemetryLogger implements ITelemetryLoggerExt {
48
54
  return unmatchedExpectedEventCount === 0;
49
55
  }
50
56
 
51
- /** Asserts that matchEvents is true, and prints the actual/expected output if not */
57
+ /**
58
+ * Asserts that matchEvents is true, and prints the actual/expected output if not.
59
+ */
52
60
  assertMatch(
53
61
  expectedEvents: Omit<ITelemetryBaseEvent, "category">[],
54
62
  message?: string,
55
63
  inlineDetailsProp: boolean = false,
56
- ) {
64
+ ): void {
57
65
  const actualEvents = this.events;
58
66
  if (!this.matchEvents(expectedEvents, inlineDetailsProp)) {
59
67
  throw new Error(`${message}
@@ -85,12 +93,14 @@ ${JSON.stringify(actualEvents)}`);
85
93
  return matchedExpectedEventCount > 0;
86
94
  }
87
95
 
88
- /** Asserts that matchAnyEvent is true, and prints the actual/expected output if not */
96
+ /**
97
+ * Asserts that matchAnyEvent is true, and prints the actual/expected output if not.
98
+ */
89
99
  assertMatchAny(
90
100
  expectedEvents: Omit<ITelemetryBaseEvent, "category">[],
91
101
  message?: string,
92
102
  inlineDetailsProp: boolean = false,
93
- ) {
103
+ ): void {
94
104
  const actualEvents = this.events;
95
105
  if (!this.matchAnyEvent(expectedEvents, inlineDetailsProp)) {
96
106
  throw new Error(`${message}
@@ -120,12 +130,14 @@ ${JSON.stringify(actualEvents)}`);
120
130
  );
121
131
  }
122
132
 
123
- /** Asserts that matchEvents is true, and prints the actual/expected output if not */
133
+ /**
134
+ * Asserts that matchEvents is true, and prints the actual/expected output if not
135
+ */
124
136
  assertMatchStrict(
125
137
  expectedEvents: Omit<ITelemetryBaseEvent, "category">[],
126
138
  message?: string,
127
139
  inlineDetailsProp: boolean = false,
128
- ) {
140
+ ): void {
129
141
  const actualEvents = this.events;
130
142
  if (!this.matchEventStrict(expectedEvents, inlineDetailsProp)) {
131
143
  throw new Error(`${message}
@@ -137,12 +149,14 @@ ${JSON.stringify(actualEvents)}`);
137
149
  }
138
150
  }
139
151
 
140
- /** Asserts that matchAnyEvent is false for the given events, and prints the actual/expected output if not */
152
+ /**
153
+ * Asserts that matchAnyEvent is false for the given events, and prints the actual/expected output if not
154
+ */
141
155
  assertMatchNone(
142
156
  disallowedEvents: Omit<ITelemetryBaseEvent, "category">[],
143
157
  message?: string,
144
158
  inlineDetailsProp: boolean = false,
145
- ) {
159
+ ): void {
146
160
  const actualEvents = this.events;
147
161
  if (this.matchAnyEvent(disallowedEvents, inlineDetailsProp)) {
148
162
  throw new Error(`${message}
@@ -159,7 +173,7 @@ ${JSON.stringify(actualEvents)}`);
159
173
  inlineDetailsProp: boolean,
160
174
  ): number {
161
175
  let iExpectedEvent = 0;
162
- this.events.forEach((event) => {
176
+ for (const event of this.events) {
163
177
  if (
164
178
  iExpectedEvent < expectedEvents.length &&
165
179
  MockLogger.eventsMatch(event, expectedEvents[iExpectedEvent], inlineDetailsProp)
@@ -167,7 +181,7 @@ ${JSON.stringify(actualEvents)}`);
167
181
  // We found the next expected event; increment
168
182
  ++iExpectedEvent;
169
183
  }
170
- });
184
+ }
171
185
 
172
186
  // Remove the events so far; next call will just compare subsequent events from here
173
187
  this.events = [];
@@ -185,19 +199,46 @@ ${JSON.stringify(actualEvents)}`);
185
199
  inlineDetailsProp: boolean,
186
200
  ): boolean {
187
201
  const { details, ...actualForMatching } = actual;
188
- let detailsExpanded = { details };
189
202
  // "details" is used in a lot of telemetry logs to group a bunch of properties together and stringify them.
190
203
  // Some of the properties in the expected event may be inside "details". So, if inlineDetailsProp is true,
191
204
  // extract the properties from "details" in the actual event and inline them in the actual event.
192
205
  if (inlineDetailsProp && details !== undefined) {
193
206
  assert(
194
207
  typeof details === "string",
208
+ // eslint-disable-next-line unicorn/numeric-separators-style
195
209
  0x6c9 /* Details should a JSON stringified string if inlineDetailsProp is true */,
196
210
  );
197
- detailsExpanded = JSON.parse(details);
211
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
212
+ const detailsExpanded = JSON.parse(details);
213
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
214
+ return matchObjects({ ...actualForMatching, ...detailsExpanded }, expected);
215
+ }
216
+ return matchObjects(actual, expected);
217
+ }
218
+ }
219
+
220
+ function matchObjects(actual: ITelemetryPropertiesExt, expected: ITelemetryPropertiesExt): boolean {
221
+ for (const [expectedKey, expectedValue] of Object.entries(expected)) {
222
+ const actualValue = actual[expectedKey];
223
+ if (
224
+ !Array.isArray(expectedValue) &&
225
+ expectedValue !== null &&
226
+ typeof expectedValue === "object"
227
+ ) {
228
+ if (
229
+ Array.isArray(actualValue) ||
230
+ actualValue === null ||
231
+ typeof actualValue !== "object" ||
232
+ !matchObjects(
233
+ actualValue as ITelemetryPropertiesExt,
234
+ expectedValue as ITelemetryPropertiesExt,
235
+ )
236
+ ) {
237
+ return false;
238
+ }
239
+ } else if (JSON.stringify(actualValue) !== JSON.stringify(expectedValue)) {
240
+ return false;
198
241
  }
199
- const actualExpanded: ITelemetryBaseEvent = { ...actualForMatching, ...detailsExpanded };
200
- const masked = { ...actualExpanded, ...expected };
201
- return JSON.stringify(masked) === JSON.stringify(actualExpanded);
202
242
  }
243
+ return true;
203
244
  }
@@ -9,14 +9,17 @@ import {
9
9
  ITelemetryProperties,
10
10
  IDisposable,
11
11
  } from "@fluidframework/core-interfaces";
12
- import { performance } from "@fluidframework/common-utils";
12
+ import { performance } from "@fluid-internal/client-utils";
13
13
  import { ITelemetryLoggerExt } from "./telemetryTypes";
14
14
 
15
+ /**
16
+ * @privateRemarks
17
+ *
18
+ * The names of the properties in this interface are the ones that will get stamped in the
19
+ * telemetry event, changes should be considered carefully. The optional properties should
20
+ * only be populated if 'includeAggregateMetrics' is true.
21
+ */
15
22
  interface Measurements {
16
- // The names of the properties in this interface are the ones that will get stamped in the
17
- // telemetry event, changes should be considered carefully. The optional properties should
18
- // only be populated if 'includeAggregateMetrics' is true.
19
-
20
23
  /**
21
24
  * The duration of the latest execution.
22
25
  */
@@ -45,7 +48,7 @@ interface Measurements {
45
48
 
46
49
  /**
47
50
  * Helper class that executes a specified code block and writes an
48
- * {@link @fluidframework/common-definitions#ITelemetryPerformanceEvent} to a specified logger every time a specified
51
+ * {@link @fluidframework/core-interfaces#ITelemetryPerformanceEvent} to a specified logger every time a specified
49
52
  * number of executions is reached (or when the class is disposed). The `duration` field in the telemetry event is
50
53
  * the duration of the latest execution (sample) of the specified function. See the documentation of the
51
54
  * `includeAggregateMetrics` parameter for additional details that can be included.
@@ -82,12 +85,13 @@ export class SampledTelemetryHelper implements IDisposable {
82
85
  ) {}
83
86
 
84
87
  /**
85
- * @param codeToMeasure -
86
- * The code to be executed and measured.
87
- * @param bucket -
88
- * A key to track executions of the code block separately. Each different value of this parameter has a separate
89
- * set of executions and metrics tracked by the class. If no such distinction needs to be made, do not provide a
90
- * value.
88
+ * Executes the specified code and keeps track of execution time statistics.
89
+ * If it's been called enough times (the sampleThreshold for the class) then it generates a log message with the necessary information.
90
+ *
91
+ * @param codeToMeasure - The code to be executed and measured.
92
+ * @param bucket - A key to track executions of the code block separately.
93
+ * Each different value of this parameter has a separate set of executions and metrics tracked by the class.
94
+ * If no such distinction needs to be made, do not provide a value.
91
95
  * @returns Whatever the passed-in code block returns.
92
96
  */
93
97
  public measure<T>(codeToMeasure: () => T, bucket: string = ""): T {
@@ -116,7 +120,7 @@ export class SampledTelemetryHelper implements IDisposable {
116
120
  return returnValue;
117
121
  }
118
122
 
119
- private flushBucket(bucket: string) {
123
+ private flushBucket(bucket: string): void {
120
124
  const measurements = this.measurementsMap.get(bucket);
121
125
  if (measurements === undefined) {
122
126
  return;
@@ -137,6 +141,6 @@ export class SampledTelemetryHelper implements IDisposable {
137
141
  }
138
142
 
139
143
  public dispose(error?: Error | undefined): void {
140
- this.measurementsMap.forEach((_, k) => this.flushBucket(k));
144
+ for (const [k] of this.measurementsMap.entries()) this.flushBucket(k);
141
145
  }
142
146
  }
@@ -3,11 +3,20 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { ITelemetryBaseLogger, TelemetryEventCategory } from "@fluidframework/core-interfaces";
6
+ import { ITelemetryBaseLogger, LogLevel, Tagged } from "@fluidframework/core-interfaces";
7
+
8
+ /**
9
+ * The categories FF uses when instrumenting the code.
10
+ *
11
+ * generic - Informational log event
12
+ * error - Error log event, ideally 0 of these are logged during a session
13
+ * performance - Includes duration, and often has _start, _end, or _cancel suffixes for activity tracking
14
+ */
15
+ export type TelemetryEventCategory = "generic" | "error" | "performance";
7
16
 
8
17
  /**
9
18
  * Property types that can be logged.
10
- * Includes extra types beyond TelemetryEventPropertyType (which will be deprecated in favor of this one)
19
+ * Includes extra types beyond TelemetryBaseEventPropertyType, which must be converted before sending to a base logger
11
20
  */
12
21
  export type TelemetryEventPropertyTypeExt =
13
22
  | string
@@ -24,6 +33,8 @@ export type TelemetryEventPropertyTypeExt =
24
33
  * A property to be logged to telemetry containing both the value and a tag. Tags are generic strings that can be used
25
34
  * to mark pieces of information that should be organized or handled differently by loggers in various first or third
26
35
  * party scenarios. For example, tags are used to mark personal information that should not be stored in logs.
36
+ *
37
+ * @deprecated Use Tagged<TelemetryEventPropertyTypeExt>
27
38
  */
28
39
  export interface ITaggedTelemetryPropertyTypeExt {
29
40
  value: TelemetryEventPropertyTypeExt;
@@ -34,7 +45,7 @@ export interface ITaggedTelemetryPropertyTypeExt {
34
45
  * JSON-serializable properties, which will be logged with telemetry.
35
46
  */
36
47
  export interface ITelemetryPropertiesExt {
37
- [index: string]: TelemetryEventPropertyTypeExt | ITaggedTelemetryPropertyTypeExt;
48
+ [index: string]: TelemetryEventPropertyTypeExt | Tagged<TelemetryEventPropertyTypeExt>;
38
49
  }
39
50
 
40
51
  /**
@@ -83,18 +94,30 @@ export interface ITelemetryLoggerExt extends ITelemetryBaseLogger {
83
94
  * Send information telemetry event
84
95
  * @param event - Event to send
85
96
  * @param error - optional error object to log
97
+ * @param logLevel - optional level of the log.
86
98
  */
87
- sendTelemetryEvent(event: ITelemetryGenericEventExt, error?: any): void;
99
+ sendTelemetryEvent(
100
+ event: ITelemetryGenericEventExt,
101
+ error?: unknown,
102
+ logLevel?: typeof LogLevel.verbose | typeof LogLevel.default,
103
+ ): void;
88
104
 
89
105
  /**
90
106
  * Send error telemetry event
91
107
  * @param event - Event to send
108
+ * @param error - optional error object to log
92
109
  */
93
- sendErrorEvent(event: ITelemetryErrorEventExt, error?: any): void;
110
+ sendErrorEvent(event: ITelemetryErrorEventExt, error?: unknown): void;
94
111
 
95
112
  /**
96
113
  * Send performance telemetry event
97
114
  * @param event - Event to send
115
+ * @param error - optional error object to log
116
+ * @param logLevel - optional level of the log.
98
117
  */
99
- sendPerformanceEvent(event: ITelemetryPerformanceEventExt, error?: any): void;
118
+ sendPerformanceEvent(
119
+ event: ITelemetryPerformanceEventExt,
120
+ error?: unknown,
121
+ logLevel?: typeof LogLevel.verbose | typeof LogLevel.default,
122
+ ): void;
100
123
  }
@@ -19,7 +19,7 @@ export class ThresholdCounter {
19
19
  /**
20
20
  * Sends the value if it's above the treshold.
21
21
  */
22
- public send(eventName: string, value: number) {
22
+ public send(eventName: string, value: number): void {
23
23
  if (value < this.threshold) {
24
24
  return;
25
25
  }
@@ -36,7 +36,7 @@ export class ThresholdCounter {
36
36
  * To be used in scenarios where we'd like to record a
37
37
  * threshold violation while reducing telemetry noise.
38
38
  */
39
- public sendIfMultiple(eventName: string, value: number) {
39
+ public sendIfMultiple(eventName: string, value: number): void {
40
40
  if (value === this.thresholdMultiple) {
41
41
  this.logger.sendPerformanceEvent({
42
42
  eventName,
package/src/utils.ts CHANGED
@@ -13,10 +13,10 @@ import {
13
13
  * @param condition - The condition to attest too
14
14
  * @param logger - The logger to log with
15
15
  * @param event - The string or event to log
16
- * @returns - The outcome of the condition
16
+ * @returns The outcome of the condition
17
17
  */
18
18
  export function logIfFalse(
19
- condition: any,
19
+ condition: unknown,
20
20
  logger: ITelemetryBaseLogger,
21
21
  event: string | ITelemetryGenericEvent,
22
22
  ): condition is true {
@@ -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
- */
11
- export declare class DebugLogger extends TelemetryLogger {
12
- private readonly debug;
13
- private readonly debugErr;
14
- /**
15
- * Create debug logger - all events are output to debug npm library
16
- * @param namespace - Telemetry event name prefix to add to all events
17
- * @param properties - Base properties to add to all events
18
- * @param propertyGetters - Getters to add additional properties to all events
19
- */
20
- static create(namespace: string, properties?: ITelemetryLoggerPropertyBags): TelemetryLogger;
21
- /**
22
- * Mix in debug logger with another logger.
23
- * Returned logger will output events to both newly created debug logger, as well as base logger
24
- * @param namespace - Telemetry event name prefix to add to all events
25
- * @param properties - Base properties to add to all events
26
- * @param propertyGetters - Getters to add additional properties to all events
27
- * @param baseLogger - Base logger to output events (in addition to debug logger being created). Can be undefined.
28
- */
29
- static mixinDebugLogger(namespace: string, baseLogger?: ITelemetryBaseLogger, properties?: ITelemetryLoggerPropertyBags): TelemetryLogger;
30
- private static tryGetBaseLoggerProps;
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,EAGf,4BAA4B,EAC5B,MAAM,UAAU,CAAC;AAElB;;GAEG;AACH,qBAAa,WAAY,SAAQ,eAAe;IAiE9C,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAjE1B;;;;;OAKG;WACW,MAAM,CACnB,SAAS,EAAE,MAAM,EACjB,UAAU,CAAC,EAAE,4BAA4B,GACvC,eAAe;IAqBlB;;;;;;;OAOG;WACW,gBAAgB,CAC7B,SAAS,EAAE,MAAM,EACjB,UAAU,CAAC,EAAE,oBAAoB,EACjC,UAAU,CAAC,EAAE,4BAA4B,GACvC,eAAe;IAclB,OAAO,CAAC,MAAM,CAAC,qBAAqB;gBAQlB,KAAK,EAAE,SAAS,EAChB,QAAQ,EAAE,SAAS,EACpC,UAAU,CAAC,EAAE,4BAA4B;IAK1C;;;;OAIG;IACI,IAAI,CAAC,KAAK,EAAE,mBAAmB,GAAG,IAAI;CA2C7C"}
@@ -1,112 +0,0 @@
1
- "use strict";
2
- /*!
3
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
- * Licensed under the MIT License.
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.DebugLogger = void 0;
8
- const common_utils_1 = require("@fluidframework/common-utils");
9
- const debug_1 = require("debug");
10
- const logger_1 = require("./logger");
11
- /**
12
- * Implementation of debug logger
13
- */
14
- class DebugLogger extends logger_1.TelemetryLogger {
15
- constructor(debug, debugErr, properties) {
16
- super(undefined, properties);
17
- this.debug = debug;
18
- this.debugErr = debugErr;
19
- }
20
- /**
21
- * Create debug logger - all events are output to debug npm library
22
- * @param namespace - Telemetry event name prefix to add to all events
23
- * @param properties - Base properties to add to all events
24
- * @param propertyGetters - Getters to add additional properties to all events
25
- */
26
- static create(namespace, properties) {
27
- // Setup base logger upfront, such that host can disable it (if needed)
28
- const debug = (0, debug_1.debug)(namespace);
29
- // Create one for errors that is always enabled
30
- // It can be silenced by replacing console.error if the debug namespace is not enabled.
31
- const debugErr = (0, debug_1.debug)(namespace);
32
- debugErr.log = function () {
33
- if (debug.enabled) {
34
- // if the namespace is enabled, just use the default logger
35
- debug_1.debug.log(...arguments);
36
- }
37
- else {
38
- // other wise, use the console logger (which could be replaced and silenced)
39
- console.error(...arguments);
40
- }
41
- };
42
- debugErr.enabled = true;
43
- return new DebugLogger(debug, debugErr, properties);
44
- }
45
- /**
46
- * Mix in debug logger with another logger.
47
- * Returned logger will output events to both newly created debug logger, as well as base logger
48
- * @param namespace - Telemetry event name prefix to add to all events
49
- * @param properties - Base properties to add to all events
50
- * @param propertyGetters - Getters to add additional properties to all events
51
- * @param baseLogger - Base logger to output events (in addition to debug logger being created). Can be undefined.
52
- */
53
- static mixinDebugLogger(namespace, baseLogger, properties) {
54
- if (!baseLogger) {
55
- return DebugLogger.create(namespace, properties);
56
- }
57
- const multiSinkLogger = new logger_1.MultiSinkLogger(undefined, properties);
58
- multiSinkLogger.addLogger(DebugLogger.create(namespace, this.tryGetBaseLoggerProps(baseLogger)));
59
- multiSinkLogger.addLogger(logger_1.ChildLogger.create(baseLogger, namespace));
60
- return multiSinkLogger;
61
- }
62
- static tryGetBaseLoggerProps(baseLogger) {
63
- if (baseLogger instanceof logger_1.TelemetryLogger) {
64
- return baseLogger.properties;
65
- }
66
- return undefined;
67
- }
68
- /**
69
- * Send an event to debug loggers
70
- *
71
- * @param event - the event to send
72
- */
73
- send(event) {
74
- const newEvent = this.prepareEvent(event);
75
- const isError = newEvent.category === "error";
76
- let logger = isError ? this.debugErr : this.debug;
77
- // Use debug's coloring schema for base of the event
78
- const index = event.eventName.lastIndexOf(logger_1.TelemetryLogger.eventNamespaceSeparator);
79
- const name = event.eventName.substring(index + 1);
80
- if (index > 0) {
81
- logger = logger.extend(event.eventName.substring(0, index));
82
- }
83
- newEvent.eventName = undefined;
84
- let tick = "";
85
- tick = `tick=${logger_1.TelemetryLogger.formatTick(common_utils_1.performance.now())}`;
86
- // Extract stack to put it last, but also to avoid escaping '\n' in it by JSON.stringify below
87
- const stack = newEvent.stack ? newEvent.stack : "";
88
- newEvent.stack = undefined;
89
- // Watch out for circular references - they can come from two sources
90
- // 1) error object - we do not control it and should remove it and retry
91
- // 2) properties supplied by telemetry caller - that's a bug that should be addressed!
92
- let payload;
93
- try {
94
- payload = JSON.stringify(newEvent);
95
- }
96
- catch (error) {
97
- newEvent.error = undefined;
98
- payload = JSON.stringify(newEvent);
99
- }
100
- if (payload === "{}") {
101
- payload = "";
102
- }
103
- // Force errors out, to help with diagnostics
104
- if (isError) {
105
- logger.enabled = true;
106
- }
107
- // Print multi-line.
108
- logger(`${name} ${payload} ${tick} ${stack}`);
109
- }
110
- }
111
- exports.DebugLogger = DebugLogger;
112
- //# sourceMappingURL=debugLogger.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"debugLogger.js","sourceRoot":"","sources":["../src/debugLogger.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAOH,+DAA2D;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nD,QAAQ,CAAC,KAAK,GAAG,SAAS,CAAC;QAE3B,qEAAqE;QACrE,wEAAwE;QACxE,sFAAsF;QACtF,IAAI,OAAe,CAAC;QACpB,IAAI;YACH,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;SACnC;QAAC,OAAO,KAAK,EAAE;YACf,QAAQ,CAAC,KAAK,GAAG,SAAS,CAAC;YAC3B,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;SACnC;QAED,IAAI,OAAO,KAAK,IAAI,EAAE;YACrB,OAAO,GAAG,EAAE,CAAC;SACb;QAED,6CAA6C;QAC7C,IAAI,OAAO,EAAE;YACZ,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC;SACtB;QAED,oBAAoB;QACpB,MAAM,CAAC,GAAG,IAAI,IAAI,OAAO,IAAI,IAAI,IAAI,KAAK,EAAE,CAAC,CAAC;IAC/C,CAAC;CACD;AAxHD,kCAwHC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under 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\tChildLogger,\n\tITelemetryLoggerPropertyBags,\n} from \"./logger\";\n\n/**\n * Implementation of debug logger\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 baseLogger - 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\tbaseLogger?: ITelemetryBaseLogger,\n\t\tproperties?: ITelemetryLoggerPropertyBags,\n\t): TelemetryLogger {\n\t\tif (!baseLogger) {\n\t\t\treturn DebugLogger.create(namespace, properties);\n\t\t}\n\n\t\tconst multiSinkLogger = new MultiSinkLogger(undefined, properties);\n\t\tmultiSinkLogger.addLogger(\n\t\t\tDebugLogger.create(namespace, this.tryGetBaseLoggerProps(baseLogger)),\n\t\t);\n\t\tmultiSinkLogger.addLogger(ChildLogger.create(baseLogger, namespace));\n\n\t\treturn multiSinkLogger;\n\t}\n\n\tprivate static tryGetBaseLoggerProps(baseLogger?: ITelemetryBaseLogger) {\n\t\tif (baseLogger instanceof TelemetryLogger) {\n\t\t\treturn (baseLogger as any as { properties: ITelemetryLoggerPropertyBags }).properties;\n\t\t}\n\t\treturn undefined;\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=${TelemetryLogger.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,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
- */
11
- export declare class DebugLogger extends TelemetryLogger {
12
- private readonly debug;
13
- private readonly debugErr;
14
- /**
15
- * Create debug logger - all events are output to debug npm library
16
- * @param namespace - Telemetry event name prefix to add to all events
17
- * @param properties - Base properties to add to all events
18
- * @param propertyGetters - Getters to add additional properties to all events
19
- */
20
- static create(namespace: string, properties?: ITelemetryLoggerPropertyBags): TelemetryLogger;
21
- /**
22
- * Mix in debug logger with another logger.
23
- * Returned logger will output events to both newly created debug logger, as well as base logger
24
- * @param namespace - Telemetry event name prefix to add to all events
25
- * @param properties - Base properties to add to all events
26
- * @param propertyGetters - Getters to add additional properties to all events
27
- * @param baseLogger - Base logger to output events (in addition to debug logger being created). Can be undefined.
28
- */
29
- static mixinDebugLogger(namespace: string, baseLogger?: ITelemetryBaseLogger, properties?: ITelemetryLoggerPropertyBags): TelemetryLogger;
30
- private static tryGetBaseLoggerProps;
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,EAGf,4BAA4B,EAC5B,MAAM,UAAU,CAAC;AAElB;;GAEG;AACH,qBAAa,WAAY,SAAQ,eAAe;IAiE9C,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAjE1B;;;;;OAKG;WACW,MAAM,CACnB,SAAS,EAAE,MAAM,EACjB,UAAU,CAAC,EAAE,4BAA4B,GACvC,eAAe;IAqBlB;;;;;;;OAOG;WACW,gBAAgB,CAC7B,SAAS,EAAE,MAAM,EACjB,UAAU,CAAC,EAAE,oBAAoB,EACjC,UAAU,CAAC,EAAE,4BAA4B,GACvC,eAAe;IAclB,OAAO,CAAC,MAAM,CAAC,qBAAqB;gBAQlB,KAAK,EAAE,SAAS,EAChB,QAAQ,EAAE,SAAS,EACpC,UAAU,CAAC,EAAE,4BAA4B;IAK1C;;;;OAIG;IACI,IAAI,CAAC,KAAK,EAAE,mBAAmB,GAAG,IAAI;CA2C7C"}