sentry

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2023 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	APIStatusEndpoint    = "GET /v1/status"
	EnsignStatusEndpoint = "/ensign.v1beta1.Ensign/Status"
	StatusSampleRate     = 0.005
)
View Source
const HeaderRequestID = "X-Request-ID"

Variables

This section is empty.

Functions

func CloneContext added in v0.5.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 NewStatusSampler added in v0.5.2

func NewStatusSampler(defaultSampleRate float64) sentry.TracesSampler

func ReportErrors added in v0.5.0

func ReportErrors(conf Config) gin.HandlerFunc

Gin middleware to capture errors set on the gin context.

func Stream added in v0.5.1

Wrap a grpc.ServerStream handler with the sentry context.

func StreamInterceptor added in v0.2.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 v0.5.0

func TransactionName(c *gin.Context) string

func UnaryInterceptor added in v0.2.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.2"`
	UseStatusSampler bool    `split_words:"true" default:"true"`
	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) GetRelease

func (c Config) GetRelease() string

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 added in v0.5.0

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 v0.5.0

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 v0.5.0

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 v0.5.0

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 v0.5.0

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 v0.5.0

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 v0.5.0

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 added in v0.5.1

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

func (*Event) Err added in v0.5.0

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

func (*Event) Int added in v0.5.1

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

func (*Event) Msg added in v0.5.0

func (e *Event) Msg(msg string)

Finalizes the event and sends it to Sentry and Zerolog

func (*Event) Msgf added in v0.5.0

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 v0.5.0

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

func (*Event) ULID added in v0.5.0

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

type Sampler added in v0.5.2

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

func NewSampler added in v0.5.2

func NewSampler(defaultSampleRate float64) *Sampler

func (*Sampler) AddRoute added in v0.5.2

func (s *Sampler) AddRoute(route string, sample float64)

func (*Sampler) Sample added in v0.5.2

func (s *Sampler) Sample(ctx sentry.SamplingContext) float64

func (*Sampler) TracesSampler added in v0.5.2

func (s *Sampler) TracesSampler() sentry.TracesSampler

type ServiceError added in v0.5.0

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

A standardized error type for fingerprinting inside of Sentry.

func (*ServiceError) Error added in v0.5.0

func (e *ServiceError) Error() string

func (*ServiceError) Is added in v0.5.0

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

func (*ServiceError) Unwrap added in v0.5.0

func (e *ServiceError) Unwrap() error

Jump to

Keyboard shortcuts

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