sentrylogrus

package
v0.24.78 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package sentrylogrus provides a simple Logrus hook for Sentry.

Index

Constants

View Source
const (
	// FieldRequest holds an *http.Request.
	FieldRequest = "request"
	// FieldUser holds a User or *User value.
	FieldUser = "user"
	// FieldTransaction holds a transaction ID as a string.
	FieldTransaction = "transaction"
	// FieldFingerprint holds a string slice ([]string), used to dictate the
	// grouping of this event.
	FieldFingerprint = "fingerprint"

	// These fields are simply omitted, as they are duplicated by the Sentry SDK.
	FieldGoVersion = "go_version"
	FieldMaxProcs  = "go_maxprocs"
)

These default log field keys are used to pass specific metadata in a way that Sentry understands. If they are found in the log fields, and the value is of the expected datatype, it will be converted from a generic field, into Sentry metadata.

These keys may be overridden by calling SetKey on the hook object.

Variables

This section is empty.

Functions

This section is empty.

Types

type FallbackFunc

type FallbackFunc func(*logrus.Entry) error

A FallbackFunc can be used to attempt to handle any errors in logging, before resorting to Logrus's standard error reporting.

type Hook

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

Hook is the logrus hook for Sentry.

It is not safe to configure the hook while logging is happening. Please perform all configuration before using it.

func New

func New(levels []logrus.Level, opts sentry.ClientOptions) (*Hook, error)

New initializes a new Logrus hook which sends logs to a new Sentry client configured according to opts.

func NewFromClient

func NewFromClient(levels []logrus.Level, client *sentry.Client) *Hook

NewFromClient initializes a new Logrus hook which sends logs to the provided sentry client.

func (*Hook) AddTags

func (h *Hook) AddTags(tags map[string]string)

AddTags adds tags to the hook's scope.

func (*Hook) Fire

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

Fire sends entry to Sentry.

func (*Hook) Flush

func (h *Hook) Flush(timeout time.Duration) bool

Flush waits until the underlying Sentry transport sends any buffered events, blocking for at most the given timeout. It returns false if the timeout was reached, in which case some events may not have been sent.

func (*Hook) Levels

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

Levels returns the list of logging levels that will be sent to Sentry.

func (*Hook) SetFallback

func (h *Hook) SetFallback(fb FallbackFunc)

SetFallback sets a fallback function, which will be called in case logging to sentry fails. In case of a logging failure in the Fire() method, the fallback function is called with the original logrus entry. If the fallback function returns nil, the error is considered handled. If it returns an error, that error is passed along to logrus as the return value from the Fire() call. If no fallback function is defined, a default error message is returned to Logrus in case of failure to send to Sentry.

func (*Hook) SetKey

func (h *Hook) SetKey(oldKey, newKey string)

SetKey sets an alternate field key. Use this if the default values conflict with other loggers, for instance. You may pass "" for new, to unset an existing alternate.

Jump to

Keyboard shortcuts

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