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 ¶
- func Close(timeout time.Duration) error
- func Enabled() bool
- func Init(opts Options) error
- func ReconcileTransaction(ctx context.Context, source string) (context.Context, func(error))
- func Recover()
- func Report(r any)
- func StartSpan(ctx context.Context, operation, description string) (context.Context, func(error))
- func Writer() io.Writer
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Close ¶
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 Init ¶
Init initializes Sentry if a DSN is configured. Returns nil if DSN is empty (Sentry disabled).
func ReconcileTransaction ¶
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.
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.