@@ -11,7 +11,7 @@ describe('applyAggregateErrorsToEvent()', () => {
1111 test ( 'should not do anything if event does not contain an exception' , ( ) => {
1212 const event : Event = { exception : undefined } ;
1313 const eventHint : EventHint = { originalException : new Error ( ) } ;
14- applyAggregateErrorsToEvent ( exceptionFromError , stackParser , 'cause' , 100 , event , eventHint ) ;
14+ applyAggregateErrorsToEvent ( exceptionFromError , stackParser , undefined , 'cause' , 100 , event , eventHint ) ;
1515
1616 // no changes
1717 expect ( event ) . toStrictEqual ( { exception : undefined } ) ;
@@ -20,15 +20,15 @@ describe('applyAggregateErrorsToEvent()', () => {
2020 test ( 'should not do anything if event does not contain exception values' , ( ) => {
2121 const event : Event = { exception : { values : undefined } } ;
2222 const eventHint : EventHint = { originalException : new Error ( ) } ;
23- applyAggregateErrorsToEvent ( exceptionFromError , stackParser , 'cause' , 100 , event , eventHint ) ;
23+ applyAggregateErrorsToEvent ( exceptionFromError , stackParser , undefined , 'cause' , 100 , event , eventHint ) ;
2424
2525 // no changes
2626 expect ( event ) . toStrictEqual ( { exception : { values : undefined } } ) ;
2727 } ) ;
2828
2929 test ( 'should not do anything if event does not contain an event hint' , ( ) => {
3030 const event : Event = { exception : { values : [ ] } } ;
31- applyAggregateErrorsToEvent ( exceptionFromError , stackParser , 'cause' , 100 , event , undefined ) ;
31+ applyAggregateErrorsToEvent ( exceptionFromError , stackParser , undefined , 'cause' , 100 , event , undefined ) ;
3232
3333 // no changes
3434 expect ( event ) . toStrictEqual ( { exception : { values : [ ] } } ) ;
@@ -37,7 +37,7 @@ describe('applyAggregateErrorsToEvent()', () => {
3737 test ( 'should not do anything if the event hint does not contain an original exception' , ( ) => {
3838 const event : Event = { exception : { values : [ ] } } ;
3939 const eventHint : EventHint = { originalException : undefined } ;
40- applyAggregateErrorsToEvent ( exceptionFromError , stackParser , 'cause' , 100 , event , eventHint ) ;
40+ applyAggregateErrorsToEvent ( exceptionFromError , stackParser , undefined , 'cause' , 100 , event , eventHint ) ;
4141
4242 // no changes
4343 expect ( event ) . toStrictEqual ( { exception : { values : [ ] } } ) ;
@@ -52,7 +52,7 @@ describe('applyAggregateErrorsToEvent()', () => {
5252 const event : Event = { exception : { values : [ exceptionFromError ( stackParser , originalException ) ] } } ;
5353 const eventHint : EventHint = { originalException } ;
5454
55- applyAggregateErrorsToEvent ( exceptionFromError , stackParser , key , 100 , event , eventHint ) ;
55+ applyAggregateErrorsToEvent ( exceptionFromError , stackParser , undefined , key , 100 , event , eventHint ) ;
5656 expect ( event ) . toStrictEqual ( {
5757 exception : {
5858 values : [
@@ -97,7 +97,7 @@ describe('applyAggregateErrorsToEvent()', () => {
9797 const event : Event = { exception : { values : [ exceptionFromError ( stackParser , originalException ) ] } } ;
9898 const eventHint : EventHint = { originalException } ;
9999
100- applyAggregateErrorsToEvent ( exceptionFromError , stackParser , 'cause' , 100 , event , eventHint ) ;
100+ applyAggregateErrorsToEvent ( exceptionFromError , stackParser , undefined , 'cause' , 100 , event , eventHint ) ;
101101
102102 // no changes
103103 expect ( event ) . toStrictEqual ( { exception : { values : [ exceptionFromError ( stackParser , originalException ) ] } } ) ;
@@ -116,7 +116,7 @@ describe('applyAggregateErrorsToEvent()', () => {
116116 }
117117
118118 const eventHint : EventHint = { originalException } ;
119- applyAggregateErrorsToEvent ( exceptionFromError , stackParser , key , 5 , event , eventHint ) ;
119+ applyAggregateErrorsToEvent ( exceptionFromError , stackParser , undefined , key , 5 , event , eventHint ) ;
120120
121121 // 6 -> one for original exception + 5 linked
122122 expect ( event . exception ?. values ) . toHaveLength ( 5 + 1 ) ;
@@ -140,7 +140,7 @@ describe('applyAggregateErrorsToEvent()', () => {
140140 const event : Event = { exception : { values : [ exceptionFromError ( stackParser , fakeAggregateError ) ] } } ;
141141 const eventHint : EventHint = { originalException : fakeAggregateError } ;
142142
143- applyAggregateErrorsToEvent ( exceptionFromError , stackParser , 'cause' , 100 , event , eventHint ) ;
143+ applyAggregateErrorsToEvent ( exceptionFromError , stackParser , undefined , 'cause' , 100 , event , eventHint ) ;
144144 expect ( event . exception ?. values ?. [ event . exception . values . length - 1 ] . mechanism ?. type ) . toBe ( 'instrument' ) ;
145145 } ) ;
146146
@@ -155,7 +155,7 @@ describe('applyAggregateErrorsToEvent()', () => {
155155 const event : Event = { exception : { values : [ exceptionFromError ( stackParser , fakeAggregateError1 ) ] } } ;
156156 const eventHint : EventHint = { originalException : fakeAggregateError1 } ;
157157
158- applyAggregateErrorsToEvent ( exceptionFromError , stackParser , 'cause' , 100 , event , eventHint ) ;
158+ applyAggregateErrorsToEvent ( exceptionFromError , stackParser , undefined , 'cause' , 100 , event , eventHint ) ;
159159 expect ( event ) . toStrictEqual ( {
160160 exception : {
161161 values : [
@@ -234,7 +234,7 @@ describe('applyAggregateErrorsToEvent()', () => {
234234 const event : Event = { exception : { values : [ exceptionFromError ( stackParser , originalException ) ] } } ;
235235 const eventHint : EventHint = { originalException } ;
236236
237- applyAggregateErrorsToEvent ( exceptionFromError , stackParser , key , 100 , event , eventHint ) ;
237+ applyAggregateErrorsToEvent ( exceptionFromError , stackParser , undefined , key , 100 , event , eventHint ) ;
238238 expect ( event ) . toStrictEqual ( {
239239 exception : {
240240 values : [
@@ -272,4 +272,52 @@ describe('applyAggregateErrorsToEvent()', () => {
272272 } ,
273273 } ) ;
274274 } ) ;
275+
276+ test ( 'should truncate the exception values if they exceed the `maxValueLength` option' , ( ) => {
277+ const originalException : ExtendedError = new Error ( 'Root Error with long message' ) ;
278+ originalException . cause = new Error ( 'Nested Error 1 with longer message' ) ;
279+ originalException . cause . cause = new Error ( 'Nested Error 2 with longer message with longer message' ) ;
280+
281+ const event : Event = { exception : { values : [ exceptionFromError ( stackParser , originalException ) ] } } ;
282+ const eventHint : EventHint = { originalException } ;
283+
284+ const maxValueLength = 15 ;
285+ applyAggregateErrorsToEvent ( exceptionFromError , stackParser , maxValueLength , 'cause' , 10 , event , eventHint ) ;
286+ expect ( event ) . toStrictEqual ( {
287+ exception : {
288+ values : [
289+ {
290+ value : 'Nested Error 2 ...' ,
291+ mechanism : {
292+ exception_id : 2 ,
293+ handled : true ,
294+ parent_id : 1 ,
295+ source : 'cause' ,
296+ type : 'chained' ,
297+ } ,
298+ } ,
299+ {
300+ value : 'Nested Error 1 ...' ,
301+ mechanism : {
302+ exception_id : 1 ,
303+ handled : true ,
304+ parent_id : 0 ,
305+ is_exception_group : true ,
306+ source : 'cause' ,
307+ type : 'chained' ,
308+ } ,
309+ } ,
310+ {
311+ value : 'Root Error with...' ,
312+ mechanism : {
313+ exception_id : 0 ,
314+ handled : true ,
315+ is_exception_group : true ,
316+ type : 'instrument' ,
317+ } ,
318+ } ,
319+ ] ,
320+ } ,
321+ } ) ;
322+ } ) ;
275323} ) ;
0 commit comments