// Helpers for shaping values into `tailor.logger` structured attributes. // // Attribute values must be a string, number, boolean, or same-typed array; the // platform silently drops nested objects, null, and mixed arrays. So an Error // and an arbitrary command input both have to be flattened before they can be // attached to a log entry. import type { LogAttributes } from "@tailor-platform/sdk/runtime/logger"; /** * Split an unknown thrown value into loggable attributes: `error` carries the * message, `errorName` the class name when one is available. */ export function errorAttrs(error: unknown): LogAttributes { if (error instanceof Error) { return { error: error.message, errorName: error.name }; } return { error: String(error) }; } /** * Serialize a command/query input for logging. Kept as a single JSON string * attribute rather than flattened into one attribute per field: these wrappers * run for every command in every module, so flattening would mint unbounded * attribute keys and silently lose fields to the platform's 32-attribute cap. * Values that cannot be serialized (circular structures, BigInt) must not break * the caller, so they degrade to a marker string. */ export function inputAttr(input: unknown): string { try { return JSON.stringify(input) ?? String(input); } catch { return "[unserializable]"; } }