grafana/k6 · error · TypeError

invalid value for metric metadata

Error message

invalid value for metric metadata '%s': only String, Boolean and Number types are accepted as a metric metadata value

What it means

metadataDynamicObject.Set (backing execution.vu.metadata[key]=value) received a value that cannot be stored as metric metadata: only String, Boolean and Number types are accepted. Any other type (object, null, undefined, symbol, function) triggers an exception in the JS runtime at assignment time.

Solutions

  1. Assign only strings, booleans, or numbers to execution.vu.metadata entries
  2. Stringify complex values before assignment (e.g. String(obj) or JSON.stringify)
  3. Avoid null/undefined metadata values
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at internal/js/modules/k6/execution/execution.go:431 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/382baa873c2aa20d. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/execution/execution.go:431

	state   *lib.State
}

// Get a property value for the key. May return nil if the property does not exist.
func (o *metadataDynamicObject) Get(key string) sobek.Value {
	tcv := o.state.Tags.GetCurrentValues()
	if metadatum, ok := tcv.Metadata[key]; ok {
		return o.runtime.ToValue(metadatum)
	}
	return nil
}

// Set a property value for the key. It returns true if successful. String, Boolean
// and Number types are implicitly converted to the Sobek's relative string
// representation. An exception is raised in case a denied type is provided.
func (o *metadataDynamicObject) Set(key string, val sobek.Value) bool {
	o.state.Tags.Modify(func(tagsAndMeta *metrics.TagsAndMeta) {
		if err := common.ApplyCustomUserMetadata(tagsAndMeta, key, val); err != nil {
			panic(o.runtime.NewTypeError(err.Error()))
		}
	})
	return true
}

// Has returns true if the property exists.
func (o *metadataDynamicObject) Has(key string) bool {
	ctv := o.state.Tags.GetCurrentValues()
	if _, ok := ctv.Metadata[key]; ok {
		return true
	}
	return false
}

// Delete deletes the property for the key. It returns true on success (note,
// that includes missing property).
func (o *metadataDynamicObject) Delete(key string) bool {
	o.state.Tags.Modify(func(tagsAndMeta *metrics.TagsAndMeta) {

View on GitHub (pinned to 01ffac6f24)