Skip to content

feat(observability): pgx + Asynq queue + DLQ metrics + Sentry/GlitchTip error tracking - #488

Merged
tayebmokni merged 3 commits into
mainfrom
feat/observability-metrics-sentry
May 26, 2026
Merged

feat(observability): pgx + Asynq queue + DLQ metrics + Sentry/GlitchTip error tracking#488
tayebmokni merged 3 commits into
mainfrom
feat/observability-metrics-sentry

Conversation

@tayebmokni

Copy link
Copy Markdown
Contributor

Closes #165, #172, #202.

tib0o0o added 3 commits May 26, 2026 23:49
Closes #165.

Adds packages/go/db/metrics.go: a prometheus.Collector implementation
that pulls pgxpool.Stat() at scrape time and emits the gonext_db_pool_*
gauges + cumulative counters defined in docs/10-observability.md §5.3.
Histograms for query duration (gonext_db_query_duration_seconds) and
transaction duration (gonext_db_tx_duration_seconds) are push-based,
fed via ObserveQuery / ObserveTx so callers wire them at the
data-access layer.

Replication lag (gonext_db_replication_lag_seconds) is gated on a
caller-supplied ReplicaProber; deployments without a replica leave it
nil and the gauge is skipped. ReplicaProberFunc adapts a plain
function for callers that want a closure over a replica pool.

Wires the collector into apps/api/cmd/server/main.go alongside the
existing metrics registry so /metrics exposes the new series without
any operator action.

Signed-off-by: Tayeb Mokni <tayeb.mokni@gmail.com>
…rics

Closes #172.

The existing metrics.go covered processed/failed/inflight/unknown,
which are sourced from handler-side middleware and only reflect the
in-process worker. The cluster-wide queue state — pending tasks,
processing lag, retry pool, archived (dead-letter) tasks, paused-ness
— lives in Redis and is accessed through Asynq's Inspector API.

Adds InspectorCollector: a prometheus.Collector that calls
Inspector.GetQueueInfo for each configured queue on every scrape and
emits gonext_jobs_queue_depth, gonext_jobs_queue_active,
gonext_jobs_queue_lag_seconds, gonext_jobs_retries, gonext_jobs_dlq_size,
and gonext_jobs_queue_paused. Failures are logged + counted on
gonext_jobs_inspector_failures_total so operators can alert on a
flapping Redis connection.

Defines QueueInspector as the minimal interface the collector needs,
so tests use a fakeInspector without standing up Redis. *asynq.Inspector
satisfies the interface directly.

Wires the collector into apps/worker/cmd/worker/main.go alongside the
existing metrics registry, with the inspector handle registered with
the shutdown orchestrator so it drains cleanly on SIGTERM.

Signed-off-by: Tayeb Mokni <tayeb.mokni@gmail.com>
…e grouping

Closes #202.

Adds packages/go/observability/errortracker: a thin wrapper around
getsentry/sentry-go that exposes Init / Capture / CaptureMessage /
Recover / WithPluginSlug and isolates the rest of the codebase from
sentry-go primitives (Hub, Scope, Event). Swapping to a different
reporter later is a one-package change.

Behavior is gated on the configured DSN (GONEXT_SENTRY_DSN env var,
or Options.DSN). When unset the package installs a no-op tracker
with zero overhead on the hot path; Shutdown is a no-op. When set,
Init wires sentry-go with attach-stacktrace, AttachStacktrace=true,
the build-info release, the config environment, and a hostname-derived
ServerName. The returned Shutdown closer flushes the in-flight event
queue with a 5s budget.

Plugin-aware grouping: WithPluginSlug stamps a gonext.plugin.slug tag
onto the event scope. Per-request middleware threads the slug on
every plugin dispatch (in follow-up wiring); end-of-chain Capture
calls inherit it via context, so events from plugin handlers group
separately from host code in the Sentry dashboard.

Wires the tracker into apps/api + apps/worker main.go with the
Shutdown closer registered against the orchestrator — drains BEFORE
the DB pool / Redis so events captured during shutdown still reach
the ingestion endpoint over a live network. Setup failures are
non-fatal (log a warning and continue without reporting), matching
the existing tracing.Setup posture.

Signed-off-by: Tayeb Mokni <tayeb.mokni@gmail.com>
@tayebmokni
tayebmokni enabled auto-merge (squash) May 26, 2026 21:57
@tayebmokni
tayebmokni merged commit 456719f into main May 26, 2026
14 of 18 checks passed
@tayebmokni
tayebmokni deleted the feat/observability-metrics-sentry branch May 26, 2026 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add database metrics (pgx query duration, pool, replication lag)

2 participants