From 783715ee63940e81e39cf5e095cd45b55d8f9f87 Mon Sep 17 00:00:00 2001 From: Carson Ip Date: Mon, 13 Apr 2026 18:31:20 +0100 Subject: [PATCH 1/2] Add error_reason dimension to messaging.kafka.{connects,connect_errors}.count --- kafka/metrics.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kafka/metrics.go b/kafka/metrics.go index d75bc1e7..72f7e2ea 100644 --- a/kafka/metrics.go +++ b/kafka/metrics.go @@ -358,6 +358,13 @@ func (h *metricHooks) OnBrokerConnect(meta kgo.BrokerMetadata, _ time.Duration, attrs = append(attrs, attribute.String("namespace", h.namespace)) } if err != nil { + errorReason := "unknown" + if errors.Is(err, context.Canceled) { + errorReason = "canceled" + } else if errors.Is(err, context.DeadlineExceeded) { + errorReason = "timeout" + } + attrs = append(attrs, attribute.String(errorReasonKey, errorReason)) h.connectErrs.Add( context.Background(), 1, From 60f3fbc4507f8faf30b87b483ca47a652c47caad Mon Sep 17 00:00:00 2001 From: Carson Ip Date: Mon, 13 Apr 2026 18:32:37 +0100 Subject: [PATCH 2/2] Fix preallocation --- kafka/metrics.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kafka/metrics.go b/kafka/metrics.go index 72f7e2ea..dd968c0c 100644 --- a/kafka/metrics.go +++ b/kafka/metrics.go @@ -352,7 +352,7 @@ func formatMetricError(name string, err error) error { } func (h *metricHooks) OnBrokerConnect(meta kgo.BrokerMetadata, _ time.Duration, _ net.Conn, err error) { - attrs := make([]attribute.KeyValue, 0, 3) + attrs := make([]attribute.KeyValue, 0, 4) attrs = append(attrs, semconv.MessagingSystem("kafka")) if h.namespace != "" { attrs = append(attrs, attribute.String("namespace", h.namespace))