{"record":{"id":"4304e0f63bac59a8","repo":"grafana/k6","slug":"failed-to-initialize-the-samples-collector-w","errorCode":null,"errorMessage":"failed to initialize the samples collector: %w","messagePattern":"failed to initialize the samples collector: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"output/cloud/expv2/output.go","lineNumber":122,"sourceCode":"// SetTestRunStopCallback receives the function that\n// that stops the engine when it is called.\n// It should be called on critical errors.\nfunc (o *Output) SetTestRunStopCallback(stopFunc func(error)) {\n\to.testStopFunc = stopFunc\n}\n\n// Start starts the goroutine that would listen\n// for metric samples and send them to the cloud.\nfunc (o *Output) Start() error {\n\to.logger.Debug(\"Starting...\")\n\tdefer o.logger.Debug(\"Started!\")\n\n\tvar err error\n\to.collector, err = newCollector(\n\t\to.config.AggregationPeriod.TimeDuration(),\n\t\to.config.AggregationWaitPeriod.TimeDuration())\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to initialize the samples collector: %w\", err)\n\t}\n\n\t// The metrics client always pushes to an explicit URL. In provisioning\n\t// mode both the HTTP client and URL are injected via the setters;\n\t// otherwise we derive the legacy /v2/metrics/<testRunID> URL from the\n\t// cloud client. The two must be set together — one without the other is\n\t// a misconfiguration rather than a silent fallback.\n\tswitch {\n\tcase o.metricsHTTPClient != nil && o.metricsURL != \"\":\n\t\t// Both injected (provisioning mode); use as-is.\n\tcase o.metricsHTTPClient == nil && o.metricsURL == \"\":\n\t\to.metricsURL, err = deriveMetricsURL(o.cloudClient.BaseURL(), o.testRunID)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to derive the metrics push URL: %w\", err)\n\t\t}\n\t\to.metricsHTTPClient = o.cloudClient\n\tdefault:\n\t\treturn errors.New(\"metrics push client misconfigured: \" +","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/output/cloud/expv2/output.go#L104-L140","documentation":"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.","triggerScenarios":"Thrown at output/cloud/expv2/output.go:122 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the wrapped error for the concrete cause","Check that aggregation period configuration options are valid","Update k6 or report the issue to grafana/k6 with the full error"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}