Skip to main content

rustfs_obs/telemetry/dial9/
disabled.rs

1// Copyright 2024 RustFS Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Stub implementation used when the `dial9` feature is off.
16//!
17//! Mirrors the surface of [`super::enabled`] so that callers never need a
18//! `#[cfg]`. Building a traced runtime always fails here, which drives callers
19//! down their standard-runtime fallback path.
20
21use crate::TelemetryError;
22
23/// Placeholder for `dial9_tokio_telemetry::telemetry::TelemetryGuard`.
24///
25/// Never constructed: [`build_traced_runtime`] always fails without the
26/// `dial9` feature.
27#[derive(Debug)]
28pub struct TelemetryGuard(());
29
30/// Placeholder session guard. Never constructed without the `dial9` feature.
31#[derive(Debug)]
32pub struct Dial9SessionGuard(());
33
34impl Dial9SessionGuard {
35    /// Always false: telemetry support is not compiled in.
36    pub fn is_active(&self) -> bool {
37        false
38    }
39}
40
41/// Mirrors the `Drop` the enabled guard uses to flush and seal the trace
42/// segment, so a caller can drop the guard before `process::exit` under either
43/// feature without `clippy::drop_non_drop` firing on this variant.
44impl Drop for Dial9SessionGuard {
45    fn drop(&mut self) {}
46}
47
48/// Always fails: telemetry support is not compiled in.
49///
50/// # Errors
51///
52/// Always returns [`TelemetryError::Io`] describing the missing feature.
53pub fn build_traced_runtime(
54    _builder: tokio::runtime::Builder,
55) -> Result<(tokio::runtime::Runtime, Dial9SessionGuard), TelemetryError> {
56    Err(TelemetryError::Io(
57        "dial9 telemetry support is not compiled in; rebuild with --features dial9".to_string(),
58    ))
59}
60
61#[cfg(test)]
62mod tests {
63    use super::*;
64
65    #[test]
66    fn build_traced_runtime_always_fails_without_the_feature() {
67        let result = build_traced_runtime(tokio::runtime::Builder::new_current_thread());
68        assert!(result.is_err());
69    }
70}