grafana/k6 · error
providing service name is required
Error message
providing service name is required
What it means
Thrown by Config.Validate() for the OpenTelemetry output when the resolved service name is empty. OTLP metric exporters require a service.name resource attribute, so k6 refuses to start the experimental-opentelemetry output (-o experimental-opentelemetry) without one.
Source
Thrown at internal/output/opentelemetry/config.go:210
if v.Headers.Valid {
cfg.Headers = v.Headers
}
if v.HTTPUsername.Valid {
cfg.HTTPUsername = v.HTTPUsername
}
if v.HTTPPassword.Valid {
cfg.HTTPPassword = v.HTTPPassword
}
return cfg
}
// Validate validates the config
func (cfg Config) Validate() error {
if cfg.ServiceName.String == "" {
return errors.New("providing service name is required")
}
// TODO: it's not actually required, but we should probably have a default
// check if it works without it
if cfg.ServiceVersion.String == "" {
return errors.New("providing service version is required")
}
if err := cfg.validateExporterProtocol(); err != nil {
return err
}
return nil
}
func (cfg Config) validateExporterProtocol() error {
if cfg.ExporterProtocol.String != "" {
if cfg.ExporterProtocol.String != grpcExporterProtocol && cfg.ExporterProtocol.String != httpExporterProtocol {
return fmt.Errorf(
"unsupported exporter protocol %q, only %q and %q are supported",
cfg.ExporterProtocol.String,View on GitHub (pinned to 93accf6570)
Solutions
- Set K6_OTEL_SERVICE_NAME to a meaningful value, e.g. K6_OTEL_SERVICE_NAME=my-service-loadtest
- Or pass it in the output argument JSON: -o experimental-opentelemetry="serviceName=my-service"
- Audit .env/CI variable expansion to ensure the value is non-empty at runtime
Example fix
# before k6 run -o experimental-opentelemetry=grpc=http://localhost:4317 script.js # -> providing service name is required # after K6_OTEL_SERVICE_NAME=my-service k6 run -o experimental-opentelemetry=grpc=http://localhost:4317 script.js
Defensive patterns
Strategy: validation
Validate before calling
: "${K6_OTEL_SERVICE_NAME:?K6_OTEL_SERVICE_NAME must be set for the opentelemetry output}" Prevention
- Create a wrapper script that hard-requires the service name before invoking k6 with -o experimental-opentelemetry
- Keep OTel settings in one sourced env file so name/version/endpoint are always set together
- Derive service name from CI_JOB_NAME or repo name automatically
When it happens
Trigger: Running with -o experimental-opentelemetry while neither K6_OTEL_SERVICE_NAME nor a serviceName in the output JSON config is set; setting K6_OTEL_SERVICE_NAME="" (empty string) or a whitespace-only value; CI templates that export the variable conditionally and leave it blank.
Common situations: First-time OTel setup where the user wires only the exporter endpoint and forgets resource attributes; environments where the service name env var failed to expand (K6_OTEL_SERVICE_NAME= in a .env file); shared scripts reused across teams with different naming.
Related errors
- providing service version is required
- gRPC exporter endpoint is required
- HTTP exporter endpoint is required
- HTTP exporter endpoint must only be host and port, no scheme
- unsupported exporter protocol %s
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/177a9a05a007dd3f.
Report an issue: GitHub.