Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

snowplow-archive/go-sentryhook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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