Documentation ¶
Index ¶
- func AttachCoreToLogger(sentryCore zapcore.Core, l *zap.Logger) *zap.Logger
- func NewCore(factory SentryClientFactory, opts ...Option) (zapcore.Core, error)
- func NewScope() zapcore.Field
- func WrapHub(hub *sentry.Hub) zapcore.Field
- func WrapScope(scope *sentry.Scope) zapcore.Field
- type DefaultExceptionProvider
- type DefaultStacktraceFrameFilter
- type ExceptionProvider
- type LevelEnabler
- type NopExceptionProvider
- type Option
- func ConvertFieldsToTags(keys ...string) Option
- func DisableStacktrace() Option
- func Level(lvl zapcore.Level) Option
- func UseHub(hub *sentry.Hub) Option
- func UseStacktraceFrameFilter(ff StacktraceFrameFilter) Option
- func WithBreadcrumbs(level zapcore.Level) Option
- func WithEnvironment(env string) Option
- func WithFlushTimeout(after time.Duration) Option
- func WithGlobalBreadcrumbs() Option
- func WithPlaform(platform string) Option
- func WithTags(tags map[string]string) Option
- type SentryClientFactory
- type StacktraceFrameFilter
- type Tagger
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AttachCoreToLogger ¶
Example ¶
package main import ( "fmt" "log" "time" "github.com/getsentry/sentry-go" "go.uber.org/zap" "go.uber.org/zap/zapcore" "go.uber.org/zap/zaptest/observer" "github.com/l2cup/zapsentry" ) func main() { // Setup zap with observer (for testing), originally we use // config = zap.NewDevelopmentConfig() // logger, err := config.Build() // to build zap logger, here we use zap/zaptest/observer for testing core, recordedLogs := observer.New(zapcore.DebugLevel) logger := zap.New(core, zap.AddStacktrace(zap.DebugLevel)) // Setup mock sentry client for testing, in general we use sentry.NewClient var recordedSentryEvent *sentry.Event sentryClient := mockSentryClient(func(event *sentry.Event) { recordedSentryEvent = event }) // Setup zapsentry core, err := zapsentry.NewCore( zapsentry.NewSentryClientFromClient(sentryClient), zapsentry.Level(zapcore.ErrorLevel), zapsentry.ConvertFieldsToTags("method"), zapsentry.WithBreadcrumbs(zapcore.InfoLevel), ) if err != nil { log.Fatal(err) } newLogger := zapsentry.AttachCoreToLogger(core, logger) // Send error log newLogger. With(zapsentry.NewScope()). Error("[error] something went wrong!", zap.String("method", "unknown")) // Check output fmt.Println(recordedLogs.All()[0].Message) fmt.Println(recordedSentryEvent.Message) fmt.Println(recordedSentryEvent.Extra) } func mockSentryClient(f func(event *sentry.Event)) *sentry.Client { client, _ := sentry.NewClient(sentry.ClientOptions{ Dsn: "", Transport: &transport{MockSendEvent: f}, }) return client } type transport struct { MockSendEvent func(event *sentry.Event) } // Flush waits until any buffered events are sent to the Sentry server, blocking // for at most the given timeout. It returns false if the timeout was reached. func (f *transport) Flush(_ time.Duration) bool { return true } // Configure is called by the Client itself, providing it it's own ClientOptions. func (f *transport) Configure(_ sentry.ClientOptions) {} // SendEvent assembles a new packet out of Event and sends it to remote server. // We use this method to capture the event for testing func (f *transport) SendEvent(event *sentry.Event) { f.MockSendEvent(event) }
Output: [error] something went wrong! [error] something went wrong! map[method:unknown]
Types ¶
type DefaultExceptionProvider ¶ added in v1.9.0
type DefaultExceptionProvider struct {
// contains filtered or unexported fields
}
func NewExceptionProvider ¶ added in v1.9.0
func NewExceptionProvider(ff StacktraceFrameFilter) *DefaultExceptionProvider
NewExceptionProvider returns anew DefaultExceptionProvider with the passed StacktraceFrameFilter as it's frame filter.
func (*DefaultExceptionProvider) Exception ¶ added in v1.9.0
func (dep *DefaultExceptionProvider) Exception(ent zapcore.Entry) []sentry.Exception
Exception accepts a zapcore.Entry and provides a sentry exception. Sentry defines it's exception as an Exception array. This array should contain one exception if an exception exists It will return an empty array if no exception is created.
type DefaultStacktraceFrameFilter ¶ added in v1.9.0
type DefaultStacktraceFrameFilter struct{}
DefaultStacktraceFrameFilter is a default StacktraceFrameFilter implementation It uses the same login as the original TheZeroSlave/zapsentry implementation of stack trace filtering uses. It has sane defaults so it's still the default stack trace filter.
func (*DefaultStacktraceFrameFilter) FilterFrames ¶ added in v1.9.0
func (sff *DefaultStacktraceFrameFilter) FilterFrames(frames []sentry.Frame) []sentry.Frame
FilterFrames will filter out unwanted stacktrace frames
type ExceptionProvider ¶ added in v1.9.0
type ExceptionProvider interface { // Exception accepts a zapcore.Entry and provides a sentry exception. // Sentry defines it's exception as an Exception array. // This array should contain one exception if an exception exists // It will return an empty array if no exception is created. Exception(ent zapcore.Entry) []sentry.Exception }
ExceptionProvider provides sentry exceptions from zapcore's entries.
type LevelEnabler ¶ added in v1.9.0
type LevelEnabler struct {
// contains filtered or unexported fields
}
type NopExceptionProvider ¶ added in v1.9.0
type NopExceptionProvider struct{}
NopExceptionProvider is a ExceptionProvider implementation which always provides an empty exception array. Used when exceptions are disabled.
func (*NopExceptionProvider) Exception ¶ added in v1.9.0
func (nep *NopExceptionProvider) Exception(_ zapcore.Entry) []sentry.Exception
Exception accepts a zapcore.Entry and provides a sentry exception. Sentry defines it's exception as an Exception array. This array should contain one exception if an exception exists It will return an empty array if no exception is created.
type Option ¶ added in v1.9.0
type Option func(c *core) error
func ConvertFieldsToTags ¶ added in v1.9.0
func DisableStacktrace ¶ added in v1.9.0
func DisableStacktrace() Option
func UseStacktraceFrameFilter ¶ added in v1.9.0
func UseStacktraceFrameFilter(ff StacktraceFrameFilter) Option
func WithBreadcrumbs ¶ added in v1.9.0
func WithEnvironment ¶ added in v1.9.0
func WithFlushTimeout ¶ added in v1.9.0
func WithGlobalBreadcrumbs ¶ added in v1.9.0
func WithGlobalBreadcrumbs() Option
func WithPlaform ¶ added in v1.9.0
type SentryClientFactory ¶
type SentryClientFactory func() (*sentry.Client, error)
func NewSentryClientFromClient ¶
func NewSentryClientFromClient(client *sentry.Client) SentryClientFactory
func NewSentryClientFromDSN ¶
func NewSentryClientFromDSN(DSN string) SentryClientFactory
type StacktraceFrameFilter ¶ added in v1.9.0
type StacktraceFrameFilter interface {
// FilterFrames will filter out unwanted stacktrace frames
FilterFrames(frames []sentry.Frame) []sentry.Frame
}
StacktraceFrameFilter filters stacktrace frames. Used to skip unnecesarry stack trace frames.