observability

package
v0.0.0-...-ea1acce Latest Latest
Warning

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

Go to latest
Published: May 6, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const LevelFatal = slog.Level(12)

Variables

This section is empty.

Functions

func CaptureException

func CaptureException(err error, tags Tags)

func CaptureMessage

func CaptureMessage(msg string, tags Tags)

func GetLoggerPath

func GetLoggerPath() (*os.File, error)

func GetLoggerPathFS

func GetLoggerPathFS(fs FileSystem) (fs.File, error)

GetLoggerPathFS function with FileSystem parameter

func InitSentry

func InitSentry(disabled bool, commit string)

func Reraise

func Reraise(err any, tags Tags)

Reraise captures an error and re-raises it. Used to capture unexpected panics.

Types

type Commit

type Commit string

Commit is a type for storing the commit hash

type CoreLogger

type CoreLogger struct {
	*slog.Logger
	// contains filtered or unexported fields
}

func NewCoreLogger

func NewCoreLogger(logger *slog.Logger, opts ...CoreLoggerOption) *CoreLogger

func NewNoOpLogger

func NewNoOpLogger() *CoreLogger

func (*CoreLogger) CaptureError

func (cl *CoreLogger) CaptureError(msg string, err error, args ...any)

CaptureError logs an error and sends it to sentry.

func (*CoreLogger) CaptureFatal

func (cl *CoreLogger) CaptureFatal(msg string, err error, args ...any)

CaptureFatal logs an error at the fatal level and sends it to sentry.

func (*CoreLogger) CaptureFatalAndPanic

func (cl *CoreLogger) CaptureFatalAndPanic(msg string, err error, args ...any)

CaptureFatalAndPanic logs an error at the fatal level and sends it to sentry. It then panics.

func (*CoreLogger) CaptureInfo

func (cl *CoreLogger) CaptureInfo(msg string, args ...any)

CaptureInfo logs an info message and sends it to sentry.

func (*CoreLogger) CaptureWarn

func (cl *CoreLogger) CaptureWarn(msg string, args ...any)

CaptureWarn logs a warning and sends it to sentry.

func (*CoreLogger) GetCaptureException

func (cl *CoreLogger) GetCaptureException() func(err error, tags Tags)

GetCaptureException returns the function used to capture exceptions.

func (*CoreLogger) GetCaptureMessage

func (cl *CoreLogger) GetCaptureMessage() func(msg string, tags Tags)

GetCaptureMessage returns the function used to capture messages.

func (*CoreLogger) GetLogger

func (cl *CoreLogger) GetLogger() *slog.Logger

GetLogger returns the underlying slog.Logger.

func (*CoreLogger) GetTags

func (cl *CoreLogger) GetTags() Tags

GetTags returns the tags associated with the logger.

func (*CoreLogger) Reraise

func (cl *CoreLogger) Reraise(args ...any)

Reraise is used to capture unexpected panics with sentry and reraise them.

func (*CoreLogger) SetTags

func (cl *CoreLogger) SetTags(tags Tags)

type CoreLoggerOption

type CoreLoggerOption func(cl *CoreLogger)

func WithCaptureException

func WithCaptureException(f func(err error, tags Tags)) CoreLoggerOption

func WithCaptureMessage

func WithCaptureMessage(f func(msg string, tags Tags)) CoreLoggerOption

func WithTags

func WithTags(tags Tags) CoreLoggerOption

type FileSystem

type FileSystem interface {
	MkdirAll(path string, perm os.FileMode) error
	OpenFile(name string, flag int, perm os.FileMode) (fs.File, error)
}

FileSystem interface to abstract file system operations

type OsFs

type OsFs struct{}

OsFs wraps standard os package functions to satisfy the FileSystem interface.

func (OsFs) MkdirAll

func (OsFs) MkdirAll(path string, perm os.FileMode) error

func (OsFs) OpenFile

func (OsFs) OpenFile(name string, flag int, perm os.FileMode) (fs.File, error)

type Peeker

type Peeker struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Peeker stores HTTP responses for failed requests.

func (*Peeker) Peek

func (p *Peeker) Peek(_ *http.Request, resp *http.Response)

func (*Peeker) Read

func (p *Peeker) Read() []*service.HttpResponse

Read returns the buffered responses and clears the buffer.

type Printer

type Printer struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Printer stores console messages to display to the user.

func NewPrinter

func NewPrinter() *Printer

func (*Printer) AtMostEvery

func (p *Printer) AtMostEvery(duration time.Duration) writeDSL

AtMostEvery allows rate-limiting how often a message is printed.

Usage:

printer.
	AtMostEvery(time.Minute).
	Write(message)

Note, this doesn't affect regular `printer.Write(message)` calls. The duration is only checked when `AtMostEvery()` is used.

This should always be used with the same duration. If the duration changes, the message is blocked until its last duration completes.

func (*Printer) Read

func (p *Printer) Read() []string

Read returns all buffered messages and clears the buffer.

func (*Printer) Write

func (p *Printer) Write(message string)

Write adds a message to the console.

type SentryClient

type SentryClient struct {
	Dsn    string
	Commit string
}

type Tags

type Tags map[string]string

func NewTags

func NewTags(args ...any) Tags

NewTags creates a new Tags from a mix of slog.Attr and a string and its corresponding value. It ignores incomplete pairs and other types.

Jump to

Keyboard shortcuts

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