{"record":{"id":"86722b06887546b0","repo":"vectordotdev/vector","slug":"metrics-initialization-failed","errorCode":null,"errorMessage":"metrics initialization failed","messagePattern":"metrics initialization failed","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/cli.rs","lineNumber":335,"sourceCode":"        ])\n        .map(|(path, hint)| config::ConfigPath::File(path, hint))\n        .chain(\n            self.config_dirs\n                .iter()\n                .map(|dir| config::ConfigPath::Dir(dir.to_path_buf())),\n        )\n        .collect()\n    }\n\n    pub fn init_global(&self) {\n        if !self.openssl_no_probe {\n            // SAFETY: Initialization runs before worker threads start.\n            unsafe {\n                openssl_probe::init_openssl_env_vars();\n            }\n        }\n\n        crate::metrics::init_global().expect(\"metrics initialization failed\");\n    }\n}\n\n/// Raise the soft file descriptor limit (RLIMIT_NOFILE) as high as the OS allows.\n///\n/// Many systems default the soft limit to 1024 (Linux) or 256 (macOS), which is too low\n/// for Vector when it monitors large numbers of log files. Raising it prevents\n/// \"Too many open files (os error 24)\" errors without requiring manual sysadmin intervention.\n///\n/// On Linux, the soft limit is raised to the hard limit (typically 65536+).\n/// On macOS, the hard limit can be RLIM_INFINITY, so we first try the hard limit,\n/// then fall back to the kernel-enforced `kern.maxfilesperproc` (typically 10240).\n#[cfg(unix)]\npub(crate) fn raise_file_descriptor_limit() {\n    use nix::sys::resource::{Resource, getrlimit, setrlimit};\n    use tracing::{info, warn};\n\n    let (soft, hard) = match getrlimit(Resource::RLIMIT_NOFILE) {","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/src/cli.rs#L317-L353","documentation":"Vector panics during global metrics initialization when `crate::metrics::init_global()` returns an Err. This function registers the process-wide metrics registry very early at startup, before any component runs, so a failure here is fatal and unrecoverable. The panic message 'metrics initialization failed' comes from the `expect` call in `init_global` in src/cli.rs.","triggerScenarios":"Calling the vector CLI (which calls `init_global` early in main) when the internal metrics registry fails to construct or has already been initialized; e.g. an unsupported/invalid metrics storage backend configuration or a double-initialization attempt.","commonSituations":"Corrupt or incompatible `METRICS`-related environment configuration; running Vector embedded twice in one process (embedding Vector in another Rust binary and calling init twice); internal regression in metrics setup.","solutions":["Check that the process does not initialize global metrics more than once (relevant when embedding Vector or running tests that each init metrics)","Review recently changed metrics-related configuration/environment and revert to defaults","Run with `VECTOR_LOG=debug` to surface the underlying error returned by init_global","Update or downgrade Vector; if reproducible on a clean config, file a bug with the underlying error message"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Only relevant when embedding Vector:\n// assert metrics not already initialized\n// std::env::vars().filter(|(k,_)| k.starts_with(\"VECTOR_\")).for_each(|(k,v)| println!(\"{k}={v}\"));","typeGuard":null,"tryCatchPattern":"// In embedded Rust usage, run init on a thread that captures panics:\nlet result = std::panic::catch_unwind(vector::cli::init_global);\nmatch result {\n    Ok(_) => {},\n    Err(e) => eprintln!(\"metrics init panicked: {:?}\", e),\n}","preventionTips":["Never initialize global metrics more than once per process","Keep metrics-related env/config at defaults unless needed","Pin stable Vector versions and read upgrade notes"],"tags":["rust","metrics","startup","panic"],"backgroundTag":"module-init-failed","analyzedSha":"bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013","analyzedAt":"2026-09-16T02:53:35.741Z","contentChangedAt":"2026-09-16T02:53:35.741Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}