Initialize the telemetry setup in the current scope. # Errors - [`InitTracingError`], if initializing the [`tracing_subscriber::Registry`] fails.
(self)
| 193 | /// |
| 194 | /// - [`InitTracingError`], if initializing the [`tracing_subscriber::Registry`] fails. |
| 195 | pub fn init(self) -> Result<impl Drop, Report<InitTracingError>> { |
| 196 | #[expect(unused)] |
| 197 | struct DropGuard<T>(T, DefaultGuard); |
| 198 | |
| 199 | #[expect(clippy::empty_drop)] |
| 200 | impl<T> Drop for DropGuard<T> { |
| 201 | fn drop(&mut self) {} |
| 202 | } |
| 203 | |
| 204 | let (registry, telemetry_guard) = self.build()?; |
| 205 | let default_guard = tracing::dispatcher::set_default(®istry.into()); |
| 206 | |
| 207 | // We have to wait until logging is initialized before we can print the warning. |
| 208 | if std::env::var("RUST_LOG").is_ok() { |
| 209 | if std::env::var("HASH_GRAPH_LOG_LEVEL").is_ok() { |
| 210 | warn!( |
| 211 | "`HASH_GRAPH_LOG_LEVEL` and `RUST_LOG` are set, `HASH_GRAPH_LOG_LEVEL` has \ |
| 212 | been used to determine the logging level." |
| 213 | ); |
| 214 | } else { |
| 215 | warn!("`RUST_LOG` is set, please use `HASH_GRAPH_LOG_LEVEL` instead"); |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | Ok(DropGuard(telemetry_guard, default_guard)) |
| 220 | } |
| 221 | |
| 222 | /// Initialize the telemetry setup. |
| 223 | /// |
no test coverage detected