in kafka/metrics.go [417:444]
func (h *metricHooks) OnBrokerRead(_ kgo.BrokerMetadata, _ int16, bytesRead int, readWait, timeToRead time.Duration, err error) {
attrs := make([]attribute.KeyValue, 0, 3)
attrs = append(attrs, semconv.MessagingSystem("kafka"))
if h.namespace != "" {
attrs = append(attrs, attribute.String("namespace", h.namespace))
}
outcome := "success"
if err != nil {
outcome = "failure"
h.readErrs.Add(
context.Background(),
1,
metric.WithAttributeSet(attribute.NewSet(attrs...)),
)
} else {
h.readBytes.Add(
context.Background(),
int64(bytesRead),
metric.WithAttributeSet(attribute.NewSet(attrs...)),
)
}
attrs = append(attrs, attribute.String("outcome", outcome))
h.messageReadLatency.Record(
context.Background(),
readWait.Seconds()+timeToRead.Seconds(),
metric.WithAttributeSet(attribute.NewSet(attrs...)),
)
}