fix: handle BaseException in trace spans to prevent span leaks on Key…#2068
Open
Di-Is wants to merge 1 commit intostrands-agents:mainfrom
Open
fix: handle BaseException in trace spans to prevent span leaks on Key…#2068Di-Is wants to merge 1 commit intostrands-agents:mainfrom
Di-Is wants to merge 1 commit intostrands-agents:mainfrom
Conversation
…boardInterrupt Trace spans were not properly closed when BaseException (e.g. KeyboardInterrupt, asyncio.CancelledError) was raised. Add explicit BaseException handlers to close spans and aclose() calls to ensure async generators are cleaned up.
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
PR #2032 switched spans from
end_on_exit=Trueto explicitspan.end()calls, fixing span timing. However, the existingexcept Exceptionhandlers don't catchBaseExceptionsubclasses likeKeyboardInterruptandasyncio.CancelledError, so spans leak when these occur.This PR ensures spans are properly closed on all exit paths, including
BaseExceptioninterruptions and premature async generator teardown.Follow-up to #2032 (which resolved #1930), split from #1939 per reviewer request.
Public API Changes
No public API changes. Internal tracer method signatures are widened from
ExceptiontoBaseException(backward-compatible).Related Issues
Documentation PR
N/A
Type of Change
Bug fix
Testing
hatch run prepareChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.