diff --git a/bin/reth/src/builder.rs b/bin/reth/src/builder.rs index 3ea5f242d654..cc87d1caec15 100644 --- a/bin/reth/src/builder.rs +++ b/bin/reth/src/builder.rs @@ -77,8 +77,13 @@ pub async fn launch_from_config( ) -> eyre::Result { info!(target: "reth::cli", "reth {} starting", SHORT_VERSION); + // Register the prometheus recorder before creating the database, + // because database init needs it to register metrics. + config.install_prometheus_recorder()?; + let database = std::mem::take(&mut config.database); let db_instance = database.init_db(config.db.log_level, config.chain.chain)?; + info!(target: "reth::cli", "Database opened"); match db_instance { DatabaseInstance::Real { db, data_dir } => { @@ -121,7 +126,6 @@ impl NodeBuilderWit let config = self.load_config()?; let prometheus_handle = self.config.install_prometheus_recorder()?; - info!(target: "reth::cli", "Database opened"); let mut provider_factory = ProviderFactory::new(Arc::clone(&self.db), Arc::clone(&self.config.chain)); diff --git a/crates/storage/db/src/metrics.rs b/crates/storage/db/src/metrics.rs index 4e3939ef2205..eef7d40ed525 100644 --- a/crates/storage/db/src/metrics.rs +++ b/crates/storage/db/src/metrics.rs @@ -14,6 +14,9 @@ const LARGE_VALUE_THRESHOLD_BYTES: usize = 4096; /// Caches metric handles for database environment to make sure handles are not re-created /// on every operation. +/// +/// Requires a metric recorder to be registered before creating an instance of this struct. +/// Otherwise, metric recording will no-op. #[derive(Debug)] pub struct DatabaseEnvMetrics { /// Caches OperationMetrics handles for each table and operation tuple.