Remove sentry and error reporting

This commit is contained in:
Jamie Curnow
2023-07-20 15:19:42 +10:00
parent 6d6021c9bb
commit fd7095ad88
18 changed files with 26 additions and 144 deletions

View File

@ -8,12 +8,11 @@ import (
)
type healthCheckResponse struct {
Version string `json:"version"`
Commit string `json:"commit"`
AcmeShVersion string `json:"acme.sh"`
Healthy bool `json:"healthy"`
IsSetup bool `json:"setup"`
ErrorReporting bool `json:"error_reporting"`
Version string `json:"version"`
Commit string `json:"commit"`
AcmeShVersion string `json:"acme.sh"`
Healthy bool `json:"healthy"`
IsSetup bool `json:"setup"`
}
// Health returns the health of the api
@ -21,12 +20,11 @@ type healthCheckResponse struct {
func Health() func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
health := healthCheckResponse{
Version: config.Version,
Commit: config.Commit,
Healthy: true,
IsSetup: config.IsSetup,
AcmeShVersion: acme.GetAcmeShVersion(),
ErrorReporting: config.ErrorReporting,
Version: config.Version,
Commit: config.Commit,
Healthy: true,
IsSetup: config.IsSetup,
AcmeShVersion: acme.GetAcmeShVersion(),
}
h.ResultResponseJSON(w, r, http.StatusOK, health)

View File

@ -12,15 +12,14 @@ import (
)
var (
r = NewRouter()
version = "3.0.0"
commit = "abcdefgh"
sentryDSN = ""
r = NewRouter()
version = "3.0.0"
commit = "abcdefgh"
)
// Tear up/down
func TestMain(m *testing.M) {
config.Init(&version, &commit, &sentryDSN)
config.Init(&version, &commit)
code := m.Run()
os.Exit(code)
}

View File

@ -3,19 +3,14 @@ package config
import (
"fmt"
golog "log"
"runtime"
"npm/internal/logger"
"github.com/getsentry/sentry-go"
"github.com/vrischmann/envconfig"
)
// Init will parse environment variables into the Env struct
func Init(version, commit, sentryDSN *string) {
// ErrorReporting is enabled until we load the status of it from the DB later
ErrorReporting = true
func Init(version, commit *string) {
Version = *version
Commit = *commit
@ -23,23 +18,22 @@ func Init(version, commit, sentryDSN *string) {
fmt.Printf("%+v\n", err)
}
initLogger(*sentryDSN)
initLogger()
logger.Info("Build Version: %s (%s)", Version, Commit)
createDataFolders()
}
// InitIPRanges will initialise the config for the ipranges command
func InitIPRanges(version, commit, sentryDSN *string) error {
ErrorReporting = true
func InitIPRanges(version, commit *string) error {
Version = *version
Commit = *commit
err := envconfig.InitWithPrefix(&Configuration, "NPM")
initLogger(*sentryDSN)
initLogger()
return err
}
// Init initialises the Log object and return it
func initLogger(sentryDSN string) {
func initLogger() {
// this removes timestamp prefixes from logs
golog.SetFlags(0)
@ -57,16 +51,6 @@ func initLogger(sentryDSN string) {
err := logger.Configure(&logger.Config{
LogThreshold: logLevel,
Formatter: Configuration.Log.Format,
SentryConfig: sentry.ClientOptions{
// This is the jc21 NginxProxyManager Sentry project,
// errors will be reported here (if error reporting is enable)
// and this project is private. No personal information should
// be sent in any error messages, only stacktraces.
Dsn: sentryDSN,
Release: Commit,
Dist: Version,
Environment: fmt.Sprintf("%s-%s", runtime.GOOS, runtime.GOARCH),
},
})
if err != nil {

View File

@ -13,9 +13,6 @@ var Commit string
// IsSetup defines whether we have an admin user or not
var IsSetup bool
// ErrorReporting defines whether we will send errors to Sentry
var ErrorReporting bool
var logLevel logger.Level
type log struct {

View File

@ -1,9 +1,7 @@
package setting
import (
"npm/internal/config"
"npm/internal/entity"
"npm/internal/logger"
"npm/internal/model"
)
@ -55,16 +53,3 @@ func List(pageInfo model.PageInfo, filters []model.Filter) (entity.ListResponse,
return result, nil
}
// ApplySettings will load settings from the DB and apply them where required
func ApplySettings() {
logger.Debug("Applying Settings")
// Error-reporting
m, err := GetByName("error-reporting")
if err != nil {
logger.Error("ApplySettingsError", err)
} else {
config.ErrorReporting = m.Value.String() == "true"
}
}

View File

@ -45,6 +45,6 @@ func (m *Model) Save() error {
if result := db.Save(m); result.Error != nil {
return result.Error
}
ApplySettings()
return nil
}

View File

@ -1,7 +1,5 @@
package logger
import "github.com/getsentry/sentry-go"
// Level type
type Level int
@ -21,7 +19,6 @@ const (
type Config struct {
LogThreshold Level
Formatter string
SentryConfig sentry.ClientOptions
}
// Interface for a logger

View File

@ -10,7 +10,6 @@ import (
"time"
"github.com/fatih/color"
"github.com/getsentry/sentry-go"
"github.com/rotisserie/eris"
)
@ -113,13 +112,6 @@ func (l *Logger) Configure(c *Config) error {
l.LogThreshold = c.LogThreshold
l.Formatter = c.Formatter
l.SentryConfig = c.SentryConfig
if c.SentryConfig.Dsn != "" {
if sentryErr := sentry.Init(c.SentryConfig); sentryErr != nil {
fmt.Printf("Sentry initialization failed: %v\n", sentryErr)
}
}
stdlog.SetFlags(0) // this removes timestamp prefixes from logs
return nil
@ -228,21 +220,4 @@ func (l *Logger) Warn(format string, args ...interface{}) {
// Attempts to log to bugsang.
func (l *Logger) Error(errorClass string, err error) {
l.logLevel(ErrorLevel, err.Error(), errorClass)
l.notifySentry(errorClass, err)
}
func (l *Logger) notifySentry(errorClass string, err error) {
if l.SentryConfig.Dsn != "" && l.SentryConfig.Dsn != "-" {
sentry.ConfigureScope(func(scope *sentry.Scope) {
scope.SetLevel(sentry.LevelError)
scope.SetTag("service", "backend")
scope.SetTag("error_class", errorClass)
})
sentry.CaptureException(err)
// Since sentry emits events in the background we need to make sure
// they are sent before we shut down
sentry.Flush(time.Second * 5)
}
}

View File

@ -7,7 +7,6 @@ import (
"os"
"testing"
"github.com/getsentry/sentry-go"
"github.com/rotisserie/eris"
"github.com/stretchr/testify/assert"
)
@ -115,7 +114,6 @@ func TestConfigure(t *testing.T) {
args: args{
&Config{
LogThreshold: InfoLevel,
SentryConfig: sentry.ClientOptions{},
},
},
wantErr: false,
@ -123,9 +121,7 @@ func TestConfigure(t *testing.T) {
{
name: "invalid log level",
args: args{
&Config{
SentryConfig: sentry.ClientOptions{},
},
&Config{},
},
wantErr: true,
},