grafana/k6 · error

failed to initialize the samples collector: %w

Error message

failed to initialize the samples collector: %w

What it means

During Output.Start for the cloud expv2 output, newCollector failed to build the background samples collector that aggregates and forwards metric samples. The wrapped error carries the concrete construction failure; without the collector the output cannot process samples, so Start aborts.

Source

Thrown at output/cloud/expv2/output.go:122

// SetTestRunStopCallback receives the function that
// that stops the engine when it is called.
// It should be called on critical errors.
func (o *Output) SetTestRunStopCallback(stopFunc func(error)) {
	o.testStopFunc = stopFunc
}

// Start starts the goroutine that would listen
// for metric samples and send them to the cloud.
func (o *Output) Start() error {
	o.logger.Debug("Starting...")
	defer o.logger.Debug("Started!")

	var err error
	o.collector, err = newCollector(
		o.config.AggregationPeriod.TimeDuration(),
		o.config.AggregationWaitPeriod.TimeDuration())
	if err != nil {
		return fmt.Errorf("failed to initialize the samples collector: %w", err)
	}

	// The metrics client always pushes to an explicit URL. In provisioning
	// mode both the HTTP client and URL are injected via the setters;
	// otherwise we derive the legacy /v2/metrics/<testRunID> URL from the
	// cloud client. The two must be set together — one without the other is
	// a misconfiguration rather than a silent fallback.
	switch {
	case o.metricsHTTPClient != nil && o.metricsURL != "":
		// Both injected (provisioning mode); use as-is.
	case o.metricsHTTPClient == nil && o.metricsURL == "":
		o.metricsURL, err = deriveMetricsURL(o.cloudClient.BaseURL(), o.testRunID)
		if err != nil {
			return fmt.Errorf("failed to derive the metrics push URL: %w", err)
		}
		o.metricsHTTPClient = o.cloudClient
	default:
		return errors.New("metrics push client misconfigured: " +

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Inspect the wrapped error for the concrete cause
  2. Check that aggregation period configuration options are valid
  3. Update k6 or report the issue to grafana/k6 with the full error
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at output/cloud/expv2/output.go:122 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/4304e0f63bac59a8. Report an issue: GitHub.