Documentation ¶
Overview ¶
sentrycore provides a Sentry sink, that captures errors passed to the logger with the log.Error function if and only if the log level is superior or equal to Error.
In order to not slow down logging when it's not necessary:
a) the underlying zapcore.Core is only processing logging events on Error and above levels.
b) consuming log events and processing them for sentry reporting are both asynchronous. This deflects most of the work into the processing go routine and leverage Sentry's client ability to send reports in batches.
In the eventuality of saturating the events buffer by producing errors quicker than we can produce them, they will be purely dropped.
In order to avoid losing events, the events are continuously sent to Sentry and don't need to be explicitly flushed. If asked explicitly to be flushed as part of the zapcore.Core interface, the Sentry sink will try to consume all log events within a reasonable time before shutting down the consumer side, and will then submit them to Sentry.
Flushing is only called in the final defer function coming from our logging API, meaning that will only happen when a service is shutting down.
In the eventuality where we are submitting events faster than we could consume then, the upper bound is a large buffered channel, which should be enough to accumulate errors while we're asynchronously reporting them to Sentry.
It would be nice to be able to know if we're dropping errors, but that would create a circular dependency from the sink toward the logger, so for now, they're just silently discarded.
Index ¶
- Variables
- type Core
- func (c *Core) Check(e zapcore.Entry, ce *zapcore.CheckedEntry) *zapcore.CheckedEntry
- func (c *Core) Core() zapcore.Core
- func (c *Core) Enabled(level zapcore.Level) bool
- func (c *Core) SetHub(hub *sentry.Hub)
- func (c *Core) Stop()
- func (c *Core) Sync() error
- func (c *Core) With(fields []zapcore.Field) zapcore.Core
- func (c *Core) Write(entry zapcore.Entry, fields []zapcore.Field) error
- type TransportMock
Constants ¶
This section is empty.
Variables ¶
var DefaultSentryClientOptions = sentry.ClientOptions{
SampleRate: 0.1,
}
DefaultSentryClientOptions represents the default options that are merged in the Sentry client options used to be build a SentryCore.
Functions ¶
This section is empty.
Types ¶
type Core ¶
type Core struct {
// contains filtered or unexported fields
}
Core turns any log message that comes with at least one error into one or more error reports. All error reports will share the same metadata, with the exception of those attached onto the errors themselves.
func NewCore ¶
func NewCore(hub *sentry.Hub) *Core
NewCore returns a new SentryCore with a ready to use worker. It should be called only once, when attaching this core onto the global logger that is then used to create scoped loggers in other parts of the codebase.
func (*Core) Check ¶
func (c *Core) Check(e zapcore.Entry, ce *zapcore.CheckedEntry) *zapcore.CheckedEntry
Check inspects e to see if it needs to be sent to Sentry.
func (*Core) SetHub ¶
func (c *Core) SetHub(hub *sentry.Hub)
SetHub replaces the sentry.Hub used to submit sentry error reports.
func (*Core) Stop ¶
func (c *Core) Stop()
Stop permanently shuts down the core. Only for testing purposes.
func (*Core) Sync ¶
Sync ensure that the remaining event are flushed, but has a hard limit of TODO seconds after which it will stop blocking to avoid interruping application shutdown.
type TransportMock ¶
type TransportMock struct {
// contains filtered or unexported fields
}
func (*TransportMock) Configure ¶
func (t *TransportMock) Configure(options sentry.ClientOptions)
func (*TransportMock) Events ¶
func (t *TransportMock) Events() []*sentry.Event
func (*TransportMock) SendEvent ¶
func (t *TransportMock) SendEvent(event *sentry.Event)