sentry

package
v0.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

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 DefaultSentryErrorHandler

func DefaultSentryErrorHandler() func(res *http.Response, url string) error

func GetSentryErrorHandler

func GetSentryErrorHandler(conditions ...Condition) func(res *http.Response, url string) error

GetSentryErrorHandler initializes sentry logger for http response errors Responses to be logged are defined via passed conditions

func SetupSentry

func SetupSentry(dsn string, opts ...Option) error

Types

type Condition

type Condition func(res *http.Response, url string) bool

type Option

type Option func(hook *logrus_sentry.SentryHook) error

func WithDefaultLoggerName

func WithDefaultLoggerName(name string) Option

func WithEnvironment

func WithEnvironment(env string) Option

func WithHTTPContext

func WithHTTPContext(h *raven.Http) Option

func WithIgnoreErrors

func WithIgnoreErrors(errs ...string) Option

func WithIncludePaths

func WithIncludePaths(p []string) Option

func WithRelease

func WithRelease(release string) Option

func WithSampleRate

func WithSampleRate(rate float32) Option

func WithServerName

func WithServerName(serverName string) Option

func WithTagsContext

func WithTagsContext(t map[string]string) Option

func WithUserContext

func WithUserContext(u *raven.User) Option

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL