|
1 | | -use std::cell::Cell; |
2 | 1 | use std::io::IsTerminal; |
3 | | -use std::time::Duration; |
4 | | -use std::time::Instant; |
5 | 2 |
|
6 | 3 | use env::otel_logs_enabled; |
7 | 4 | use env::otel_metrics_enabled; |
@@ -67,9 +64,6 @@ pub fn init(spin_version: String) -> anyhow::Result<ShutdownGuard> { |
67 | 64 | .add_directive("[{app_log_non_utf8}]=off".parse()?), |
68 | 65 | ); |
69 | 66 |
|
70 | | - // Even if metrics or tracing aren't enabled we're okay to turn on the global error handler |
71 | | - opentelemetry::global::set_error_handler(otel_error_handler)?; |
72 | | - |
73 | 67 | let otel_tracing_layer = if otel_tracing_enabled() { |
74 | 68 | Some(traces::otel_tracing_layer(spin_version.clone())?) |
75 | 69 | } else { |
@@ -100,37 +94,6 @@ pub fn init(spin_version: String) -> anyhow::Result<ShutdownGuard> { |
100 | 94 | Ok(ShutdownGuard) |
101 | 95 | } |
102 | 96 |
|
103 | | -fn otel_error_handler(err: opentelemetry::global::Error) { |
104 | | - // Track the error count |
105 | | - let signal = match err { |
106 | | - opentelemetry::global::Error::Metric(_) => "metrics", |
107 | | - opentelemetry::global::Error::Trace(_) => "traces", |
108 | | - opentelemetry::global::Error::Log(_) => "logs", |
109 | | - _ => "unknown", |
110 | | - }; |
111 | | - metrics::monotonic_counter!(spin.otel_error_count = 1, signal = signal); |
112 | | - |
113 | | - // Only log the first error at ERROR level, subsequent errors will be logged at higher levels and rate limited |
114 | | - static FIRST_OTEL_ERROR: std::sync::Once = std::sync::Once::new(); |
115 | | - FIRST_OTEL_ERROR.call_once(|| { |
116 | | - tracing::error!(?err, "OpenTelemetry error"); |
117 | | - tracing::error!("There has been an error with the OpenTelemetry system. Traces, logs or metrics are likely failing to export."); |
118 | | - tracing::error!("Further OpenTelemetry errors will be available at WARN level (rate limited) or at TRACE level."); |
119 | | - }); |
120 | | - |
121 | | - // Rate limit the logging of the OTel errors to not occur more frequently on each thread than OTEL_ERROR_INTERVAL |
122 | | - const OTEL_ERROR_INTERVAL: Duration = Duration::from_millis(5000); |
123 | | - thread_local! { |
124 | | - static LAST_OTEL_ERROR: Cell<Instant> = Cell::new(Instant::now() - OTEL_ERROR_INTERVAL); |
125 | | - } |
126 | | - if LAST_OTEL_ERROR.get().elapsed() > OTEL_ERROR_INTERVAL { |
127 | | - LAST_OTEL_ERROR.set(Instant::now()); |
128 | | - tracing::warn!(?err, "OpenTelemetry error"); |
129 | | - } else { |
130 | | - tracing::trace!(?err, "OpenTelemetry error"); |
131 | | - } |
132 | | -} |
133 | | - |
134 | 97 | /// An RAII implementation for connection to open telemetry services. |
135 | 98 | /// |
136 | 99 | /// Shutdown of the open telemetry services will happen on `Drop`. |
|
0 commit comments