Documentation ¶
Index ¶
- Variables
- func DefaultSentryErrorHandler() func(res *http.Response, url string) error
- func GetSentryErrorHandler(conditions ...Condition) func(res *http.Response, url string) error
- func SetupSentry(dsn string, opts ...Option) error
- type Condition
- type Option
- func WithDefaultLoggerName(name string) Option
- func WithEnvironment(env string) Option
- func WithHTTPContext(h *raven.Http) Option
- func WithIgnoreErrors(errs ...string) Option
- func WithIncludePaths(p []string) Option
- func WithRelease(release string) Option
- func WithSampleRate(rate float32) Option
- func WithServerName(serverName string) Option
- func WithTagsContext(t map[string]string) Option
- func WithUserContext(u *raven.User) Option
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ConditionAnd returns true only when all conditions are satisfied ConditionAnd = func(conditions ...Condition) Condition { return func(res *http.Response, url string) bool { result := true for _, condition := range conditions { if !condition(res, url) { result = false break } } return result } } // ConditionOr return true when any of conditions is satisfied ConditionOr = func(conditions ...Condition) Condition { return func(res *http.Response, url string) bool { for _, condition := range conditions { if condition(res, url) { return true } } return false } } ConditionNotStatusOk = func(res *http.Response, _ string) bool { return res.StatusCode < 200 || res.StatusCode > 299 } ConditionNotStatusBadRequest = func(res *http.Response, _ string) bool { return res.StatusCode != http.StatusBadRequest } ConditionNotStatusNotFound = func(res *http.Response, _ string) bool { return res.StatusCode != http.StatusNotFound } )
View Source
var SentryErrorHandler = func(res *http.Response, url string) error { statusCode := res.StatusCode if statusCode != http.StatusOK && statusCode != http.StatusNotFound { log.WithFields(log.Fields{ "tags": raven.Tags{ {Key: "status_code", Value: strconv.Itoa(res.StatusCode)}, {Key: "host", Value: res.Request.URL.Host}, {Key: "path", Value: res.Request.URL.Path}, {Key: "body", Value: getBody(res)}, }, "url": url, "fingerprint": []string{"client_errors"}, }).Error("Client Errors") } return nil }
Functions ¶
func GetSentryErrorHandler ¶
GetSentryErrorHandler initializes sentry logger for http response errors Responses to be logged are defined via passed conditions
func SetupSentry ¶
Types ¶
type Option ¶
type Option func(hook *logrus_sentry.SentryHook) error
func WithDefaultLoggerName ¶
func WithEnvironment ¶
func WithHTTPContext ¶
func WithHTTPContext(h *raven.Http) Option
func WithIgnoreErrors ¶
func WithIncludePaths ¶
func WithRelease ¶
func WithSampleRate ¶
func WithServerName ¶
func WithTagsContext ¶
func WithUserContext ¶
func WithUserContext(u *raven.User) Option
Click to show internal directories.
Click to hide internal directories.