grafana/k6 · error
encoding metrics as Protobuf write request failed: %w
Error message
encoding metrics as Protobuf write request failed: %w
What it means
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.
Source
Thrown at output/cloud/expv2/metrics_client.go:96
return io.NopCloser(bytes.NewReader(b)), nil
}
req.Header.Set("Content-Type", "application/x-protobuf")
req.Header.Set("Content-Encoding", "snappy")
req.Header.Set("K6-Metrics-Protocol-Version", "2.0")
err = mc.httpClient.Do(req, nil)
if err != nil {
return err
}
return nil
}
func newRequestBody(data *pbcloud.MetricSet) ([]byte, error) {
b, err := proto.Marshal(data)
if err != nil {
return nil, fmt.Errorf("encoding metrics as Protobuf write request failed: %w", err)
}
// TODO: use the framing format
// https://github.com/google/snappy/blob/main/framing_format.txt
// It can be done replacing the encode with
// https://pkg.go.dev/github.com/klauspost/compress/snappy#NewBufferedWriter
if snappy.MaxEncodedLen(len(b)) < 0 {
return nil, fmt.Errorf("the Protobuf message is too large to be handled by Snappy encoder; "+
"size: %d, limit: %d", len(b), 0xffffffff)
}
return snappy.Encode(nil, b), nil
}
View on GitHub (pinned to 01ffac6f24)
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
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at output/cloud/expv2/metrics_client.go:96 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/21ca179e9a58eb5a.
Report an issue: GitHub.