Fix nil actor errors in Sentry API handler
What does this MR do and why?
The Golang SDK often sends up multiple exceptions, with the second one containing more context with the appropriate stack trace. Previously the API handler assumed that the stacktrace existed for the first exception. However, this assumption can be wrong, leading to 500 errors when clients attempt to report an error to GitLab.
Since the GitLab API can only track one Sentry exception, we now choose the first exception that has a stacktrace. We also also gracefully handle an empty stacktrace by reporting no actor.
Relates to #348672 (closed)
Screenshots or screen recordings
This exception was created with https://github.com/getsentry/sentry-go/blob/master/example/basic/main.go:
{
<snip>
"exception": [
{
"type": "*errors.errorString",
"value": "unsupported protocol scheme \"\""
},
{
"type": "*url.Error",
"value": "Get \"foobar\": unsupported protocol scheme \"\"",
"stacktrace": {
"frames": [
{
"function": "main",
"module": "main",
"abs_path": "/Users/stanhu/github/sentry-go/example/basic/main.go",
"lineno": 54,
"pre_context": [
"\t// Set the timeout to the maximum duration the program can afford to wait.",
"\tdefer sentry.Flush(2 * time.Second)",
"",
"\tresp, err := http.Get(os.Args[1])",
"\tif err != nil {"
],
"context_line": "\t\tsentry.CaptureException(err)",
"post_context": [
"\t\tlog.Printf(\"reported to Sentry: %s\", err)",
"\t\treturn",
"\t}",
"\tdefer resp.Body.Close()",
""
],
"in_app": true
}
]
}
}
],
"timestamp": "2021-12-25T22:32:06.191665-08:00"
}
How to set up and validate locally
git clone https://github.com/getsentry/sentry-go
cd sentry-go/example/basic
go build .
-
SENTRY_DSN=http://user:passf@<localhost:9999>/1 ./main foobar
(substitute GitLab API if desired)
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.