Skip to content

Support Python SDK 3.0.0 #92011

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 99 commits into from
Jul 2, 2025
Merged

Conversation

antonpirker
Copy link
Member

@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
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     

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
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.

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 sl0thentr0py requested a review from a team as a code owner July 1, 2025 12:17
@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

@sl0thentr0py sl0thentr0py merged commit dee16a1 into master Jul 2, 2025
67 checks passed
@sl0thentr0py sl0thentr0py deleted the antonpirker/code-changes-for-sdk-3.0.0 branch July 2, 2025 12:03
@wedamija wedamija added the Trigger: Revert Add to a merged PR to revert it (skips CI) label Jul 2, 2025
@getsentry-bot
Copy link
Contributor

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

wedamija added a commit that referenced this pull request Jul 2, 2025
wedamija added a commit that referenced this pull request Jul 2, 2025
This reverts commit dee16a1.

<!-- Describe your PR here. -->
@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.

andrewshie-sentry pushed a commit that referenced this pull request Jul 14, 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:
- make sure `traces_sampler` works the same as before (check for
`sample_rate`): #93011
- make **all** `get_isolation_scope` calls use the top-level API.
Currently, some calls where we `from sentry_sdk import Scope` then call
`Scope.get_isolation_scope` still need to be converted to the top-level
API: #93307
- check `event["measurements"]` places if those can be removed (because
SDK does not support measurements anymore):
#92718
- change set_span_data() to set_span_attribute() but check for value NOT
be a dict: #92946
- replace `with sentry_sdk.init(dsn=...)` with `with
sentry_sdk.new_scope() as scope:
scope.set_client(sentry_sdk.Client(dsn=...))` in
`src/sentry/runner/main.py`: #92944
- remove `propagate_hub=True` from `ThreadingIntegration`: #93016
- remove minimetrics from the sentry codebase, because the metrics
product was never released: #93595
- getsentry/getsentry#17553
- getsentry/devenv#194
- getsentry/devservices#277
- getsentry/pytest-sentry#39
- getsentry/sentry-docs#13939

---------

Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
Co-authored-by: Daniel Szoke <[email protected]>
Co-authored-by: Daniel Szoke <[email protected]>
Co-authored-by: Ivana Kellyer <[email protected]>
Co-authored-by: Neel Shah <[email protected]>
andrewshie-sentry pushed a commit that referenced this pull request Jul 14, 2025
This reverts commit dee16a1.

<!-- Describe your PR here. -->
@github-actions github-actions bot locked and limited conversation to collaborators Jul 18, 2025
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.