Skip to content

Support Python SDK 3.0.0#92011

Merged
sl0thentr0py merged 99 commits intomasterfrom
antonpirker/code-changes-for-sdk-3.0.0
Jul 2, 2025
Merged

Support Python SDK 3.0.0#92011
sl0thentr0py merged 99 commits intomasterfrom
antonpirker/code-changes-for-sdk-3.0.0

Conversation

@antonpirker
Copy link
Contributor

@antonpirker antonpirker commented May 21, 2025

Update the codebase so it works with Sentry Python SDK 3.0.0 alpha.

Sentry SDK 3.0.0 has some backwards incompatibilities and uses Opentelementry under the hood to create spans.

What this PR does:

  • replace sentry_sdk.start_transaction() with sentry_sdk.start_span()
  • replace span.set_data() with span.set_attribute()
  • replace scope.transaction with scope.root_span
  • replace Span.containing_transaction with Span.root_span
  • replace custom_sampling_context with attributes parameter
  • replace sentry_sdk.scope.get_*_scope() with sentry_sdk.get_*_scope()
  • replace one scope.add_attachment() with sentry_sdk.add_attachment()
  • change one continue_trace() to the new context manager.
  • update traces_sampler to use new sampling_context format
  • added a few tests

See also the migration guide:
https://docs.sentry.io/platforms/python/migration/2.x-to-3.x


Related, but split out into separate PRs:

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label May 21, 2025
@codecov
Copy link

codecov bot commented May 21, 2025

Codecov Report

Attention: Patch coverage is 92.55319% with 14 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/stacktraces/processing.py 0.00% 5 Missing ⚠️
src/sentry/replays/usecases/ingest/__init__.py 0.00% 2 Missing ⚠️
src/sentry/tempest/tasks.py 0.00% 2 Missing ⚠️
src/sentry/api/base.py 0.00% 1 Missing ⚠️
src/sentry/cache/base.py 0.00% 1 Missing ⚠️
src/sentry/processing/backpressure/monitor.py 0.00% 1 Missing ⚠️
src/sentry/scim/endpoints/utils.py 66.66% 1 Missing ⚠️
src/sentry/utils/snuba.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #92011      +/-   ##
==========================================
+ Coverage   84.22%   88.00%   +3.78%     
==========================================
  Files       10441    10439       -2     
  Lines      603621   603584      -37     
  Branches    23491    23444      -47     
==========================================
+ Hits       508384   531177   +22793     
+ Misses      94871    71901   -22970     
- Partials      366      506     +140     

pytest-metadata==3.1.1
pytest-rerunfailures==15.0
pytest-sentry==0.3.0
pytest-sentry==0.5.0
Copy link
Contributor

Choose a reason for hiding this comment

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

did you end up fixing the leaky sdk bits in pytest-sentry that were causing the code under test to report to the tests project?

Copy link
Contributor Author

@antonpirker antonpirker Jun 26, 2025

Choose a reason for hiding this comment

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

was sidetracked by ai agents stuff, so this is still on my list.

@antonpirker
Copy link
Contributor Author

@asottile-sentry do you know if those errors I get ( django.db.utils.OperationalError: ObjectInUse('database "test_region" is being accessed by other users\nDETAIL: There are 12 other sessions using the database.\n') are flakes?

@asottile-sentry
Copy link
Contributor

@asottile-sentry do you know if those errors I get ( django.db.utils.OperationalError: ObjectInUse('database "test_region" is being accessed by other users\nDETAIL: There are 12 other sessions using the database.\n') are flakes?

this means some background thread started a database connection in some test (it's pretty hard to actually narrow down). it's likely caused by this PR unfortunately :(

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@untitaker
Copy link
Member

this means some background thread started a database connection in some test (it's pretty hard to actually narrow down). it's likely caused by this PR unfortunately :(

I think this flake also exists on main. @joshuarli tagged me in a flaky test ticket that had the same issue.

@asottile-sentry
Copy link
Contributor

this means some background thread started a database connection in some test (it's pretty hard to actually narrow down). it's likely caused by this PR unfortunately :(

I think this flake also exists on main. @joshuarli tagged me in a flaky test ticket that had the same issue.

it's a bit flaky on mainline yeah -- but not to the level it is failing here

cursor[bot]

This comment was marked as outdated.

@sl0thentr0py
Copy link
Member

only one test is failing now after the pytest-sentry update, I think that substantially reduced the reports here
https://sentry.sentry.io/issues/?project=2423079&query=is%3Aunresolved%20pytest_environ.GITHUB_REF%3Arefs%2Fpull%2F92011%2Fmerge&referrer=issue-list&statsPeriod=1h
but there's still a few of them that I think are valid? please correct me if I'm wrong!

@untitaker
Copy link
Member

the test failure you see here is present on master, it's currently being debugged

@getsentry-bot
Copy link
Contributor

revert failed (conflict? already reverted?) -- check the logs

@sentrivana
Copy link
Contributor

Reverted because a change in issue grouping introduced by this release backlogged canary. We'll fix this and dogfood again next week.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Do Not Merge Don't merge Scope: Backend Automatically applied to PRs that change backend components Scope: Frontend Automatically applied to PRs that change frontend components Trigger: Revert Add to a merged PR to revert it (skips CI)

Projects

None yet

Development

Successfully merging this pull request may close these issues.