@fluidframework/telemetry-utils 2.0.0-internal.7.1.1 → 2.0.0-internal.7.2.1

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