sentryhook

package module
v0.0.0-...-21bf7f9 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2021 License: MIT Imports: 6 Imported by: 1

README

Sentry hook for Logrus

Release

A simple hook for Logrus to allow easy integration of Sentry. The hook leverages the errors package under the hood to allow for stacktraces to be extracted.

How to use?

import (
	"github.com/pkg/errors"
	"github.com/sirupsen/logrus"
	"github.com/getsentry/sentry-go"

	"github.com/snowplow-devops/go-sentryhook"
)

func main() {
	err := sentry.Init(sentry.ClientOptions{
		Dsn:              "https://your-dsn/1",
		AttachStacktrace: true,
	})
	if err != nil {
		log.Fatal(err)
	}

	logrus.AddHook(sentryhook.New([]log.Level{log.PanicLevel, log.FatalLevel, log.ErrorLevel}))

	// Simple error logged
	logrus.Error("This will be sent to Sentry!")

	// Error logged with stracktrace
	// Note: The error has to be included as an extra field for the stacktrace to be extracted
	errWithStacktrace := errors.New("This will be sent to Sentry with a StrackTrace!")
	logrus.WithFields(logrus.Fields{"error": errWithStacktrace}).Error(errWithStacktrace)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hook

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

Hook contains the structure for a Logrus hook

func New

func New(levels []logrus.Level) Hook

New returns a new hook for use by Logrus

func (Hook) Fire

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

Fire sends an event to Sentry

func (Hook) Levels

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

Levels returns the levels that this hook fires on

Jump to

Keyboard shortcuts

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