grafana/k6 · error
failed to parse headers: %w
Error message
failed to parse headers: %w
What it means
The OpenTelemetry output was configured with custom headers (K6_OTEL_HEADERS), and the header list could not be parsed into key=value pairs. getExporter wraps the parseHeaders failure while constructing the metric exporter.
Source
Thrown at internal/output/opentelemetry/exporter.go:38
// ctx isn't used at any point in the exporter
// later on, it could be used for the connection timeout
ctx := context.Background()
tlsConfig, err := buildTLSConfig(
cfg.TLSInsecureSkipVerify,
cfg.TLSCertificate,
cfg.TLSClientCertificate,
cfg.TLSClientKey,
)
if err != nil {
return nil, err
}
headers := make(map[string]string)
if cfg.Headers.Valid {
headers, err = parseHeaders(cfg.Headers.String)
if err != nil {
return nil, fmt.Errorf("failed to parse headers: %w", err)
}
}
// if at least valid user was configured, use basic auth
if cfg.HTTPUsername.Valid {
auth := []byte(cfg.HTTPUsername.String + ":" + cfg.HTTPPassword.String)
headers["Authorization"] = fmt.Sprintf("Basic %s", base64.StdEncoding.EncodeToString(auth))
}
switch cfg.ExporterProtocol.String {
case grpcExporterProtocol:
return buildGRPCExporter(ctx, cfg, tlsConfig, headers)
case httpExporterProtocol:
return buildHTTPExporter(ctx, cfg, tlsConfig, headers)
default:
return nil, errors.New("unsupported exporter protocol " + cfg.ExporterProtocol.String)
}
}View on GitHub (pinned to 01ffac6f24)
Solutions
- Format headers as comma-separated key=value pairs, e.g. K6_OTEL_HEADERS=key1=value1,key2=value2
- Use percent-encoding for special characters in keys or values
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at internal/output/opentelemetry/exporter.go:38 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/1302ab67fc384ef6.
Report an issue: GitHub.