types

package
v0.0.0-...-183aff7 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EntryPropertyErrorMonitoringEventEntry is a logger.EntryProperty implementation which marks that
	// the entry is an error monitoring event.
	EntryPropertyErrorMonitoringEventEntry = entryPropertyErrorEvent(iota + 1)

	// EntryPropertyErrorEvent is a logger.EntryProperty implementation which marks that
	// the event is an error event.
	EntryPropertyErrorEvent

	// EntryPropertyPanicEvent is a logger.EntryProperty implementation which marks that
	// the event is a panic event.
	EntryPropertyPanicEvent
)
View Source
const (

	// FieldPropEnvironment means the field contains information about the environment (prod, dev etc)
	FieldPropEnvironment

	// FieldPropRelease means the field contains information about the release version.
	FieldPropRelease

	// FieldPropServerName means the field contains information about the server name.
	FieldPropServerName
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Breadcrumb struct {
	TS         time.Time
	Path       []string
	Categories []string
	Data       any
}

Breadcrumb contains auxiliary information about something that happened before an Event happened, which supposed to help to investigate the Event.

func (bc *Breadcrumb) ForEachField(callback func(f *field.Field) bool) bool

ForEachField implements field.ForEachFieldser

type Emitter

type Emitter interface {
	// Flush forces to flush all buffers.
	Flush()

	// SendEvent sends an Event and optionally adds a value to ExternalIDs.
	Emit(*Event)
}

Emitter is a sender of already generated Events.

type Emitters

type Emitters []Emitter

Emitters is a collection of Emitter-s.

func (Emitters) Emit

func (s Emitters) Emit(ev *Event)

Emit implements Emitter

func (Emitters) Flush

func (s Emitters) Flush()

Flush implements Emitter

type ErrError

type ErrError struct {
	Event *Event
}

ErrError is a wrapper of an Event which implements `error` in case if the Event conveys an error event.

func (ErrError) Error

func (err ErrError) Error() string

Error implements interface `error`.

func (ErrError) Unwrap

func (err ErrError) Unwrap() error

Unwrap implements go1.13 errors unwrapping.

type ErrPanic

type ErrPanic struct {
	Event *Event
}

ErrPanic is a wrapper of an Event which implements `error` in case if the Event conveys a panic event.

func (ErrPanic) Error

func (err ErrPanic) Error() string

Error implements interface `error`.

type ErrorMonitor

type ErrorMonitor interface {
	belt.Tool

	// Emitter returns the Emitter.
	//
	// A read-only value, do not change it.
	Emitter() Emitter

	// ObserveError issues an error event if `err` is not an untyped nil. Additional
	// data (left by various observability tooling) is extracted from `belt`.
	//
	// Returns an Event only if one was issued (and for example was not sampled out by a Sampler Hook).
	ObserveError(*belt.Belt, error) *Event

	// ObserveRecover issues a panic event if `recoverResult` is not an untyped nil.
	// Additional data (left by various observability tooling) is extracted from `belt`.
	//
	// Is supposed to be used in constructions like:
	//
	//     defer func() { errmon.ObserveRecover(ctx, recover()) }()
	//
	// See also: https://go.dev/ref/spec#Handling_panics
	//
	// Returns an Event only if one was issued (and for example was not sampled out by a Sampler Hook).
	ObserveRecover(_ *belt.Belt, recoverResult any) *Event

	// WithPreHooks returns a ErrorMonitor derivative which also includes/appends pre-hooks from the arguments.
	//
	// Special case: to reset hooks use `WithHooks()` (without any arguments).
	WithPreHooks(...PreHook) ErrorMonitor

	// WithHooks returns a ErrorMonitor derivative which also includes/appends hooks from the arguments.
	//
	// Special case: to reset hooks use `WithHooks()` (without any arguments).
	WithHooks(...Hook) ErrorMonitor
}

ErrorMonitor is an observability Tool (belt.Tool) which allows to report about any exceptions which happen for debugging. It collects any useful information it can.

An ErrorMonitor implementation is not supposed to be fast, but it supposed to provide verbose reports (sufficient enough to debug found problems).

type Event

type Event struct {
	// Entry is a general-purpose structured information.
	logger.Entry

	// ID is an unique ID of the Event.
	ID EventID

	// ExternalIDs is a list of IDs of the Event in external systems.
	ExternalIDs []any

	// Exception is the information about what went wrong.
	Exception

	// Spans is the tracer spans opened in the context of the Event.
	Spans tracer.Spans

	// CurrentGoroutineID is the ID of the goroutine where the Event was observed.
	CurrentGoroutineID int

	// Goroutines is the information about all the goroutines at the moment when the Event was observed.
	Goroutines []Goroutine
}

Event is the full collection of data collected on a specific event to be reported (like a panic or an error).

func (*Event) AsError

func (ev *Event) AsError() error

AsError is a syntax-sugar function which returns a non-nil value only if there was an error or a panic observed.

For example this block:

defer func() {
	ev := errmon.ObserveRecoverCtx(ctx, recover())
	if ev != nil {
		err = fmt.Errorf("got panic: %v (event ID: '%s')", ev.PanicValue, ev.ID)
	}
}()

Could be replaced with simpler:

defer func() { err = errmon.ObserveRecoverCtx(ctx, recover()).AsError() }()

func (*Event) GetID

func (ev *Event) GetID() EventID

GetID is a safe accessor of an event ID, it returns an empty ID if Event is nil.

type EventID

type EventID string

EventID is an unique ID (usually UUIDv4) assigned to an issued event.

func RandomEventID

func RandomEventID() EventID

RandomEventID returns a new random EventID.

type Exception

type Exception struct {
	IsPanic    bool
	PanicValue any
	Error      error

	StackTrace runtime.StackTrace
}

Exception is the immediate information about what gone wrong.

type Goroutine

type Goroutine = gostackparse.Goroutine

Goroutine is a full collection of data collected on a specific goroutine.

type HTTPRequest

type HTTPRequest http.Request

HTTPRequest contains information about an HTTP request.

Supposed to be added as a field (for example through "WithField").

func (*HTTPRequest) ForEachField

func (r *HTTPRequest) ForEachField(callback func(f *field.Field) bool) bool

ForEachField implements field.ForEachFielder

type Hook

type Hook interface {
	// Process performs the modification of an Event and/or returns
	// false to prevent an Event from being sent (or returns true
	// to allow sending the Event).
	Process(*Event) bool
}

Hook is a pre-processor for an Event which is ran before sending it. It may modify the event or prevent from being sent.

type Hooks

type Hooks []Hook

Hooks is a collection of Hook-s

func (Hooks) Process

func (s Hooks) Process(ev *Event) bool

Process implements Hook.

type Package

type Package struct {
	Name       string
	Version    string
	CustomData []any
}

Package contains information about a software package.

Supposed to be added as a field (for example through "WithField").

func (*Package) ForEachField

func (p *Package) ForEachField(callback func(f *field.Field) bool) bool

ForEachField implements field.ForEachFielder

type PreHook

type PreHook interface {
	ProcessInputError(belt.TraceIDs, error) PreHookResult
	ProcessInputPanic(belt.TraceIDs, any) PreHookResult
}

PreHook is similar to a Hook, but is used before all the information is collected and the Event is generated. It might be useful for example for a Sampler to avoid computations for sampled out events.

type PreHookResult

type PreHookResult struct {
	Skip        bool
	ExtraFields field.AbstractFields
}

PreHookResult is the result of a PreHook.

type PreHooks

type PreHooks []PreHook

PreHooks is a collection of PreHook-s.

func (PreHooks) ProcessInputError

func (s PreHooks) ProcessInputError(traceIDs belt.TraceIDs, err error) PreHookResult

ProcessInputError implements PreHook.

func (PreHooks) ProcessInputPanic

func (s PreHooks) ProcessInputPanic(traceIDs belt.TraceIDs, panicValue any) PreHookResult

ProcessInputPanic implements PreHook.

type Tag

type Tag struct {
	Key   string
	Value string
}

Tag contains information about a tag.

Supposed to be added as a field (for example through "WithField").

type User

type User struct {
	ID         int64
	Name       string
	CustomData []any
}

User contains information about an user.

Supposed to be added as a field (for example through "WithField").

Jump to

Keyboard shortcuts

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