-
Notifications
You must be signed in to change notification settings - Fork 227
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
Missing stack trace when using the logrus integration #677
Comments
Hi mj3c. nice to meet you. Go's standard errors don't come with a stack by themselves. https://github.com/pkg/errors You can take a look at this function I hope my answer is helpful. |
Hi @yiuiua, thank you! That is also what I've gathered from looking at the source code, that a 3rd party library for errors is needed. Though if you look at the examples/screenshots I've provided, which are both done using Go's standard errors, you can see that the stack trace is present when the issue is reported using |
Would you be up opening a PR that adds stack traces to our logrus integration? |
@mj3c Yay, you're right, i overlooked your examples/screenshots, and I apologize.
|
Hey @yiuiua, that's exactly the solution I came up with too. Also, if you test that, you will notice that all errors will be sent with type Here's a patch that I think works okay: diff --git a/logrus/logrusentry.go b/logrus/logrusentry.go
index 0a3a722..fea68ff 100644
--- a/logrus/logrusentry.go
+++ b/logrus/logrusentry.go
@@ -4,6 +4,7 @@ package sentrylogrus
import (
"errors"
"net/http"
+ "reflect"
"time"
sentry "github.com/getsentry/sentry-go"
@@ -184,7 +185,7 @@ func (h *Hook) entryToEvent(l *logrus.Entry) *sentry.Event {
func (h *Hook) exceptions(err error) []sentry.Exception {
if !h.hub.Client().Options().AttachStacktrace {
return []sentry.Exception{{
- Type: "error",
+ Type: reflect.TypeOf(err).String(),
Value: err.Error(),
}}
}
@@ -192,7 +193,7 @@ func (h *Hook) exceptions(err error) []sentry.Exception {
var last *sentry.Exception
for ; err != nil; err = errors.Unwrap(err) {
exc := sentry.Exception{
- Type: "error",
+ Type: reflect.TypeOf(err).String(),
Value: err.Error(),
Stacktrace: sentry.ExtractStacktrace(err),
}
@@ -208,6 +209,11 @@ func (h *Hook) exceptions(err error) []sentry.Exception {
excs = append(excs, exc)
last = &excs[len(excs)-1]
}
+
+ if excs[0].Stacktrace == nil {
+ excs[0].Stacktrace = sentry.NewStacktrace()
+ }
+
// reverse
for i, j := 0, len(excs)-1; i < j; i, j = i+1, j-1 {
excs[i], excs[j] = excs[j], excs[i] However this would require updating some tests as well, and there may be more to this change as I did not have time to really test it and create a PR. In the meantime we ended up creating a custom logger that has the same interface as logrus but also utilizes |
Hi @yiuiua ! I noticed there's been an open PR for this for a while. Could you provide any updates on its progress? Thank you in advance for your time and contributions. |
* fix: missing stack trace for parsing error in logrusentry (#677) * add changes from RFC 0079 (parent_id, exception_id, is_exception_group) * use SetException in logrus --------- Co-authored-by: Emir Ribić <[email protected]>
Summary
When using the logrus approach to report Sentry issues (such as in the example), the issues appear on Sentry but they don't have the nicely formatted stack trace, and the JSON event is missing the
frames
property which I assume is related.If I try to use the basic example with
sentry.CaptureException(err)
, the stack trace shows up and the JSON object has the frames.Steps To Reproduce
Expected Behavior
This is the Sentry issue in JSON format, it's missing the
frames
property next totype
andvalue
.Screenshots
What I get:
What I expect to get (as with
sentry.CaptureException
):Environment
SDK
sentry-go
version: 0.22.0Sentry
Additional context
From what I managed to find while debugging, the problem comes from the fact that when using Sentry with logrus, the
ExtractStackTrace
function exits (which is expected I assume with Go's standard errors) and theNewStackTrace
function is never called, but it is called when using plainsentry.CaptureException
even though I am using Go's standard errors. Any particular reason why the behaviour is different? Am I missing something to have the stack trace frames generated when using Sentry with logrus?The text was updated successfully, but these errors were encountered: