grafana/k6 · error
metric '%s' already exists but with a value type %s, instead
Error message
metric '%s' already exists but with a value type %s, instead of %s
What it means
Raised by Registry.NewMetric when a metric with the same name was already registered holding a different value type (data vs time), detected while a value type is explicitly requested for the new registration.
Source
Thrown at metrics/registry.go:62
r.l.Lock()
defer r.l.Unlock()
if !checkName(name) {
return nil, fmt.Errorf("Invalid metric name: '%s'. %s", name, badNameWarning) //nolint:staticcheck
}
oldMetric, ok := r.metrics[name]
if !ok {
m := r.newMetric(name, typ, t...)
r.metrics[name] = m
return m, nil
}
if oldMetric.Type != typ {
return nil, fmt.Errorf("metric '%s' already exists but with type %s, instead of %s", name, oldMetric.Type, typ)
}
if len(t) > 0 {
if t[0] != oldMetric.Contains {
return nil, fmt.Errorf("metric '%s' already exists but with a value type %s, instead of %s",
name, oldMetric.Contains, t[0])
}
}
return oldMetric, nil
}
// MustNewMetric is like NewMetric, but will panic if there is an error
func (r *Registry) MustNewMetric(name string, typ MetricType, t ...ValueType) *Metric {
m, err := r.NewMetric(name, typ, t...)
if err != nil {
panic(err)
}
return m
}
// All returns all the registered metrics.
func (r *Registry) All() []*Metric {
r.l.RLock()View on GitHub (pinned to 01ffac6f24)
Solutions
- Keep the value type consistent across all uses of the metric name
- Register the new metric under a different name
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at metrics/registry.go:62 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/55a0621152bb501b.
Report an issue: GitHub.