Skip to content

fix: finish shutdown after a provider error - #158

Open
bruno-espino wants to merge 3 commits into
pydantic:mainfrom
bruno-espino:codex/shutdown-provider-error
Open

bruno-espino wants to merge 3 commits into
pydantic:mainfrom
bruno-espino:codex/shutdown-provider-error

Conversation

@bruno-espino

@bruno-espino bruno-espino commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Logfire::shutdown() returns on the first provider error. This skips the remaining providers and the background runtime shutdown signal. Attempt all provider shutdowns and send the runtime signal before returning the first error.

Exercise explicit guard shutdown and guard drop after a trace provider error.
Check the metric export, log export and runtime shutdown signal.
`Logfire::shutdown()` returns on the first provider error. This skips the remaining providers and the background runtime shutdown signal. Attempt all provider shutdowns and send the runtime signal before returning the first error.

The explicit shutdown and guard drop regressions fail before the fix and pass after it. Each checks a counter, a log and the runtime signal. Workspace tests, Clippy and repository hooks pass.

This change does not add a shutdown deadline or handle provider panics.
@codecov-commenter

codecov-commenter commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Comment thread logfire/src/logfire.rs Outdated
}

#[cfg(test)]
mod shutdown_failure_regression {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really know we need this change tested to such a degree. Let's omit the tests but leave the main change

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed them

Comment thread logfire/src/logfire.rs
Comment on lines +175 to 179
for result in results {
result?;
}

Ok(())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should change ShutdownError to be

struct ShutdownError {
    tracing: Optional<OTelSdkError>,
    metrics: Optional<OTelSdkError>,
    logging: Optional<OTelSdkError>,
}

so that we can capture all the errors, if multiple failed. Or we could just have a Vec<OTelSdkError> and not distinguish from which source the error came.

@cetra3 would be interested in your opinion whether we need to bother capturing all of the errors.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to add the variant here if you and @cetra3 want it, otherwise it can be a follow up

Comment thread logfire/src/logfire.rs
if let Ok(mut sender_guard) = self.0.shutdown_sender.lock()
&& let Some(sender) = sender_guard.take()
{
let _ = sender.send(());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In principle the background runtime thread could fail to shutdown, I wonder whether we want to try to wait for that shutdown and capture any shutdown error.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants