Skip to content

Commit

Permalink
sentrycore: set generated exceptionType on last exception instead of …
Browse files Browse the repository at this point in the history
…the first (#60)

Every once in a while an unhelpfully formatted error shows up in our
Sentry reporting:


![image](https://github.com/sourcegraph/log/assets/23356519/9777f12a-09e9-4945-a0b2-d78be3472dd3)

After digging into this because it bothers me, turns out that even
though the Sentry library says "first" exception is used for the title
it actually uses the last one! Sure enough, this is mentioned in the
cockroach error source:


https://github.com/cockroachdb/errors/blob/26622367a22260fa287d2f7aa2a085b0324c74ee/report/report.go#L324-L325

and we see it in action in the Sentry UI, the title is the exception we
_don't_ overwrite when there are multiple:


![image](https://github.com/sourcegraph/log/assets/23356519/2f5318dd-cb6f-4467-9857-cdcc1b3c3fc3)

Another example:
https://sourcegraph.sentry.io/issues/4193949796/?project=6583153

The errors where the title is what we want all have only 1 generated
exception.

I originally thought that maybe we should overwrite each detected
exception individually with a different generated message that has been
tidied up, but the Sentry exception struct is a bit weird so I figured
whatever, we can revisit this next time.
  • Loading branch information
bobheadxi committed May 23, 2023
1 parent 1102986 commit ad2d71b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion internal/sinkcores/sentrycore/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,17 @@ func (w *worker) capture(errCtx *errorContext) {
// description. And of course we include the scope, because we want to promote
// its use as ways to identify and understand the context of observability
// elements.
event.Exception[0].Type = fmt.Sprintf("[%s] %s: %s",
//
// HOWEVER!!!! It turns out when Sentry says "first exception" it ACTUALLY means
// the LAST exception:
//
// // Note that "first exception" is the last item in the slice,
// // because... Sentry is annoying.
//
// Source: https://github.com/cockroachdb/errors/blob/26622367a22260fa287d2f7aa2a085b0324c74ee/report/report.go#L324-L325
// We've observed this behaviour in practice as well. So here, make sure we are
// overwriting Type on the LAST exception instead of the first.
event.Exception[len(event.Exception)-1].Type = fmt.Sprintf("[%s] %s: %s",
errCtx.Scope, errCtx.Message, errors.Cause(errCtx.Error).Error())
}

Expand Down

0 comments on commit ad2d71b

Please sign in to comment.