Skip to main content

rustfs_obs/
error.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
15use crate::OtelGuard;
16use std::sync::{Arc, Mutex};
17use tokio::sync::SetError;
18
19/// Error type for global guard operations
20#[derive(Debug, thiserror::Error)]
21pub enum GlobalError {
22    /// Occurs when attempting to set a global recorder (e.g., via [`crate::Recorder::install_global`] or [`metrics::set_global_recorder`])
23    /// but a global recorder is already initialized.
24    ///
25    /// [`crate::Recorder::install_global`]: crate::Recorder::install_global
26    /// [`metrics::set_global_recorder`]: https://docs.rs/metrics/latest/metrics/fn.set_global_recorder.html
27    #[error("Failed to set a global recorder: {0}")]
28    SetRecorder(#[from] metrics::SetRecorderError<crate::Recorder>),
29    #[error("Failed to set global guard: {0}")]
30    SetError(#[from] SetError<Arc<Mutex<Option<OtelGuard>>>>),
31    #[error("Global guard not initialized")]
32    NotInitialized,
33    #[error("Global guard lock poisoned: {0}")]
34    GuardPoisoned(&'static str),
35    #[error("Global system metrics err: {0}")]
36    MetricsError(String),
37    #[error("Failed to get current PID: {0}")]
38    PidError(String),
39    #[error("Process with PID {0} not found")]
40    ProcessNotFound(u32),
41    #[error("Failed to get physical core count")]
42    CoreCountError,
43    #[error("GPU initialization failed: {0}")]
44    GpuInitError(String),
45    #[error("GPU device not found: {0}")]
46    GpuDeviceError(String),
47    #[error("Failed to send log: {0}")]
48    SendFailed(&'static str),
49    #[error("Operation timed out: {0}")]
50    Timeout(&'static str),
51    #[error("Telemetry initialization failed: {0}")]
52    TelemetryError(#[from] TelemetryError),
53}
54
55#[derive(Debug, thiserror::Error)]
56pub enum TelemetryError {
57    #[error("Span exporter build failed: {0}")]
58    BuildSpanExporter(String),
59    #[error("Metric exporter build failed: {0}")]
60    BuildMetricExporter(String),
61    #[error("Log exporter build failed: {0}")]
62    BuildLogExporter(String),
63    #[error("RUSTFS_OBS_TLS_CA_FILE must be an absolute path")]
64    OtlpTlsCaPathNotAbsolute,
65    #[error("Failed to read RUSTFS_OBS_TLS_CA_FILE")]
66    OtlpTlsCaRead(#[source] std::io::Error),
67    #[error("RUSTFS_OBS_TLS_CA_FILE does not contain a PEM certificate")]
68    OtlpTlsCaEmpty,
69    #[error("RUSTFS_OBS_TLS_CA_FILE does not contain a valid PEM certificate")]
70    OtlpTlsCaInvalid,
71    #[error("Failed to parse RUSTFS_OBS_TLS_CA_FILE as a PEM certificate bundle")]
72    OtlpTlsCaParse(#[source] reqwest::Error),
73    #[error("Failed to build OTLP HTTP client")]
74    BuildOtlpHttpClient(#[source] reqwest::Error),
75    #[error("Install metrics recorder failed: {0}")]
76    InstallMetricsRecorder(String),
77    #[error("Tracing subscriber init failed: {0}")]
78    SubscriberInit(String),
79    #[error("I/O error: {0}")]
80    Io(String),
81    #[error("Set permissions failed: {0}")]
82    SetPermissions(String),
83    #[error("Log sink conflict: {0}")]
84    LogSinkConflict(String),
85}
86
87impl From<std::io::Error> for TelemetryError {
88    fn from(e: std::io::Error) -> Self {
89        TelemetryError::Io(e.to_string())
90    }
91}