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:
Douwe Osinga
2026-05-18 09:58:05 -04:00
committed by GitHub
parent cefc685d7f
commit 64edb978cd
3 changed files with 15 additions and 6 deletions
-1
View File
@@ -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();
}
+15 -4
View File
@@ -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}");
}
}
}