feat(metrics): add SubscriptionMetrics OTel observer for subscriptions #150
Reference in New Issue
Block a user
Delete Branch "feat/subscription-metrics"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Adds
otelsetup.NewSubscriptionMetrics(subscription string)— an OTel observer for the cross-service read-your-writes subscriptions (ADR-0012). This is the home for the skip/drop metrics flagged as a follow-up in both subscription-lib migration reviews (authz #782, accounting #949).Why / how
The
subscriptionslibrary exposes anObserverinterface (Pushed/PushSkipped/Dropped/ChannelFull) but deliberately doesn't depend on OTel.otelsetupdoes. So*SubscriptionMetricssatisfies that interface structurally (otelsetup does not importsubscriptions), and each service wires it:It records one
Int64Countersubscription.notificationslabelled only bysubscription+outcome(pushed/skipped/dropped/channel_full). The subscriber key (company id / user email) is intentionally NOT a label — that would be unbounded cardinality; the key stays in the library's logs.skip-rate = skipped / (pushed + skipped)is the alert-worthy signal (chronic projection lag);dropped/channel_fullflag burst back-pressure / stuck clients.Review
Infrastructure Expert — sound, ship-ready, no Critical/High. Confirmed: the single-counter-with-
outcome-attribute is the right shape (matches the eventsourced adapter's boolean-attribute idiom); cardinality is bounded;context.Background()is fine for a counter; no-op-when-disabled is free; naming/units match house style; auto-tag will cut v0.4.0 (feat→ minor; do not hand-edit.version/CHANGELOG). Addressed: corrected the non-compiling usage snippet in the doc, marked the structural-guard coupling (consumer-sidevar _ subscriptions.Observerguard to be added in the service wiring), and added a disabled-provider test.Tests
go build/vet/gofumpt/goimports,go test -race, golangci-lint, prek all green. Tests assert per-outcome counts, the cardinality guard (distinct keys → one series per outcome), and the no-op-provider safety.Follow-up
The per-service wiring (pass
WithObserver(otelsetup.NewSubscriptionMetrics(...))in authz + accountingsubscription.New, + a Grafana skip/drop panel) lands once #782/#949 merge and this releases — tracked in Ambix (019ed07d).🤖 Generated with Claude Code
Coverage Report
Total coverage: 28%