Skip to content

Don't fail if there is no _context_manager_state #4698

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sentrivana
Copy link
Contributor

@sentrivana sentrivana commented Aug 13, 2025

Root cause fix to follow once we figure it out. This PR just makes the SDK not boom.

If we manage to fix the root cause before the next release, this PR is not necessary.

@sentrivana sentrivana changed the title Do not fail if there is no _context_manager_state Don't fail if there is no _context_manager_state Aug 13, 2025
@sentrivana sentrivana marked this pull request as ready for review August 13, 2025 14:24
@sentrivana sentrivana requested a review from a team as a code owner August 13, 2025 14:24

scope.profile = old_profile
scope.profile = old_profile
Copy link

Choose a reason for hiding this comment

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

Bug: Context Manager Exception Handling Flaw

The __exit__ method's capture_internal_exceptions() block is overly broad. It silently swallows exceptions from self.stop(), masking legitimate bugs. Additionally, if accessing _context_manager_state fails, the subsequent scope restoration (scope.profile = old_profile) is skipped, leaving the scope referencing a stopped profile and creating an inconsistent state.

Fix in Cursor Fix in Web

Copy link

codecov bot commented Aug 13, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.11%. Comparing base (1804955) to head (6b923fe).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4698      +/-   ##
==========================================
+ Coverage   85.07%   85.11%   +0.04%     
==========================================
  Files         156      156              
  Lines       15984    15985       +1     
  Branches     2718     2718              
==========================================
+ Hits        13598    13606       +8     
+ Misses       1600     1594       -6     
+ Partials      786      785       -1     
Files with missing lines Coverage Δ
sentry_sdk/profiler/transaction_profiler.py 87.46% <100.00%> (+1.53%) ⬆️

... and 2 files with indirect coverage changes

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.

1 participant