sentry

package
v1.7.7 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func CloneContext added in v1.7.1

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 added in v1.7.1

func ReportErrors(conf Config) gin.HandlerFunc

Gin middleware to capture errors set on the gin context.

func RequestContext added in v1.7.1

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

func Stream added in v1.7.1

Wrap a grpc.ServerStream handler with the sentry context.

func StreamInterceptor added in v1.7.0

func StreamInterceptor(conf Config) grpc.StreamServerInterceptor

StreamInterceptor for gRPC services that are using Sentry. Ensures that Sentry is used in a thread-safe manner and that performance, panics, and errors are correctly tracked with gRPC method names. Streaming RPCs don't necessarily benefit from Sentry performance tracking, but it is helpful to see average durations.

func TrackPerformance

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

Gin middleware that tracks HTTP request performance with Sentry

func TransactionName added in v1.7.1

func TransactionName(c *gin.Context) string

func UnaryInterceptor added in v1.7.0

func UnaryInterceptor(conf Config) grpc.UnaryServerInterceptor

UnaryInterceptor for gRPC services that are using Sentry. Ensures that Sentry is used in a thread-safe manner and that performance, panics, and errors are correctly tracked with gRPC method names.

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"`
	Release          string  `split_words:"true"`
	TrackPerformance bool    `split_words:"true" default:"false"`
	SampleRate       float64 `split_words:"true" default:"0.85"`
	ReportErrors     bool    `split_words:"true" default:"false"`
	Repanic          bool    `ignored:"true"`
	Debug            bool    `default:"false"`
}

Sentry configuration

func (Config) ClientOptions added in v1.7.1

func (c Config) ClientOptions() sentry.ClientOptions

func (Config) GetRelease

func (c Config) GetRelease() string

Get the configured version string or the current semantic version if not configured.

func (Config) UsePerformanceTracking

func (c Config) UsePerformanceTracking() bool

Returns True if performance tracking is enabled.

func (Config) UseSentry

func (c Config) UseSentry() bool

Returns True if Sentry is enabled.

func (Config) Validate

func (c Config) Validate() error

type Dictionary added in v1.7.1

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

func Dict added in v1.7.1

func Dict() *Dictionary

func (*Dictionary) Int added in v1.7.1

func (d *Dictionary) Int(key string, value int) *Dictionary

func (*Dictionary) Str added in v1.7.1

func (d *Dictionary) Str(key, val string) *Dictionary

func (*Dictionary) Uint64 added in v1.7.1

func (d *Dictionary) Uint64(key string, value uint64) *Dictionary

type Event added in v1.7.1

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 added in v1.7.1

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 added in v1.7.1

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 added in v1.7.1

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 added in v1.7.1

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 added in v1.7.1

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 added in v1.7.1

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) Bool added in v1.7.1

func (e *Event) Bool(key string, value bool) *Event

func (*Event) Bytes added in v1.7.1

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

func (*Event) Dict added in v1.7.1

func (e *Event) Dict(key string, dict *Dictionary) *Event

func (*Event) Err added in v1.7.1

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

func (*Event) Errs added in v1.7.1

func (e *Event) Errs(errs []error) *Event

func (*Event) Int added in v1.7.1

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

func (*Event) Int32 added in v1.7.1

func (e *Event) Int32(key string, value int32) *Event

func (*Event) Int64 added in v1.7.1

func (e *Event) Int64(key string, value int64) *Event

func (*Event) Msg added in v1.7.1

func (e *Event) Msg(msg string)

Finalizes the event and sends it to Sentry and Zerolog

func (*Event) Msgf added in v1.7.1

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 added in v1.7.1

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

func (*Event) ULID added in v1.7.1

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

func (*Event) Uint64 added in v1.7.1

func (e *Event) Uint64(key string, value uint64) *Event

func (*Event) Uint8 added in v1.7.1

func (e *Event) Uint8(key string, value uint8) *Event

type Logger added in v1.7.1

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

Logger is an intermediate struct that holds a zero-log context.

func With added in v1.7.1

func With(ctx interface{}) *Logger

func (*Logger) Bool added in v1.7.1

func (l *Logger) Bool(key string, value bool) *Logger

func (Logger) Debug added in v1.7.1

func (l Logger) Debug() *Event

func (*Logger) Dict added in v1.7.1

func (l *Logger) Dict(key string, dict *Dictionary) *Logger

func (Logger) Error added in v1.7.1

func (l Logger) Error() *Event

func (Logger) Info added in v1.7.1

func (l Logger) Info() *Event

func (*Logger) Int added in v1.7.1

func (l *Logger) Int(key string, value int) *Logger

func (*Logger) Str added in v1.7.1

func (l *Logger) Str(key, value string) *Logger

func (Logger) Trace added in v1.7.1

func (l Logger) Trace() *zerolog.Event

func (Logger) Warn added in v1.7.1

func (l Logger) Warn() *Event

type ServiceError added in v1.7.1

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

A standardized error type for fingerprinting inside of Sentry.

func (*ServiceError) Error added in v1.7.1

func (e *ServiceError) Error() string

func (*ServiceError) Is added in v1.7.1

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

func (*ServiceError) Unwrap added in v1.7.1

func (e *ServiceError) Unwrap() error

Jump to

Keyboard shortcuts

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