diff --git a/packages/utils/telemetry-utils/src/errorLogging.ts b/packages/utils/telemetry-utils/src/errorLogging.ts index 9711ef8d4638..40aa849854a6 100644 --- a/packages/utils/telemetry-utils/src/errorLogging.ts +++ b/packages/utils/telemetry-utils/src/errorLogging.ts @@ -87,9 +87,9 @@ function copyProps( target: ITelemetryPropertiesExt | LoggingError, source: ITelemetryPropertiesExt, ): void { - for (const key of Object.keys(source)) { + for (const [key, value] of Object.entries(source)) { if (target[key] === undefined) { - target[key] = source[key]; + target[key] = value; } } } diff --git a/packages/utils/telemetry-utils/src/logger.ts b/packages/utils/telemetry-utils/src/logger.ts index 9f74be64bcb9..11133973ef6e 100644 --- a/packages/utils/telemetry-utils/src/logger.ts +++ b/packages/utils/telemetry-utils/src/logger.ts @@ -289,11 +289,10 @@ export abstract class TelemetryLogger implements ITelemetryLoggerExt { } for (const props of properties) { if (props !== undefined) { - for (const key of Object.keys(props)) { + for (const [key, getterOrValue] of Object.entries(props)) { if (eventLike[key] !== undefined) { continue; } - const getterOrValue = props[key]; // If this throws, hopefully it is handled elsewhere const value = typeof getterOrValue === "function" ? getterOrValue() : getterOrValue; @@ -326,8 +325,7 @@ export class TaggedLoggerAdapter implements ITelemetryBaseLogger { category: eventWithTagsMaybe.category, eventName: eventWithTagsMaybe.eventName, }; - for (const key of Object.keys(eventWithTagsMaybe)) { - const taggableProp = eventWithTagsMaybe[key]; + for (const [key, taggableProp] of Object.entries(eventWithTagsMaybe)) { const { value, tag } = typeof taggableProp === "object" ? taggableProp diff --git a/packages/utils/telemetry-utils/src/mockLogger.ts b/packages/utils/telemetry-utils/src/mockLogger.ts index 23714cd9ed0a..be46d59cfd43 100644 --- a/packages/utils/telemetry-utils/src/mockLogger.ts +++ b/packages/utils/telemetry-utils/src/mockLogger.ts @@ -7,6 +7,7 @@ import { type ITelemetryBaseEvent, type ITelemetryBaseLogger, LogLevel, + type Tagged, } from "@fluidframework/core-interfaces"; import { assert } from "@fluidframework/core-utils/internal"; @@ -15,6 +16,7 @@ import type { ITelemetryEventExt, ITelemetryLoggerExt, ITelemetryPropertiesExt, + TelemetryEventPropertyTypeExt, } from "./telemetryTypes.js"; /** @@ -334,7 +336,10 @@ function matchObjects( expected: ITelemetryPropertiesExt, ): boolean { for (const [expectedKey, expectedValue] of Object.entries(expected)) { - const actualValue = actual[expectedKey]; + const actualValue: + | TelemetryEventPropertyTypeExt + | Tagged + | undefined = actual[expectedKey]; if ( !Array.isArray(expectedValue) && expectedValue !== null && diff --git a/packages/utils/telemetry-utils/src/test/config.spec.ts b/packages/utils/telemetry-utils/src/test/config.spec.ts index 2962eb311033..5279d5a662b0 100644 --- a/packages/utils/telemetry-utils/src/test/config.spec.ts +++ b/packages/utils/telemetry-utils/src/test/config.spec.ts @@ -22,7 +22,8 @@ const getMockStore = (settings: Record): Storage => { return { getItem: (key: string): string | null => { ops.push(key); - return settings[key]; + // eslint-disable-next-line unicorn/no-null + return settings[key] ?? null; }, getOps: (): Readonly => ops, length: Object.keys(settings).length, diff --git a/packages/utils/telemetry-utils/src/test/errorLogging.spec.ts b/packages/utils/telemetry-utils/src/test/errorLogging.spec.ts index ef1a02635796..591a69779d75 100644 --- a/packages/utils/telemetry-utils/src/test/errorLogging.spec.ts +++ b/packages/utils/telemetry-utils/src/test/errorLogging.spec.ts @@ -689,7 +689,7 @@ const annotationCases: Record = { describe("normalizeError", () => { describe("Valid Errors (Legacy and Current)", () => { for (const annotationCase of Object.keys(annotationCases)) { - const annotations = annotationCases[annotationCase]; + const annotations: IFluidErrorAnnotations | undefined = annotationCases[annotationCase]; it(`Valid Fluid Error - untouched (annotations: ${annotationCase})`, () => { // Arrange const fluidError = new TestFluidError({ errorType: "et1", message: "m1" }); @@ -914,11 +914,9 @@ describe("normalizeError", () => { expected.withExpectedTelemetryProps({ stack: inputStack }); } } - for (const annotationCase of Object.keys(annotationCases)) { - const annotations = annotationCases[annotationCase]; + for (const [annotationCase, annotations] of Object.entries(annotationCases)) { let doneOnceForThisAnnotationCase = false; - for (const caseName of Object.keys(testCases)) { - const getTestCase = testCases[caseName]; + for (const [caseName, getTestCase] of Object.entries(testCases)) { if (!doneOnceForThisAnnotationCase) { doneOnceForThisAnnotationCase = true; // Each test case only differs by what stack/error are. Test the rest only once per annotation case.