Log all user settings to enable measurement of experiment impacts (#11354)

This commit is contained in:
owenofbrien
2025-10-17 15:54:35 -05:00
committed by GitHub
parent d3bdbc6978
commit 08e87a59d5
3 changed files with 51 additions and 18 deletions

View File

@@ -11,6 +11,8 @@
* @param space - Optional space parameter for formatting (defaults to no formatting)
* @returns JSON string with circular references replaced by [Circular]
*/
import type { Config } from '../config/config.js';
export function safeJsonStringify(
obj: unknown,
space?: string | number,
@@ -30,3 +32,37 @@ export function safeJsonStringify(
space,
);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function removeEmptyObjects(data: any): object {
const cleanedObject: { [key: string]: unknown } = {};
for (const k in data) {
const v = data[k];
if (v !== null && v !== undefined && typeof v === 'boolean') {
cleanedObject[k] = v;
}
}
return cleanedObject;
}
/**
* Safely stringifies an object to JSON, retaining only non-null, Boolean-valued members.
*
* @param obj - The object to stringify
* @returns JSON string with circular references skipped and only non-null, Boolean member values retained.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function safeJsonStringifyBooleanValuesOnly(obj: any): string {
let configSeen = false;
return JSON.stringify(removeEmptyObjects(obj), (key, value) => {
if ((value as Config) !== null && !configSeen) {
configSeen = true;
return value;
}
if (typeof value === 'boolean') {
return value;
}
return '';
});
}