grafana/k6 · error

K6_CLOUD_LOGS_PUSH_URL requires K6_CLOUD_TEST_RUN_TOKEN

Error message

K6_CLOUD_LOGS_PUSH_URL requires K6_CLOUD_TEST_RUN_TOKEN

What it means

In applyExternalProvisioningCreds (internal/cmd/outputs_cloud.go:231), a configured logs push URL (conf.LogsPushURL, sourced from K6_CLOUD_LOGS_PUSH_URL) is authenticated with the same scoped token as metrics. If the token is empty, k6 refuses to start rather than silently streaming nothing to an endpoint that will reject it.

Solutions

  1. Export K6_CLOUD_TEST_RUN_TOKEN alongside K6_CLOUD_LOGS_PUSH_URL (and typically K6_CLOUD_METRICS_PUSH_URL, since URL and token must pair per error 44).
  2. If you did not intend log shipping, unset K6_CLOUD_LOGS_PUSH_URL / remove logsPushURL from the cloud config.

Example fix

# before
export K6_CLOUD_LOGS_PUSH_URL="https://ingest.../logs"
k6 run -o cloud script.js
# after
export K6_CLOUD_LOGS_PUSH_URL="https://ingest.../logs"
export K6_CLOUD_METRICS_PUSH_URL="https://ingest.../metrics"
export K6_CLOUD_TEST_RUN_TOKEN="<token>"
k6 run -o cloud script.js
Defensive patterns

Strategy: validation

Validate before calling

# logs push URL implies token
[ -n "$K6_CLOUD_LOGS_PUSH_URL" ] && [ -z "$K6_CLOUD_TEST_RUN_TOKEN" ] && { echo 'K6_CLOUD_LOGS_PUSH_URL requires K6_CLOUD_TEST_RUN_TOKEN'; exit 1; }

Prevention

When it happens

Trigger: Setting K6_CLOUD_LOGS_PUSH_URL (or a LogsPushURL via config) without K6_CLOUD_TEST_RUN_TOKEN; commonly when enabling cloud log shipping in env-only provisioning setups.

Common situations: Enabling the logs-push feature flag/URL in CI but keeping the token in a different, unexported secret store; docs walkthroughs that show the URL variable but omit token provisioning.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at internal/cmd/outputs_cloud.go:231

func applyExternalProvisioningCreds(
	gs *state.GlobalState, test *loadedAndConfiguredTest, conf *cloudapi.Config,
) error {
	// The log-push config is env-supplied for an external run and likewise not
	// env-bound on the Config, so read it explicitly here (before the checks
	// below, which require the token when a logs URL is set).
	if err := applyExternalLogsConfig(gs, conf); err != nil {
		return err
	}
	pushURL := gs.Env["K6_CLOUD_METRICS_PUSH_URL"]
	token := gs.Env["K6_CLOUD_TEST_RUN_TOKEN"]
	if (pushURL == "") != (token == "") {
		return errors.New("both K6_CLOUD_METRICS_PUSH_URL and " +
			"K6_CLOUD_TEST_RUN_TOKEN must be set together")
	}
	// A logs push URL is authenticated with the same scoped token, so reject a
	// logs URL supplied without it rather than silently streaming nothing.
	if token == "" && conf.LogsPushURL.Valid && conf.LogsPushURL.String != "" {
		return errors.New("K6_CLOUD_LOGS_PUSH_URL requires K6_CLOUD_TEST_RUN_TOKEN")
	}
	if pushURL == "" {
		return nil
	}

	conf.MetricsPushURL = null.StringFrom(pushURL)
	conf.TestRunToken = null.StringFrom(token)
	raw, err := cloudConfToRawMessage(*conf)
	if err != nil {
		return fmt.Errorf("could not serialize cloud configuration: %w", err)
	}
	if test.derivedConfig.Collectors == nil {
		test.derivedConfig.Collectors = make(map[string]json.RawMessage)
	}
	test.derivedConfig.Collectors[builtinOutputCloud.String()] = raw
	return nil
}

View on GitHub (pinned to 01ffac6f24)