sentrus

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2022 License: MIT Imports: 3 Imported by: 1

README

Sentrus

Sentrus provides a Sentry hook for the logrus package, using the latest Sentry SDK (sentry-go). Extensible, it can be integrated with a variety of popular frameworks and packages in the Go ecosystem.

Usage

import(
    "github.com/getsentry/sentry-go"
    "github.com/sirupsen/logrus"
    "github.com/orandin/sentrus"
)

// Sentry init
if err := sentry.Init(sentry.ClientOptions{Dsn: "YOUR_DSN"}); err != nil {
    logger.WithError(err).Fatal("Cannot initiate Sentry")
}
defer sentry.Flush(2 * time.Second)

// Add Sentrus hook
loggrus.AddHook(sentrus.NewHook(
    []logrus.Level{logrus.WarnLevel, logrus.ErrorLevel},

    // Optional: add tags to add in each Sentry event
    sentrus.WithTags(map[string]string{"foo": "bar"}),

    // Optional: set custom CaptureLog function
    sentrus.WithCustomCaptureLog(sentrus.DefaultCaptureLog),
))

logrus.Info("foo") // Not sent to Sentry
logrus.Warn("bar") // Sent to Sentry

// With an error
err := fmt.Errorf("awesome error")

logrus.WithError(err).Info("foo with an error") // Not sent to Sentry
logrus.WithError(err).Warn("bar with an error") // Sent to Sentry
Integration with a framework

Like Sentry, Sentrus can be integrated with a variety of popular frameworks and packages in the Go ecosystem. For more detailed information, checkout the guides:

An integration with a framework or package is missing?

Sentrus is extensible. You can develop custom CaptureLog functions to format and push the Sentry events. Don't hesitate to look the code of already existing integrations and feel free to contribute.

Stack traces improvement

By default, Sentrus and Logrus will be considered by Sentry SDK as part of your application in stack traces. The consequence is to have stack traces less readable from Sentry UI.

At this time, sentry-go doesn't make isInAppFrame customizable by clients. So, a Sentry integration (sentrus.IsNotInAppFrameIntegration) has been created as a workaround, and it is activated automatically when the hook is initialized. Each event will be modified to no longer consider Sentrus and Logrus as part of your application.

License

Licensed under MIT License, see LICENSE.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	LevelMap = map[logrus.Level]sentry.Level{
		logrus.TraceLevel: sentry.LevelDebug,
		logrus.DebugLevel: sentry.LevelDebug,
		logrus.InfoLevel:  sentry.LevelInfo,
		logrus.WarnLevel:  sentry.LevelWarning,
		logrus.ErrorLevel: sentry.LevelError,
		logrus.FatalLevel: sentry.LevelFatal,
		logrus.PanicLevel: sentry.LevelFatal,
	}
)

Functions

func DefaultCaptureLog

func DefaultCaptureLog(entry *logrus.Entry, hub *sentry.Hub, tags map[string]string) error

func GetErrorFromEntry

func GetErrorFromEntry(entry *logrus.Entry) (error, bool)

Types

type CaptureLog

type CaptureLog func(entry *logrus.Entry, defaultHub *sentry.Hub, tags map[string]string) error

type Hook

type Hook struct {
	// contains filtered or unexported fields
}

func NewHook

func NewHook(levels []logrus.Level, options ...Option) Hook

func (Hook) Fire

func (h Hook) Fire(entry *logrus.Entry) error

func (Hook) Levels

func (h Hook) Levels() []logrus.Level

type IsNotInAppFrameIntegration

type IsNotInAppFrameIntegration struct{}

func (*IsNotInAppFrameIntegration) Name

func (sentrusIntegration *IsNotInAppFrameIntegration) Name() string

func (*IsNotInAppFrameIntegration) SetupOnce

func (sentrusIntegration *IsNotInAppFrameIntegration) SetupOnce(client *sentry.Client)

type Option

type Option func(h *Hook)

func WithCustomCaptureLog

func WithCustomCaptureLog(captureLog CaptureLog) Option

func WithCustomHub

func WithCustomHub(hub *sentry.Hub) Option

func WithTags

func WithTags(tags map[string]string) Option

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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