{"record":{"id":"8558fbc7d6f41781","repo":"grafana/k6","slug":"metric-q-is-not-a-gauge","errorCode":null,"errorMessage":"metric %q is not a gauge","messagePattern":"metric %q is not a gauge","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/output/opentelemetry/registry.go","lineNumber":116,"sourceCode":"\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))\n\t}\n\n\tgauge, err := r.meter.Float64Gauge(name, opts...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create gauge for %q: %w\", name, err)\n\t}\n\n\tr.logger.Debugf(\"registered gauge metric %q \", name)\n\n\tr.gauges.Store(name, gauge)\n\treturn gauge, nil\n}\n","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/output/opentelemetry/registry.go#L98-L134","documentation":"getOrCreateGauge looks up the name in the gauges sync.Map and type-asserts to otelMetric.Float64Gauge. If a value exists but is not a gauge, the same metric name was registered earlier as another instrument type; a naming collision in registry state makes dispatch fail. Internal consistency error, not user-caused.","triggerScenarios":"Thrown at internal/output/opentelemetry/registry.go:116 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Rename the gauge metric to avoid name collisions with counters/histograms","Use distinct names per metric type"],"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"}