Skip to content

Commit

Permalink
feat: Add max-depth options (#428)
Browse files Browse the repository at this point in the history
Co-authored-by: Semen Shaplygin <sashaplygin@avito.ru>
  • Loading branch information
sshaplygin and Semen Shaplygin authored Apr 20, 2022
1 parent b243527 commit d67b699
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ coverage.txt
# Just my personal way of tracking stuff — Kamil
FIXME.md
TODO.md
!NOTES.md
!NOTES.md

# IDE system files
.idea
.vscode
14 changes: 13 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit d67b699

Please sign in to comment.