sentry

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const HeaderRequestID = "X-Request-ID"

Variables

This section is empty.

Functions

func CloneContext

func CloneContext(c *gin.Context) context.Context

func Flush

func Flush(timeout time.Duration) bool

Flush the Sentry log, usually called before shutting down servers

func Init

func Init(conf Config) (err error)

Initialize the Sentry SDK with the configuration; must be called before servers are started

func ReportErrors

func ReportErrors(conf Config) gin.HandlerFunc

Gin middleware to capture errors set on the gin context.

func TrackPerformance

func TrackPerformance(tags map[string]string) gin.HandlerFunc

Gin middleware that tracks HTTP request performance with Sentry

func TransactionName

func TransactionName(c *gin.Context) string

func UseTags

func UseTags(tags map[string]string) gin.HandlerFunc

Gin middleware that adds request-level tags to the Sentry scope.

Types

type Config

type Config struct {
	DSN              string  `split_words:"true"`
	ServerName       string  `split_words:"true"`
	Environment      string  `split_words:"true" default:"production"`
	Release          string  `split_words:"true"`
	TrackPerformance bool    `split_words:"true" default:"true"`
	SampleRate       float64 `split_words:"true" default:"0.25"`
	ReportErrors     bool    `split_words:"true" default:"true"`
	Repanic          bool    `ignored:"true"`
	Debug            bool    `default:"false"`
}

Sentry configuration for use in application-configuration

func (Config) ClientOptions

func (c Config) ClientOptions() sentry.ClientOptions

func (Config) UsePerformanceTracking

func (c Config) UsePerformanceTracking() bool

Performance tracking is enabled if Sentry is enabled and track performance is explicitly set

func (Config) UseSentry

func (c Config) UseSentry() bool

Returns true if Sentry is enabled (e.g. a DSN is configured)

func (Config) Validate

func (c Config) Validate() error

type Event

type Event struct {
	// contains filtered or unexported fields
}

Event is a top-level function for dealing with errors in a robust manner. It logs the error using zerolog at the specified level, sends an error to Sentry if the hub is available, adds the error to the gin context if it's available and performs other tasks related to monitoring and alerting of errors in the Ensign project.

This should only be used if the error needs to generate an alert; otherwise use zerolog directly rather than using this Event type.

The sentry level is mapped to the zerolog level, which means the zerolog.TraceLevel and zerolog.PanicLevel are not available in this Event type.

Not safe for concurrent use!

func CreateEvent

func CreateEvent(level sentry.Level, ctx interface{}) *Event

The ctx should be either a gin.Context or a context.Context; the hub is extracted from the context if it was set by middleware or interceptors. Once the event is created it must be sent using Msg or Msgf.

func Debug

func Debug(ctx interface{}) *Event

Reports a debug level event to Sentry and logs a debug message. Use this method when the debug message should produce an alert that the team can take action on (which should happen only very rarely in code). Most of the time you should use zerolog.Debug directly unless this is at the top level of the stack.

func Error

func Error(ctx interface{}) *Event

Report an error to Sentry and log an error message. This is the most commonly used method for Sentry on top level service handlers and is intended to produce alerts that something is going wrong and that the team needs to handle it. When not in a service handler, feel free to use zerolog.Error but probably zerolog.Warn is more appropriate for most cases.

func Fatal

func Fatal(ctx interface{}) *Event

Report a critical error to Sentry and log a fatal error message. While this method will not cause the process to exit, it should create a serious alert that will cause on call personnel to immediately act. Use with care!

func Info

func Info(ctx interface{}) *Event

Reports an info level event to Sentry and logs an info message. Use this method when the info message should produce an alert that the team can take action on (which should happen very rarely in code and is probably related to a third party service such as rate limits or usage thresholds). Most of the time you should use zerolog.Info directly unless this is at the top level of the stack.

func Warn

func Warn(ctx interface{}) *Event

Report a warning level event to Sentry and logs a warning messages. Use this method on top level service handlers to produce alerts that something is going wrong in the code such as bad requests or not found errors. The team will likely not take action on these errors but will get a general sense of what is going on in code. When not in a service handler it is better to use zerolog.Warn directly.

func (*Event) Bytes

func (e *Event) Bytes(key string, value []byte) *Event

func (*Event) Err

func (e *Event) Err(err error) *Event

func (*Event) Int

func (e *Event) Int(key string, value int) *Event

func (*Event) Msg

func (e *Event) Msg(msg string)

Finalizes the event and sends it to Sentry and Zerolog

func (*Event) Msgf

func (e *Event) Msgf(format string, args ...interface{})

Finalizes the event with the format string and arguments then sends it to Sentry and Zerolog.

func (*Event) Str

func (e *Event) Str(key, value string) *Event

func (*Event) ULID

func (e *Event) ULID(key string, value ulid.ULID) *Event

type ServiceError

type ServiceError struct {
	// contains filtered or unexported fields
}

A standardized error type for fingerprinting inside of Sentry.

func (*ServiceError) Error

func (e *ServiceError) Error() string

func (*ServiceError) Is

func (e *ServiceError) Is(target error) bool

func (*ServiceError) Unwrap

func (e *ServiceError) Unwrap() error

Jump to

Keyboard shortcuts

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