@fluidframework/telemetry-utils 2.0.0-rc.4.0.6 → 2.0.0-rc.5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.cjs +1 -1
- package/CHANGELOG.md +27 -0
- package/api-extractor/api-extractor-lint-bundle.json +5 -0
- package/api-extractor/api-extractor-lint-legacy.cjs.json +5 -0
- package/api-extractor/api-extractor-lint-legacy.esm.json +5 -0
- package/api-extractor/api-extractor-lint-public.cjs.json +5 -0
- package/api-extractor/api-extractor-lint-public.esm.json +5 -0
- package/api-extractor.json +1 -1
- package/api-report/telemetry-utils.alpha.api.md +107 -0
- package/api-report/telemetry-utils.beta.api.md +29 -0
- package/api-report/telemetry-utils.public.api.md +29 -0
- package/biome.jsonc +4 -0
- package/dist/config.d.ts +2 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/error.d.ts +5 -5
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js.map +1 -1
- package/dist/errorLogging.d.ts +2 -6
- package/dist/errorLogging.d.ts.map +1 -1
- package/dist/errorLogging.js +22 -29
- package/dist/errorLogging.js.map +1 -1
- package/dist/eventEmitterWithErrorHandling.d.ts +2 -2
- package/dist/eventEmitterWithErrorHandling.d.ts.map +1 -1
- package/dist/eventEmitterWithErrorHandling.js.map +1 -1
- package/dist/events.js.map +1 -1
- package/dist/fluidErrorBase.d.ts +0 -6
- package/dist/fluidErrorBase.d.ts.map +1 -1
- package/dist/fluidErrorBase.js +1 -12
- package/dist/fluidErrorBase.js.map +1 -1
- package/dist/index.d.ts +8 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +3 -5
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js.map +1 -1
- package/dist/mathTools.d.ts +13 -0
- package/dist/mathTools.d.ts.map +1 -0
- package/dist/mathTools.js +20 -0
- package/dist/mathTools.js.map +1 -0
- package/dist/mockLogger.d.ts +99 -19
- package/dist/mockLogger.d.ts.map +1 -1
- package/dist/mockLogger.js +120 -33
- package/dist/mockLogger.js.map +1 -1
- package/dist/sampledTelemetryHelper.d.ts +6 -2
- package/dist/sampledTelemetryHelper.d.ts.map +1 -1
- package/dist/sampledTelemetryHelper.js +11 -3
- package/dist/sampledTelemetryHelper.js.map +1 -1
- package/dist/telemetryEventBatcher.d.ts +64 -0
- package/dist/telemetryEventBatcher.d.ts.map +1 -0
- package/dist/telemetryEventBatcher.js +86 -0
- package/dist/telemetryEventBatcher.js.map +1 -0
- package/dist/telemetryTypes.d.ts +32 -18
- package/dist/telemetryTypes.d.ts.map +1 -1
- package/dist/telemetryTypes.js.map +1 -1
- package/dist/thresholdCounter.d.ts +1 -1
- package/dist/thresholdCounter.d.ts.map +1 -1
- package/dist/thresholdCounter.js.map +1 -1
- package/dist/utils.d.ts +14 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +30 -2
- package/dist/utils.js.map +1 -1
- package/lib/config.d.ts +2 -2
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js.map +1 -1
- package/lib/error.d.ts +5 -5
- package/lib/error.d.ts.map +1 -1
- package/lib/error.js.map +1 -1
- package/lib/errorLogging.d.ts +2 -6
- package/lib/errorLogging.d.ts.map +1 -1
- package/lib/errorLogging.js +23 -30
- package/lib/errorLogging.js.map +1 -1
- package/lib/eventEmitterWithErrorHandling.d.ts +2 -2
- package/lib/eventEmitterWithErrorHandling.d.ts.map +1 -1
- package/lib/eventEmitterWithErrorHandling.js.map +1 -1
- package/lib/events.js.map +1 -1
- package/lib/fluidErrorBase.d.ts +0 -6
- package/lib/fluidErrorBase.d.ts.map +1 -1
- package/lib/fluidErrorBase.js +0 -10
- package/lib/fluidErrorBase.js.map +1 -1
- package/lib/index.d.ts +8 -7
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -3
- package/lib/index.js.map +1 -1
- package/lib/logger.d.ts +3 -5
- package/lib/logger.d.ts.map +1 -1
- package/lib/logger.js.map +1 -1
- package/lib/mathTools.d.ts +13 -0
- package/lib/mathTools.d.ts.map +1 -0
- package/lib/mathTools.js +16 -0
- package/lib/mathTools.js.map +1 -0
- package/lib/mockLogger.d.ts +99 -19
- package/lib/mockLogger.d.ts.map +1 -1
- package/lib/mockLogger.js +118 -32
- package/lib/mockLogger.js.map +1 -1
- package/lib/sampledTelemetryHelper.d.ts +6 -2
- package/lib/sampledTelemetryHelper.d.ts.map +1 -1
- package/lib/sampledTelemetryHelper.js +11 -3
- package/lib/sampledTelemetryHelper.js.map +1 -1
- package/lib/telemetryEventBatcher.d.ts +64 -0
- package/lib/telemetryEventBatcher.d.ts.map +1 -0
- package/lib/telemetryEventBatcher.js +82 -0
- package/lib/telemetryEventBatcher.js.map +1 -0
- package/lib/telemetryTypes.d.ts +32 -18
- package/lib/telemetryTypes.d.ts.map +1 -1
- package/lib/telemetryTypes.js.map +1 -1
- package/lib/thresholdCounter.d.ts +1 -1
- package/lib/thresholdCounter.d.ts.map +1 -1
- package/lib/thresholdCounter.js.map +1 -1
- package/lib/tsdoc-metadata.json +1 -1
- package/lib/utils.d.ts +14 -2
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +28 -1
- package/lib/utils.js.map +1 -1
- package/package.json +30 -16
- package/src/config.ts +16 -16
- package/src/error.ts +13 -13
- package/src/errorLogging.ts +32 -46
- package/src/eventEmitterWithErrorHandling.ts +3 -3
- package/src/fluidErrorBase.ts +0 -15
- package/src/index.ts +17 -16
- package/src/logger.ts +21 -21
- package/src/mathTools.ts +16 -0
- package/src/mockLogger.ts +165 -35
- package/src/sampledTelemetryHelper.ts +15 -5
- package/src/telemetryEventBatcher.ts +103 -0
- package/src/telemetryTypes.ts +38 -19
- package/src/thresholdCounter.ts +1 -1
- package/src/utils.ts +31 -2
- package/tsconfig.json +2 -0
- package/tsdoc.json +4 -0
- package/api-report/telemetry-utils.api.md +0 -425
package/src/errorLogging.ts
CHANGED
|
@@ -7,12 +7,7 @@ import type { ITelemetryBaseProperties, Tagged } from "@fluidframework/core-inte
|
|
|
7
7
|
import type { ILoggingError } from "@fluidframework/core-interfaces/internal";
|
|
8
8
|
import { v4 as uuid } from "uuid";
|
|
9
9
|
|
|
10
|
-
import {
|
|
11
|
-
IFluidErrorBase,
|
|
12
|
-
hasErrorInstanceId,
|
|
13
|
-
isFluidError,
|
|
14
|
-
isValidLegacyError,
|
|
15
|
-
} from "./fluidErrorBase.js";
|
|
10
|
+
import { type IFluidErrorBase, hasErrorInstanceId, isFluidError } from "./fluidErrorBase.js";
|
|
16
11
|
import { convertToBasePropertyType } from "./logger.js";
|
|
17
12
|
import type {
|
|
18
13
|
ITelemetryLoggerExt,
|
|
@@ -111,19 +106,6 @@ export interface IFluidErrorAnnotations {
|
|
|
111
106
|
props?: ITelemetryBaseProperties;
|
|
112
107
|
}
|
|
113
108
|
|
|
114
|
-
/**
|
|
115
|
-
* For backwards compatibility with pre-errorInstanceId valid errors
|
|
116
|
-
*/
|
|
117
|
-
function patchLegacyError(
|
|
118
|
-
legacyError: Omit<IFluidErrorBase, "errorInstanceId">,
|
|
119
|
-
): asserts legacyError is IFluidErrorBase {
|
|
120
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any
|
|
121
|
-
const patchMe: { -readonly [P in "errorInstanceId"]?: IFluidErrorBase[P] } = legacyError as any;
|
|
122
|
-
if (patchMe.errorInstanceId === undefined) {
|
|
123
|
-
patchMe.errorInstanceId = uuid();
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
109
|
/**
|
|
128
110
|
* Normalize the given error yielding a valid Fluid Error
|
|
129
111
|
* @returns A valid Fluid Error with any provided annotations applied
|
|
@@ -136,11 +118,6 @@ export function normalizeError(
|
|
|
136
118
|
error: unknown,
|
|
137
119
|
annotations: IFluidErrorAnnotations = {},
|
|
138
120
|
): IFluidErrorBase {
|
|
139
|
-
// Back-compat, while IFluidErrorBase is rolled out
|
|
140
|
-
if (isValidLegacyError(error)) {
|
|
141
|
-
patchLegacyError(error);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
121
|
if (isFluidError(error)) {
|
|
145
122
|
// We can simply add the telemetry props to the error and return it
|
|
146
123
|
error.addTelemetryProperties(annotations.props ?? {});
|
|
@@ -180,7 +157,12 @@ export function normalizeError(
|
|
|
180
157
|
|
|
181
158
|
const errorTelemetryProps = LoggingError.typeCheck(error)
|
|
182
159
|
? error.getTelemetryProperties()
|
|
183
|
-
: {
|
|
160
|
+
: {
|
|
161
|
+
untrustedOrigin: 1, // This will let us filter errors that did not originate from our own codebase
|
|
162
|
+
// FUTURE: Once 2.0 becomes LTS, switch to this more explicit property name
|
|
163
|
+
// Consider using a string to distinguish cases like "dependency" v. "callback"
|
|
164
|
+
// errorRunningExternalCode: 1,
|
|
165
|
+
};
|
|
184
166
|
|
|
185
167
|
fluidError.addTelemetryProperties({
|
|
186
168
|
...errorTelemetryProps,
|
|
@@ -244,7 +226,10 @@ export function wrapError<T extends LoggingError>(
|
|
|
244
226
|
innerError: unknown,
|
|
245
227
|
newErrorFn: (message: string) => T,
|
|
246
228
|
): T {
|
|
247
|
-
const { message, stack } = extractLogSafeErrorProperties(
|
|
229
|
+
const { message, stack } = extractLogSafeErrorProperties(
|
|
230
|
+
innerError,
|
|
231
|
+
false /* sanitizeStack */,
|
|
232
|
+
);
|
|
248
233
|
|
|
249
234
|
const newError = newErrorFn(message);
|
|
250
235
|
|
|
@@ -254,7 +239,12 @@ export function wrapError<T extends LoggingError>(
|
|
|
254
239
|
|
|
255
240
|
// Mark external errors with untrustedOrigin flag
|
|
256
241
|
if (isExternalError(innerError)) {
|
|
257
|
-
newError.addTelemetryProperties({
|
|
242
|
+
newError.addTelemetryProperties({
|
|
243
|
+
untrustedOrigin: 1,
|
|
244
|
+
// FUTURE: Once 2.0 becomes LTS, switch to this more explicit property name
|
|
245
|
+
// Consider using a string to distinguish cases like "dependency" v. "callback"
|
|
246
|
+
// errorRunningExternalCode: 1,
|
|
247
|
+
});
|
|
258
248
|
}
|
|
259
249
|
|
|
260
250
|
// Reuse errorInstanceId
|
|
@@ -266,7 +256,7 @@ export function wrapError<T extends LoggingError>(
|
|
|
266
256
|
}
|
|
267
257
|
|
|
268
258
|
// Lastly, copy over all other telemetry properties. Note these will not overwrite existing properties
|
|
269
|
-
// This will include the untrustedOrigin
|
|
259
|
+
// This will include the untrustedOrigin/errorRunningExternalCode info if the inner error itself was created from an external error
|
|
270
260
|
if (isILoggingError(innerError)) {
|
|
271
261
|
newError.addTelemetryProperties(innerError.getTelemetryProperties());
|
|
272
262
|
}
|
|
@@ -331,15 +321,18 @@ export function overwriteStack(error: IFluidErrorBase | LoggingError, stack: str
|
|
|
331
321
|
*/
|
|
332
322
|
export function isExternalError(error: unknown): boolean {
|
|
333
323
|
// LoggingErrors are an internal FF error type. However, an external error can be converted
|
|
334
|
-
// into a LoggingError if it is normalized. In this case we must use the untrustedOrigin flag to
|
|
335
|
-
// determine whether the original error was
|
|
324
|
+
// into a LoggingError if it is normalized. In this case we must use the untrustedOrigin/errorRunningExternalCode flag to
|
|
325
|
+
// determine whether the original error was in fact external.
|
|
336
326
|
if (LoggingError.typeCheck(error)) {
|
|
337
327
|
if ((error as NormalizedLoggingError).errorType === NORMALIZED_ERROR_TYPE) {
|
|
338
|
-
|
|
328
|
+
const props = error.getTelemetryProperties();
|
|
329
|
+
// NOTE: errorRunningExternalCode is not currently used - once this "read" code reaches LTS,
|
|
330
|
+
// we can switch to writing this more explicit property
|
|
331
|
+
return props.untrustedOrigin === 1 || !!props.errorRunningExternalCode;
|
|
339
332
|
}
|
|
340
333
|
return false;
|
|
341
334
|
}
|
|
342
|
-
return
|
|
335
|
+
return true;
|
|
343
336
|
}
|
|
344
337
|
|
|
345
338
|
/**
|
|
@@ -354,6 +347,8 @@ export function isTaggedTelemetryPropertyValue(
|
|
|
354
347
|
return typeof (x as Partial<Tagged<unknown>>)?.tag === "string";
|
|
355
348
|
}
|
|
356
349
|
|
|
350
|
+
// TODO: Use `unknown` instead (API breaking change)
|
|
351
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
357
352
|
/**
|
|
358
353
|
* Borrowed from
|
|
359
354
|
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value#examples}
|
|
@@ -363,8 +358,6 @@ export function isTaggedTelemetryPropertyValue(
|
|
|
363
358
|
*
|
|
364
359
|
* @internal
|
|
365
360
|
*/
|
|
366
|
-
// TODO: Use `unknown` instead (API breaking change)
|
|
367
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
368
361
|
export const getCircularReplacer = (): ((key: string, value: unknown) => any) => {
|
|
369
362
|
const seen = new WeakSet();
|
|
370
363
|
return (key: string, value: unknown): any => {
|
|
@@ -393,27 +386,20 @@ export class LoggingError
|
|
|
393
386
|
implements ILoggingError, Omit<IFluidErrorBase, "errorType">
|
|
394
387
|
{
|
|
395
388
|
private _errorInstanceId = uuid();
|
|
396
|
-
get errorInstanceId(): string {
|
|
389
|
+
public get errorInstanceId(): string {
|
|
397
390
|
return this._errorInstanceId;
|
|
398
391
|
}
|
|
399
|
-
overwriteErrorInstanceId(id: string): void {
|
|
392
|
+
public overwriteErrorInstanceId(id: string): void {
|
|
400
393
|
this._errorInstanceId = id;
|
|
401
394
|
}
|
|
402
395
|
|
|
403
|
-
/**
|
|
404
|
-
* Backwards compatibility to appease {@link isFluidError} in old code that may handle this error.
|
|
405
|
-
*/
|
|
406
|
-
// @ts-expect-error - This field shouldn't be referenced in the current version, but needs to exist at runtime.
|
|
407
|
-
// eslint-disable-next-line @typescript-eslint/prefer-as-const
|
|
408
|
-
private readonly fluidErrorCode: "-" = "-";
|
|
409
|
-
|
|
410
396
|
/**
|
|
411
397
|
* Create a new LoggingError
|
|
412
398
|
* @param message - Error message to use for Error base class
|
|
413
399
|
* @param props - telemetry props to include on the error for when it's logged
|
|
414
400
|
* @param omitPropsFromLogging - properties by name to omit from telemetry props
|
|
415
401
|
*/
|
|
416
|
-
constructor(
|
|
402
|
+
public constructor(
|
|
417
403
|
message: string,
|
|
418
404
|
props?: ITelemetryBaseProperties,
|
|
419
405
|
private readonly omitPropsFromLogging: Set<string> = new Set(),
|
|
@@ -494,9 +480,9 @@ export const NORMALIZED_ERROR_TYPE = "genericError";
|
|
|
494
480
|
class NormalizedLoggingError extends LoggingError {
|
|
495
481
|
// errorType "genericError" is used as a default value throughout the code.
|
|
496
482
|
// Note that this matches ContainerErrorTypes/DriverErrorTypes' genericError
|
|
497
|
-
errorType = NORMALIZED_ERROR_TYPE;
|
|
483
|
+
public readonly errorType = NORMALIZED_ERROR_TYPE;
|
|
498
484
|
|
|
499
|
-
constructor(errorProps: Pick<IFluidErrorBase, "message" | "stack">) {
|
|
485
|
+
public constructor(errorProps: Pick<IFluidErrorBase, "message" | "stack">) {
|
|
500
486
|
super(errorProps.message);
|
|
501
487
|
|
|
502
488
|
if (errorProps.stack !== undefined) {
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { EventEmitterEventType, TypedEventEmitter } from "@fluid-internal/client-utils";
|
|
7
|
-
import { IEvent } from "@fluidframework/core-interfaces";
|
|
6
|
+
import { type EventEmitterEventType, TypedEventEmitter } from "@fluid-internal/client-utils";
|
|
7
|
+
import type { IEvent } from "@fluidframework/core-interfaces";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Event Emitter helper class
|
|
@@ -20,7 +20,7 @@ import { IEvent } from "@fluidframework/core-interfaces";
|
|
|
20
20
|
export class EventEmitterWithErrorHandling<
|
|
21
21
|
TEvent extends IEvent = IEvent,
|
|
22
22
|
> extends TypedEventEmitter<TEvent> {
|
|
23
|
-
constructor(
|
|
23
|
+
public constructor(
|
|
24
24
|
// TODO: use `unknown` instead (breaking API change)
|
|
25
25
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
26
|
private readonly errorHandler: (eventName: EventEmitterEventType, error: any) => void,
|
package/src/fluidErrorBase.ts
CHANGED
|
@@ -96,18 +96,3 @@ export function isFluidError(error: unknown): error is IFluidErrorBase {
|
|
|
96
96
|
hasTelemetryPropFunctions(error)
|
|
97
97
|
);
|
|
98
98
|
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Type guard for old standard of valid/known errors.
|
|
102
|
-
*
|
|
103
|
-
* @internal
|
|
104
|
-
*/
|
|
105
|
-
export function isValidLegacyError(
|
|
106
|
-
error: unknown,
|
|
107
|
-
): error is Omit<IFluidErrorBase, "errorInstanceId"> {
|
|
108
|
-
return (
|
|
109
|
-
typeof (error as Partial<IFluidErrorBase>)?.errorType === "string" &&
|
|
110
|
-
typeof (error as Partial<IFluidErrorBase>)?.message === "string" &&
|
|
111
|
-
hasTelemetryPropFunctions(error)
|
|
112
|
-
);
|
|
113
|
-
}
|
package/src/index.ts
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
|
|
6
6
|
export {
|
|
7
7
|
createChildMonitoringContext,
|
|
8
|
-
MonitoringContext,
|
|
8
|
+
type MonitoringContext,
|
|
9
9
|
sessionStorageConfigProvider,
|
|
10
10
|
mixinMonitoringContext,
|
|
11
|
-
IConfigProvider,
|
|
11
|
+
type IConfigProvider,
|
|
12
12
|
loggerToMonitoringContext,
|
|
13
13
|
wrapConfigProviderWithDefaults,
|
|
14
14
|
} from "./config.js";
|
|
@@ -25,7 +25,7 @@ export {
|
|
|
25
25
|
generateErrorWithStack,
|
|
26
26
|
generateStack,
|
|
27
27
|
getCircularReplacer,
|
|
28
|
-
IFluidErrorAnnotations,
|
|
28
|
+
type IFluidErrorAnnotations,
|
|
29
29
|
isExternalError,
|
|
30
30
|
isILoggingError,
|
|
31
31
|
isTaggedTelemetryPropertyValue,
|
|
@@ -43,34 +43,34 @@ export {
|
|
|
43
43
|
raiseConnectedEvent,
|
|
44
44
|
safeRaiseEvent,
|
|
45
45
|
} from "./events.js";
|
|
46
|
-
export {
|
|
47
|
-
hasErrorInstanceId,
|
|
48
|
-
IFluidErrorBase,
|
|
49
|
-
isFluidError,
|
|
50
|
-
isValidLegacyError,
|
|
51
|
-
} from "./fluidErrorBase.js";
|
|
46
|
+
export { hasErrorInstanceId, type IFluidErrorBase, isFluidError } from "./fluidErrorBase.js";
|
|
52
47
|
export {
|
|
53
48
|
eventNamespaceSeparator,
|
|
54
49
|
createChildLogger,
|
|
55
50
|
createMultiSinkLogger,
|
|
56
51
|
formatTick,
|
|
57
|
-
IPerformanceEventMarkers,
|
|
58
|
-
ITelemetryLoggerPropertyBag,
|
|
59
|
-
ITelemetryLoggerPropertyBags,
|
|
60
|
-
MultiSinkLoggerProperties,
|
|
52
|
+
type IPerformanceEventMarkers,
|
|
53
|
+
type ITelemetryLoggerPropertyBag,
|
|
54
|
+
type ITelemetryLoggerPropertyBags,
|
|
55
|
+
type MultiSinkLoggerProperties,
|
|
61
56
|
numberFromString,
|
|
62
57
|
PerformanceEvent,
|
|
63
58
|
TaggedLoggerAdapter,
|
|
64
59
|
tagData,
|
|
65
60
|
tagCodeArtifacts,
|
|
66
61
|
TelemetryDataTag,
|
|
67
|
-
TelemetryEventPropertyTypes,
|
|
62
|
+
type TelemetryEventPropertyTypes,
|
|
68
63
|
} from "./logger.js";
|
|
69
|
-
export { MockLogger } from "./mockLogger.js";
|
|
64
|
+
export { createMockLoggerExt, type IMockLoggerExt, MockLogger } from "./mockLogger.js";
|
|
70
65
|
export { ThresholdCounter } from "./thresholdCounter.js";
|
|
71
66
|
export { SampledTelemetryHelper } from "./sampledTelemetryHelper.js";
|
|
72
|
-
export { createSampledLogger, IEventSampler, ISampledTelemetryLogger } from "./utils.js";
|
|
73
67
|
export {
|
|
68
|
+
createSampledLogger,
|
|
69
|
+
type IEventSampler,
|
|
70
|
+
type ISampledTelemetryLogger,
|
|
71
|
+
measure,
|
|
72
|
+
} from "./utils.js";
|
|
73
|
+
export type {
|
|
74
74
|
TelemetryEventPropertyTypeExt,
|
|
75
75
|
ITelemetryEventExt,
|
|
76
76
|
ITelemetryGenericEventExt,
|
|
@@ -81,3 +81,4 @@ export {
|
|
|
81
81
|
ITelemetryPropertiesExt,
|
|
82
82
|
TelemetryEventCategory,
|
|
83
83
|
} from "./telemetryTypes.js";
|
|
84
|
+
export { TelemetryEventBatcher } from "./telemetryEventBatcher.js";
|
package/src/logger.ts
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
import { performance } from "@fluid-internal/client-utils";
|
|
7
7
|
import {
|
|
8
|
-
ITelemetryBaseEvent,
|
|
9
|
-
ITelemetryBaseLogger,
|
|
8
|
+
type ITelemetryBaseEvent,
|
|
9
|
+
type ITelemetryBaseLogger,
|
|
10
10
|
LogLevel,
|
|
11
|
-
Tagged,
|
|
12
|
-
TelemetryBaseEventPropertyType,
|
|
11
|
+
type Tagged,
|
|
12
|
+
type TelemetryBaseEventPropertyType,
|
|
13
13
|
} from "@fluidframework/core-interfaces";
|
|
14
14
|
|
|
15
15
|
import {
|
|
@@ -23,8 +23,8 @@ import {
|
|
|
23
23
|
isILoggingError,
|
|
24
24
|
isTaggedTelemetryPropertyValue,
|
|
25
25
|
} from "./errorLogging.js";
|
|
26
|
-
import {
|
|
27
|
-
|
|
26
|
+
import type {
|
|
27
|
+
ITelemetryErrorEventExt,
|
|
28
28
|
ITelemetryEventExt,
|
|
29
29
|
ITelemetryGenericEventExt,
|
|
30
30
|
ITelemetryLoggerExt,
|
|
@@ -60,9 +60,10 @@ export type TelemetryEventPropertyTypes = ITelemetryPropertiesExt[string];
|
|
|
60
60
|
/**
|
|
61
61
|
* @alpha
|
|
62
62
|
*/
|
|
63
|
-
export
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
export type ITelemetryLoggerPropertyBag = Record<
|
|
64
|
+
string,
|
|
65
|
+
TelemetryEventPropertyTypes | (() => TelemetryEventPropertyTypes)
|
|
66
|
+
>;
|
|
66
67
|
|
|
67
68
|
/**
|
|
68
69
|
* @alpha
|
|
@@ -273,10 +274,9 @@ export abstract class TelemetryLogger implements ITelemetryLoggerExt {
|
|
|
273
274
|
return this.extendProperties(newEvent, includeErrorProps);
|
|
274
275
|
}
|
|
275
276
|
|
|
276
|
-
private extendProperties<
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
): T {
|
|
277
|
+
private extendProperties<
|
|
278
|
+
T extends ITelemetryLoggerPropertyBag = ITelemetryLoggerPropertyBag,
|
|
279
|
+
>(toExtend: T, includeErrorProps: boolean): T {
|
|
280
280
|
const eventLike: ITelemetryLoggerPropertyBag = toExtend;
|
|
281
281
|
if (this.properties) {
|
|
282
282
|
const properties: (undefined | ITelemetryLoggerPropertyBag)[] = [];
|
|
@@ -421,8 +421,8 @@ export class ChildLogger extends TelemetryLogger {
|
|
|
421
421
|
baseLogger.namespace === undefined
|
|
422
422
|
? namespace
|
|
423
423
|
: namespace === undefined
|
|
424
|
-
|
|
425
|
-
|
|
424
|
+
? baseLogger.namespace
|
|
425
|
+
: `${baseLogger.namespace}${TelemetryLogger.eventNamespaceSeparator}${namespace}`;
|
|
426
426
|
|
|
427
427
|
const child = new ChildLogger(
|
|
428
428
|
baseLogger.baseLogger,
|
|
@@ -533,7 +533,7 @@ export class MultiSinkLogger extends TelemetryLogger {
|
|
|
533
533
|
* @param loggers - The list of loggers to use as sinks
|
|
534
534
|
* @param tryInheritProperties - Will attempted to copy those loggers properties to this loggers if they are of a known type e.g. one from this package
|
|
535
535
|
*/
|
|
536
|
-
constructor(
|
|
536
|
+
public constructor(
|
|
537
537
|
namespace?: string,
|
|
538
538
|
properties?: ITelemetryLoggerPropertyBags,
|
|
539
539
|
loggers: ITelemetryBaseLogger[] = [],
|
|
@@ -855,7 +855,7 @@ export function convertToBasePropertyType(
|
|
|
855
855
|
? {
|
|
856
856
|
value: convertToBasePropertyTypeUntagged(x.value),
|
|
857
857
|
tag: x.tag,
|
|
858
|
-
|
|
858
|
+
}
|
|
859
859
|
: convertToBasePropertyTypeUntagged(x);
|
|
860
860
|
}
|
|
861
861
|
|
|
@@ -920,11 +920,11 @@ export const tagData = <
|
|
|
920
920
|
? () => {
|
|
921
921
|
value: ReturnType<V[P]>;
|
|
922
922
|
tag: T;
|
|
923
|
-
|
|
923
|
+
}
|
|
924
924
|
: {
|
|
925
925
|
value: Exclude<V[P], undefined>;
|
|
926
926
|
tag: T;
|
|
927
|
-
|
|
927
|
+
})
|
|
928
928
|
| (V[P] extends undefined ? undefined : never);
|
|
929
929
|
} =>
|
|
930
930
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
@@ -982,10 +982,10 @@ export const tagCodeArtifacts = <
|
|
|
982
982
|
? () => {
|
|
983
983
|
value: ReturnType<T[P]>;
|
|
984
984
|
tag: TelemetryDataTag.CodeArtifact;
|
|
985
|
-
|
|
985
|
+
}
|
|
986
986
|
: {
|
|
987
987
|
value: Exclude<T[P], undefined>;
|
|
988
988
|
tag: TelemetryDataTag.CodeArtifact;
|
|
989
|
-
|
|
989
|
+
})
|
|
990
990
|
| (T[P] extends undefined ? undefined : never);
|
|
991
991
|
} => tagData<TelemetryDataTag.CodeArtifact, T>(TelemetryDataTag.CodeArtifact, values);
|
package/src/mathTools.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Function to round a number to a specified number of decimal places.
|
|
8
|
+
*
|
|
9
|
+
* @param number - The number to round.
|
|
10
|
+
* @param decimalPlaces - The number of decimal places to round to.
|
|
11
|
+
* @returns The rounded number.
|
|
12
|
+
*/
|
|
13
|
+
export function roundToDecimalPlaces(number: number, decimalPlaces: number): number {
|
|
14
|
+
const factor = Math.pow(10, decimalPlaces);
|
|
15
|
+
return Math.round(number * factor) / factor;
|
|
16
|
+
}
|