mirror of
https://github.com/aaif-goose/goose.git
synced 2026-07-03 14:10:03 +02:00
Flush OTLP traces reliably on exit with configurable timeout (#9228)
Signed-off-by: Douwe Osinga <douwe@squareup.com> Co-authored-by: Douwe Osinga <douwe@squareup.com>
This commit is contained in:
@@ -23,7 +23,6 @@ async fn run() -> Result<()> {
|
||||
|
||||
#[cfg(feature = "otel")]
|
||||
if goose::otel::otlp::is_otlp_initialized() {
|
||||
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
|
||||
goose::otel::otlp::shutdown_otlp();
|
||||
}
|
||||
|
||||
|
||||
@@ -158,7 +158,6 @@ pub async fn run() -> Result<()> {
|
||||
|
||||
#[cfg(feature = "otel")]
|
||||
if goose::otel::otlp::is_otlp_initialized() {
|
||||
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
|
||||
goose::otel::otlp::shutdown_otlp();
|
||||
}
|
||||
|
||||
|
||||
@@ -359,28 +359,39 @@ fn create_otlp_logs_filter() -> FilterFn<impl Fn(&Metadata<'_>) -> bool> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Shutdown OTLP providers gracefully
|
||||
pub fn shutdown_otlp() {
|
||||
let timeout = std::time::Duration::from_millis(
|
||||
crate::config::Config::global()
|
||||
.get_param::<u64>("otel_shutdown_timeout_ms")
|
||||
.unwrap_or(5000),
|
||||
);
|
||||
|
||||
if let Some(provider) = TRACER_PROVIDER
|
||||
.lock()
|
||||
.unwrap_or_else(|e| e.into_inner())
|
||||
.take()
|
||||
{
|
||||
let _ = provider.shutdown();
|
||||
if let Err(e) = provider.shutdown_with_timeout(timeout) {
|
||||
tracing::warn!("OTLP tracer provider shutdown error: {e}");
|
||||
}
|
||||
}
|
||||
if let Some(provider) = METER_PROVIDER
|
||||
.lock()
|
||||
.unwrap_or_else(|e| e.into_inner())
|
||||
.take()
|
||||
{
|
||||
let _ = provider.shutdown();
|
||||
if let Err(e) = provider.shutdown_with_timeout(timeout) {
|
||||
tracing::warn!("OTLP meter provider shutdown error: {e}");
|
||||
}
|
||||
}
|
||||
if let Some(provider) = LOGGER_PROVIDER
|
||||
.lock()
|
||||
.unwrap_or_else(|e| e.into_inner())
|
||||
.take()
|
||||
{
|
||||
let _ = provider.shutdown();
|
||||
if let Err(e) = provider.shutdown_with_timeout(timeout) {
|
||||
tracing::warn!("OTLP logger provider shutdown error: {e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user