grafana/k6 · error

metric tags: %w

Error message

metric tags: %w

What it means

params.tags is applied with common.ApplyCustomUserTags (js/common/tags.go:15), which accepts only String, Boolean and Number values for each tag key. An object, array, null or other kind as a tag value returns 'invalid value for metric tag ...', surfaced by the gRPC module prefixed with 'metric tags: '.

Source

Thrown at internal/js/modules/k6/grpc/params.go:53

	if common.IsNullish(input) {
		return result, nil
	}

	rt := vu.Runtime()
	params := input.ToObject(rt)

	for _, k := range params.Keys() {
		switch k {
		case "metadata":
			md, err := newMetadata(params.Get(k))
			if err != nil {
				return result, fmt.Errorf("invalid metadata param: %w", err)
			}

			result.Metadata = md
		case "tags":
			if err := common.ApplyCustomUserTags(rt, &result.TagsAndMeta, params.Get(k)); err != nil {
				return result, fmt.Errorf("metric tags: %w", err)
			}
		case "timeout":
			var err error
			v := params.Get(k).Export()
			result.Timeout, err = types.GetDurationValue(v)
			if err != nil {
				return result, fmt.Errorf("invalid timeout value: %w", err)
			}
		case "discardResponseMessage":
			result.DiscardResponseMessage = params.Get(k).ToBoolean()
		default:
			return result, fmt.Errorf("unknown param: %q", k)
		}
	}

	return result, nil
}

View on GitHub (pinned to 93accf6570)

Solutions

  1. Flatten nested values to strings before tagging
  2. Use String()/Number()/Boolean() conversions for scalars
  3. Join arrays manually, e.g. roles.join(',')

Example fix

// before
client.invoke(method, req, { tags: { user: userObj } });

// after
client.invoke(method, req, { tags: { userId: String(userObj.id) } });
Defensive patterns

Strategy: validation

Validate before calling

function isValidTagValue(v) {
  const t = typeof v;
  return t === 'string' || t === 'boolean' || t === 'number';
}
function assertTags(tags) {
  if (tags == null) return;
  for (const [k, v] of Object.entries(tags)) {
    if (!isValidTagValue(v)) throw new Error(`tag '${k}' must be a string, boolean or number`);
  }
}
assertTags(params.tags);
client.invoke(method, req, params);

Type guard

function isScalarTag(v) {
  const t = typeof v;
  return t === 'string' || t === 'boolean' || t === 'number';
}

Prevention

When it happens

Trigger: { tags: { user: { id: 7 } } }; { tags: { roles: ['admin'] } }; { tags: { parent: null } }.

Common situations: Tagging with decoded JSON bodies or nested identity objects; shared tag-builders that sometimes emit undefined or structured values.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/e45e00aa6c2042a2. Report an issue: GitHub.