feat(BRIDGE-238): Added host information to sentry events; new sentry event for keychain issues

This commit is contained in:
Atanas Janeshliev
2024-10-25 16:40:46 +02:00
parent 810be2d423
commit 4d2b328589
7 changed files with 71 additions and 28 deletions

View File

@ -21,18 +21,13 @@
package sentry
import (
"github.com/elastic/go-sysinfo"
"github.com/elastic/go-sysinfo/types"
"golang.org/x/sys/unix"
)
const translatedProcDarwin = "sysctl.proc_translated"
func getHostArch() string {
host, err := sysinfo.Host()
if err != nil {
return "not-detected"
}
func getHostArch(host types.Host) string {
// It is not possible to retrieve real hardware architecture once using
// rosetta. But it is possible to detect the process translation if
// rosetta is used.

View File

@ -20,12 +20,10 @@
package sentry
import "github.com/elastic/go-sysinfo"
import (
"github.com/elastic/go-sysinfo/types"
)
func getHostArch() string {
host, err := sysinfo.Host()
if err != nil {
return "not-detected"
}
func getHostArch(host types.Host) string {
return host.Info().Architecture
}

View File

@ -30,10 +30,13 @@ import (
"github.com/ProtonMail/proton-bridge/v3/internal/constants"
"github.com/ProtonMail/proton-bridge/v3/pkg/algo"
"github.com/ProtonMail/proton-bridge/v3/pkg/restarter"
"github.com/elastic/go-sysinfo"
"github.com/getsentry/sentry-go"
"github.com/sirupsen/logrus"
)
const hostNotDetectedField = "not-detected"
var skippedFunctions = []string{} //nolint:gochecknoglobals
func init() { //nolint:gochecknoinits
@ -70,17 +73,50 @@ func init() { //nolint:gochecknoinits
)
}
type hostInfoData struct {
hostArch string
hostName string
hostVersion string
hostBuild string
}
func newHostInfoData() hostInfoData {
return hostInfoData{
hostArch: hostNotDetectedField,
hostName: hostNotDetectedField,
hostVersion: hostNotDetectedField,
hostBuild: hostNotDetectedField,
}
}
type Reporter struct {
appName string
appVersion string
identifier Identifier
hostArch string
hostInfo hostInfoData
}
type Identifier interface {
GetUserAgent() string
}
func getHostInfo() hostInfoData {
data := newHostInfoData()
host, err := sysinfo.Host()
if err != nil {
return data
}
data.hostArch = getHostArch(host)
osInfo := host.Info().OS
data.hostName = osInfo.Name
data.hostVersion = osInfo.Version
data.hostBuild = osInfo.Build
return data
}
func GetProtectedHostname() string {
hostname, err := os.Hostname()
if err != nil {
@ -100,7 +136,7 @@ func NewReporter(appName string, identifier Identifier) *Reporter {
appName: appName,
appVersion: constants.Revision,
identifier: identifier,
hostArch: getHostArch(),
hostInfo: getHostInfo(),
}
}
@ -152,11 +188,14 @@ func (r *Reporter) scopedReport(context map[string]interface{}, doReport func())
}
tags := map[string]string{
"OS": runtime.GOOS,
"Client": r.appName,
"Version": r.appVersion,
"UserAgent": r.identifier.GetUserAgent(),
"HostArch": r.hostArch,
"OS": runtime.GOOS,
"Client": r.appName,
"Version": r.appVersion,
"UserAgent": r.identifier.GetUserAgent(),
"HostArch": r.hostInfo.hostArch,
"HostName": r.hostInfo.hostName,
"HostVersion": r.hostInfo.hostVersion,
"HostBuild": r.hostInfo.hostBuild,
}
sentry.WithScope(func(scope *sentry.Scope) {