@fluidframework/telemetry-utils 2.0.0-internal.7.2.2 → 2.0.0-internal.7.4.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 (130) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +1 -2
  3. package/api-extractor-lint.json +13 -0
  4. package/api-extractor.json +3 -3
  5. package/api-report/telemetry-utils.api.md +66 -57
  6. package/dist/config.d.ts +37 -10
  7. package/dist/config.d.ts.map +1 -1
  8. package/dist/config.js +30 -0
  9. package/dist/config.js.map +1 -1
  10. package/dist/error.d.ts +12 -0
  11. package/dist/error.d.ts.map +1 -1
  12. package/dist/error.js +18 -1
  13. package/dist/error.js.map +1 -1
  14. package/dist/errorLogging.d.ts +7 -2
  15. package/dist/errorLogging.d.ts.map +1 -1
  16. package/dist/errorLogging.js +7 -2
  17. package/dist/errorLogging.js.map +1 -1
  18. package/dist/eventEmitterWithErrorHandling.d.ts +6 -0
  19. package/dist/eventEmitterWithErrorHandling.d.ts.map +1 -1
  20. package/dist/eventEmitterWithErrorHandling.js +6 -0
  21. package/dist/eventEmitterWithErrorHandling.js.map +1 -1
  22. package/dist/events.d.ts +16 -0
  23. package/dist/events.d.ts.map +1 -1
  24. package/dist/events.js +16 -0
  25. package/dist/events.js.map +1 -1
  26. package/dist/fluidErrorBase.d.ts +8 -0
  27. package/dist/fluidErrorBase.d.ts.map +1 -1
  28. package/dist/fluidErrorBase.js +6 -0
  29. package/dist/fluidErrorBase.js.map +1 -1
  30. package/dist/index.d.ts +20 -3
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +2 -1
  33. package/dist/index.js.map +1 -1
  34. package/dist/logger.d.ts +117 -17
  35. package/dist/logger.d.ts.map +1 -1
  36. package/dist/logger.js +82 -12
  37. package/dist/logger.js.map +1 -1
  38. package/dist/mockLogger.d.ts +2 -0
  39. package/dist/mockLogger.d.ts.map +1 -1
  40. package/dist/mockLogger.js +2 -0
  41. package/dist/mockLogger.js.map +1 -1
  42. package/dist/sampledTelemetryHelper.d.ts +7 -3
  43. package/dist/sampledTelemetryHelper.d.ts.map +1 -1
  44. package/dist/sampledTelemetryHelper.js +7 -3
  45. package/dist/sampledTelemetryHelper.js.map +1 -1
  46. package/dist/telemetry-utils-alpha.d.ts +270 -0
  47. package/dist/telemetry-utils-beta.d.ts +205 -0
  48. package/dist/telemetry-utils-public.d.ts +205 -0
  49. package/dist/telemetry-utils-untrimmed.d.ts +1123 -0
  50. package/dist/telemetryTypes.d.ts +27 -8
  51. package/dist/telemetryTypes.d.ts.map +1 -1
  52. package/dist/telemetryTypes.js.map +1 -1
  53. package/dist/thresholdCounter.d.ts +3 -2
  54. package/dist/thresholdCounter.d.ts.map +1 -1
  55. package/dist/thresholdCounter.js +3 -2
  56. package/dist/thresholdCounter.js.map +1 -1
  57. package/dist/tsdoc-metadata.json +1 -1
  58. package/dist/utils.d.ts +6 -0
  59. package/dist/utils.d.ts.map +1 -1
  60. package/dist/utils.js +6 -0
  61. package/dist/utils.js.map +1 -1
  62. package/lib/config.d.ts +37 -10
  63. package/lib/config.d.ts.map +1 -1
  64. package/lib/config.js +30 -0
  65. package/lib/config.js.map +1 -1
  66. package/lib/error.d.ts +12 -0
  67. package/lib/error.d.ts.map +1 -1
  68. package/lib/error.js +16 -0
  69. package/lib/error.js.map +1 -1
  70. package/lib/errorLogging.d.ts +7 -2
  71. package/lib/errorLogging.d.ts.map +1 -1
  72. package/lib/errorLogging.js +7 -2
  73. package/lib/errorLogging.js.map +1 -1
  74. package/lib/eventEmitterWithErrorHandling.d.ts +6 -0
  75. package/lib/eventEmitterWithErrorHandling.d.ts.map +1 -1
  76. package/lib/eventEmitterWithErrorHandling.js +6 -0
  77. package/lib/eventEmitterWithErrorHandling.js.map +1 -1
  78. package/lib/events.d.ts +16 -0
  79. package/lib/events.d.ts.map +1 -1
  80. package/lib/events.js +16 -0
  81. package/lib/events.js.map +1 -1
  82. package/lib/fluidErrorBase.d.ts +8 -0
  83. package/lib/fluidErrorBase.d.ts.map +1 -1
  84. package/lib/fluidErrorBase.js +6 -0
  85. package/lib/fluidErrorBase.js.map +1 -1
  86. package/lib/index.d.ts +20 -3
  87. package/lib/index.d.ts.map +1 -1
  88. package/lib/index.js +1 -1
  89. package/lib/index.js.map +1 -1
  90. package/lib/logger.d.ts +117 -17
  91. package/lib/logger.d.ts.map +1 -1
  92. package/lib/logger.js +82 -12
  93. package/lib/logger.js.map +1 -1
  94. package/lib/mockLogger.d.ts +2 -0
  95. package/lib/mockLogger.d.ts.map +1 -1
  96. package/lib/mockLogger.js +2 -0
  97. package/lib/mockLogger.js.map +1 -1
  98. package/lib/sampledTelemetryHelper.d.ts +7 -3
  99. package/lib/sampledTelemetryHelper.d.ts.map +1 -1
  100. package/lib/sampledTelemetryHelper.js +7 -3
  101. package/lib/sampledTelemetryHelper.js.map +1 -1
  102. package/lib/telemetry-utils-alpha.d.ts +270 -0
  103. package/lib/telemetry-utils-beta.d.ts +205 -0
  104. package/lib/telemetry-utils-public.d.ts +205 -0
  105. package/lib/telemetry-utils-untrimmed.d.ts +1123 -0
  106. package/lib/telemetryTypes.d.ts +27 -8
  107. package/lib/telemetryTypes.d.ts.map +1 -1
  108. package/lib/telemetryTypes.js.map +1 -1
  109. package/lib/thresholdCounter.d.ts +3 -2
  110. package/lib/thresholdCounter.d.ts.map +1 -1
  111. package/lib/thresholdCounter.js +3 -2
  112. package/lib/thresholdCounter.js.map +1 -1
  113. package/lib/utils.d.ts +6 -0
  114. package/lib/utils.d.ts.map +1 -1
  115. package/lib/utils.js +6 -0
  116. package/lib/utils.js.map +1 -1
  117. package/package.json +36 -17
  118. package/src/config.ts +41 -12
  119. package/src/error.ts +21 -0
  120. package/src/errorLogging.ts +7 -2
  121. package/src/eventEmitterWithErrorHandling.ts +6 -0
  122. package/src/events.ts +18 -0
  123. package/src/fluidErrorBase.ts +8 -0
  124. package/src/index.ts +21 -2
  125. package/src/logger.ts +125 -17
  126. package/src/mockLogger.ts +2 -0
  127. package/src/sampledTelemetryHelper.ts +7 -3
  128. package/src/telemetryTypes.ts +27 -8
  129. package/src/thresholdCounter.ts +3 -2
  130. package/src/utils.ts +6 -0
@@ -0,0 +1,1123 @@
1
+ /// <reference types="node" />
2
+
3
+ import { EventEmitter } from 'events';
4
+ import { EventEmitterEventType } from '@fluid-internal/client-utils';
5
+ import { IConfigProviderBase as IConfigProviderBase_2 } from '@fluidframework/core-interfaces';
6
+ import { IDisposable } from '@fluidframework/core-interfaces';
7
+ import { IErrorBase } from '@fluidframework/core-interfaces';
8
+ import { IEvent } from '@fluidframework/core-interfaces';
9
+ import { IGenericError } from '@fluidframework/core-interfaces';
10
+ import { ILoggingError } from '@fluidframework/core-interfaces';
11
+ import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
12
+ import { ITelemetryBaseEvent } from '@fluidframework/core-interfaces';
13
+ import { ITelemetryBaseLogger } from '@fluidframework/core-interfaces';
14
+ import { ITelemetryBaseProperties } from '@fluidframework/core-interfaces';
15
+ import { ITelemetryErrorEvent } from '@fluidframework/core-interfaces';
16
+ import { ITelemetryGenericEvent } from '@fluidframework/core-interfaces';
17
+ import { ITelemetryPerformanceEvent } from '@fluidframework/core-interfaces';
18
+ import { ITelemetryProperties } from '@fluidframework/core-interfaces';
19
+ import { IUsageError } from '@fluidframework/core-interfaces';
20
+ import { Lazy } from '@fluidframework/core-utils';
21
+ import { LogLevel } from '@fluidframework/core-interfaces';
22
+ import { Tagged } from '@fluidframework/core-interfaces';
23
+ import { TelemetryBaseEventPropertyType } from '@fluidframework/core-interfaces';
24
+ import { TelemetryEventPropertyType } from '@fluidframework/core-interfaces';
25
+ import { TypedEventEmitter } from '@fluid-internal/client-utils';
26
+
27
+ /**
28
+ * Types supported by {@link IConfigProviderBase}.
29
+ * @deprecated Use ConfigTypes from fluidFramework/core-interfaces
30
+ *
31
+ * @internal
32
+ */
33
+ export declare type ConfigTypes = string | number | boolean | number[] | string[] | boolean[] | undefined;
34
+
35
+ /**
36
+ * @internal
37
+ */
38
+ export declare const connectedEventName = "connected";
39
+
40
+ /**
41
+ * Create a child logger based on the provided props object.
42
+ *
43
+ * @remarks
44
+ * Passing in no props object (i.e. undefined) will return a logger that is effectively a no-op.
45
+ *
46
+ * @param props - logger is the base logger the child will log to after it's processing, namespace will be prefixed to all event names, properties are default properties that will be applied events.
47
+ *
48
+ * @internal
49
+ */
50
+ export declare function createChildLogger(props?: {
51
+ logger?: ITelemetryBaseLogger;
52
+ namespace?: string;
53
+ properties?: ITelemetryLoggerPropertyBags;
54
+ }): ITelemetryLoggerExt;
55
+
56
+ /**
57
+ * Creates a child logger with a {@link MonitoringContext}.
58
+ *
59
+ * @see {@link loggerToMonitoringContext}
60
+ * @internal
61
+ */
62
+ export declare function createChildMonitoringContext(props: Parameters<typeof createChildLogger>[0]): MonitoringContext;
63
+
64
+ /**
65
+ * Create a logger which logs to multiple other loggers based on the provided props object.
66
+ *
67
+ * @internal
68
+ */
69
+ export declare function createMultiSinkLogger(props: MultiSinkLoggerProperties): ITelemetryLoggerExt;
70
+
71
+ /**
72
+ * Wraps around an existing logger matching the {@link ITelemetryLoggerExt} interface and provides the ability to only log a subset of events using a sampling strategy provided by an ${@link IEventSampler}.
73
+ * You can chose to not provide an event sampler which is effectively a no-op, meaning that it will be treated as if the sampler always returns true.
74
+ *
75
+ * @remarks
76
+ * The sampling functionality uses the Fluid telemetry logging configuration along with the optionally provided event sampling callback to determine whether an event should
77
+ * be logged or not.
78
+ *
79
+ * Configuration object parameters:
80
+ * 'Fluid.Telemetry.DisableSampling': if this config value is set to true, all events will be unsampled and therefore logged.
81
+ * Otherwise only a sample will be logged according to the provided event sampler callback.
82
+ *
83
+ * Note that the same sampler is used for all APIs of the returned logger. If you want separate events flowing through the returned logger to be sampled separately, the {@link IEventSampler} you provide should track them separately.
84
+ *
85
+ * @internal
86
+ */
87
+ export declare function createSampledLogger(logger: ITelemetryLoggerExt, eventSampler?: IEventSampler): ISampledTelemetryLogger;
88
+
89
+ /**
90
+ * DataCorruptionError indicates that we encountered definitive evidence that the data at rest
91
+ * backing this container is corrupted, and this container would never be expected to load properly again
92
+ *
93
+ * @internal
94
+ */
95
+ export declare class DataCorruptionError extends LoggingError implements IErrorBase, IFluidErrorBase {
96
+ readonly errorType: "dataCorruptionError";
97
+ readonly canRetry = false;
98
+ constructor(message: string, props: ITelemetryBaseProperties);
99
+ }
100
+
101
+ /**
102
+ * Indicates we hit a fatal error while processing incoming data from the Fluid Service.
103
+ *
104
+ * @remarks
105
+ *
106
+ * The error will often originate in the dataStore or DDS implementation that is responding to incoming changes.
107
+ * This differs from {@link DataCorruptionError} in that this may be a transient error that will not repro in another
108
+ * client or session.
109
+ *
110
+ * @internal
111
+ */
112
+ export declare class DataProcessingError extends LoggingError implements IErrorBase, IFluidErrorBase {
113
+ /**
114
+ * {@inheritDoc IFluidErrorBase.errorType}
115
+ */
116
+ readonly errorType: "dataProcessingError";
117
+ readonly canRetry = false;
118
+ private constructor();
119
+ /**
120
+ * Create a new `DataProcessingError` detected and raised within the Fluid Framework.
121
+ */
122
+ static create(errorMessage: string, dataProcessingCodepath: string, sequencedMessage?: ISequencedDocumentMessage, props?: ITelemetryBaseProperties): IFluidErrorBase;
123
+ /**
124
+ * Wrap the given error in a `DataProcessingError`, unless the error is already of a known type
125
+ * with the exception of a normalized {@link LoggingError}, which will still be wrapped.
126
+ *
127
+ * In either case, the error will have some relevant properties added for telemetry.
128
+ *
129
+ * @remarks
130
+ *
131
+ * We wrap conditionally since known error types represent well-understood failure modes, and ideally
132
+ * one day we will move away from throwing these errors but rather we'll return them.
133
+ * But an unrecognized error needs to be classified as `DataProcessingError`.
134
+ *
135
+ * @param originalError - The error to be converted.
136
+ * @param dataProcessingCodepath - Which code-path failed while processing data.
137
+ * @param messageLike - Message to include info about via telemetry props.
138
+ *
139
+ * @returns Either a new `DataProcessingError`, or (if wrapping is deemed unnecessary) the given error.
140
+ */
141
+ static wrapIfUnrecognized(originalError: unknown, dataProcessingCodepath: string, messageLike?: Partial<Pick<ISequencedDocumentMessage, "clientId" | "sequenceNumber" | "clientSequenceNumber" | "referenceSequenceNumber" | "minimumSequenceNumber" | "timestamp">>): IFluidErrorBase;
142
+ }
143
+
144
+ /**
145
+ * @internal
146
+ */
147
+ export declare const disconnectedEventName = "disconnected";
148
+
149
+ /**
150
+ * Event Emitter helper class
151
+ *
152
+ * @remarks
153
+ * Any exceptions thrown by listeners will be caught and raised through "error" event.
154
+ * Any exception thrown by "error" listeners will propagate to the caller.
155
+ * @privateRemarks
156
+ * This probably doesn't belong in this package, as it is not telemetry-specific, and is really only intended for internal fluid-framework use.
157
+ * We should consider moving it to the `core-utils` package.
158
+ * @alpha
159
+ */
160
+ export declare class EventEmitterWithErrorHandling<TEvent extends IEvent = IEvent> extends TypedEventEmitter<TEvent> {
161
+ private readonly errorHandler;
162
+ constructor(errorHandler: (eventName: EventEmitterEventType, error: any) => void);
163
+ emit(event: EventEmitterEventType, ...args: unknown[]): boolean;
164
+ }
165
+
166
+ /**
167
+ * String used to concatenate the namespace of parent loggers and their child loggers.
168
+ * @internal
169
+ */
170
+ export declare const eventNamespaceSeparator: ":";
171
+
172
+ /**
173
+ * Inspect the given error for common "safe" props and return them.
174
+ *
175
+ * @internal
176
+ */
177
+ export declare function extractLogSafeErrorProperties(error: unknown, sanitizeStack: boolean): {
178
+ message: string;
179
+ errorType?: string | undefined;
180
+ stack?: string | undefined;
181
+ };
182
+
183
+ /**
184
+ * Extracts specific properties from the provided message that we know are safe to log.
185
+ *
186
+ * @param messageLike - Message to include info about via telemetry props.
187
+ *
188
+ * @internal
189
+ */
190
+ export declare const extractSafePropertiesFromMessage: (messageLike: Partial<Pick<ISequencedDocumentMessage, "clientId" | "sequenceNumber" | "clientSequenceNumber" | "referenceSequenceNumber" | "minimumSequenceNumber" | "timestamp">>) => {
191
+ messageClientId: string | undefined;
192
+ messageSequenceNumber: number | undefined;
193
+ messageClientSequenceNumber: number | undefined;
194
+ messageReferenceSequenceNumber: number | undefined;
195
+ messageMinimumSequenceNumber: number | undefined;
196
+ messageTimestamp: number | undefined;
197
+ };
198
+
199
+ /**
200
+ * @internal
201
+ */
202
+ export declare function formatTick(tick: number): number;
203
+
204
+ /**
205
+ * The purpose of this function is to provide ability to capture stack context quickly.
206
+ * Accessing new Error().stack is slow, and the slowest part is accessing stack property itself.
207
+ * There are scenarios where we generate error with stack, but error is handled in most cases and
208
+ * stack property is not accessed.
209
+ * For such cases it's better to not read stack property right away, but rather delay it until / if it's needed
210
+ * Some browsers will populate stack right away, others require throwing Error, so we do auto-detection on the fly.
211
+ * @returns Error object that has stack populated.
212
+ *
213
+ * @internal
214
+ */
215
+ export declare function generateErrorWithStack(): Error;
216
+
217
+ /**
218
+ * Generate a stack at this callsite as if an error were thrown from here.
219
+ * @returns the callstack (does not throw)
220
+ *
221
+ * @internal
222
+ */
223
+ export declare function generateStack(): string | undefined;
224
+
225
+ /**
226
+ * Generic wrapper for an unrecognized/uncategorized error object
227
+ *
228
+ * @internal
229
+ */
230
+ export declare class GenericError extends LoggingError implements IGenericError, IFluidErrorBase {
231
+ readonly error?: any;
232
+ readonly errorType: "genericError";
233
+ /**
234
+ * Create a new GenericError
235
+ * @param message - Error message
236
+ * @param error - inner error object
237
+ * @param props - Telemetry props to include when the error is logged
238
+ */
239
+ constructor(message: string, error?: any, props?: ITelemetryBaseProperties);
240
+ }
241
+
242
+ /**
243
+ * Borrowed from
244
+ * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value#examples}
245
+ * Avoids runtime errors with circular references.
246
+ * Not ideal, as will cut values that are not necessarily circular references.
247
+ * Could be improved by implementing Node's util.inspect() for browser (minus all the coloring code)
248
+ *
249
+ * @internal
250
+ */
251
+ export declare const getCircularReplacer: () => (key: string, value: unknown) => any;
252
+
253
+ /**
254
+ * Type guard for error data containing the {@link IFluidErrorBase.errorInstanceId} property.
255
+ *
256
+ * @internal
257
+ */
258
+ export declare const hasErrorInstanceId: (x: unknown) => x is {
259
+ errorInstanceId: string;
260
+ };
261
+
262
+ /**
263
+ * Explicitly typed interface for reading configurations.
264
+ *
265
+ * @internal
266
+ */
267
+ export declare interface IConfigProvider extends IConfigProviderBase_2 {
268
+ getBoolean(name: string): boolean | undefined;
269
+ getNumber(name: string): number | undefined;
270
+ getString(name: string): string | undefined;
271
+ getBooleanArray(name: string): boolean[] | undefined;
272
+ getNumberArray(name: string): number[] | undefined;
273
+ getStringArray(name: string): string[] | undefined;
274
+ }
275
+
276
+ /**
277
+ * Base interface for providing configurations to enable/disable/control features.
278
+ *
279
+ * @deprecated Use IConfigProviderBase from fluidFramework/core-interfaces
280
+ *
281
+ * @internal
282
+ */
283
+ export declare interface IConfigProviderBase {
284
+ getRawConfig(name: string): ConfigTypes;
285
+ }
286
+
287
+ /**
288
+ * An object that contains a callback used in conjunction with the {@link createSampledLogger} utility function to provide custom logic for sampling events.
289
+ *
290
+ * @internal
291
+ */
292
+ export declare interface IEventSampler {
293
+ /**
294
+ * @returns true if the event should be sampled or false if not
295
+ */
296
+ sample: () => boolean | undefined;
297
+ }
298
+
299
+ /**
300
+ * Metadata to annotate an error object when annotating or normalizing it
301
+ *
302
+ * @internal
303
+ */
304
+ export declare interface IFluidErrorAnnotations {
305
+ /**
306
+ * Telemetry props to log with the error
307
+ */
308
+ props?: ITelemetryBaseProperties;
309
+ }
310
+
311
+ /**
312
+ * An error emitted by the Fluid Framework.
313
+ *
314
+ * @remarks
315
+ *
316
+ * All normalized errors flowing through the Fluid Framework adhere to this readonly interface.
317
+ *
318
+ * It features the members of {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error | Error}
319
+ * made readonly, as well as {@link IFluidErrorBase.errorType} and {@link IFluidErrorBase.errorInstanceId}.
320
+ * It also features getters and setters for telemetry props to be included when the error is logged.
321
+ *
322
+ * @internal
323
+ */
324
+ export declare interface IFluidErrorBase extends Error {
325
+ /**
326
+ * Classification of what type of error this is.
327
+ *
328
+ * @remarks Used programmatically by consumers to interpret the error.
329
+ */
330
+ readonly errorType: string;
331
+ /**
332
+ * Error's message property, made readonly.
333
+ *
334
+ * @remarks
335
+ *
336
+ * Recommendations:
337
+ *
338
+ * Be specific, but also take care when including variable data to consider suitability for aggregation in telemetry.
339
+ * Also avoid including any data that jeopardizes the user's privacy. Add a tagged telemetry property instead.
340
+ */
341
+ readonly message: string;
342
+ /**
343
+ * See {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/stack}.
344
+ */
345
+ readonly stack?: string;
346
+ /**
347
+ * See {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name}.
348
+ */
349
+ readonly name: string;
350
+ /**
351
+ * A Guid identifying this error instance.
352
+ *
353
+ * @remarks
354
+ *
355
+ * Useful in telemetry for deduplicating multiple logging events arising from the same error,
356
+ * or correlating an error with an inner error that caused it, in case of error wrapping.
357
+ */
358
+ readonly errorInstanceId: string;
359
+ /**
360
+ * Get the telemetry properties stashed on this error for logging.
361
+ */
362
+ getTelemetryProperties(): ITelemetryProperties;
363
+ /**
364
+ * Add telemetry properties to this error which will be logged with the error
365
+ */
366
+ addTelemetryProperties: (props: ITelemetryProperties) => void;
367
+ }
368
+
369
+ /**
370
+ * Describes what events {@link PerformanceEvent} should log.
371
+ *
372
+ * @remarks
373
+ * By default, all events are logged, but the client can override this behavior.
374
+ *
375
+ * For example, there is rarely a need to record a start event, as we're really after
376
+ * success / failure tracking, including duration (on success).
377
+ *
378
+ * @internal
379
+ */
380
+ export declare interface IPerformanceEventMarkers {
381
+ start?: true;
382
+ end?: true;
383
+ cancel?: "generic" | "error";
384
+ }
385
+
386
+ /**
387
+ * A telemetry logger that has sampling capabilities
388
+ *
389
+ * @internal
390
+ */
391
+ export declare interface ISampledTelemetryLogger extends ITelemetryLoggerExt {
392
+ /**
393
+ * Indicates if the feature flag to disable sampling is set.
394
+ *
395
+ * @remarks Exposed to enable some advanced scenarios where the code using the sampled logger
396
+ * could take advantage of skipping the execution of some logic when it can determine
397
+ * it won't be necessary because the telemetry event that needs it wouldn't be
398
+ * emitted anyway.
399
+ */
400
+ isSamplingDisabled: boolean;
401
+ }
402
+
403
+ /**
404
+ * True for any error object that is an (optionally normalized) external error
405
+ * False for any error we created and raised within the FF codebase via LoggingError base class,
406
+ * or wrapped in a well-known error type
407
+ *
408
+ * @internal
409
+ */
410
+ export declare function isExternalError(error: unknown): boolean;
411
+
412
+ /**
413
+ * Type guard for {@link IFluidErrorBase}.
414
+ *
415
+ * @internal
416
+ */
417
+ export declare function isFluidError(error: unknown): error is IFluidErrorBase;
418
+
419
+ /**
420
+ * Type-guard for {@link @fluidframework/core-interfaces#ILoggingError}.
421
+ *
422
+ * @internal
423
+ */
424
+ export declare const isILoggingError: (x: unknown) => x is ILoggingError;
425
+
426
+ /**
427
+ * Type guard to identify if a particular telemetry property appears to be a
428
+ * {@link @fluidframework/core-interfaces#Tagged} telemetry property.
429
+ *
430
+ * @internal
431
+ */
432
+ export declare function isTaggedTelemetryPropertyValue(x: Tagged<TelemetryEventPropertyTypeExt> | TelemetryEventPropertyTypeExt): x is Tagged<TelemetryEventPropertyTypeExt>;
433
+
434
+ /**
435
+ * Type guard for old standard of valid/known errors.
436
+ *
437
+ * @internal
438
+ */
439
+ export declare function isValidLegacyError(error: unknown): error is Omit<IFluidErrorBase, "errorInstanceId">;
440
+
441
+ /**
442
+ * A property to be logged to telemetry containing both the value and a tag. Tags are generic strings that can be used
443
+ * to mark pieces of information that should be organized or handled differently by loggers in various first or third
444
+ * party scenarios. For example, tags are used to mark personal information that should not be stored in logs.
445
+ *
446
+ * @deprecated Use {@link @fluidframework/core-interfaces#Tagged}\<{@link TelemetryEventPropertyTypeExt}\>
447
+ * @internal
448
+ */
449
+ export declare interface ITaggedTelemetryPropertyTypeExt {
450
+ value: TelemetryEventPropertyTypeExt;
451
+ tag: string;
452
+ }
453
+
454
+ /**
455
+ * Error telemetry event.
456
+ * @remarks Maps to category = "error"
457
+ * @alpha
458
+ */
459
+ export declare interface ITelemetryErrorEventExt extends ITelemetryPropertiesExt {
460
+ eventName: string;
461
+ }
462
+
463
+ /**
464
+ * Interface for logging telemetry statements.
465
+ * @remarks May contain any number of properties that get serialized as json payload.
466
+ * @param category - category of the event, like "error", "performance", "generic", etc.
467
+ * @param eventName - name of the event.
468
+ *
469
+ * @internal
470
+ */
471
+ export declare interface ITelemetryEventExt extends ITelemetryPropertiesExt {
472
+ category: string;
473
+ eventName: string;
474
+ }
475
+
476
+ /**
477
+ * Informational (non-error) telemetry event
478
+ * @remarks Maps to category = "generic"
479
+ * @alpha
480
+ */
481
+ export declare interface ITelemetryGenericEventExt extends ITelemetryPropertiesExt {
482
+ eventName: string;
483
+ category?: TelemetryEventCategory;
484
+ }
485
+
486
+ /**
487
+ * An extended {@link @fluidframework/core-interfaces#ITelemetryBaseLogger} which allows for more lenient event types.
488
+ *
489
+ * @remarks
490
+ * This interface is meant to be used internally within the Fluid Framework,
491
+ * and `ITelemetryBaseLogger` should be used when loggers are passed between layers.
492
+ * @alpha
493
+ */
494
+ export declare interface ITelemetryLoggerExt extends ITelemetryBaseLogger {
495
+ /**
496
+ * Send information telemetry event
497
+ * @param event - Event to send
498
+ * @param error - optional error object to log
499
+ * @param logLevel - optional level of the log.
500
+ */
501
+ sendTelemetryEvent(event: ITelemetryGenericEventExt, error?: unknown, logLevel?: typeof LogLevel.verbose | typeof LogLevel.default): void;
502
+ /**
503
+ * Send error telemetry event
504
+ * @param event - Event to send
505
+ * @param error - optional error object to log
506
+ */
507
+ sendErrorEvent(event: ITelemetryErrorEventExt, error?: unknown): void;
508
+ /**
509
+ * Send performance telemetry event
510
+ * @param event - Event to send
511
+ * @param error - optional error object to log
512
+ * @param logLevel - optional level of the log.
513
+ */
514
+ sendPerformanceEvent(event: ITelemetryPerformanceEventExt, error?: unknown, logLevel?: typeof LogLevel.verbose | typeof LogLevel.default): void;
515
+ }
516
+
517
+ /**
518
+ * @internal
519
+ */
520
+ export declare interface ITelemetryLoggerPropertyBag {
521
+ [index: string]: TelemetryEventPropertyTypes | (() => TelemetryEventPropertyTypes);
522
+ }
523
+
524
+ /**
525
+ * @internal
526
+ */
527
+ export declare interface ITelemetryLoggerPropertyBags {
528
+ all?: ITelemetryLoggerPropertyBag;
529
+ error?: ITelemetryLoggerPropertyBag;
530
+ }
531
+
532
+ /**
533
+ * Performance telemetry event.
534
+ * @remarks Maps to category = "performance"
535
+ * @alpha
536
+ */
537
+ export declare interface ITelemetryPerformanceEventExt extends ITelemetryGenericEventExt {
538
+ duration?: number;
539
+ }
540
+
541
+ /**
542
+ * JSON-serializable properties, which will be logged with telemetry.
543
+ *
544
+ * @alpha
545
+ */
546
+ export declare interface ITelemetryPropertiesExt {
547
+ [index: string]: TelemetryEventPropertyTypeExt | Tagged<TelemetryEventPropertyTypeExt>;
548
+ }
549
+
550
+ /**
551
+ * Creates a {@link MonitoringContext} from the provided logger, if it isn't already one.
552
+ *
553
+ * @internal
554
+ */
555
+ export declare function loggerToMonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt>(logger: L): MonitoringContext<L>;
556
+
557
+ /**
558
+ * Base class for "trusted" errors we create, whose properties can generally be logged to telemetry safely.
559
+ * All properties set on the object, or passed in (via the constructor or addTelemetryProperties),
560
+ * will be logged in accordance with their tag, if present.
561
+ *
562
+ * PLEASE take care to avoid setting sensitive data on this object without proper tagging!
563
+ *
564
+ * @internal
565
+ */
566
+ export declare class LoggingError extends Error implements ILoggingError, Omit<IFluidErrorBase, "errorType"> {
567
+ private readonly omitPropsFromLogging;
568
+ private _errorInstanceId;
569
+ get errorInstanceId(): string;
570
+ overwriteErrorInstanceId(id: string): void;
571
+ /**
572
+ * Backwards compatibility to appease {@link isFluidError} in old code that may handle this error.
573
+ */
574
+ private readonly fluidErrorCode;
575
+ /**
576
+ * Create a new LoggingError
577
+ * @param message - Error message to use for Error base class
578
+ * @param props - telemetry props to include on the error for when it's logged
579
+ * @param omitPropsFromLogging - properties by name to omit from telemetry props
580
+ */
581
+ constructor(message: string, props?: ITelemetryBaseProperties, omitPropsFromLogging?: Set<string>);
582
+ /**
583
+ * Determines if a given object is an instance of a LoggingError
584
+ * @param object - any object
585
+ * @returns true if the object is an instance of a LoggingError, false if not.
586
+ */
587
+ static typeCheck(object: unknown): object is LoggingError;
588
+ /**
589
+ * Add additional properties to be logged
590
+ */
591
+ addTelemetryProperties(props: ITelemetryBaseProperties): void;
592
+ /**
593
+ * Get all properties fit to be logged to telemetry for this error
594
+ */
595
+ getTelemetryProperties(): ITelemetryBaseProperties;
596
+ }
597
+
598
+ /**
599
+ * Like assert, but logs only if the condition is false, rather than throwing
600
+ * @param condition - The condition to attest too
601
+ * @param logger - The logger to log with
602
+ * @param event - The string or event to log
603
+ * @returns The outcome of the condition
604
+ *
605
+ * @internal
606
+ *
607
+ * @deprecated
608
+ * This API will be removed in a future release.
609
+ * No replacement API is intended, but reproducing its behavior should be trivial for anyone who needs it.
610
+ */
611
+ export declare function logIfFalse(condition: unknown, logger: ITelemetryBaseLogger, event: string | ITelemetryGenericEvent): condition is true;
612
+
613
+ /**
614
+ * Creates a {@link MonitoringContext} from the provided logger.
615
+ *
616
+ * @remarks
617
+ * Assumes that the provided logger is not itself already a {@link MonitoringContext}, and will throw an error if it is.
618
+ * If you are unsure, use {@link loggerToMonitoringContext} instead.
619
+ *
620
+ * @throws If the provided logger is already a {@link MonitoringContext}.
621
+ *
622
+ * @internal
623
+ */
624
+ export declare function mixinMonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt>(logger: L, ...configs: (IConfigProviderBase_2 | undefined)[]): MonitoringContext<L>;
625
+
626
+ /**
627
+ * The MockLogger records events sent to it, and then can walk back over those events
628
+ * searching for a set of expected events to match against the logged events.
629
+ *
630
+ * @internal
631
+ */
632
+ export declare class MockLogger implements ITelemetryBaseLogger {
633
+ readonly minLogLevel?: LogLevel | undefined;
634
+ events: ITelemetryBaseEvent[];
635
+ constructor(minLogLevel?: LogLevel | undefined);
636
+ clear(): void;
637
+ toTelemetryLogger(): ITelemetryLoggerExt;
638
+ send(event: ITelemetryBaseEvent): void;
639
+ /**
640
+ * Search events logged since the last time matchEvents was called, looking for the given expected
641
+ * events in order.
642
+ * @param expectedEvents - events in order that are expected to appear in the recorded log.
643
+ * @param inlineDetailsProp - true if the "details" property in the actual event should be extracted and inlined.
644
+ * These event objects may be subsets of the logged events.
645
+ * Note: category is omitted from the type because it's usually uninteresting and tedious to type.
646
+ */
647
+ matchEvents(expectedEvents: Omit<ITelemetryBaseEvent, "category">[], inlineDetailsProp?: boolean): boolean;
648
+ /**
649
+ * Asserts that matchEvents is true, and prints the actual/expected output if not.
650
+ */
651
+ assertMatch(expectedEvents: Omit<ITelemetryBaseEvent, "category">[], message?: string, inlineDetailsProp?: boolean): void;
652
+ /**
653
+ * Search events logged since the last time matchEvents was called, looking for any of the given
654
+ * expected events.
655
+ * @param expectedEvents - events that are expected to appear in the recorded log.
656
+ * @param inlineDetailsProp - true if the "details" property in the actual event should be extracted and inlined.
657
+ * These event objects may be subsets of the logged events.
658
+ * Note: category is omitted from the type because it's usually uninteresting and tedious to type.
659
+ * @returns if any of the expected events is found.
660
+ */
661
+ matchAnyEvent(expectedEvents: Omit<ITelemetryBaseEvent, "category">[], inlineDetailsProp?: boolean): boolean;
662
+ /**
663
+ * Asserts that matchAnyEvent is true, and prints the actual/expected output if not.
664
+ */
665
+ assertMatchAny(expectedEvents: Omit<ITelemetryBaseEvent, "category">[], message?: string, inlineDetailsProp?: boolean): void;
666
+ /**
667
+ * Search events logged since the last time matchEvents was called, looking only for the given expected
668
+ * events in order.
669
+ * @param expectedEvents - events in order that are expected to be the only events in the recorded log.
670
+ * @param inlineDetailsProp - true if the "details" property in the actual event should be extracted and inlined.
671
+ * These event objects may be subsets of the logged events.
672
+ * Note: category is omitted from the type because it's usually uninteresting and tedious to type.
673
+ */
674
+ matchEventStrict(expectedEvents: Omit<ITelemetryBaseEvent, "category">[], inlineDetailsProp?: boolean): boolean;
675
+ /**
676
+ * Asserts that matchEvents is true, and prints the actual/expected output if not
677
+ */
678
+ assertMatchStrict(expectedEvents: Omit<ITelemetryBaseEvent, "category">[], message?: string, inlineDetailsProp?: boolean): void;
679
+ /**
680
+ * Asserts that matchAnyEvent is false for the given events, and prints the actual/expected output if not
681
+ */
682
+ assertMatchNone(disallowedEvents: Omit<ITelemetryBaseEvent, "category">[], message?: string, inlineDetailsProp?: boolean): void;
683
+ private getMatchedEventsCount;
684
+ /**
685
+ * Ensure the expected event is a strict subset of the actual event
686
+ */
687
+ private static eventsMatch;
688
+ }
689
+
690
+ /**
691
+ * A type containing both a telemetry logger and a configuration provider.
692
+ *
693
+ * @internal
694
+ */
695
+ export declare interface MonitoringContext<L extends ITelemetryBaseLogger = ITelemetryLoggerExt> {
696
+ config: IConfigProvider;
697
+ logger: L;
698
+ }
699
+
700
+ /**
701
+ * Input properties for {@link createMultiSinkLogger}.
702
+ *
703
+ * @internal
704
+ */
705
+ export declare interface MultiSinkLoggerProperties {
706
+ /**
707
+ * Will be prefixed to all event names.
708
+ */
709
+ namespace?: string;
710
+ /**
711
+ * Default properties that will be applied to all events flowing through this logger.
712
+ */
713
+ properties?: ITelemetryLoggerPropertyBags;
714
+ /**
715
+ * The base loggers that this logger will forward the logs to, after it processes them.
716
+ */
717
+ loggers?: (ITelemetryBaseLogger | undefined)[];
718
+ /**
719
+ * If true, the logger will attempt to copy the custom properties (if they are of a known type, i.e. one from this package) of all the base loggers passed to it, to apply them itself to logs that flow through.
720
+ */
721
+ tryInheritProperties?: true;
722
+ }
723
+
724
+ /**
725
+ * The Error class used when normalizing an external error
726
+ *
727
+ * @internal
728
+ */
729
+ export declare const NORMALIZED_ERROR_TYPE = "genericError";
730
+
731
+ /**
732
+ * Normalize the given error yielding a valid Fluid Error
733
+ * @returns A valid Fluid Error with any provided annotations applied
734
+ * @param error - The error to normalize
735
+ * @param annotations - Annotations to apply to the normalized error
736
+ *
737
+ * @internal
738
+ */
739
+ export declare function normalizeError(error: unknown, annotations?: IFluidErrorAnnotations): IFluidErrorBase;
740
+
741
+ /**
742
+ * Attempts to parse number from string.
743
+ * If it fails, it will return the original string.
744
+ *
745
+ * @remarks
746
+ * Used to make telemetry data typed (and support math operations, like comparison),
747
+ * in places where we do expect numbers (like contentsize/duration property in http header).
748
+ *
749
+ * @internal
750
+ */
751
+ export declare function numberFromString(str: string | null | undefined): string | number | undefined;
752
+
753
+ /**
754
+ * Attempts to overwrite the error's stack
755
+ *
756
+ * There have been reports of certain JS environments where overwriting stack will throw.
757
+ * If that happens, this adds the given stack as the telemetry property "stack2"
758
+ *
759
+ * @internal
760
+ */
761
+ export declare function overwriteStack(error: IFluidErrorBase | LoggingError, stack: string): void;
762
+
763
+ /**
764
+ * Helper class to log performance events.
765
+ *
766
+ * @internal
767
+ */
768
+ export declare class PerformanceEvent {
769
+ private readonly logger;
770
+ private readonly markers;
771
+ private readonly recordHeapSize;
772
+ private readonly emitLogs;
773
+ /**
774
+ * Creates an instance of {@link PerformanceEvent} and starts measurements
775
+ * @param logger - the logger to be used for publishing events
776
+ * @param event - the logging event details which will be published with the performance measurements
777
+ * @param markers - See {@link IPerformanceEventMarkers}
778
+ * @param recordHeapSize - whether or not to also record memory performance
779
+ * @param emitLogs - should this instance emit logs. If set to false, logs will not be emitted to the logger,
780
+ * but measurements will still be performed and any specified markers will be generated.
781
+ * @returns An instance of {@link PerformanceEvent}
782
+ */
783
+ static start(logger: ITelemetryLoggerExt, event: ITelemetryGenericEvent, markers?: IPerformanceEventMarkers, recordHeapSize?: boolean, emitLogs?: boolean): PerformanceEvent;
784
+ /**
785
+ * Measure a synchronous task
786
+ * @param logger - the logger to be used for publishing events
787
+ * @param event - the logging event details which will be published with the performance measurements
788
+ * @param callback - the task to be executed and measured
789
+ * @param markers - See {@link IPerformanceEventMarkers}
790
+ * @param sampleThreshold - events with the same name and category will be sent to the logger
791
+ * only when we hit this many executions of the task. If unspecified, all events will be sent.
792
+ * @returns The results of the executed task
793
+ *
794
+ * @remarks Note that if the "same" event (category + eventName) would be emitted by different
795
+ * tasks (`callback`), `sampleThreshold` is still applied only based on the event's category + eventName,
796
+ * so executing either of the tasks will increase the internal counter and they
797
+ * effectively "share" the sampling rate for the event.
798
+ */
799
+ static timedExec<T>(logger: ITelemetryLoggerExt, event: ITelemetryGenericEvent, callback: (event: PerformanceEvent) => T, markers?: IPerformanceEventMarkers, sampleThreshold?: number): T;
800
+ /**
801
+ * Measure an asynchronous task
802
+ * @param logger - the logger to be used for publishing events
803
+ * @param event - the logging event details which will be published with the performance measurements
804
+ * @param callback - the task to be executed and measured
805
+ * @param markers - See {@link IPerformanceEventMarkers}
806
+ * @param recordHeapSize - whether or not to also record memory performance
807
+ * @param sampleThreshold - events with the same name and category will be sent to the logger
808
+ * only when we hit this many executions of the task. If unspecified, all events will be sent.
809
+ * @returns The results of the executed task
810
+ *
811
+ * @remarks Note that if the "same" event (category + eventName) would be emitted by different
812
+ * tasks (`callback`), `sampleThreshold` is still applied only based on the event's category + eventName,
813
+ * so executing either of the tasks will increase the internal counter and they
814
+ * effectively "share" the sampling rate for the event.
815
+ */
816
+ static timedExecAsync<T>(logger: ITelemetryLoggerExt, event: ITelemetryGenericEvent, callback: (event: PerformanceEvent) => Promise<T>, markers?: IPerformanceEventMarkers, recordHeapSize?: boolean, sampleThreshold?: number): Promise<T>;
817
+ get duration(): number;
818
+ private event?;
819
+ private readonly startTime;
820
+ private startMark?;
821
+ private startMemoryCollection;
822
+ protected constructor(logger: ITelemetryLoggerExt, event: ITelemetryGenericEvent, markers?: IPerformanceEventMarkers, recordHeapSize?: boolean, emitLogs?: boolean);
823
+ reportProgress(props?: ITelemetryProperties, eventNameSuffix?: string): void;
824
+ private autoEnd;
825
+ end(props?: ITelemetryProperties): void;
826
+ private performanceEndMark;
827
+ cancel(props?: ITelemetryProperties, error?: unknown): void;
828
+ /**
829
+ * Report the event, if it hasn't already been reported.
830
+ */
831
+ reportEvent(eventNameSuffix: string, props?: ITelemetryProperties, error?: unknown): void;
832
+ private static readonly eventHits;
833
+ private static shouldReport;
834
+ }
835
+
836
+ /**
837
+ * Raises events pertaining to the connection
838
+ * @param logger - The logger to log telemetry
839
+ * @param emitter - The event emitter instance
840
+ * @param connected - A boolean tracking whether the connection was in a connected state or not
841
+ * @param clientId - The connected/disconnected clientId
842
+ * @param disconnectedReason - The reason for the connection to be disconnected (Used for telemetry purposes only)
843
+ *
844
+ * @internal
845
+ */
846
+ export declare function raiseConnectedEvent(logger: ITelemetryLoggerExt, emitter: EventEmitter, connected: boolean, clientId?: string, disconnectedReason?: string): void;
847
+
848
+ /**
849
+ * @internal
850
+ */
851
+ export declare function safeRaiseEvent(emitter: EventEmitter, logger: ITelemetryLoggerExt, event: string, ...args: unknown[]): void;
852
+
853
+ /**
854
+ * Helper class that executes a specified code block and writes an
855
+ * {@link @fluidframework/core-interfaces#ITelemetryPerformanceEvent} to a specified logger every time a specified
856
+ * number of executions is reached (or when the class is disposed).
857
+ *
858
+ * The `duration` field in the telemetry event is the duration of the latest execution (sample) of the specified
859
+ * function. See the documentation of the `includeAggregateMetrics` parameter for additional details that can be
860
+ * included.
861
+ *
862
+ * @internal
863
+ */
864
+ export declare class SampledTelemetryHelper implements IDisposable {
865
+ private readonly eventBase;
866
+ private readonly logger;
867
+ private readonly sampleThreshold;
868
+ private readonly includeAggregateMetrics;
869
+ private readonly perBucketProperties;
870
+ disposed: boolean;
871
+ private readonly measurementsMap;
872
+ /**
873
+ * @param eventBase -
874
+ * Custom properties to include in the telemetry performance event when it is written.
875
+ * @param logger -
876
+ * The logger to use to write the telemetry performance event.
877
+ * @param sampleThreshold -
878
+ * Telemetry performance events will be generated every time we hit this many executions of the code block.
879
+ * @param includeAggregateMetrics -
880
+ * If set to `true`, the telemetry performance event will include aggregated metrics (total duration, min duration,
881
+ * max duration) for all the executions in between generated events.
882
+ * @param perBucketProperties -
883
+ * Map of strings that represent different buckets (which can be specified when calling the 'measure' method), to
884
+ * properties which should be added to the telemetry event for that bucket. If a bucket being measured does not
885
+ * have an entry in this map, no additional properties will be added to its telemetry events. The following keys are
886
+ * reserved for use by this class: "duration", "count", "totalDuration", "minDuration", "maxDuration". If any of
887
+ * them is specified as a key in one of the ITelemetryProperties objects in this map, that key-value pair will be
888
+ * ignored.
889
+ */
890
+ constructor(eventBase: ITelemetryGenericEvent, logger: ITelemetryLoggerExt, sampleThreshold: number, includeAggregateMetrics?: boolean, perBucketProperties?: Map<string, ITelemetryProperties>);
891
+ /**
892
+ * Executes the specified code and keeps track of execution time statistics.
893
+ * If it's been called enough times (the sampleThreshold for the class) then it generates a log message with the necessary information.
894
+ *
895
+ * @param codeToMeasure - The code to be executed and measured.
896
+ * @param bucket - A key to track executions of the code block separately.
897
+ * Each different value of this parameter has a separate set of executions and metrics tracked by the class.
898
+ * If no such distinction needs to be made, do not provide a value.
899
+ * @returns Whatever the passed-in code block returns.
900
+ */
901
+ measure<T>(codeToMeasure: () => T, bucket?: string): T;
902
+ private flushBucket;
903
+ dispose(error?: Error | undefined): void;
904
+ }
905
+
906
+ /**
907
+ * Creates a base configuration provider based on `sessionStorage`
908
+ *
909
+ * @returns A lazy initialized base configuration provider with `sessionStorage` as the underlying config store
910
+ *
911
+ * @internal
912
+ */
913
+ export declare const sessionStorageConfigProvider: Lazy<IConfigProviderBase_2>;
914
+
915
+ /**
916
+ * Tags all provided `values` as {@link TelemetryDataTag.CodeArtifact}.
917
+ *
918
+ * @param values - The values to be tagged.
919
+ *
920
+ * @remarks
921
+ * It supports properties of type {@link @fluidframework/core-interfaces#TelemetryBaseEventPropertyType},
922
+ * as well as callbacks that return that type.
923
+ *
924
+ * @example Sample usage
925
+ * ```typescript
926
+ * {
927
+ * // ...Other properties being added to a telemetry event
928
+ * ...tagCodeArtifacts("someTag", {foo: 1, bar: 2}),
929
+ * // ...
930
+ * }
931
+ * ```
932
+ * This will result in `foo` and `bar` added to the event with their values tagged as {@link TelemetryDataTag.CodeArtifact}.
933
+ *
934
+ * @see {@link tagData}
935
+ *
936
+ * @internal
937
+ */
938
+ export declare const tagCodeArtifacts: <T extends Record<string, TelemetryEventPropertyType | (() => TelemetryBaseEventPropertyType)>>(values: T) => { [P in keyof T]: (T[P] extends () => TelemetryBaseEventPropertyType ? () => {
939
+ value: ReturnType<T[P]>;
940
+ tag: TelemetryDataTag.CodeArtifact;
941
+ } : {
942
+ value: Exclude<T[P], undefined>;
943
+ tag: TelemetryDataTag.CodeArtifact;
944
+ }) | (T[P] extends undefined ? undefined : never); };
945
+
946
+ /**
947
+ * Tags all given `values` with the same `tag`.
948
+ *
949
+ * @param tag - The tag with which all `values` will be annotated.
950
+ * @param values - The values to be tagged.
951
+ *
952
+ * @remarks
953
+ * It supports properties of type {@link @fluidframework/core-interfaces#TelemetryBaseEventPropertyType},
954
+ * as well as callbacks that return that type.
955
+ *
956
+ * @example Sample usage
957
+ * ```typescript
958
+ * {
959
+ * // ...Other properties being added to a telemetry event
960
+ * ...tagData("someTag", {foo: 1, bar: 2}),
961
+ * // ...
962
+ * }
963
+ * ```
964
+ * This will result in `foo` and `bar` added to the event with their values tagged.
965
+ *
966
+ * @internal
967
+ */
968
+ export declare const tagData: <T extends TelemetryDataTag, V extends Record<string, TelemetryEventPropertyType | (() => TelemetryBaseEventPropertyType)>>(tag: T, values: V) => { [P in keyof V]: (V[P] extends () => TelemetryBaseEventPropertyType ? () => {
969
+ value: ReturnType<V[P]>;
970
+ tag: T;
971
+ } : {
972
+ value: Exclude<V[P], undefined>;
973
+ tag: T;
974
+ }) | (V[P] extends undefined ? undefined : never); };
975
+
976
+ /**
977
+ * @deprecated 0.56, remove TaggedLoggerAdapter once its usage is removed from
978
+ * container-runtime. Issue: #8191
979
+ * TaggedLoggerAdapter class can add tag handling to your logger.
980
+ *
981
+ * @internal
982
+ */
983
+ export declare class TaggedLoggerAdapter implements ITelemetryBaseLogger {
984
+ private readonly logger;
985
+ constructor(logger: ITelemetryBaseLogger);
986
+ /**
987
+ * {@inheritDoc @fluidframework/core-interfaces#ITelemetryBaseLogger.send}
988
+ */
989
+ send(eventWithTagsMaybe: ITelemetryBaseEvent): void;
990
+ }
991
+
992
+ /**
993
+ * Broad classifications to be applied to individual properties as they're prepared to be logged to telemetry.
994
+ *
995
+ * @privateRemarks Please do not modify existing entries, to maintain backwards compatibility.
996
+ *
997
+ * @internal
998
+ */
999
+ export declare enum TelemetryDataTag {
1000
+ /**
1001
+ * Data containing terms or IDs from code packages that may have been dynamically loaded
1002
+ */
1003
+ CodeArtifact = "CodeArtifact",
1004
+ /**
1005
+ * Personal data of a variety of classifications that pertains to the user
1006
+ */
1007
+ UserData = "UserData"
1008
+ }
1009
+
1010
+ /**
1011
+ * The categories FF uses when instrumenting the code.
1012
+ *
1013
+ * generic - Informational log event
1014
+ *
1015
+ * error - Error log event, ideally 0 of these are logged during a session
1016
+ *
1017
+ * performance - Includes duration, and often has _start, _end, or _cancel suffixes for activity tracking
1018
+ * @alpha
1019
+ */
1020
+ export declare type TelemetryEventCategory = "generic" | "error" | "performance";
1021
+
1022
+ /**
1023
+ * Property types that can be logged.
1024
+ *
1025
+ * @remarks
1026
+ * Includes extra types beyond {@link @fluidframework/core-interfaces#TelemetryBaseEventPropertyType}, which must be
1027
+ * converted before sending to a base logger.
1028
+ *
1029
+ * @alpha
1030
+ */
1031
+ export declare type TelemetryEventPropertyTypeExt = string | number | boolean | undefined | (string | number | boolean)[] | {
1032
+ [key: string]: // Flat objects can have the same properties as the event itself
1033
+ string | number | boolean | undefined | (string | number | boolean)[];
1034
+ };
1035
+
1036
+ /**
1037
+ * @internal
1038
+ */
1039
+ export declare type TelemetryEventPropertyTypes = ITelemetryBaseProperties[string];
1040
+
1041
+ /**
1042
+ * Null logger that no-ops for all telemetry events passed to it.
1043
+ *
1044
+ * @deprecated This will be removed in a future release.
1045
+ * For internal use within the FluidFramework codebase, use {@link createChildLogger} with no arguments instead.
1046
+ * For external consumers we recommend writing a trivial implementation of {@link @fluidframework/core-interfaces#ITelemetryBaseLogger}
1047
+ * where the send() method does nothing and using that.
1048
+ *
1049
+ * @internal
1050
+ */
1051
+ export declare class TelemetryNullLogger implements ITelemetryLoggerExt {
1052
+ send(event: ITelemetryBaseEvent): void;
1053
+ sendTelemetryEvent(event: ITelemetryGenericEvent, error?: unknown): void;
1054
+ sendErrorEvent(event: ITelemetryErrorEvent, error?: unknown): void;
1055
+ sendPerformanceEvent(event: ITelemetryPerformanceEvent, error?: unknown): void;
1056
+ }
1057
+
1058
+ /**
1059
+ * Utility counter which will send event only if the provided value is above a configured threshold.
1060
+ *
1061
+ * @internal
1062
+ */
1063
+ export declare class ThresholdCounter {
1064
+ private readonly threshold;
1065
+ private readonly logger;
1066
+ private thresholdMultiple;
1067
+ constructor(threshold: number, logger: ITelemetryLoggerExt, thresholdMultiple?: number);
1068
+ /**
1069
+ * Sends the value if it's above the treshold.
1070
+ */
1071
+ send(eventName: string, value: number): void;
1072
+ /**
1073
+ * Sends the value if it's above the threshold
1074
+ * and a multiple of the threshold.
1075
+ *
1076
+ * To be used in scenarios where we'd like to record a
1077
+ * threshold violation while reducing telemetry noise.
1078
+ */
1079
+ sendIfMultiple(eventName: string, value: number): void;
1080
+ }
1081
+
1082
+ /**
1083
+ * Error indicating an API is being used improperly resulting in an invalid operation.
1084
+ *
1085
+ * @internal
1086
+ */
1087
+ export declare class UsageError extends LoggingError implements IUsageError, IFluidErrorBase {
1088
+ readonly errorType: "usageError";
1089
+ constructor(message: string, props?: ITelemetryBaseProperties);
1090
+ }
1091
+
1092
+ /**
1093
+ * Throws a UsageError with the given message if the condition is not met.
1094
+ * Use this API when `false` indicates a precondition is not met on a public API (for any FF layer).
1095
+ *
1096
+ * @param condition - The condition that should be true, if the condition is false a UsageError will be thrown.
1097
+ * @param message - The message to include in the error when the condition does not hold.
1098
+ * @param props - Telemetry props to include on the error when the condition does not hold.
1099
+ * @internal
1100
+ */
1101
+ export declare function validatePrecondition(condition: boolean, message: string, props?: ITelemetryBaseProperties): asserts condition;
1102
+
1103
+ /**
1104
+ * Create a new error using newErrorFn, wrapping and caused by the given unknown error.
1105
+ * Copies the inner error's stack, errorInstanceId and telemetry props over to the new error if present
1106
+ * @param innerError - An error from untrusted/unknown origins
1107
+ * @param newErrorFn - callback that will create a new error given the original error's message
1108
+ * @returns A new error object "wrapping" the given error
1109
+ *
1110
+ * @internal
1111
+ */
1112
+ export declare function wrapError<T extends LoggingError>(innerError: unknown, newErrorFn: (message: string) => T): T;
1113
+
1114
+ /**
1115
+ * The same as wrapError, but also logs the innerError, including the wrapping error's instance ID.
1116
+ *
1117
+ * @typeParam T - The kind of wrapper error to create.
1118
+ *
1119
+ * @internal
1120
+ */
1121
+ export declare function wrapErrorAndLog<T extends LoggingError>(innerError: unknown, newErrorFn: (message: string) => T, logger: ITelemetryLoggerExt): T;
1122
+
1123
+ export { }