sentrycore

package
v0.0.0-...-431bcb6 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

Check inspects e to see if it needs to be sent to Sentry.

func (*Core) Core

func (c *Core) Core() zapcore.Core

Core returns the underlying zapcore.

func (*Core) Enabled

func (c *Core) Enabled(level zapcore.Level) bool

Enabled returns false when the log level is below the Error level.

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

func (c *Core) Sync() error

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.

func (*Core) With

func (c *Core) With(fields []zapcore.Field) zapcore.Core

With stores fields passed to the core into a new core that will be then used to contruct the final error report.

It does not capture errors, because we may get additional context in a subsequent With or Write call that will also need to be included.

func (*Core) Write

func (c *Core) Write(entry zapcore.Entry, fields []zapcore.Field) error

Write will asynchronoulsy send out all errors and the fields that have been accumulated during the lifetime of the core.

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) Flush

func (t *TransportMock) Flush(timeout time.Duration) bool

func (*TransportMock) SendEvent

func (t *TransportMock) SendEvent(event *sentry.Event)

Jump to

Keyboard shortcuts

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