11import 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' ;
33import { defineIntegration } from '../integration' ;
44
55import { DEBUG_BUILD } from '../debug-build' ;
@@ -27,8 +27,9 @@ const _extraErrorDataIntegration = ((options: Partial<ExtraErrorDataOptions> = {
2727 const { depth = 3 , captureErrorCause = true } = options ;
2828 return {
2929 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 ) ;
3233 } ,
3334 } ;
3435} ) satisfies IntegrationFn ;
@@ -40,13 +41,14 @@ function _enhanceEventWithErrorData(
4041 hint : EventHint = { } ,
4142 depth : number ,
4243 captureErrorCause : boolean ,
44+ maxValueLength : number ,
4345) : Event {
4446 if ( ! hint . originalException || ! isError ( hint . originalException ) ) {
4547 return event ;
4648 }
4749 const exceptionName = ( hint . originalException as ExtendedError ) . name || hint . originalException . constructor . name ;
4850
49- const errorData = _extractErrorData ( hint . originalException as ExtendedError , captureErrorCause ) ;
51+ const errorData = _extractErrorData ( hint . originalException as ExtendedError , captureErrorCause , maxValueLength ) ;
5052
5153 if ( errorData ) {
5254 const contexts : Contexts = {
@@ -74,7 +76,11 @@ function _enhanceEventWithErrorData(
7476/**
7577 * Extract extra information from the Error object
7678 */
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 {
7884 // We are trying to enhance already existing event, so no harm done if it won't succeed
7985 try {
8086 const nativeKeys = [
@@ -97,7 +103,7 @@ function _extractErrorData(error: ExtendedError, captureErrorCause: boolean): Re
97103 continue ;
98104 }
99105 const value = error [ key ] ;
100- extraErrorInfo [ key ] = isError ( value ) ? value . toString ( ) : value ;
106+ extraErrorInfo [ key ] = truncate ( isError ( value ) ? value . toString ( ) : value , maxValueLength ) ;
101107 }
102108
103109 // Error.cause is a standard property that is non enumerable, we therefore need to access it separately.
0 commit comments