Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Source Tracking

English | 中文 | 日本語 | 한국어 | Français | Deutsch | Español | Português | Svenska | Suomi | Nederlands

Use load_config_with_figment to keep the Figment graph used by runtime loading:

#![allow(unused)]
fn main() {
use rust_config_tree::load_config_with_figment;

let (config, figment) = load_config_with_figment::<AppConfig>("config.yaml")?;
let _ = config;
Ok::<(), Box<dyn std::error::Error + Send + Sync>>(())
}

The returned Figment value can answer source questions for runtime values:

#![allow(unused)]
fn main() {
if let Some(metadata) = figment.find_metadata("database.pool_size") {
    let source = metadata.interpolate(
        &figment::Profile::Default,
        &["database", "pool_size"],
    );

    println!("database.pool_size came from {source}");
}
}

For values supplied by ConfiqueEnvProvider, interpolation returns the native environment variable name declared in the schema:

database.pool_size came from APP_DATABASE_POOL_SIZE

TRACE Events

The loader emits source tracking events with tracing::trace!. It does this only when TRACE is enabled:

#![allow(unused)]
fn main() {
use rust_config_tree::{load_config_with_figment, trace_config_sources};

let (config, figment) = load_config_with_figment::<AppConfig>("config.yaml")?;

// If the tracing subscriber is initialized after config loading, emit the
// same source events again after installing the subscriber.
trace_config_sources::<AppConfig>(&figment);
let _ = config;
Ok::<(), Box<dyn std::error::Error + Send + Sync>>(())
}

Each event uses the rust_config_tree::config target and includes:

  • config_key: the dotted config key.
  • source: the rendered source metadata.

Values that came only from confique defaults do not have Figment runtime metadata. They are reported as confique default or unset optional field.