1
1
import type { Contexts , Event , EventHint , ExtendedError , IntegrationFn } from '@sentry/types' ;
2
- import { addNonEnumerableProperty , isError , isPlainObject , logger , normalize } from '@sentry/utils' ;
2
+ import { addNonEnumerableProperty , isError , isPlainObject , logger , normalize , truncate } from '@sentry/utils' ;
3
3
import { defineIntegration } from '../integration' ;
4
4
5
5
import { DEBUG_BUILD } from '../debug-build' ;
@@ -27,8 +27,9 @@ const _extraErrorDataIntegration = ((options: Partial<ExtraErrorDataOptions> = {
27
27
const { depth = 3 , captureErrorCause = true } = options ;
28
28
return {
29
29
name : INTEGRATION_NAME ,
30
- processEvent ( event , hint ) {
31
- return _enhanceEventWithErrorData ( event , hint , depth , captureErrorCause ) ;
30
+ processEvent ( event , hint , client ) {
31
+ const { maxValueLength = 250 } = client . getOptions ( ) ;
32
+ return _enhanceEventWithErrorData ( event , hint , depth , captureErrorCause , maxValueLength ) ;
32
33
} ,
33
34
} ;
34
35
} ) satisfies IntegrationFn ;
@@ -40,13 +41,14 @@ function _enhanceEventWithErrorData(
40
41
hint : EventHint = { } ,
41
42
depth : number ,
42
43
captureErrorCause : boolean ,
44
+ maxValueLength : number ,
43
45
) : Event {
44
46
if ( ! hint . originalException || ! isError ( hint . originalException ) ) {
45
47
return event ;
46
48
}
47
49
const exceptionName = ( hint . originalException as ExtendedError ) . name || hint . originalException . constructor . name ;
48
50
49
- const errorData = _extractErrorData ( hint . originalException as ExtendedError , captureErrorCause ) ;
51
+ const errorData = _extractErrorData ( hint . originalException as ExtendedError , captureErrorCause , maxValueLength ) ;
50
52
51
53
if ( errorData ) {
52
54
const contexts : Contexts = {
@@ -74,7 +76,11 @@ function _enhanceEventWithErrorData(
74
76
/**
75
77
* Extract extra information from the Error object
76
78
*/
77
- function _extractErrorData ( error : ExtendedError , captureErrorCause : boolean ) : Record < string , unknown > | null {
79
+ function _extractErrorData (
80
+ error : ExtendedError ,
81
+ captureErrorCause : boolean ,
82
+ maxValueLength : number ,
83
+ ) : Record < string , unknown > | null {
78
84
// We are trying to enhance already existing event, so no harm done if it won't succeed
79
85
try {
80
86
const nativeKeys = [
@@ -97,7 +103,7 @@ function _extractErrorData(error: ExtendedError, captureErrorCause: boolean): Re
97
103
continue ;
98
104
}
99
105
const value = error [ key ] ;
100
- extraErrorInfo [ key ] = isError ( value ) ? value . toString ( ) : value ;
106
+ extraErrorInfo [ key ] = truncate ( isError ( value ) ? value . toString ( ) : value , maxValueLength ) ;
101
107
}
102
108
103
109
// Error.cause is a standard property that is non enumerable, we therefore need to access it separately.
0 commit comments