ops

package
v0.5.11 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PanicHandler

func PanicHandler(r ErrorReporter, next http.Handler) http.Handler

PanicHandler returns a http.Handler that will recover any panics and report them as request errors. If a panic is caught, the handler will return HTTP 500.

Types

type AirbrakeReporter

type AirbrakeReporter struct {
	*gobrake.Notifier
}

AirbrakeReporter is an ErrorReporter for the Airbrake service (airbrake.io)

func NewAirbrakeReporter

func NewAirbrakeReporter(credentials string) (*AirbrakeReporter, error)

NewAirbrakeReporter builds an AirbrakeReporter from a credentials string. The credentials string should be in the pattern $PROJECT_ID:$PROJECT_KEY (aka username:password).

func (*AirbrakeReporter) ReportError

func (r *AirbrakeReporter) ReportError(err error)

ReportError will deliver the given error to Airbrake in a background routine

func (*AirbrakeReporter) ReportRequestError

func (r *AirbrakeReporter) ReportRequestError(err error, req *http.Request)

ReportRequestError will deliver the given error to Sentry in a background routine along with data relevant to the current http.Request.

NOTE: POST data is never reported to Airbrake, so passwords remain private.

type ErrorReporter

type ErrorReporter interface {
	ReportError(err error)
	ReportRequestError(err error, r *http.Request)
}

ErrorReporter is a thing that exports details about errors and panics to another service. Care must be taken by each implementation to ensure that passwords are not leaked.

func NewErrorReporter

func NewErrorReporter(credentials string, t ErrorReporterType, logger logrus.FieldLogger) (ErrorReporter, error)

NewErrorReporter will instantiate an ErrorReporter for a known type

type ErrorReporterType

type ErrorReporterType int

ErrorReporterType exists to provide context for plain strings in configuration

const (
	Log ErrorReporterType = iota
	Sentry
	Airbrake
)

all known types of ErrorReporter

type LogReporter

type LogReporter struct {
	logrus.FieldLogger
}

LogReporter is an ErrorReporter that prints to the log (likely STDOUT)

func (*LogReporter) ReportError

func (r *LogReporter) ReportError(err error)

ReportError logs error information. The printed details are not robust.

func (*LogReporter) ReportRequestError

func (r *LogReporter) ReportRequestError(err error, req *http.Request)

ReportRequestError logs error information. The printed details are not robust.

type SentryReporter

type SentryReporter struct {
}

SentryReporter is an ErrorReporter for the Sentry service (sentry.io)

func NewSentryReporter

func NewSentryReporter(dsn string) (*SentryReporter, error)

NewSentryReporter builds a SentryReporter from a credentials string

func (*SentryReporter) ReportError

func (r *SentryReporter) ReportError(err error)

ReportError will deliver the given error to Sentry in a background routine.

func (*SentryReporter) ReportRequestError

func (r *SentryReporter) ReportRequestError(err error, req *http.Request)

todo NOTE: POST data is never reported to Sentry, so passwords remain private.

Jump to

Keyboard shortcuts

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