sentrytools

package
v4.0.1 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package sentrytools contains all sorts of tools for using Sentry.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GoRoutineWrapper

func GoRoutineWrapper(
	ctx context.Context,
	logger *slog.Logger,
	name string,
	f func(ctx context.Context, logger *slog.Logger) error,
)

GoRoutineWrapper wraps a go routine with Sentry logic for error and performance tracking.

func Init

func Init(env string, options sentry.ClientOptions) (*sentry.Hub, error)

Init initializes Sentry and returns a hub clone suitable for use on background contexts (e.g. job queues). Returns nil, nil when the DSN is empty or env is config.TestEnv — in those cases no initialization is performed and Middleware() handles its own setup. Must be called before Middleware().

func Middleware

func Middleware(env string) (helpers.Middleware, error)

Middleware is middleware used to configure and enable Sentry. Call Init at application startup before using this middleware. When env is config.TestEnv, a mocked sentry.Hub will be used and Sentry is self-initialized with mock options.

func MockedHubEvents

func MockedHubEvents(hub *sentry.Hub) []*sentry.Event

MockedHubEvents returns events captured by a hub created via MockedSentryHub.

func MockedSentryClientOptions

func MockedSentryClientOptions() sentry.ClientOptions

MockedSentryClientOptions returns a mocked version of sentry.ClientOptions.

func MockedSentryHub

func MockedSentryHub() *sentry.Hub

MockedSentryHub returns a mocked version of *sentry.Hub.

func NewLogHandler

func NewLogHandler(env string, handler slog.Handler) slog.Handler

NewLogHandler returns a new [SentryLogHandler].

Types

type LogHandler

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

LogHandler is used for capturing logs and sending these to Sentry.

func (*LogHandler) Enabled

func (l *LogHandler) Enabled(_ context.Context, level slog.Level) bool

Enabled checks if logs are enabled in a LogHandler for a certain slog.Level.

func (*LogHandler) Handle

func (l *LogHandler) Handle(ctx context.Context, record slog.Record) error

Handle handles a slog.Record by a [SentryLogHandler].

func (*LogHandler) WithAttrs

func (l *LogHandler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs adds [[]slog.Attr] to a [SentryLogHandler].

func (*LogHandler) WithGroup

func (l *LogHandler) WithGroup(name string) slog.Handler

WithGroup adds a group to a [SentryLogHandler].

Jump to

Keyboard shortcuts

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