{"record":{"id":"ace6d626207adc97","repo":"grafana/k6","slug":"cannot-add-tags-for-the-s-custom-metric-w","errorCode":null,"errorMessage":"cannot add tags for the '%s' custom metric: %w","messagePattern":"cannot add tags for the '(.+?)' custom metric: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/metrics/metrics.go","lineNumber":115,"sourceCode":"\t\treturn raiseErr(fmt.Errorf(\"no value was provided for metric '%s', a number or a boolean value is expected\",\n\t\t\tm.metric.Name))\n\t}\n\tif sobek.IsNull(v) {\n\t\treturn raiseNan()\n\t}\n\n\tvfloat := v.ToFloat()\n\tif vfloat == 0 && v.ToBoolean() {\n\t\tvfloat = 1.0\n\t}\n\n\tif math.IsNaN(vfloat) {\n\t\treturn raiseNan()\n\t}\n\n\tctm := state.Tags.GetCurrentValues()\n\tif err := common.ApplyCustomUserTags(m.vu.Runtime(), &ctm, addTags); err != nil {\n\t\treturn false, fmt.Errorf(\"cannot add tags for the '%s' custom metric: %w\", m.metric.Name, err)\n\t}\n\n\tsample := metrics.Sample{\n\t\tTimeSeries: metrics.TimeSeries{\n\t\t\tMetric: m.metric,\n\t\t\tTags:   ctm.Tags,\n\t\t},\n\t\tTime:     time.Now(),\n\t\tMetadata: ctm.Metadata,\n\t\tValue:    vfloat,\n\t}\n\tmetrics.PushIfNotDone(m.vu.Context(), state.Samples, sample)\n\treturn true, nil\n}\n\ntype (\n\t// RootModule is the root metrics module\n\tRootModule struct{}","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/metrics/metrics.go#L97-L133","documentation":"Returned by Metric.add when applying the optional tags argument fails. The helper common.ApplyCustomUserTags could not interpret the second argument of add(value, tags) as a valid tags object (e.g. not an object or containing invalid values). Note this error is returned directly, not routed through raiseErr, so it propagates regardless of the throw option; the metric sample is never emitted.","triggerScenarios":"Thrown at internal/js/modules/k6/metrics/metrics.go:115 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass tags as a plain object: myCounter.add(1, { env: 'staging' })","Omit the second argument if no custom tags are needed","Inspect the wrapped error for the exact tag that failed validation"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}