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
- Check what concrete type requestMetadata.ProtocolLabels holds at the call site; if it is nil or non-HTTP, that is the trigger.
- For non-HTTP traffic today, do not send it through the insights mapper — restrict insights to HTTP requests until support lands.
- Add a case for your labels type in setProtocolLabels (mappers.go:53) mapping it to the matching k6.RequestMetadata_* oneof wrapper.
- 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
- Keep protocol-label type sets in sync between producers and the insights mapper switch.
- Unit-test every ProtocolLabels implementation you ship against setProtocolLabels's supported set.
- Fail loudly during development (xk6 build) rather than at runtime on the ingest path.
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
- failed to create request metadata request: %w
- script name not set, please specify K6_CLOUD_NAME or options
- tests with unspecified duration are not allowed when outputt
- both K6_CLOUD_METRICS_PUSH_URL and K6_CLOUD_TEST_RUN_TOKEN m
- TestRunID is required
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/134d53561fc010a0.
Report an issue: GitHub.