sentry

package
v0.47.8 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package sentry provides Sentry error tracking and performance monitoring for bosun. It is opt-in via the BOSUN_SENTRY_DSN environment variable.

When enabled, Sentry hooks into the logging layer via the zerolog writer integration. Error/Fatal logs become Sentry events; Info/Warn logs become breadcrumbs. This means every existing log.Error() call in the codebase automatically reports to Sentry with zero changes to existing code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close(timeout time.Duration) error

Close flushes pending Sentry events and shuts down the writer. It clears the active state before flushing so concurrent readers cannot acquire a writer that is already shutting down. Repeated calls are safe no-ops. Flush and writer-close failures are returned together. Should be called during graceful shutdown.

func Enabled

func Enabled() bool

Enabled returns whether Sentry is active.

func Init

func Init(opts Options) error

Init initializes Sentry if a DSN is configured. Returns nil if DSN is empty (Sentry disabled).

func ReconcileTransaction

func ReconcileTransaction(ctx context.Context, source string) (context.Context, func(error))

ReconcileTransaction starts a Sentry transaction for a reconcile operation. Returns a new context with the transaction and a finish function. The finish function should be called with the final error (or nil) when done. If Sentry is disabled, returns the original context and a no-op finish function.

func Recover

func Recover()

Recover recovers a panic in the current goroutine, always logging it so the process stays up, and additionally reports it to Sentry when enabled. Must be deferred directly: `defer sentry.Recover()`.

Recovery must not depend on Sentry being configured: previously this returned before ever calling Go's recover() when Sentry was disabled (the default, opt-in-only posture), so every "defer sentrypkg.Recover()" safety net in the daemon was decorative dead code unless BOSUN_SENTRY_DSN was set — a panic in, say, the reconcile goroutine propagated unhandled and crashed the process instead of being recovered (#364).

Callers that need to convert the panic into a named return error (recover() only succeeds once per panic, so a caller can't both call it directly and also defer this function) should call recover() themselves and pass the result to Report instead — see Daemon.Run's top-level defer.

func Report added in v0.38.4

func Report(r any)

Report logs an already-recovered panic value and forwards it to Sentry when enabled. Use after calling Go's recover() directly (e.g. to also set a named return error from the same panic) instead of Recover(), which calls recover() itself and would find nothing left to recover.

func StartSpan

func StartSpan(ctx context.Context, operation, description string) (context.Context, func(error))

StartSpan starts a child span on the current transaction in the context. Returns the context with the span and a finish function. If no transaction exists or Sentry is disabled, returns a no-op.

func Writer

func Writer() io.Writer

Writer returns the Sentry zerolog writer for use with MultiLevelWriter. Returns nil if Sentry is not enabled.

Types

type Options

type Options struct {
	// DSN is the Sentry Data Source Name. Empty disables Sentry.
	DSN string

	// Environment identifies the deployment (e.g. "production", "staging").
	Environment string

	// Release is the application version string.
	Release string

	// TracesSampleRate controls what fraction of transactions are sent (0.0-1.0).
	TracesSampleRate float64
}

Options configures Sentry integration.

func ConfigFromEnv

func ConfigFromEnv() Options

ConfigFromEnv loads Sentry configuration from environment variables.

Jump to

Keyboard shortcuts

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