a2a_protocol_server/otel/telemetry/
error.rs1#[derive(Debug)]
8#[non_exhaustive]
9pub enum TelemetryError {
10 Config {
12 variable: String,
14 value: String,
16 reason: String,
18 },
19 Exporter {
21 signal: &'static str,
23 source: opentelemetry_otlp::ExporterBuildError,
25 },
26 Tls(String),
28 Runtime(std::io::Error),
30 Export(Vec<String>),
32}
33
34impl TelemetryError {
35 pub(super) fn config(variable: &str, value: &str, reason: impl Into<String>) -> Self {
36 Self::Config {
37 variable: variable.to_owned(),
38 value: value.to_owned(),
39 reason: reason.into(),
40 }
41 }
42}
43
44impl std::fmt::Display for TelemetryError {
45 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46 match self {
47 Self::Config {
48 variable,
49 value,
50 reason,
51 } if value.is_empty() => {
52 write!(f, "{variable}: {reason}")
53 }
54 Self::Config {
55 variable,
56 value,
57 reason,
58 } => write!(f, "{variable}={value:?}: {reason}"),
59 Self::Exporter { signal, source } => write!(f, "{signal} exporter: {source}"),
60 Self::Tls(reason) => write!(f, "OTLP TLS: {reason}"),
61 Self::Runtime(e) => write!(f, "OTLP export thread: {e}"),
62 Self::Export(failed) => write!(f, "OTLP export failed: {}", failed.join("; ")),
63 }
64 }
65}
66
67impl std::error::Error for TelemetryError {
68 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
69 match self {
70 Self::Exporter { source, .. } => Some(source),
71 Self::Runtime(e) => Some(e),
72 _ => None,
73 }
74 }
75}