grafana/k6 · error

providing service name is required

Error message

providing service name is required

What it means

The OpenTelemetry metrics output requires a service name for the exported resource. k6 ships a default ('k6'), but Validate() rejects the config when ServiceName.String is empty — which in practice happens when K6_OTEL_SERVICE_NAME or the JSON output config overrides the default with an empty string (empty env vars still count as Valid overrides).

Solutions

  1. Set a real value, e.g. export K6_OTEL_SERVICE_NAME=my-service
  2. Remove the empty K6_OTEL_SERVICE_NAME from the environment so the 'k6' default applies
  3. Guard CI templates to skip exporting the variable when its value is empty

Example fix

# before
export K6_OTEL_SERVICE_NAME=    # accidentally empty
k6 run -o opentelemetry script.js
# after
export K6_OTEL_SERVICE_NAME=checkout-api
k6 run -o opentelemetry script.js
Defensive patterns

Strategy: validation

Validate before calling

// Shell: treat empty as unset
: "${K6_OTEL_SERVICE_NAME:=k6}"
export K6_OTEL_SERVICE_NAME
k6 run -o opentelemetry script.js

Prevention

When it happens

Trigger: export K6_OTEL_SERVICE_NAME= (defined but empty, common in CI matrices); an output config JSON with "serviceName": "".

Common situations: CI systems that predefine placeholder variables as empty strings; parameterized pipelines where the service-name variable is populated per-job and this job missed it.

Related errors


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/177a9a05a007dd3f. Report an issue: GitHub.

Appendix: 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 01ffac6f24)