Skip to content
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

fix: missing stack trace for parsing error in logrusentry #689

Merged
merged 8 commits into from
Apr 2, 2024
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

## Unreleased

### Features

- Accept `interface{}` for span data values ([#784](https://github.com/getsentry/sentry-go/pull/784))
- Automatic transactions for Echo integration ([#722](https://github.com/getsentry/sentry-go/pull/722))
- Add `http.request.method` attribute for performance span data ([#786](https://github.com/getsentry/sentry-go/pull/786))
- Automatic transactions for Fasthttp integration ([#732](https://github.com/getsentry/sentry-go/pull/723))
- Add `Fiber` integration ([#795](https://github.com/getsentry/sentry-go/pull/795))
- Use `errors.Unwrap()` to create exception groups ([#792](https://github.com/getsentry/sentry-go/pull/792))

### Fixes

- Fix missing stack trace for parsing error in logrusentry ([#689](https://github.com/getsentry/sentry-go/pull/689))

## 0.27.0

The Sentry SDK team is happy to announce the immediate availability of Sentry Go SDK v0.27.0.
Expand Down
5 changes: 3 additions & 2 deletions interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,15 +338,16 @@ type Event struct {
// SetException appends the unwrapped errors to the event's exception list.
//
// maxErrorDepth is the maximum depth of the error chain we will look
// into while unwrapping the errors.
// into while unwrapping the errors. If maxErrorDepth is -1, we will
// unwrap all errors in the chain.
func (e *Event) SetException(exception error, maxErrorDepth int) {
if exception == nil {
return
}

err := exception

for i := 0; err != nil && i < maxErrorDepth; i++ {
for i := 0; err != nil && (i < maxErrorDepth || maxErrorDepth == -1); i++ {
// Add the current error to the exception slice with its details
e.Exception = append(e.Exception, Exception{
Value: err.Error(),
Expand Down
40 changes: 3 additions & 37 deletions logrus/logrusentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (
"net/http"
"time"

sentry "github.com/getsentry/sentry-go"
"github.com/sirupsen/logrus"

sentry "github.com/getsentry/sentry-go"
)

// The identifier of the Logrus SDK.
Expand Down Expand Up @@ -160,8 +161,7 @@ func (h *Hook) entryToEvent(l *logrus.Entry) *sentry.Event {
}
if err, ok := s.Extra[logrus.ErrorKey].(error); ok {
delete(s.Extra, logrus.ErrorKey)
ex := h.exceptions(err)
s.Exception = ex
s.SetException(err, -1)
}
key = h.key(FieldUser)
if user, ok := s.Extra[key].(sentry.User); ok {
Expand All @@ -187,40 +187,6 @@ func (h *Hook) entryToEvent(l *logrus.Entry) *sentry.Event {
return s
}

func (h *Hook) exceptions(err error) []sentry.Exception {
if !h.hub.Client().Options().AttachStacktrace {
return []sentry.Exception{{
Type: "error",
Value: err.Error(),
}}
}
excs := []sentry.Exception{}
var last *sentry.Exception
for ; err != nil; err = errors.Unwrap(err) {
exc := sentry.Exception{
Type: "error",
Value: err.Error(),
Stacktrace: sentry.ExtractStacktrace(err),
}
if last != nil && exc.Value == last.Value {
if last.Stacktrace == nil {
last.Stacktrace = exc.Stacktrace
continue
}
if exc.Stacktrace == nil {
continue
}
}
excs = append(excs, exc)
last = &excs[len(excs)-1]
}
// reverse
for i, j := 0, len(excs)-1; i < j; i, j = i+1, j-1 {
excs[i], excs[j] = excs[j], excs[i]
}
return excs
}

// Flush waits until the underlying Sentry transport sends any buffered events,
// blocking for at most the given timeout. It returns false if the timeout was
// reached, in which case some events may not have been sent.
Expand Down
Loading
Loading