logrusentry

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package logrusentry provides a simple Logrus hook for Sentry.

Deprecated: This package has been merged into the official sentry-go package. Use github.com/getsentry/sentry-go/logrus instead.

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
	// deduplication 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 ClientOptions

type ClientOptions = sentry.ClientOptions

ClientOptions is an alias for sentry.ClientOptions, and is all of the options available for configuring the sentry SDK client.

type Event

type Event = sentry.Event

Event is an alias for sentry.Event.

type EventHint

type EventHint = sentry.EventHint

EventHint is an alias for sentry.EventHint

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 ClientOptions) (*Hook, error)

New initializes a new Sentry hook.

func (*Hook) AddTags

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

AddTags adds tags to the hook's scope.

func (*Hook) Fallback

func (h *Hook) Fallback(fb FallbackFunc)

Fallback 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) 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) 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.

type Tag added in v0.0.2

type Tag string

Tag indicates that the value should be sent to sentry as a tag, rather than as Extra data.

Example usage:

traceID := req.Header.Get("X-Trace-ID")
log.WithFields("trace-id", logrusentry.Tag(traceID)).Info(...)

type User

type User = sentry.User

User is an alias for sentry.User. Pass a this value with key FieldUser, and it will be passed to Sentry appropriately.

Jump to

Keyboard shortcuts

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