diff --git a/packages/core/src/utils/aggregate-errors.ts b/packages/core/src/utils/aggregate-errors.ts index f472e5b9968b..16d100d60c09 100644 --- a/packages/core/src/utils/aggregate-errors.ts +++ b/packages/core/src/utils/aggregate-errors.ts @@ -99,10 +99,9 @@ function aggregateExceptionsFromError( } function applyExceptionGroupFieldsForParentException(exception: Exception, exceptionId: number): void { - // Don't know if this default makes sense. The protocol requires us to set these values so we pick *some* default. - exception.mechanism = exception.mechanism || { type: 'generic', handled: true }; - exception.mechanism = { + handled: true, + type: 'auto.core.linked_errors', ...exception.mechanism, ...(exception.type === 'AggregateError' && { is_exception_group: true }), exception_id: exceptionId, @@ -115,10 +114,8 @@ function applyExceptionGroupFieldsForChildException( exceptionId: number, parentId: number | undefined, ): void { - // Don't know if this default makes sense. The protocol requires us to set these values so we pick *some* default. - exception.mechanism = exception.mechanism || { type: 'generic', handled: true }; - exception.mechanism = { + handled: true, ...exception.mechanism, type: 'chained', source, diff --git a/packages/core/test/lib/utils/aggregate-errors.test.ts b/packages/core/test/lib/utils/aggregate-errors.test.ts index 01ede6d9186a..fa11fd22f7c8 100644 --- a/packages/core/test/lib/utils/aggregate-errors.test.ts +++ b/packages/core/test/lib/utils/aggregate-errors.test.ts @@ -160,6 +160,26 @@ describe('applyAggregateErrorsToEvent()', () => { expect(event.exception?.values?.[event.exception.values.length - 1]?.mechanism?.type).toBe('instrument'); }); + test('should assign a defualt mechanism type for the root exception', () => { + const fakeAggregateError = new FakeAggregateError( + [new Error('Nested Error 1'), new Error('Nested Error 2')], + 'Root Error', + ); + + const exceptionFromError = (_stackParser: StackParser, ex: Error): Exception => { + return { value: ex.message, type: ex.name }; + }; + + const event: Event = { exception: { values: [exceptionFromError(stackParser, fakeAggregateError)] } }; + const eventHint: EventHint = { originalException: fakeAggregateError }; + + applyAggregateErrorsToEvent(exceptionFromError, stackParser, 'cause', 100, event, eventHint); + + expect(event.exception?.values?.[event.exception.values.length - 1]?.mechanism?.type).toBe( + 'auto.core.linked_errors', + ); + }); + test('should recursively walk mixed errors (Aggregate errors and based on `key`)', () => { const chainedError: ExtendedError = new Error('Nested Error 3'); chainedError.cause = new Error('Nested Error 4');