{"record":{"id":"9190fea361be3173","repo":"grafana/k6","slug":"get-or-create-counter-for-rate-metric-q-w","errorCode":null,"errorMessage":"get or create counter for Rate metric %q: %w","messagePattern":"get or create counter for Rate metric %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/output/opentelemetry/output.go","lineNumber":194,"sourceCode":"\tcase metrics.Rate:\n\t\tif err := o.singleCounterForRate(ctx, name, attributeSetOpt, entry); err != nil {\n\t\t\treturn err\n\t\t}\n\tdefault:\n\t\treturn fmt.Errorf(\"metric %q has unsupported metric type\", entry.Metric.Name)\n\t}\n\treturn nil\n}\n\nfunc (o *Output) singleCounterForRate(\n\tctx context.Context,\n\tmetricName string,\n\tattributeSetOpt otelMetric.MeasurementOption,\n\tentry metrics.Sample,\n) error {\n\trate, err := o.metricsRegistry.getOrCreateCounterForRate(metricName)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"get or create counter for Rate metric %q: %w\", metricName, err)\n\t}\n\tvar valueType string\n\tif entry.Value != 0 {\n\t\tvalueType = \"nonzero\"\n\t} else {\n\t\tvalueType = \"zero\"\n\t}\n\tvalset := attribute.NewSet(attribute.String(\"condition\", valueType))\n\trate.Add(ctx, 1, attributeSetOpt, otelMetric.WithAttributeSet(valset))\n\treturn nil\n}\n\nfunc normalizeMetricName(cfg Config, name string) string {\n\treturn cfg.MetricPrefix.String + name\n}\n\nfunc normalizeUnit(vt metrics.ValueType) string {\n\tswitch vt {","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/output/opentelemetry/output.go#L176-L212","documentation":"While exporting a Rate metric, the OTel registry failed to look up or create the companion Int64Counter used to track the rate numerator. singleCounterForRate wraps the registry error for the named metric.","triggerScenarios":"Thrown at internal/output/opentelemetry/output.go:194 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the wrapped error (instrument creation failure or type collision)","Ensure no other metric with the same name plus .total suffix exists with a different type"],"exampleFix":null,"handlingStrategy":"fallback","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"}