mirror of
https://github.com/status-im/status-go.git
synced 2025-01-19 03:04:54 +00:00
987a9e8707
* feat_: report panics to sentry * test_: sentry options, params and utils * feat_: toggle sentry with centralized metrics * test_: sentry init, report and close * refactor_: rename public api to generic * docs_: sentry * fix_: typo in internal/sentry/README.md Co-authored-by: osmaczko <33099791+osmaczko@users.noreply.github.com> * fix_: linter --------- Co-authored-by: osmaczko <33099791+osmaczko@users.noreply.github.com>
66 lines
1.2 KiB
Go
66 lines
1.2 KiB
Go
package sentry
|
|
|
|
import (
|
|
"slices"
|
|
|
|
"github.com/getsentry/sentry-go"
|
|
)
|
|
|
|
var stacktraceFilters = []struct {
|
|
Module string
|
|
Functions []string
|
|
}{
|
|
{
|
|
Module: "github.com/status-im/status-go/internal/sentry",
|
|
Functions: []string{"Recover", "RecoverError"},
|
|
},
|
|
{
|
|
Module: "github.com/status-im/status-go/common",
|
|
Functions: []string{"LogOnPanic"},
|
|
},
|
|
{
|
|
Module: "github.com/status-im/status-go/mobile/callog",
|
|
Functions: []string{"Call.func1"},
|
|
},
|
|
}
|
|
|
|
func trimStacktrace(stacktrace *sentry.Stacktrace) {
|
|
if stacktrace == nil {
|
|
return
|
|
}
|
|
|
|
if len(stacktrace.Frames) <= 1 {
|
|
return
|
|
}
|
|
|
|
trim := 0
|
|
|
|
// Trim max 2 frames from the end
|
|
for i := len(stacktrace.Frames) - 1; i >= 0; i-- {
|
|
if !matchFilter(stacktrace.Frames[i]) {
|
|
// break as soon as we find a frame that doesn't match
|
|
break
|
|
}
|
|
|
|
trim++
|
|
if trim == 2 {
|
|
break
|
|
}
|
|
}
|
|
|
|
stacktrace.Frames = stacktrace.Frames[:len(stacktrace.Frames)-trim]
|
|
}
|
|
|
|
func matchFilter(frame sentry.Frame) bool {
|
|
for _, filter := range stacktraceFilters {
|
|
if frame.Module != filter.Module {
|
|
continue
|
|
}
|
|
if !slices.Contains(filter.Functions, frame.Function) {
|
|
continue
|
|
}
|
|
return true
|
|
}
|
|
return false
|
|
}
|