fix: remove global string slice to guarantee JSON parseability

This commit is contained in:
Spencer
2026-04-14 18:26:00 +00:00
parent 5357770a3d
commit dd4d7301ba
2 changed files with 0 additions and 20 deletions
-12
View File
@@ -124,18 +124,6 @@ describe('truncateForTelemetry', () => {
);
});
it('should enforce a global payload string limit', () => {
const obj = {
a: 'x'.repeat(100),
b: 'y'.repeat(100),
};
// Let's cap global string length to 50
const result = truncateForTelemetry(obj, 100, 100, 4, 50) as string;
expect(result.length).toBeGreaterThan(50);
expect(result).toContain('...[TRUNCATED: original payload length');
expect(result.startsWith('{"a":"xxxx')).toBe(true);
});
it('should stringify objects unchanged if within maxLength', () => {
const obj = { a: 1 };
expect(truncateForTelemetry(obj, 100)).toBe(JSON.stringify(obj));
-8
View File
@@ -67,7 +67,6 @@ export function truncateForTelemetry(
maxStringLength = 10000,
maxArrayLength = 100,
maxDepth = 4,
maxGlobalStringLength = 50000,
): AttributeValue | undefined {
const truncateObj = (v: unknown, depth: number): unknown => {
if (typeof v === 'string') {
@@ -149,13 +148,6 @@ export function truncateForTelemetry(
}
const stringified = safeJsonStringify(truncated);
if (stringified.length > maxGlobalStringLength) {
const graphemes = Array.from(stringified);
if (graphemes.length > maxGlobalStringLength) {
return (graphemes.slice(0, maxGlobalStringLength).join('') +
`...[TRUNCATED: original payload length ${graphemes.length}]`) as AttributeValue;
}
}
return stringified as AttributeValue;
}