grafana/k6 · error

invalid URL scheme

Error message

invalid URL scheme

What it means

When a URL is given in the traces output line (otel=<url>), params.parseURL requires an explicit http:// or https:// scheme; the scheme also selects the http transport and insecure mode. url.Parse of a bare host:port/path yields an empty scheme, which triggers ErrInvalidURLScheme. The error message includes the offending scheme.

Solutions

  1. Prefix the URL with http:// or https://, e.g. otel=http://127.0.0.1:4318/v1/traces
  2. Use https:// when the collector is TLS-secured (insecure is then false)
  3. For a plain grpc endpoint without a path, omit the URL and use defaults or proto=grpc

Example fix

# before
k6 run --traces-output='otel=127.0.0.1:4318/v1/traces,proto=http' script.js
# after
k6 run --traces-output='otel=http://127.0.0.1:4318/v1/traces,proto=http' script.js
Defensive patterns

Strategy: validation

Validate before calling

// Shell: require an explicit scheme in the URL part
url_part="$(echo "$TRACES_OUTPUT" | sed -n 's/^otel=\([^,]*\).*/\1/p')"
case "$url_part" in
  http://*|https://*) ;;
  "") ;;
  *) echo "traces URL must start with http:// or https://" >&2; exit 1 ;;
esac

Type guard

function hasHttpScheme(u) {
  return /^https?:\/\//.test(u);
}

Prevention

When it happens

Trigger: --traces-output=otel=127.0.0.1:4318/v1/traces (no scheme, so u.Scheme is ''); non-http(s) schemes like otel=grpc://collector:4317 or otel=unix:///tmp/sock.

Common situations: Writing the endpoint the way OTel collector configs or grpc targets look (host:port without scheme); assuming the scheme is optional as it is in some other tools.

Related errors


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

Appendix: source

Thrown at internal/lib/trace/otel.go:31

	"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp"
	"go.opentelemetry.io/otel/sdk/resource"
	sdktrace "go.opentelemetry.io/otel/sdk/trace"
	semconv "go.opentelemetry.io/otel/semconv/v1.20.0"
	"go.opentelemetry.io/otel/trace"
	"go.opentelemetry.io/otel/trace/noop"

	"go.k6.io/k6/v2/internal/lib/strvals"
)

const serviceName = "k6"

var (
	// ErrInvalidTracesOutput indicates that the defined traces output is not valid.
	ErrInvalidTracesOutput = errors.New("invalid traces output")
	// ErrInvalidProto indicates that the defined exporter protocol is not valid.
	ErrInvalidProto = errors.New("invalid protocol")
	// ErrInvalidURLScheme indicates that the defined exporter URL scheme is not valid.
	ErrInvalidURLScheme = errors.New("invalid URL scheme")
	// ErrInvalidGRPCWithURLPath indicates that an exporter using gRPC protocol does not support URL path.
	ErrInvalidGRPCWithURLPath = errors.New("grpc protocol does not support URL path")
)

type (
	tracerProvShutdownFunc func(ctx context.Context) error
)

// TracerProvider provides methods for tracers initialization and shutdown of the
// processing pipeline.
type TracerProvider struct {
	trace.TracerProvider
	shutdown tracerProvShutdownFunc
}

type tracerProviderParams struct {
	proto    string
	endpoint string

View on GitHub (pinned to 01ffac6f24)