grafana/k6 · error

parsing metric name failed

Error message

parsing metric name failed

What it means

Sentinel error (ErrMetricNameParsing) indicating a metric name expression of the form name{tag:value,...} is malformed. ParseMetricName wraps it with specifics: unmatched curly braces, or a closing brace appearing before the opening one.

Solutions

  1. Balance the curly braces in the metric expression, e.g. 'http_req_duration{status:200}'
  2. Ensure the closing '}' comes after the opening '{' and there is at most one brace group
Defensive patterns

Strategy: validation

When it happens

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

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at metrics/metric.go:85

	}

	subMetric := &Submetric{
		Name:   m.Name + "{" + keyValues + "}",
		Suffix: keyValues,
		Tags:   tags,
		Parent: m,
	}
	subMetricMetric := m.registry.newMetric(subMetric.Name, m.Type, m.Contains)
	subMetricMetric.Sub = subMetric // sigh
	subMetric.Metric = subMetricMetric

	m.Submetrics = append(m.Submetrics, subMetric)

	return subMetric, nil
}

// ErrMetricNameParsing indicates parsing a metric name failed
var ErrMetricNameParsing = errors.New("parsing metric name failed")

// ParseMetricName parses a metric name expression of the form metric_name{tag_key:tag_value,...}
// Its first return value is the parsed metric name, second are parsed tags as as slice
// of "key:value" strings. On failure, it returns an error containing the `ErrMetricNameParsing` in its chain.
func ParseMetricName(name string) (string, []string, error) {
	openingTokenPos := strings.IndexByte(name, '{')
	closingTokenPos := strings.LastIndexByte(name, '}')
	containsOpeningToken := openingTokenPos != -1
	containsClosingToken := closingTokenPos != -1

	// Neither the opening '{' token nor the closing '}' token
	// are present, thus the metric name only consists of a literal.
	if !containsOpeningToken && !containsClosingToken {
		return name, nil, nil
	}

	// If the name contains an opening or closing token, but not
	// its counterpart, the expression is malformed.

View on GitHub (pinned to 01ffac6f24)