{"record":{"id":"8a3905d11fe02ad0","repo":"grafana/k6","slug":"metric-q-stored-not-as-counter","errorCode":null,"errorMessage":"metric %q stored not as counter","messagePattern":"metric %q stored not as counter","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/output/opentelemetry/registry.go","lineNumber":103,"sourceCode":"\n\ttotalName := name + \".total\"\n\n\tvar err error\n\tvar totalCounter otelMetric.Int64Counter\n\n\tstoredTotalCounter, ok := r.rateCounters.Load(totalName)\n\tif !ok {\n\t\ttotalCounter, err = r.meter.Int64Counter(totalName)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to create counter for %q: %w\", totalName, err)\n\t\t}\n\n\t\tr.rateCounters.Store(totalName, totalCounter)\n\t\tr.logger.Debugf(\"registered counter metric %q\", totalName)\n\t} else {\n\t\ttotalCounter, ok = storedTotalCounter.(otelMetric.Int64Counter)\n\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"metric %q stored not as counter\", totalName)\n\t\t}\n\t}\n\n\treturn totalCounter, nil\n}\n\nfunc (r *registry) getOrCreateGauge(name, unit string) (otelMetric.Float64Gauge, error) {\n\tif gauge, ok := r.gauges.Load(name); ok {\n\t\tif v, ok := gauge.(otelMetric.Float64Gauge); ok {\n\t\t\treturn v, nil\n\t\t}\n\n\t\treturn nil, fmt.Errorf(\"metric %q is not a gauge\", name)\n\t}\n\n\topts := []otelMetric.Float64GaugeOption{}\n\tif unit != \"\" {\n\t\topts = append(opts, otelMetric.WithUnit(unit))","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/output/opentelemetry/registry.go#L85-L121","documentation":"getOrCreateCounterForRate keeps a sync.Map of <name>.total counters. If a stored entry under that name fails the type assertion to otelMetric.Int64Counter, the registry state is inconsistent (the same metric name was previously registered as a different instrument type). This is an internal invariant violation, not user input error.","triggerScenarios":"Thrown at internal/output/opentelemetry/registry.go:103 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Rename the rate metric so '<name>.total' doesn't collide with an existing differently-typed instrument","Avoid mixing metric types under the same base name"],"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-14T00:17:10.932Z"}