{"record":{"id":"5ae2d18642bb268d","repo":"grafana/k6","slug":"metric-q-is-not-a-counter","errorCode":null,"errorMessage":"metric %q is not a counter","messagePattern":"metric %q is not a counter","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/output/opentelemetry/registry.go","lineNumber":36,"sourceCode":"\thistograms   sync.Map\n\trateCounters sync.Map\n}\n\n// newRegistry creates a new registry.\nfunc newRegistry(meter otelMetric.Meter, logger logrus.FieldLogger) *registry {\n\treturn &registry{\n\t\tmeter:  meter,\n\t\tlogger: logger,\n\t}\n}\n\nfunc (r *registry) getOrCreateCounter(name, unit string) (otelMetric.Float64Counter, error) {\n\tif counter, ok := r.counters.Load(name); ok {\n\t\tif v, ok := counter.(otelMetric.Float64Counter); ok {\n\t\t\treturn v, nil\n\t\t}\n\n\t\treturn nil, fmt.Errorf(\"metric %q is not a counter\", name)\n\t}\n\n\topts := []otelMetric.Float64CounterOption{}\n\tif unit != \"\" {\n\t\topts = append(opts, otelMetric.WithUnit(unit))\n\t}\n\n\tc, err := r.meter.Float64Counter(name, opts...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create counter for %q: %w\", name, err)\n\t}\n\n\tr.logger.Debugf(\"registered counter metric %q\", name)\n\n\tr.counters.Store(name, c)\n\treturn c, nil\n}\n","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/output/opentelemetry/registry.go#L18-L54","documentation":"The OTel registry found a cached instrument under this metric name, but its stored dynamic type is not Float64Counter — a different metric kind (histogram/gauge) already claimed the same name in the counters map.","triggerScenarios":"Thrown at internal/output/opentelemetry/registry.go:36 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Rename one of the conflicting metrics so counter vs other types don't share a name","Avoid registering the same metric name with different types in one run"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}