absentry

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package absentry wires Sentry into the backend services.

Everything here is safe to call when no DSN is configured: Init becomes a no-op and every helper silently does nothing. That is the normal case for local development, CI and forks, so an absent DSN must never fail boot.

Scope is errors and panics only — no tracing. Backend distributed tracing goes to VictoriaTraces via OTLP, not Sentry.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CaptureAMQPErr

func CaptureAMQPErr(ctx context.Context, err error, exchange, routingKey, messageID string)

CaptureAMQPErr reports err tagged with component "amqp" plus safe routing metadata (exchange, routing key, message ID), through a single hub.

hubFor(ctx) clones a fresh hub whenever ctx carries none (the normal case for an AMQP delivery, which has no request-scoped hub), so tagging one hubFor(ctx) call and then reporting through a second, separate hubFor(ctx) call in CaptureErr would silently drop the routing tags. Capturing directly through one hub avoids that.

Deliberately: exchange, routing key and message ID only. NEVER the delivery body — an AMQP payload can carry decrypted user content.

func CaptureAMQPPanic

func CaptureAMQPPanic(ctx context.Context, r interface{}, exchange, routingKey, messageID string)

CaptureAMQPPanic reports a recovered panic tagged with component "amqp" plus safe routing metadata, through a single hub. See CaptureAMQPErr for why the tag and the capture must go through the same hub.

func CaptureErr

func CaptureErr(ctx context.Context, err error, component string)

CaptureErr reports err tagged with the component it came from (http, grpc.user, grpc.admin, amqp, smtp, cron).

The component tag is what replaces a second DSN: it separates API from worker traffic inside one project, at any granularity, and stays queryable.

func CapturePanic

func CapturePanic(ctx context.Context, r interface{}, component string)

CapturePanic reports a recovered panic value.

func ConnectInterceptor

func ConnectInterceptor(component string) connect.Interceptor

ConnectInterceptor reports errors returned by RPC handlers. It sees the returned error and the procedure name, which the HTTP wrapper above cannot (by then Connect has serialised the error into a response).

Unary only. connect.UnaryInterceptorFunc does not wrap streaming handlers, so an error RETURNED by a streaming handler is not captured here; a PANIC in one still is, via HTTPRecovery above. Every RPC in this platform is unary today, so this costs nothing now — implement WrapStreamingHandler on a full connect.Interceptor before adding the first streaming endpoint.

Client-fault codes are normal traffic, not incidents, and are ignored.

func Cron

func Cron(name string, job func()) func()

Cron wraps a scheduled job so a panic is reported instead of killing the process. Apply it at the registration line:

gocron.Every(5).Minutes().Do(absentry.Cron("waiting_list", cron.WaitingListCron))

It deliberately does NOT re-panic: cron jobs share the process with the HTTP API, so a failing job must not take the API down with it.

func Enabled

func Enabled() bool

Enabled reports whether Sentry was initialised with a usable DSN.

func GinErrors

func GinErrors() gin.HandlerFunc

GinErrors reports errors after the handler has run. Any handler using the idiomatic c.Error(err) is covered with no Sentry-specific code, so new routes are reported by virtue of existing.

A 5xx with no c.Errors entry is still reported, at lower fidelity, so a handler that skipped c.Error degrades rather than going silent.

func GinRecovery

func GinRecovery() gin.HandlerFunc

GinRecovery reports panics, then re-panics so gin.Recovery() still owns the 500 response.

It MUST be registered AFTER gin.Recovery(). Gin's middleware chain runs via an index-advancing c.Next(), so the FIRST-registered middleware's deferred recover() is the OUTERMOST — it unwinds LAST, not first. If GinRecovery were registered before gin.Recovery(), gin.Recovery()'s recover() would fire first and swallow the panic before it ever reaches GinRecovery's defer, making GinRecovery's recover() permanently return nil — dead code, silently dropping every panic report.

Correct order: gin.Recovery() first (outermost, still owns the 500), GinRecovery() second (innermost, closest to the handler, sees the panic first, reports it, and re-panics outward so gin.Recovery() still responds). Services therefore use gin.New() with this explicit ordering rather than gin.Default() (which only installs Recovery, with no hook for this one).

func HTTPRecovery

func HTTPRecovery(component string, next http.Handler) http.Handler

HTTPRecovery wraps a mux so a panic in any handler is reported and contained instead of killing the process.

This is the coverage guarantee for RPC: every service registers all its handlers on one mux behind one wrapper, so a NEW endpoint is covered the moment it is registered, with no per-endpoint wiring.

func Init

func Init(service string) func()

Init configures Sentry for service and returns a flush function to defer in main(). Sentry's transport is async, so without that flush the last events before a crash are lost — exactly the ones worth having.

Types

This section is empty.

Jump to

Keyboard shortcuts

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