Documentation ¶
Index ¶
- Constants
- func CloneContext(c *gin.Context) context.Context
- func Flush(timeout time.Duration) bool
- func Init(conf Config) (err error)
- func ReportErrors(conf Config) gin.HandlerFunc
- func TrackPerformance(tags map[string]string) gin.HandlerFunc
- func TransactionName(c *gin.Context) string
- func UseTags(tags map[string]string) gin.HandlerFunc
- type Config
- type Event
- func (e *Event) Bytes(key string, value []byte) *Event
- func (e *Event) Err(err error) *Event
- func (e *Event) Int(key string, value int) *Event
- func (e *Event) Msg(msg string)
- func (e *Event) Msgf(format string, args ...interface{})
- func (e *Event) Str(key, value string) *Event
- func (e *Event) ULID(key string, value ulid.ULID) *Event
- type ServiceError
Constants ¶
const HeaderRequestID = "X-Request-ID"
Variables ¶
This section is empty.
Functions ¶
func Init ¶
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 ¶
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 ¶
Performance tracking is enabled if Sentry is enabled and track performance is explicitly set
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.
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