Documentation ¶
Index ¶
Constants ¶
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 )
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 ¶
Breadcrumb contains auxiliary information about something that happened before an Event happened, which supposed to help to investigate the Event.
func (*Breadcrumb) ForEachField ¶
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 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.
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.
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 ¶
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() }()
type EventID ¶
type EventID string
EventID is an unique ID (usually UUIDv4) assigned to an issued event.
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 ¶
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 Package ¶
Package contains information about a software package.
Supposed to be added as a field (for example through "WithField").
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.