From 7279eac949408175584abdf004bce18f28363eac Mon Sep 17 00:00:00 2001 From: mkelvers Date: Tue, 26 May 2026 22:24:59 +0200 Subject: [PATCH] fix: avoid metrics panic --- internal/observability/metrics.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/observability/metrics.go b/internal/observability/metrics.go index 9b8ff6c..c03df95 100644 --- a/internal/observability/metrics.go +++ b/internal/observability/metrics.go @@ -129,6 +129,9 @@ func (c *counterVec) Inc(labelValues ...string) { defer c.mu.Unlock() key, labels := buildLabelKey(c.labelNames, labelValues) + if labels == nil { + return + } sample, ok := c.samples[key] if !ok { sample = &counterSample{labels: labels} @@ -166,6 +169,9 @@ func (h *histogramVec) Observe(value float64, labelValues ...string) { defer h.mu.Unlock() key, labels := buildLabelKey(h.labelNames, labelValues) + if labels == nil { + return + } sample, ok := h.samples[key] if !ok { sample = &histogramSample{ @@ -206,7 +212,7 @@ func (h *histogramVec) snapshot() []histogramSample { func buildLabelKey(labelNames []string, labelValues []string) (string, map[string]string) { if len(labelNames) != len(labelValues) { - panic("label cardinality mismatch") + return "", nil } labels := make(map[string]string, len(labelNames))