{"record":{"id":"5ff75382e110adb4","repo":"grafana/k6","slug":"unknown-metric-s","errorCode":null,"errorMessage":"unknown metric: %s","messagePattern":"unknown metric: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/dashboard/aggregate.go","lineNumber":246,"sourceCode":"\n\tthresholds := make([]string, 0, len(tres))\n\n\tfor _, res := range tres {\n\t\tthresholds = append(thresholds, res.String())\n\t}\n\n\t_, err = agg.registry.getOrNew(name, metricType, valueType, thresholds)\n\n\treturn err\n}\n\nfunc (agg *aggregator) processPoint(data []byte) error {\n\ttimestamp := gjson.GetBytes(data, \"data.time\").Time()\n\tname := gjson.GetBytes(data, \"metric\").String()\n\n\tmetric := agg.registry.Get(name)\n\tif metric == nil {\n\t\treturn fmt.Errorf(\"%w: %s\", errUnknownMetric, name)\n\t}\n\n\ttags := agg.tagSetFrom(gjson.GetBytes(data, \"data.tags\"))\n\n\tsample := metrics.Sample{ //nolint:exhaustruct\n\t\tTime:  timestamp,\n\t\tValue: gjson.GetBytes(data, \"data.value\").Float(),\n\t\tTimeSeries: metrics.TimeSeries{ //nolint:exhaustruct\n\t\t\tMetric: metric,\n\t\t\tTags:   tags,\n\t\t},\n\t}\n\n\tcontainer := metrics.ConnectedSamples{ //nolint:exhaustruct\n\t\tSamples: []metrics.Sample{sample},\n\t\tTime:    sample.Time,\n\t\tTags:    tags,\n\t}","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/dashboard/aggregate.go#L228-L264","documentation":"The web dashboard output consumes the JSON sample stream and resolves each sample's 'metric' field by name in a registry built from ingested metric definitions. processPoint returns the errUnknownMetric sentinel wrapped with the metric name when a sample references a metric the registry does not contain — meaning the sample stream and the metric registry are out of sync (samples emitted for a metric that was never defined, or a stream/registry mismatch).","triggerScenarios":"Running with the dashboard enabled (K6_WEB_DASHBOARD=true or --web-dashboard) while an extension or custom output emits samples whose metric name was never registered via the metrics registry that the aggregator ingested; version skew between an extension and the k6 core changing the sample schema.","commonSituations":"Extensions emitting custom metrics without registering them first; feeding externally produced JSON streams into a mismatched dashboard build; regressions after upgrading k6 or an xk6 extension.","solutions":["Ensure every custom metric is registered through the module/extension API (metrics.NewCounter/NewGauge/etc.) before any sample with that name is emitted","Re-run with K6_WEB_DASHBOARD=false to confirm the test itself is healthy and isolate the problem to the dashboard path","Rebuild extensions against the same k6 version as the binary to eliminate schema skew","If it occurs with a stock output, report it at https://github.com/grafana/k6/issues with the script and versions"],"exampleFix":"// before (extension emits an unregistered metric name)\nsamples.push({ metric: 'my_ext_requests', ... });\n// after (register the metric in the module's registry at init, reuse the handle)\nconst reqCounter = metrics.NewCounter('my_ext_requests'); // registered via New().Metrics\nsamples.push({ metric: reqCounter.Name, ... });","handlingStrategy":"validation","validationCode":"// In an extension: register every metric before emitting, and never hardcode names at emit time\n// func New() *Module { m.Metrics[\"my_ext_requests\"] = metrics.NewCounter(\"my_ext_requests\") }\nif _, ok := m.Metrics[\"my_ext_requests\"]; !ok {\n    return fmt.Errorf(\"metric my_ext_requests not registered\")\n}\n// Quick isolation when the error appears:\n# K6_WEB_DASHBOARD=false k6 run script.js   # confirms the run itself is healthy","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Register all custom metrics via the module API before the first sample is emitted","Rebuild extensions against the same k6 version as the core","Define metric names as constants shared by registration and emission","Report stock-output occurrences upstream with script and versions"],"tags":["dashboard","metrics","web-dashboard","extensions"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}