grafana/k6 · error

invalid ws.connect() metric tags: %w

Error message

invalid ws.connect() metric tags: %w

What it means

The `tags` option passed in the params object of ws.connect() failed to apply. common.ApplyUserTags expects a plain object of string tag name/value pairs; it fires when tags is not an object, a tag value is not a string or convertible to one, or a tag name is empty/invalid. The connection is never attempted — argument parsing aborts.

Source

Thrown at internal/js/modules/k6/ws/ws.go:675

	// Parse the optional second argument (params)
	params := paramsV.ToObject(rt)
	for _, k := range params.Keys() {
		switch k {
		case "headers":
			headersV := params.Get(k)
			if common.IsNullish(headersV) {
				continue
			}
			headersObj := headersV.ToObject(rt)
			if headersObj == nil {
				continue
			}
			for _, key := range headersObj.Keys() {
				parsedArgs.headers.Set(key, headersObj.Get(key).String())
			}
		case "tags":
			if err := common.ApplyCustomUserTags(rt, parsedArgs.tagsAndMeta, params.Get(k)); err != nil {
				return nil, fmt.Errorf("invalid ws.connect() metric tags: %w", err)
			}
		case "jar":
			jarV := params.Get(k)
			if common.IsNullish(jarV) {
				continue
			}
			if v, ok := jarV.Export().(*httpModule.CookieJar); ok {
				parsedArgs.cookieJar = v.Jar
			}
		case "compression":
			// deflate compression algorithm is supported - as defined in RFC7692
			// compression here relies on the implementation in gorilla/websocket package, usage is
			// experimental and may result in decreased performance. package supports
			// only "no context takeover" scenario

			algoString := strings.TrimSpace(params.Get(k).ToString().String())
			if algoString == "" {
				continue

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Pass tags as a plain object of string keys to string values, e.g. ws.connect(url, { tags: { name: 'myws' } })
  2. Do not pass arrays, numbers, or nested objects as tag values; convert them to strings first
  3. If computing tags dynamically, guard that the value is neither null nor undefined before building the tags object
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/js/modules/k6/ws/ws.go:675 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/470402ed8b90a1ea. Report an issue: GitHub.