{"record":{"id":"21ca179e9a58eb5a","repo":"grafana/k6","slug":"encoding-metrics-as-protobuf-write-request-failed","errorCode":null,"errorMessage":"encoding metrics as Protobuf write request failed: %w","messagePattern":"encoding metrics as Protobuf write request failed: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"output/cloud/expv2/metrics_client.go","lineNumber":96,"sourceCode":"\t\treturn io.NopCloser(bytes.NewReader(b)), nil\n\t}\n\n\treq.Header.Set(\"Content-Type\", \"application/x-protobuf\")\n\treq.Header.Set(\"Content-Encoding\", \"snappy\")\n\treq.Header.Set(\"K6-Metrics-Protocol-Version\", \"2.0\")\n\n\terr = mc.httpClient.Do(req, nil)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\treturn nil\n}\n\nfunc newRequestBody(data *pbcloud.MetricSet) ([]byte, error) {\n\tb, err := proto.Marshal(data)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"encoding metrics as Protobuf write request failed: %w\", err)\n\t}\n\t// TODO: use the framing format\n\t// https://github.com/google/snappy/blob/main/framing_format.txt\n\t// It can be done replacing the encode with\n\t// https://pkg.go.dev/github.com/klauspost/compress/snappy#NewBufferedWriter\n\tif snappy.MaxEncodedLen(len(b)) < 0 {\n\t\treturn nil, fmt.Errorf(\"the Protobuf message is too large to be handled by Snappy encoder; \"+\n\t\t\t\"size: %d, limit: %d\", len(b), 0xffffffff)\n\t}\n\treturn snappy.Encode(nil, b), nil\n}\n","sourceCodeStart":78,"sourceCodeEnd":108,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/output/cloud/expv2/metrics_client.go#L78-L108","documentation":"In newRequestBody, proto.Marshal failed to serialize the pbcloud.MetricSet into a Protobuf wire-format message before it is Snappy-compressed and sent to the cloud. This indicates the in-memory MetricSet is malformed or contains a field the marshaller rejects — an internal serialization failure, not a network problem.","triggerScenarios":"Thrown at output/cloud/expv2/metrics_client.go:96 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Update k6 to the latest version in case of a serialization regression","Check for mixed k6 versions between the binary and any custom builds/extensions","Report the issue to grafana/k6 with the error details if it persists"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}