Documentation ¶
Index ¶
- Constants
- func CloneContext(c *gin.Context) context.Context
- func Flush(timeout time.Duration) bool
- func Init(conf Config) (err error)
- func NewStatusSampler(defaultSampleRate float64) sentry.TracesSampler
- func ReportErrors(conf Config) gin.HandlerFunc
- func Stream(s grpc.ServerStream, ctx context.Context) grpc.ServerStream
- func StreamInterceptor(conf Config) grpc.StreamServerInterceptor
- func TrackPerformance(tags map[string]string) gin.HandlerFunc
- func TransactionName(c *gin.Context) string
- func UnaryInterceptor(conf Config) grpc.UnaryServerInterceptor
- 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 Sampler
- type ServiceError
Constants ¶
const ( APIStatusEndpoint = "GET /v1/status" EnsignStatusEndpoint = "/ensign.v1beta1.Ensign/Status" StatusSampleRate = 0.005 )
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 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
func Stream(s grpc.ServerStream, ctx context.Context) grpc.ServerStream
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 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.
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 (Config) UsePerformanceTracking ¶
Performance tracking is enabled if Sentry is enabled and track performance is explicitly set
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.
type Sampler ¶ added in v0.5.2
type Sampler struct {
// contains filtered or unexported fields
}
func NewSampler ¶ added in v0.5.2
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