grafana/k6 · error · ErrMetricNameParsing

%w, metric %q tag expression is malformed

Error message

%w, metric %q tag expression is malformed

What it means

Raised by ParseMetricName while splitting the brace contents of a tagged metric name: one comma-separated entry has no ':value' part (empty value after Cut), e.g. my_metric{status}. Wraps the ErrMetricNameParsing sentinel.

Source

Thrown at metrics/metric.go:139

		err := fmt.Errorf(
			"%w, metric %q lacks a closing curly brace in its last position",
			ErrMetricNameParsing,
			name,
		)
		return "", nil, err
	}

	// We already know the position of the opening and closing curly brace
	// tokens. Thus, we extract the string in between them, and split its
	// content to obtain the tags key values.
	tags := strings.Split(name[openingTokenPos+1:closingTokenPos], ",")

	// For each tag definition, ensure it is correctly formed
	for i, t := range tags {
		_, value, _ := strings.Cut(t, ":")

		if value == "" {
			return "", nil, fmt.Errorf("%w, metric %q tag expression is malformed", ErrMetricNameParsing, t)
		}

		tags[i] = strings.TrimSpace(t)
	}

	return name[0:openingTokenPos], tags, nil
}

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Write each tag as key:value, e.g. my_metric{status:200,method:GET}
  2. Remove empty entries caused by trailing commas
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at metrics/metric.go:139 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/5e3575f30a816904. Report an issue: GitHub.