Skip to content

fix(tracing): Use hasattr for _ctx_token #4541

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

Merged
merged 1 commit into from
Jul 1, 2025

Conversation

szokeasaurusrex
Copy link
Member

We currently use an if self._ctx_token check to determine if a span has a _ctx_token. However, this check is incorrect, since _ctx_token is only sometimes set. Furthermore, when _ctx_token is set, we should always have a _ctx_token.

Therefore, using hasattr is what we want.


Thank you for contributing to sentry-python! Please add tests to validate your changes, and lint your code using tox -e linters.

Running the test suite on your PR might require maintainer approval.

We currently use an `if self._ctx_token` check to determine if a span has a `_ctx_token`. However, this check is incorrect, since `_ctx_token` is only sometimes set. Furthermore, when `_ctx_token` is set, we should always have a `_ctx_token`.

Therefore, using `hasattr` is what we want.
@szokeasaurusrex szokeasaurusrex requested a review from a team as a code owner June 30, 2025 15:53
Copy link

codecov bot commented Jun 30, 2025

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 84.87%. Comparing base (b07438d) to head (02cef85).
Report is 2 commits behind head on potel-base.

❌ Unsupported file format

Upload processing failed due to unsupported file format. Please review the parser error message:
Error parsing JUnit XML in /home/runner/work/sentry-python/sentry-python/.junitxml at 1:1766

Caused by:
RuntimeError: Error parsing XML

Caused by:
    0: ill-formed document: close tag `</testsuite>` does not match any open tag
    1: close tag `&lt;/testsuite&gt;` does not match any open tag</code></pre>

For more help, visit our troubleshooting guide.

Files with missing lines Patch % Lines
sentry_sdk/tracing.py 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@              Coverage Diff               @@
##           potel-base    #4541      +/-   ##
==============================================
- Coverage       84.87%   84.87%   -0.01%     
==============================================
  Files             144      144              
  Lines           15005    15005              
  Branches         2374     2374              
==============================================
- Hits            12736    12735       -1     
  Misses           1541     1541              
- Partials          728      729       +1     
Files with missing lines Coverage Δ
sentry_sdk/tracing.py 80.41% <0.00%> (ø)

... and 1 file with indirect coverage changes

@szokeasaurusrex szokeasaurusrex merged commit cd422af into potel-base Jul 1, 2025
123 of 124 checks passed
@szokeasaurusrex szokeasaurusrex deleted the szokeasaurusrex/fix-span-deactivate branch July 1, 2025 08:23
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.

2 participants