@@ -11,7 +11,7 @@ describe('applyAggregateErrorsToEvent()', () => {
11
11
test ( 'should not do anything if event does not contain an exception' , ( ) => {
12
12
const event : Event = { exception : undefined } ;
13
13
const eventHint : EventHint = { originalException : new Error ( ) } ;
14
- applyAggregateErrorsToEvent ( exceptionFromError , stackParser , 'cause' , 100 , event , eventHint ) ;
14
+ applyAggregateErrorsToEvent ( exceptionFromError , stackParser , undefined , 'cause' , 100 , event , eventHint ) ;
15
15
16
16
// no changes
17
17
expect ( event ) . toStrictEqual ( { exception : undefined } ) ;
@@ -20,15 +20,15 @@ describe('applyAggregateErrorsToEvent()', () => {
20
20
test ( 'should not do anything if event does not contain exception values' , ( ) => {
21
21
const event : Event = { exception : { values : undefined } } ;
22
22
const eventHint : EventHint = { originalException : new Error ( ) } ;
23
- applyAggregateErrorsToEvent ( exceptionFromError , stackParser , 'cause' , 100 , event , eventHint ) ;
23
+ applyAggregateErrorsToEvent ( exceptionFromError , stackParser , undefined , 'cause' , 100 , event , eventHint ) ;
24
24
25
25
// no changes
26
26
expect ( event ) . toStrictEqual ( { exception : { values : undefined } } ) ;
27
27
} ) ;
28
28
29
29
test ( 'should not do anything if event does not contain an event hint' , ( ) => {
30
30
const event : Event = { exception : { values : [ ] } } ;
31
- applyAggregateErrorsToEvent ( exceptionFromError , stackParser , 'cause' , 100 , event , undefined ) ;
31
+ applyAggregateErrorsToEvent ( exceptionFromError , stackParser , undefined , 'cause' , 100 , event , undefined ) ;
32
32
33
33
// no changes
34
34
expect ( event ) . toStrictEqual ( { exception : { values : [ ] } } ) ;
@@ -37,7 +37,7 @@ describe('applyAggregateErrorsToEvent()', () => {
37
37
test ( 'should not do anything if the event hint does not contain an original exception' , ( ) => {
38
38
const event : Event = { exception : { values : [ ] } } ;
39
39
const eventHint : EventHint = { originalException : undefined } ;
40
- applyAggregateErrorsToEvent ( exceptionFromError , stackParser , 'cause' , 100 , event , eventHint ) ;
40
+ applyAggregateErrorsToEvent ( exceptionFromError , stackParser , undefined , 'cause' , 100 , event , eventHint ) ;
41
41
42
42
// no changes
43
43
expect ( event ) . toStrictEqual ( { exception : { values : [ ] } } ) ;
@@ -52,7 +52,7 @@ describe('applyAggregateErrorsToEvent()', () => {
52
52
const event : Event = { exception : { values : [ exceptionFromError ( stackParser , originalException ) ] } } ;
53
53
const eventHint : EventHint = { originalException } ;
54
54
55
- applyAggregateErrorsToEvent ( exceptionFromError , stackParser , key , 100 , event , eventHint ) ;
55
+ applyAggregateErrorsToEvent ( exceptionFromError , stackParser , undefined , key , 100 , event , eventHint ) ;
56
56
expect ( event ) . toStrictEqual ( {
57
57
exception : {
58
58
values : [
@@ -97,7 +97,7 @@ describe('applyAggregateErrorsToEvent()', () => {
97
97
const event : Event = { exception : { values : [ exceptionFromError ( stackParser , originalException ) ] } } ;
98
98
const eventHint : EventHint = { originalException } ;
99
99
100
- applyAggregateErrorsToEvent ( exceptionFromError , stackParser , 'cause' , 100 , event , eventHint ) ;
100
+ applyAggregateErrorsToEvent ( exceptionFromError , stackParser , undefined , 'cause' , 100 , event , eventHint ) ;
101
101
102
102
// no changes
103
103
expect ( event ) . toStrictEqual ( { exception : { values : [ exceptionFromError ( stackParser , originalException ) ] } } ) ;
@@ -116,7 +116,7 @@ describe('applyAggregateErrorsToEvent()', () => {
116
116
}
117
117
118
118
const eventHint : EventHint = { originalException } ;
119
- applyAggregateErrorsToEvent ( exceptionFromError , stackParser , key , 5 , event , eventHint ) ;
119
+ applyAggregateErrorsToEvent ( exceptionFromError , stackParser , undefined , key , 5 , event , eventHint ) ;
120
120
121
121
// 6 -> one for original exception + 5 linked
122
122
expect ( event . exception ?. values ) . toHaveLength ( 5 + 1 ) ;
@@ -140,7 +140,7 @@ describe('applyAggregateErrorsToEvent()', () => {
140
140
const event : Event = { exception : { values : [ exceptionFromError ( stackParser , fakeAggregateError ) ] } } ;
141
141
const eventHint : EventHint = { originalException : fakeAggregateError } ;
142
142
143
- applyAggregateErrorsToEvent ( exceptionFromError , stackParser , 'cause' , 100 , event , eventHint ) ;
143
+ applyAggregateErrorsToEvent ( exceptionFromError , stackParser , undefined , 'cause' , 100 , event , eventHint ) ;
144
144
expect ( event . exception ?. values ?. [ event . exception . values . length - 1 ] . mechanism ?. type ) . toBe ( 'instrument' ) ;
145
145
} ) ;
146
146
@@ -155,7 +155,7 @@ describe('applyAggregateErrorsToEvent()', () => {
155
155
const event : Event = { exception : { values : [ exceptionFromError ( stackParser , fakeAggregateError1 ) ] } } ;
156
156
const eventHint : EventHint = { originalException : fakeAggregateError1 } ;
157
157
158
- applyAggregateErrorsToEvent ( exceptionFromError , stackParser , 'cause' , 100 , event , eventHint ) ;
158
+ applyAggregateErrorsToEvent ( exceptionFromError , stackParser , undefined , 'cause' , 100 , event , eventHint ) ;
159
159
expect ( event ) . toStrictEqual ( {
160
160
exception : {
161
161
values : [
@@ -234,7 +234,7 @@ describe('applyAggregateErrorsToEvent()', () => {
234
234
const event : Event = { exception : { values : [ exceptionFromError ( stackParser , originalException ) ] } } ;
235
235
const eventHint : EventHint = { originalException } ;
236
236
237
- applyAggregateErrorsToEvent ( exceptionFromError , stackParser , key , 100 , event , eventHint ) ;
237
+ applyAggregateErrorsToEvent ( exceptionFromError , stackParser , undefined , key , 100 , event , eventHint ) ;
238
238
expect ( event ) . toStrictEqual ( {
239
239
exception : {
240
240
values : [
@@ -272,4 +272,52 @@ describe('applyAggregateErrorsToEvent()', () => {
272
272
} ,
273
273
} ) ;
274
274
} ) ;
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
+ } ) ;
275
323
} ) ;
0 commit comments