From b9baa13497aaa314e1c7fdded983fa8569db481c Mon Sep 17 00:00:00 2001 From: s1gr1d <32902192+s1gr1d@users.noreply.github.com> Date: Tue, 28 Oct 2025 13:49:13 +0100 Subject: [PATCH 1/3] feat(core): Include all exception object keys instead of truncating --- packages/core/src/utils/object.ts | 25 ++--------------- packages/core/test/lib/utils/object.test.ts | 30 ++++++++++++--------- 2 files changed, 19 insertions(+), 36 deletions(-) diff --git a/packages/core/src/utils/object.ts b/packages/core/src/utils/object.ts index e212b9f3b833..1432a5448b2c 100644 --- a/packages/core/src/utils/object.ts +++ b/packages/core/src/utils/object.ts @@ -176,32 +176,11 @@ function getOwnProperties(obj: unknown): { [key: string]: unknown } { * and truncated list that will be used inside the event message. * eg. `Non-error exception captured with keys: foo, bar, baz` */ -export function extractExceptionKeysForMessage(exception: Record, maxLength: number = 40): string { +export function extractExceptionKeysForMessage(exception: Record): string { const keys = Object.keys(convertToPlainObject(exception)); keys.sort(); - const firstKey = keys[0]; - - if (!firstKey) { - return '[object has no keys]'; - } - - if (firstKey.length >= maxLength) { - return truncate(firstKey, maxLength); - } - - for (let includedKeys = keys.length; includedKeys > 0; includedKeys--) { - const serialized = keys.slice(0, includedKeys).join(', '); - if (serialized.length > maxLength) { - continue; - } - if (includedKeys === keys.length) { - return serialized; - } - return truncate(serialized, maxLength); - } - - return ''; + return !keys[0] ? '[object has no keys]' : keys.join(', '); } /** diff --git a/packages/core/test/lib/utils/object.test.ts b/packages/core/test/lib/utils/object.test.ts index bc8c7611abb8..11a77d2b1f0a 100644 --- a/packages/core/test/lib/utils/object.test.ts +++ b/packages/core/test/lib/utils/object.test.ts @@ -142,29 +142,33 @@ describe('fill()', () => { describe('extractExceptionKeysForMessage()', () => { test('no keys', () => { - expect(extractExceptionKeysForMessage({}, 10)).toEqual('[object has no keys]'); + expect(extractExceptionKeysForMessage({})).toEqual('[object has no keys]'); }); test('one key should be returned as a whole if not over the length limit', () => { - expect(extractExceptionKeysForMessage({ foo: '_' }, 10)).toEqual('foo'); - expect(extractExceptionKeysForMessage({ foobarbazx: '_' }, 10)).toEqual('foobarbazx'); - }); - - test('one key should be appended with ... and truncated when over the limit', () => { - expect(extractExceptionKeysForMessage({ foobarbazqux: '_' }, 10)).toEqual('foobarbazq...'); + expect(extractExceptionKeysForMessage({ foo: '_' })).toEqual('foo'); + expect(extractExceptionKeysForMessage({ foobarbazx: '_' })).toEqual('foobarbazx'); }); test('multiple keys should be sorted and joined as a whole if not over the length limit', () => { - expect(extractExceptionKeysForMessage({ foo: '_', bar: '_' }, 10)).toEqual('bar, foo'); + expect(extractExceptionKeysForMessage({ foo: '_', bar: '_', baz: '_' })).toEqual('bar, baz, foo'); }); - test('multiple keys should include only as much keys as can fit into the limit', () => { - expect(extractExceptionKeysForMessage({ foo: '_', bar: '_', baz: '_' }, 10)).toEqual('bar, baz'); - expect(extractExceptionKeysForMessage({ footoolong: '_', verylongkey: '_', baz: '_' }, 10)).toEqual('baz'); + test('multiple keys should truncate first key if its too long', () => { + expect(extractExceptionKeysForMessage({ barbazquxfoo: '_', baz: '_', qux: '_' })).toEqual('barbazquxfoo, baz, qux'); }); - test('multiple keys should truncate first key if its too long', () => { - expect(extractExceptionKeysForMessage({ barbazquxfoo: '_', baz: '_', qux: '_' }, 10)).toEqual('barbazquxf...'); + test('sorts keys alphabetically and does not truncate multiple keys or long keys', () => { + const exception = { + property1: 'a', + thisIsAnExtremelyLongPropertyNameThatExceedsFortyCharacters: 'b', + property3: 'c', + property4: 'd', + property5: 'e', + }; + expect(extractExceptionKeysForMessage(exception)).toEqual( + 'property1, property3, property4, property5, thisIsAnExtremelyLongPropertyNameThatExceedsFortyCharacters', + ); }); }); From 85b0fb394414ec438027bc902b0bb080533d323b Mon Sep 17 00:00:00 2001 From: s1gr1d <32902192+s1gr1d@users.noreply.github.com> Date: Wed, 29 Oct 2025 10:39:27 +0100 Subject: [PATCH 2/3] update test case names --- packages/core/test/lib/utils/object.test.ts | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/packages/core/test/lib/utils/object.test.ts b/packages/core/test/lib/utils/object.test.ts index 11a77d2b1f0a..a4d2a4b56ea3 100644 --- a/packages/core/test/lib/utils/object.test.ts +++ b/packages/core/test/lib/utils/object.test.ts @@ -145,29 +145,22 @@ describe('extractExceptionKeysForMessage()', () => { expect(extractExceptionKeysForMessage({})).toEqual('[object has no keys]'); }); - test('one key should be returned as a whole if not over the length limit', () => { + test('one key should be returned as a whole', () => { expect(extractExceptionKeysForMessage({ foo: '_' })).toEqual('foo'); expect(extractExceptionKeysForMessage({ foobarbazx: '_' })).toEqual('foobarbazx'); }); - test('multiple keys should be sorted and joined as a whole if not over the length limit', () => { - expect(extractExceptionKeysForMessage({ foo: '_', bar: '_', baz: '_' })).toEqual('bar, baz, foo'); - }); - - test('multiple keys should truncate first key if its too long', () => { - expect(extractExceptionKeysForMessage({ barbazquxfoo: '_', baz: '_', qux: '_' })).toEqual('barbazquxfoo, baz, qux'); - }); - - test('sorts keys alphabetically and does not truncate multiple keys or long keys', () => { + test('multiple keys should be sorted and joined as a whole (without truncating)', () => { const exception = { property1: 'a', thisIsAnExtremelyLongPropertyNameThatExceedsFortyCharacters: 'b', + barbazquxfooabc: 'x', property3: 'c', property4: 'd', property5: 'e', }; expect(extractExceptionKeysForMessage(exception)).toEqual( - 'property1, property3, property4, property5, thisIsAnExtremelyLongPropertyNameThatExceedsFortyCharacters', + 'barbazquxfooabc, property1, property3, property4, property5, thisIsAnExtremelyLongPropertyNameThatExceedsFortyCharacters', ); }); }); From 76f0f7f78f8904578f31fa893d28b5a63d0ac62a Mon Sep 17 00:00:00 2001 From: s1gr1d <32902192+s1gr1d@users.noreply.github.com> Date: Wed, 29 Oct 2025 14:57:05 +0100 Subject: [PATCH 3/3] remove unused import --- packages/core/src/utils/object.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/core/src/utils/object.ts b/packages/core/src/utils/object.ts index 1432a5448b2c..06f80e12d7f7 100644 --- a/packages/core/src/utils/object.ts +++ b/packages/core/src/utils/object.ts @@ -4,7 +4,6 @@ import type { WrappedFunction } from '../types-hoist/wrappedfunction'; import { htmlTreeAsString } from './browser'; import { debug } from './debug-logger'; import { isElement, isError, isEvent, isInstanceOf, isPrimitive } from './is'; -import { truncate } from './string'; /** * Replace a method in an object with a wrapped version of itself.