{"record":{"id":"60bdf463dfa6c45a","repo":"block/buzz","slug":"buzz-relay-private-key-must-be-set-run-just-boot","errorCode":null,"errorMessage":"BUZZ_RELAY_PRIVATE_KEY must be set. Run `just bootstrap` for local development or configure a stable 32-byte hex private key.","messagePattern":"BUZZ_RELAY_PRIVATE_KEY must be set\\. Run `just bootstrap` for local development or configure a stable 32-byte hex private key\\.","errorType":"console","errorClass":"anyhow::Error","httpStatus":null,"severity":"critical","filePath":"crates/buzz-relay/src/main.rs","lineNumber":52,"sourceCode":"        )\n    })\n}\n\nasync fn connect_audit_pool(config: &DbConfig) -> anyhow::Result<sqlx::PgPool> {\n    let audit_config = DbConfig {\n        read_database_url: None,\n        max_connections: 5,\n        min_connections: 1,\n        ..config.clone()\n    };\n    Db::connect_writer_pool(&audit_config)\n        .await\n        .map_err(Into::into)\n}\n\nfn relay_keypair_from_config(relay_private_key: Option<&str>) -> anyhow::Result<nostr::Keys> {\n    let hex = relay_private_key.ok_or_else(|| {\n        anyhow::anyhow!(\n            \"BUZZ_RELAY_PRIVATE_KEY must be set. Run `just bootstrap` for local \\\n             development or configure a stable 32-byte hex private key.\"\n        )\n    })?;\n    nostr::Keys::parse(hex).map_err(|e| anyhow::anyhow!(\"invalid BUZZ_RELAY_PRIVATE_KEY: {e}\"))\n}\n\n/// Controls how many per-community gauge series the usage poller emits.\n///\n/// Datadog cost is proportional to the number of unique time-series.  With ~25\n/// gauge label combinations per community, a relay hosting thousands of\n/// communities would incur five-figure monthly costs if every community always\n/// gets a full set of series.  This knob is the cost lever.\n///\n/// Fleet-wide totals (`buzz_total_*`) always emit regardless of mode.\n///\n/// Set via `BUZZ_USAGE_METRICS_PER_COMMUNITY`:\n///   - `all` — emit per-community series for every community (default)","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/block/buzz/blob/dad5a33865fc81a2e55b3b60746632f615ec1e3a/crates/buzz-relay/src/main.rs#L34-L70","documentation":"relay_keypair_from_config requires the relay's stable identity key from the BUZZ_RELAY_PRIVATE_KEY environment variable. This error is raised at relay startup when the variable is unset (None). The relay identity must be stable across restarts so events it signs (snapshots, ref states) remain attributable, so it refuses to generate an ephemeral key.","triggerScenarios":"Starting the relay without sourcing .env (skipping `. ./.env` or the just recipe), running the binary outside the dev environment, or a config loader failing to read .env; also hit directly in tests configured_relay_identity_is_preserved / missing_relay_identity_is_rejected.","commonSituations":"Fresh clone where .env was never copied from .env.example (`just bootstrap` skipped); CI job or systemd unit missing the env var; running `cargo run -p buzz-relay` from a shell where .env wasn't sourced.","solutions":["Run `just bootstrap` to generate .env with a stable BUZZ_RELAY_PRIVATE_KEY for local development.","Copy .env.example to .env and set BUZZ_RELAY_PRIVATE_KEY to a valid 64-char hex 32-byte key, then restart the relay.","In CI/production, inject BUZZ_RELAY_PRIVATE_KEY into the environment (never commit the key).","After fixing, confirm with the companion error 'invalid BUZZ_RELAY_PRIVATE_KEY' not appearing — the key must also parse."],"exampleFix":"// before: shell without env\ncargo run -p buzz-relay   // ERROR: BUZZ_RELAY_PRIVATE_KEY must be set\n// after\n. ./bin/activate-hermit && cp .env.example .env && just bootstrap && just relay","handlingStrategy":"validation","validationCode":"if std::env::var(\"BUZZ_RELAY_PRIVATE_KEY\").is_err() {\n    eprintln!(\"BUZZ_RELAY_PRIVATE_KEY not set — run `just bootstrap`\");\n    std::process::exit(1);\n}","typeGuard":null,"tryCatchPattern":"let keys = relay_keypair_from_config(config.relay_private_key.as_deref())\n    .context(\"relay identity missing; refusing to start with ephemeral key\")?;","preventionTips":["Always `cp .env.example .env` and run `just bootstrap` before `just relay`.","In CI/systemd, assert the env var exists before launching the relay.","Never rely on shell state — have the app load .env explicitly at startup."],"tags":["configuration","environment","startup","missing-env-var"],"backgroundTag":"missing-env-var","analyzedSha":"dad5a33865fc81a2e55b3b60746632f615ec1e3a","analyzedAt":"2026-09-05T18:13:50.666Z","contentChangedAt":"2026-09-05T18:13:50.666Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}