diff --git a/.gitignore b/.gitignore index 29bfd6f1..5d0e90c5 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,8 @@ coverage.txt # Just my personal way of tracking stuff — Kamil FIXME.md TODO.md -!NOTES.md \ No newline at end of file +!NOTES.md + +# IDE system files +.idea +.vscode diff --git a/client.go b/client.go index c01ef5ac..1cc33690 100644 --- a/client.go +++ b/client.go @@ -192,6 +192,14 @@ type ClientOptions struct { HTTPSProxy string // An optional set of SSL certificates to use. CaCerts *x509.CertPool + // MaxErrorDepth is the maximum number of errors reported in a chain of errors. + // This protects the SDK from an arbitrarily long chain of wrapped errors. + // + // An additional consideration is that arguably reporting a long chain of errors + // is of little use when debugging production errors with Sentry. The Sentry UI + // is not optimized for long chains either. The top-level error together with a + // stack trace is often the most useful information. + MaxErrorDepth int } // Client is the underlying processor that is used by the main API and Hub @@ -238,6 +246,10 @@ func NewClient(options ClientOptions) (*Client, error) { options.Environment = os.Getenv("SENTRY_ENVIRONMENT") } + if options.MaxErrorDepth == 0 { + options.MaxErrorDepth = maxErrorDepth + } + // SENTRYGODEBUG is a comma-separated list of key=value pairs (similar // to GODEBUG). It is not a supported feature: recognized debug options // may change any time. @@ -460,7 +472,7 @@ func (client *Client) eventFromException(exception error, level Level) *Event { event := NewEvent() event.Level = level - for i := 0; i < maxErrorDepth && err != nil; i++ { + for i := 0; i < client.options.MaxErrorDepth && err != nil; i++ { event.Exception = append(event.Exception, Exception{ Value: err.Error(), Type: reflect.TypeOf(err).String(),