Skip to main content

init_if_enabled

Function init_if_enabled 

Source
pub fn init_if_enabled(enabled: bool) -> bool
Expand description

Initialises tracing if both:

  1. The crate was compiled with the otel feature, and
  2. enabled is true (typically driven by the --trace CLI flag).

On (true, true): installs a tracing-subscriber global dispatcher with JSON formatting to stdout, level filter from RUST_LOG (default info).

In any other case: returns immediately, no global state mutated.

§Returns

true if a subscriber was installed; false otherwise.

§Examples

use ssg::otel::init_if_enabled;

// Disabled ⇒ always returns false, never installs a subscriber.
assert!(!init_if_enabled(false));