-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added sentry hint with the original errs #37
base: master
Are you sure you want to change the base?
Changes from all commits
3cb797b
c329f69
7fc473c
eabd111
0e16c0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
package zapsentry | ||
|
||
import ( | ||
"errors" | ||
"reflect" | ||
"strings" | ||
"time" | ||
|
||
"github.com/pkg/errors" | ||
|
||
"github.com/getsentry/sentry-go" | ||
"go.uber.org/zap" | ||
"go.uber.org/zap/zapcore" | ||
|
@@ -128,7 +129,7 @@ func (c *core) Write(ent zapcore.Entry, fs []zapcore.Field) error { | |
} | ||
} | ||
|
||
_ = c.client.CaptureEvent(event, nil, c.scope()) | ||
_ = c.client.CaptureEvent(event, c.createHint(), c.scope()) | ||
} | ||
|
||
// We may be crashing the program, so should flush any buffered events. | ||
|
@@ -188,25 +189,32 @@ func (c *core) addExceptionsFromError( | |
err error, | ||
) []sentry.Exception { | ||
for i := 0; i < maxErrorDepth && err != nil; i++ { | ||
wrappedErr := err | ||
err = errors.Cause(err) | ||
if _, ok := processedErrors[getTypeOf(err)]; ok { | ||
return exceptions | ||
} | ||
|
||
processedErrors[getTypeOf(err)] = struct{}{} | ||
|
||
exception := sentry.Exception{Value: err.Error(), Type: reflect.TypeOf(err).String()} | ||
if strings.HasSuffix(exception.Type, "errors.fundamental") { | ||
// err was created with `errors.New(msg)` - make `msg` the type, | ||
Comment on lines
+201
to
+202
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually see Is the comment maybe not up-to-date? Or the check? Also, this type doesn't seem to have ever been renamed since its introduction 12 years ago, but it may still be a bit brittle to check directly against it. Maybe it would be enough to check for any error type inside of |
||
// and get the wrapped value as the value | ||
exception.Type = exception.Value | ||
exception.Value = wrappedErr.Error() | ||
} | ||
|
||
if !c.cfg.DisableStacktrace { | ||
exception.Stacktrace = sentry.ExtractStacktrace(err) | ||
// extract from wrappedErr - if err was not wrapped, its the same | ||
exception.Stacktrace = sentry.ExtractStacktrace(wrappedErr) | ||
} | ||
|
||
exceptions = append(exceptions, exception) | ||
|
||
switch previousProvider := err.(type) { | ||
case interface{ Unwrap() error }: | ||
err = previousProvider.Unwrap() | ||
case interface{ Cause() error }: | ||
err = previousProvider.Cause() | ||
default: | ||
err = nil | ||
} | ||
|
@@ -300,6 +308,16 @@ func (c *core) GetClient() *sentry.Client { | |
return c.client | ||
} | ||
|
||
func (c *core) createHint() *sentry.EventHint { | ||
hint := sentry.EventHint{ | ||
Data: c.errs, | ||
} | ||
if len(c.errs) > 0 { | ||
hint.OriginalException = c.errs[0] | ||
} | ||
return &hint | ||
} | ||
|
||
type core struct { | ||
client *sentry.Client | ||
cfg *Configuration | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alternatively, why not keep the
select
logic below, and just keep track of a - possiblynil
-previousErr
, initialized outside the loop?this way we need mentally less "special-casing" of this specific lib.