SkillAgentSearch skills...

Sentryhook

Sentry (https://sentry.io/) hook for logrus (https://github.com/sirupsen/logrus)

Install / Use

/learn @dmksnnk/Sentryhook
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Logrus Sentry Hook

Go Report Card pipeline status coverage report GoDoc

A hook for logrus logger for sending errors and messages to the Sentry on specific log level. It uses default sentry client, so all you need is to add a hook.

Usage

err := raven.SetDSN(dsn)
if err != nil {
    log.Fatalf("%+v", errors.Wrap(err, "Can't set up raven"))
}

hook := sentryhook.New(nil) // will use raven.DefaultClient, or provide custom client
hook.SetAsync(logrus.ErrorLevel)                   // async (non-bloking) hook for errors
hook.SetSync(logrus.PanicLevel, logrus.FatalLevel) // sync (blocking) for fatal stuff

logrus.AddHook(hook)

Now, when you will make a log statement, like:

log.WithError(errors.New("some error")).WithField("BBB", map[string]int{"bb": 111}).Fatal("This is a fatal message")

hook will send an error to the Sentry and add log fields as tags.

In a case of log message without an error, hook will send a message with or without tags:

log.WithField("BBB", map[string]int{"bb": 111}).Error("This is a warning message") // with tags
log.Error("This is a warning message") // without tags, just message

Pro tip

Wrap your errors with github.com/pkg/errors, sentry client is able to parse stack trace, so you will have fancy issues with all trace and context you need.

View on GitHub
GitHub Stars12
CategoryDevelopment
Updated4y ago
Forks1

Languages

Go

Security Score

65/100

Audited on Jul 27, 2021

No findings