-
Notifications
You must be signed in to change notification settings - Fork 506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Global Log handler cleanup - Logs SDK #2184
Changes from 2 commits
d7fc754
f6e5cb9
76bafef
3006c16
d63957d
96e652a
a4a812f
886a583
0d5bf14
a8d772e
c25923d
b8819c4
0bd341b
4979249
f1182ff
40f7a5c
f695605
e99195b
a566aac
8d88392
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
use super::{BatchLogProcessor, LogProcessor, LogRecord, SimpleLogProcessor, TraceContext}; | ||
use crate::{export::logs::LogExporter, runtime::RuntimeChannel, Resource}; | ||
use opentelemetry::otel_warn; | ||
use opentelemetry::{ | ||
global, | ||
logs::{LogError, LogResult}, | ||
otel_error, otel_warn, | ||
trace::TraceContextExt, | ||
Context, InstrumentationLibrary, | ||
}; | ||
|
@@ -114,9 +113,9 @@ | |
let mut errs = vec![]; | ||
for processor in &self.inner.processors { | ||
if let Err(err) = processor.shutdown() { | ||
otel_warn!( | ||
name: "logger_provider_shutdown_error", | ||
error = format!("{:?}", err) | ||
otel_error!( | ||
name: "LoggerProvider.Shutdown.Error", | ||
error = err | ||
); | ||
errs.push(err); | ||
} | ||
|
@@ -128,10 +127,13 @@ | |
Err(LogError::Other(format!("{errs:?}").into())) | ||
} | ||
} else { | ||
let error = LogError::Other("logger provider already shut down".into()); | ||
|
||
otel_warn!( | ||
name: "logger_provider_already_shutdown" | ||
name: "LoggerProvider.Shutdown.AlreadyShutdown", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this looks redundant, as returned Result already contains this information. If we need to keep this, then maybe keep it at debug/info level. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So if the error is returned as Result to the user, we decide not to log it even if this could be actionable ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not to log or log at a very low severity. Do you see any reason why this should be logged, given Result already carries this information? "Internal logging" is more for things that are otherwise hard to figure out, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer logging at a lower severity (debug?) for internal debugging. When we request logs from the customer at the debug level, they should include everything necessary for troubleshooting, even if the customer disregards the shutdown result. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is a good point! Agree with debug! here. It won't cause noise in normal operations, but when we ask users to report bug/issues, we can ask to collect all logs, including debug, so we'll have enough to investigate. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed this to debug now. |
||
error = error | ||
cijothomas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
Err(LogError::Other("logger provider already shut down".into())) | ||
Err(error) | ||
} | ||
} | ||
} | ||
|
@@ -146,7 +148,10 @@ | |
fn drop(&mut self) { | ||
for processor in &mut self.processors { | ||
if let Err(err) = processor.shutdown() { | ||
global::handle_error(err); | ||
otel_warn!( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think we should do more changes to this part - this is the automatically invoked shutdown upon drop right? I believe we should first check if user has already called shutdown, and if yes, return without any logs (maybe a debug level log?) if user has not called shutdown, then we need to call shutdown ourselves. Even here - should we log for each processor? or just log once saying shutdownfailed. The detailed failure reason should be part of the individual processor's own log. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Modified it accordingly, and add debug log for already shutdown.
The Processor::shutdown() returns the error, and we are now logging each to debug (instead of warn). |
||
name: "LoggerProvider.Drop.AlreadyShutdown", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure how we assume that the error is due to "AlreadyShutdown". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes good catch I have changed it to |
||
error = err | ||
); | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,7 +100,8 @@ | |
// noop after shutdown | ||
if self.is_shutdown.load(std::sync::atomic::Ordering::Relaxed) { | ||
otel_warn!( | ||
name: "simple_log_processor_emit_after_shutdown" | ||
name: "SimpleLogProcessor.Export.AfterShutdown", | ||
error = LogError::Other("Attempted to export a log after processor shutdown".into()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there any advantage of wrapping this into LogError? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find it useful - it adds convenience on top of std::error::Error, by declaring various error types as enum and mapping it to actual error string. We don't need to add the error string while returning the error. |
||
); | ||
return; | ||
} | ||
|
@@ -115,10 +116,9 @@ | |
}); | ||
if let Err(err) = result { | ||
otel_error!( | ||
name: "simple_log_processor_emit_error", | ||
error = format!("{:?}", err) | ||
name: "SimpleLogProcessor.Export.Error", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. its not easy to tell if this is useful or not.. The failure could be due to
I don't have a good solution in mind, so probably okay to just replace current global error handler with otel_error! for now until we can find a better alternative. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have modified it to differentiate between MutexPoisoning and Exporter failure - I think we can further extend it in future. |
||
error = err | ||
); | ||
global::handle_error(err); | ||
} | ||
} | ||
|
||
|
@@ -133,9 +133,6 @@ | |
exporter.shutdown(); | ||
Ok(()) | ||
} else { | ||
otel_error!( | ||
name: "simple_log_processor_shutdown_error" | ||
); | ||
Err(LogError::Other( | ||
"simple logprocessor mutex poison during shutdown".into(), | ||
)) | ||
|
@@ -172,8 +169,8 @@ | |
|
||
if let Err(err) = result { | ||
otel_error!( | ||
name: "batch_log_processor_emit_error", | ||
error = format!("{:?}", err) | ||
name: "BatchLogProcessor.Export.Error", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will this be triggered when channel is full? If yes, we need to rethink this, as this can spam the log output. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this error only triggers when channel is full or closed. We need to add some throttling or logic to prevent flooding - have added the TODO for now, as we need common strategy for such flooding. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree we need a common strategy, but lets remove the error log from here. It'll flood as-is when buffer is full. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we remove altogether, or make it otel_debug for now - with comment to change it to otel_error once throttling is ready. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. either of them are fine with me, though I slightly prefer removing altogether, as I don't know if we can ship a throttling solution for next release. |
||
error = err | ||
); | ||
global::handle_error(LogError::Other(err.into())); | ||
} | ||
|
@@ -243,10 +240,9 @@ | |
|
||
if let Err(err) = result { | ||
otel_error!( | ||
name: "batch_log_processor_export_error", | ||
error = format!("{:?}", err) | ||
name: "BatchLogProcessor.Export.Error", | ||
error = err | ||
); | ||
global::handle_error(err); | ||
} | ||
} | ||
} | ||
|
@@ -261,24 +257,12 @@ | |
.await; | ||
|
||
if let Some(channel) = res_channel { | ||
if let Err(result) = channel.send(result) { | ||
global::handle_error(LogError::from(format!( | ||
"failed to send flush result: {:?}", | ||
result | ||
))); | ||
if let Err(send_error) = channel.send(result) { | ||
otel_error!( | ||
name: "batch_log_processor_flush_error", | ||
error = format!("{:?}", result), | ||
message = "Failed to send flush result" | ||
name: "BatchLogProcessor.Flush.SendResultError", | ||
cijothomas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
error = format!("{:?}", send_error), | ||
); | ||
} | ||
} else if let Err(err) = result { | ||
otel_error!( | ||
name: "batch_log_processor_flush_error", | ||
error = format!("{:?}", err), | ||
message = "Flush failed" | ||
); | ||
global::handle_error(err); | ||
} | ||
} | ||
// Stream has terminated or processor is shutdown, return to finish execution. | ||
|
@@ -294,15 +278,12 @@ | |
exporter.shutdown(); | ||
|
||
if let Err(result) = ch.send(result) { | ||
otel_error!( | ||
name: "batch_log_processor_shutdown_error", | ||
error = format!("{:?}", result), | ||
message = "Failed to send shutdown result" | ||
); | ||
global::handle_error(LogError::from(format!( | ||
"failed to send batch processor shutdown result: {:?}", | ||
result | ||
))); | ||
if let Err(err) = result { | ||
otel_error!( | ||
name: "BatchLogProcessor.Shutdown.SendResultError", | ||
error = err | ||
); | ||
} | ||
} | ||
|
||
break; | ||
|
@@ -357,13 +338,7 @@ | |
pin_mut!(timeout); | ||
match future::select(export, timeout).await { | ||
Either::Left((export_res, _)) => export_res, | ||
Either::Right((_, _)) => { | ||
otel_error!( | ||
name: "export_with_timeout_timeout", | ||
timeout_duration = time_out.as_millis() | ||
); | ||
ExportResult::Err(LogError::ExportTimedOut(time_out)) | ||
} | ||
Either::Right((_, _)) => ExportResult::Err(LogError::ExportTimedOut(time_out)), | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as https://github.com/open-telemetry/opentelemetry-rust/pull/2184/files#r1793832380, this feels redundant, given Result will carry this info already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#2184 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed this to debug now.