grafana/k6 · error

get or create counter for Rate metric %q: %w

Error message

get or create counter for Rate metric %q: %w

What it means

While exporting a Rate metric, the OTel registry failed to look up or create the companion Int64Counter used to track the rate numerator. singleCounterForRate wraps the registry error for the named metric.

Source

Thrown at internal/output/opentelemetry/output.go:194

	case metrics.Rate:
		if err := o.singleCounterForRate(ctx, name, attributeSetOpt, entry); err != nil {
			return err
		}
	default:
		return fmt.Errorf("metric %q has unsupported metric type", entry.Metric.Name)
	}
	return nil
}

func (o *Output) singleCounterForRate(
	ctx context.Context,
	metricName string,
	attributeSetOpt otelMetric.MeasurementOption,
	entry metrics.Sample,
) error {
	rate, err := o.metricsRegistry.getOrCreateCounterForRate(metricName)
	if err != nil {
		return fmt.Errorf("get or create counter for Rate metric %q: %w", metricName, err)
	}
	var valueType string
	if entry.Value != 0 {
		valueType = "nonzero"
	} else {
		valueType = "zero"
	}
	valset := attribute.NewSet(attribute.String("condition", valueType))
	rate.Add(ctx, 1, attributeSetOpt, otelMetric.WithAttributeSet(valset))
	return nil
}

func normalizeMetricName(cfg Config, name string) string {
	return cfg.MetricPrefix.String + name
}

func normalizeUnit(vt metrics.ValueType) string {
	switch vt {

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Inspect the wrapped error (instrument creation failure or type collision)
  2. Ensure no other metric with the same name plus .total suffix exists with a different type
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at internal/output/opentelemetry/output.go:194 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/9190fea361be3173. Report an issue: GitHub.