mirror of
https://github.com/xiaoxinpro/nginx-proxy-manager-zh.git
synced 2025-01-22 21:08:13 -05:00
Remove sentry and error reporting
This commit is contained in:
parent
6d6021c9bb
commit
fd7095ad88
@ -16,7 +16,6 @@ import (
|
||||
|
||||
var commit string
|
||||
var version string
|
||||
var sentryDSN string
|
||||
|
||||
var cloudfrontURL = "https://ip-ranges.amazonaws.com/ip-ranges.json"
|
||||
var cloudflare4URL = "https://www.cloudflare.com/ips-v4"
|
||||
@ -24,7 +23,7 @@ var cloudflare6URL = "https://www.cloudflare.com/ips-v6"
|
||||
|
||||
func main() {
|
||||
config.InitArgs(&version, &commit)
|
||||
if err := config.InitIPRanges(&version, &commit, &sentryDSN); err != nil {
|
||||
if err := config.InitIPRanges(&version, &commit); err != nil {
|
||||
fmt.Printf("# Config ERROR: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import (
|
||||
"npm/internal/database"
|
||||
"npm/internal/entity/certificate"
|
||||
"npm/internal/entity/host"
|
||||
"npm/internal/entity/setting"
|
||||
"npm/internal/entity/user"
|
||||
"npm/internal/errors"
|
||||
"npm/internal/jobqueue"
|
||||
@ -20,11 +19,10 @@ import (
|
||||
|
||||
var commit string
|
||||
var version string
|
||||
var sentryDSN string
|
||||
|
||||
func main() {
|
||||
config.InitArgs(&version, &commit)
|
||||
config.Init(&version, &commit, &sentryDSN)
|
||||
config.Init(&version, &commit)
|
||||
|
||||
database.Migrate(func() {
|
||||
if err := jwt.LoadKeys(); err != nil {
|
||||
@ -32,7 +30,6 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
setting.ApplySettings()
|
||||
checkSetup()
|
||||
|
||||
// Internal Job Queue
|
||||
@ -79,9 +76,6 @@ func checkSetup() {
|
||||
config.IsSetup = true
|
||||
logger.Info("Application is setup")
|
||||
}
|
||||
if config.ErrorReporting {
|
||||
logger.Warn("Error reporting is enabled - Application Errors WILL be sent to Sentry, you can disable this in the Settings interface")
|
||||
}
|
||||
} else {
|
||||
logger.Error("DatabaseError", errors.ErrDatabaseUnavailable)
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
"type": "object",
|
||||
"description": "HealthObject",
|
||||
"additionalProperties": false,
|
||||
"required": ["version", "commit", "healthy", "setup", "error_reporting"],
|
||||
"required": ["version", "commit", "healthy", "setup"],
|
||||
"properties": {
|
||||
"version": {
|
||||
"type": "string",
|
||||
@ -22,10 +22,6 @@
|
||||
"type": "boolean",
|
||||
"description": "Is the application set up?"
|
||||
},
|
||||
"error_reporting": {
|
||||
"type": "boolean",
|
||||
"description": "Will the application send any error reporting?"
|
||||
},
|
||||
"acme.sh": {
|
||||
"type": "string",
|
||||
"description": "Acme.sh version",
|
||||
|
@ -22,8 +22,7 @@
|
||||
"version": "3.0.0",
|
||||
"commit": "9f119b6",
|
||||
"healthy": true,
|
||||
"setup": true,
|
||||
"error_reporting": true
|
||||
"setup": true
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -33,8 +32,7 @@
|
||||
"version": "3.0.0",
|
||||
"commit": "9f119b6",
|
||||
"healthy": false,
|
||||
"setup": true,
|
||||
"error_reporting": true
|
||||
"setup": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,14 +30,6 @@ INSERT INTO `setting` (
|
||||
`description`,
|
||||
`value`
|
||||
) VALUES
|
||||
-- Default error reporting setting
|
||||
(
|
||||
ROUND(UNIX_TIMESTAMP(CURTIME(4)) * 1000),
|
||||
ROUND(UNIX_TIMESTAMP(CURTIME(4)) * 1000),
|
||||
"error-reporting",
|
||||
"If enabled, any application errors are reported to Sentry. Sensitive information is not sent.",
|
||||
"true" -- remember this is json
|
||||
),
|
||||
-- Default site
|
||||
(
|
||||
ROUND(UNIX_TIMESTAMP(CURTIME(4)) * 1000),
|
||||
|
@ -30,14 +30,6 @@ INSERT INTO "setting" (
|
||||
"description",
|
||||
"value"
|
||||
) VALUES
|
||||
-- Default error reporting setting
|
||||
(
|
||||
EXTRACT(EPOCH FROM TIMESTAMP '2011-05-17 10:40:28.876944') * 1000,
|
||||
EXTRACT(EPOCH FROM TIMESTAMP '2011-05-17 10:40:28.876944') * 1000,
|
||||
'error-reporting',
|
||||
'If enabled, any application errors are reported to Sentry. Sensitive information is not sent.',
|
||||
'true' -- remember this is json
|
||||
),
|
||||
-- Default site
|
||||
(
|
||||
EXTRACT(EPOCH FROM TIMESTAMP '2011-05-17 10:40:28.876944') * 1000,
|
||||
|
@ -23,21 +23,6 @@ INSERT INTO `capability` (
|
||||
("streams.manage"),
|
||||
("users.manage");
|
||||
|
||||
-- Default error reporting setting
|
||||
INSERT INTO `setting` (
|
||||
created_at,
|
||||
updated_at,
|
||||
name,
|
||||
description,
|
||||
value
|
||||
) VALUES (
|
||||
unixepoch() * 1000,
|
||||
unixepoch() * 1000,
|
||||
"error-reporting",
|
||||
"If enabled, any application errors are reported to Sentry. Sensitive information is not sent.",
|
||||
"true" -- remember this is json
|
||||
);
|
||||
|
||||
-- Default site
|
||||
INSERT INTO `setting` (
|
||||
created_at,
|
||||
|
@ -9,7 +9,6 @@ require (
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible
|
||||
github.com/drexedam/gravatar v0.0.0-20210327211422-e94eea8c338e
|
||||
github.com/fatih/color v1.15.0
|
||||
github.com/getsentry/sentry-go v0.21.0
|
||||
github.com/glebarez/sqlite v1.8.0
|
||||
github.com/go-chi/chi/v5 v5.0.8
|
||||
github.com/go-chi/cors v1.2.1
|
||||
|
@ -20,8 +20,6 @@ github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkp
|
||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
|
||||
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
|
||||
github.com/getsentry/sentry-go v0.21.0 h1:c9l5F1nPF30JIppulk4veau90PK6Smu3abgVtVQWon4=
|
||||
github.com/getsentry/sentry-go v0.21.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY=
|
||||
github.com/glebarez/go-sqlite v1.21.1 h1:7MZyUPh2XTrHS7xNEHQbrhfMZuPSzhkm2A1qgg0y5NY=
|
||||
github.com/glebarez/go-sqlite v1.21.1/go.mod h1:ISs8MF6yk5cL4n/43rSOmVMGJJjHYr7L2MbZZ5Q4E2E=
|
||||
github.com/glebarez/sqlite v1.8.0 h1:02X12E2I/4C1n+v90yTqrjRa8yuo7c3KeHI3FRznCvc=
|
||||
@ -32,7 +30,6 @@ github.com/go-chi/cors v1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4=
|
||||
github.com/go-chi/cors v1.2.1/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58=
|
||||
github.com/go-chi/jwtauth/v5 v5.1.0 h1:wJyf2YZ/ohPvNJBwPOzZaQbyzwgMZZceE1m8FOzXLeA=
|
||||
github.com/go-chi/jwtauth/v5 v5.1.0/go.mod h1:MA93hc1au3tAQwCKry+fI4LqJ5MIVN4XSsglOo+lSc8=
|
||||
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
|
||||
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
|
||||
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
|
||||
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
|
||||
@ -108,7 +105,6 @@ github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7P
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
|
||||
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
|
@ -13,7 +13,6 @@ type healthCheckResponse struct {
|
||||
AcmeShVersion string `json:"acme.sh"`
|
||||
Healthy bool `json:"healthy"`
|
||||
IsSetup bool `json:"setup"`
|
||||
ErrorReporting bool `json:"error_reporting"`
|
||||
}
|
||||
|
||||
// Health returns the health of the api
|
||||
@ -26,7 +25,6 @@ func Health() func(http.ResponseWriter, *http.Request) {
|
||||
Healthy: true,
|
||||
IsSetup: config.IsSetup,
|
||||
AcmeShVersion: acme.GetAcmeShVersion(),
|
||||
ErrorReporting: config.ErrorReporting,
|
||||
}
|
||||
|
||||
h.ResultResponseJSON(w, r, http.StatusOK, health)
|
||||
|
@ -15,12 +15,11 @@ var (
|
||||
r = NewRouter()
|
||||
version = "3.0.0"
|
||||
commit = "abcdefgh"
|
||||
sentryDSN = ""
|
||||
)
|
||||
|
||||
// Tear up/down
|
||||
func TestMain(m *testing.M) {
|
||||
config.Init(&version, &commit, &sentryDSN)
|
||||
config.Init(&version, &commit)
|
||||
code := m.Run()
|
||||
os.Exit(code)
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,6 @@ func (m *Model) Save() error {
|
||||
if result := db.Save(m); result.Error != nil {
|
||||
return result.Error
|
||||
}
|
||||
ApplySettings()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user