grafana/k6 · error

failed to set protocol labels: %w

Error message

failed to set protocol labels: %w

What it means

Returned by newCreateRequestMetadataRequest (internal/cloudapi/insights/mappers.go:43) when setProtocolLabels fails to translate the request's protocol-specific labels into the protobuf oneof field. The only concrete failure is the default branch at mappers.go:63: 'unknown protocol labels type' — the mapper currently implements just ProtocolHTTPLabels (see the TODO for other protocols). It means the RequestMetadata is otherwise fine but its ProtocolLabels value has no protobuf representation yet.

Source

Thrown at internal/cloudapi/insights/mappers.go:43

		Requests: reqs,
	}, nil
}

func newCreateRequestMetadataRequest(requestMetadata RequestMetadata) (*ingester.CreateRequestMetadataRequest, error) {
	rm := &k6.RequestMetadata{
		TraceID:           requestMetadata.TraceID,
		StartTimeUnixNano: requestMetadata.Start.UnixNano(),
		EndTimeUnixNano:   requestMetadata.End.UnixNano(),
		TestRunLabels: &k6.TestRunLabels{
			ID:       requestMetadata.TestRunLabels.ID,
			Scenario: requestMetadata.TestRunLabels.Scenario,
			Group:    requestMetadata.TestRunLabels.Group,
		},
		ProtocolLabels: nil,
	}

	if err := setProtocolLabels(rm, requestMetadata.ProtocolLabels); err != nil {
		return nil, fmt.Errorf("failed to set protocol labels: %w", err)
	}

	return &ingester.CreateRequestMetadataRequest{
		RequestMetadata: rm,
	}, nil
}

func setProtocolLabels(rm *k6.RequestMetadata, labels ProtocolLabels) error {
	// TODO(lukasz, other-proto-support): Set other protocol labels.
	switch l := labels.(type) {
	case ProtocolHTTPLabels:
		rm.ProtocolLabels = &k6.RequestMetadata_HTTPLabels{
			HTTPLabels: &k6.HTTPLabels{
				Url:        l.URL,
				Method:     l.Method,
				StatusCode: l.StatusCode,
			},
		}

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Check what concrete type requestMetadata.ProtocolLabels holds at the call site; if it is nil or non-HTTP, that is the trigger.
  2. For non-HTTP traffic today, do not send it through the insights mapper — restrict insights to HTTP requests until support lands.
  3. Add a case for your labels type in setProtocolLabels (mappers.go:53) mapping it to the matching k6.RequestMetadata_* oneof wrapper.
  4. Handle nil explicitly (return nil or an explicit error) if nil labels should be legal in your flow.

Example fix

// before
if err := setProtocolLabels(rm, requestMetadata.ProtocolLabels); err != nil {
	return nil, fmt.Errorf("failed to set protocol labels: %w", err)
}

// after (caller-side guard)
if _, ok := requestMetadata.ProtocolLabels.(insights.ProtocolHTTPLabels); requestMetadata.ProtocolLabels != nil && !ok {
	return nil, fmt.Errorf("protocol labels type %T not supported for insights", requestMetadata.ProtocolLabels)
}
Defensive patterns

Strategy: validation

Validate before calling

// Assert the mapper supports this entry before mapping.
if rm.ProtocolLabels != nil {
	if _, ok := rm.ProtocolLabels.(insights.ProtocolHTTPLabels); !ok {
		return fmt.Errorf("insights: protocol labels type %T not supported", rm.ProtocolLabels)
	}
}

Type guard

func isHTTPProtocolLabels(l insights.ProtocolLabels) bool {
	_, ok := l.(insights.ProtocolHTTPLabels)
	return ok
}

Try / catch

if _, err := insights.NewCreateRequestMetadataRequest(rm); err != nil {
	if strings.HasSuffix(err.Error(), "unknown protocol labels type") {
		// skip this metadata or add support in setProtocolLabels
	} else {
		return err
	}
}

Prevention

When it happens

Trigger: Calling newCreateRequestMetadataRequest with requestMetadata.ProtocolLabels set to nil, or to a concrete type that is not ProtocolHTTPLabels (e.g. a hypothetical ProtocolGRPCLabels/ProtocolWebSocketLabels struct added by an extension).

Common situations: Developing tracing/insights support for non-HTTP protocols in k6; test fixtures constructing RequestMetadata without labels; version skew where an xk6 extension emits a labels type newer than the k6 build supports.

Related errors


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