grafana/k6 · error

failed to create counter for %q: %w

Error message

failed to create counter for %q: %w

What it means

The OTel Meter rejected creation of a Float64Counter instrument for this metric name (e.g. name/instrument conflict from a previously registered instrument of a different kind). getOrCreateCounter wraps the SDK error.

Source

Thrown at internal/output/opentelemetry/registry.go:46

}

func (r *registry) getOrCreateCounter(name, unit string) (otelMetric.Float64Counter, error) {
	if counter, ok := r.counters.Load(name); ok {
		if v, ok := counter.(otelMetric.Float64Counter); ok {
			return v, nil
		}

		return nil, fmt.Errorf("metric %q is not a counter", name)
	}

	opts := []otelMetric.Float64CounterOption{}
	if unit != "" {
		opts = append(opts, otelMetric.WithUnit(unit))
	}

	c, err := r.meter.Float64Counter(name, opts...)
	if err != nil {
		return nil, fmt.Errorf("failed to create counter for %q: %w", name, err)
	}

	r.logger.Debugf("registered counter metric %q", name)

	r.counters.Store(name, c)
	return c, nil
}

func (r *registry) getOrCreateHistogram(name, unit string) (otelMetric.Float64Histogram, error) {
	if histogram, ok := r.histograms.Load(name); ok {
		if v, ok := histogram.(otelMetric.Float64Histogram); ok {
			return v, nil
		}

		return nil, fmt.Errorf("metric %q is not a histogram", name)
	}

	opts := []otelMetric.Float64HistogramOption{}

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Check the wrapped error from the meter provider
  2. Use a unique metric name that doesn't collide with other instruments
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at internal/output/opentelemetry/registry.go:46 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/41ca224af9f732b7. Report an issue: GitHub.