{"record":{"id":"134d53561fc010a0","repo":"grafana/k6","slug":"failed-to-set-protocol-labels-w","errorCode":null,"errorMessage":"failed to set protocol labels: %w","messagePattern":"failed to set protocol labels: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cloudapi/insights/mappers.go","lineNumber":43,"sourceCode":"\t\tRequests: reqs,\n\t}, nil\n}\n\nfunc newCreateRequestMetadataRequest(requestMetadata RequestMetadata) (*ingester.CreateRequestMetadataRequest, error) {\n\trm := &k6.RequestMetadata{\n\t\tTraceID:           requestMetadata.TraceID,\n\t\tStartTimeUnixNano: requestMetadata.Start.UnixNano(),\n\t\tEndTimeUnixNano:   requestMetadata.End.UnixNano(),\n\t\tTestRunLabels: &k6.TestRunLabels{\n\t\t\tID:       requestMetadata.TestRunLabels.ID,\n\t\t\tScenario: requestMetadata.TestRunLabels.Scenario,\n\t\t\tGroup:    requestMetadata.TestRunLabels.Group,\n\t\t},\n\t\tProtocolLabels: nil,\n\t}\n\n\tif err := setProtocolLabels(rm, requestMetadata.ProtocolLabels); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to set protocol labels: %w\", err)\n\t}\n\n\treturn &ingester.CreateRequestMetadataRequest{\n\t\tRequestMetadata: rm,\n\t}, nil\n}\n\nfunc setProtocolLabels(rm *k6.RequestMetadata, labels ProtocolLabels) error {\n\t// TODO(lukasz, other-proto-support): Set other protocol labels.\n\tswitch l := labels.(type) {\n\tcase ProtocolHTTPLabels:\n\t\trm.ProtocolLabels = &k6.RequestMetadata_HTTPLabels{\n\t\t\tHTTPLabels: &k6.HTTPLabels{\n\t\t\t\tUrl:        l.URL,\n\t\t\t\tMethod:     l.Method,\n\t\t\t\tStatusCode: l.StatusCode,\n\t\t\t},\n\t\t}","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/cloudapi/insights/mappers.go#L25-L61","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nif err := setProtocolLabels(rm, requestMetadata.ProtocolLabels); err != nil {\n\treturn nil, fmt.Errorf(\"failed to set protocol labels: %w\", err)\n}\n\n// after (caller-side guard)\nif _, ok := requestMetadata.ProtocolLabels.(insights.ProtocolHTTPLabels); requestMetadata.ProtocolLabels != nil && !ok {\n\treturn nil, fmt.Errorf(\"protocol labels type %T not supported for insights\", requestMetadata.ProtocolLabels)\n}","handlingStrategy":"validation","validationCode":"// Assert the mapper supports this entry before mapping.\nif rm.ProtocolLabels != nil {\n\tif _, ok := rm.ProtocolLabels.(insights.ProtocolHTTPLabels); !ok {\n\t\treturn fmt.Errorf(\"insights: protocol labels type %T not supported\", rm.ProtocolLabels)\n\t}\n}","typeGuard":"func isHTTPProtocolLabels(l insights.ProtocolLabels) bool {\n\t_, ok := l.(insights.ProtocolHTTPLabels)\n\treturn ok\n}","tryCatchPattern":"if _, err := insights.NewCreateRequestMetadataRequest(rm); err != nil {\n\tif strings.HasSuffix(err.Error(), \"unknown protocol labels type\") {\n\t\t// skip this metadata or add support in setProtocolLabels\n\t} else {\n\t\treturn err\n\t}\n}","preventionTips":["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."],"tags":["k6","insights","cloud","protobuf","type-switch","protocol-labels"],"backgroundTag":"unsupported-protocol-type","analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}