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

Open
wants to merge 82 commits into
base: master
Choose a base branch
from

Conversation

antonpirker
Copy link
Member

@antonpirker antonpirker commented May 21, 2025

[work in progress]

Update the code so it works with the upcoming major release of the Sentry Python SDK 3.0.0.

Sentry SDK 3.0.0 has massive changes on how the data flows through the SDK compared to 2.x. (3.0 uses Opentelementry under the hood to create spans)

Some APIs in 3.0 is not backwards compatible with 2.x so we need to change a lot of call sites.

What this PR does:

  • change all .start_transaction() to .start_span() (without ever setting only_if_parent)
  • replace span.set_data() with span.set_attribute() with the same params
  • change one continue_trace() to the new context manager.
  • change one scope.add_attachment() to sentry_sdk.add_attachment()
  • replace scope.transaction with scope.root_span
  • replace Span.containing_transaction with Span.root_span
  • check that attributes in start_span() can NOT be a dict. (Note: It only had sample_rate set which is a float.
  • moved sampled=False from assigning to a span into the start_span() call.
  • replace custom_sampling_context with attributes parameter in @trace_func
  • replace custom_sampling_context param in .start_span() with attributes
  • remove custom_sampling_context everywhere in code base (given to spans)
  • remove @metrics_noop decorator, because there are no metrics anymore only span.data, so we do not need it.
  • remove helper src/sentry/utils/sdk.py::set_measurement() because it is not used in sentry.
  • check that set_attribute() value is NOT a dict. See: Do not use dicts in .set_data().  #92720

Related, but split out in separate PRs:

requires https://github.com/getsentry/getsentry/pull/17553
requires getsentry/devenv#194
requires getsentry/devservices#277
requires getsentry/pytest-sentry#39
requires getsentry/sentry-docs#13939

@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

❌ 3 Tests Failed:

Tests completed Failed Passed Skipped
26647 3 26644 230
View the top 3 failed test(s) by shortest run time
tests.relay_integration.test_sdk::test_encoding[MONOLITH]
Stack Traces | 106s run time
#x1B[1m#x1B[31mtests/relay_integration/test_sdk.py#x1B[0m:98: in test_encoding
    assert event.data["project"] == settings.SENTRY_PROJECT
#x1B[1m#x1B[31mE   AttributeError: 'NoneType' object has no attribute 'data'#x1B[0m
tests.relay_integration.test_sdk::test_simple[MONOLITH]
Stack Traces | 116s run time
#x1B[1m#x1B[31mtests/relay_integration/test_sdk.py#x1B[0m:64: in test_simple
    assert event
#x1B[1m#x1B[31mE   assert None#x1B[0m
tests.relay_integration.test_sdk::test_recursion_breaker[MONOLITH]
Stack Traces | 116s run time
#x1B[1m#x1B[31mtests/relay_integration/test_sdk.py#x1B[0m:81: in test_recursion_breaker
    with pytest.raises(Exception):
#x1B[1m#x1B[31mE   Failed: DID NOT RAISE <class 'Exception'>#x1B[0m

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

szokeasaurusrex and others added 2 commits June 11, 2025 17:08
<!-- Describe your PR here. -->

<!--

  Sentry employees and contractors can delete or ignore the following.

-->

### Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated
in the State of Delaware in 2015 as Functional Software, Inc. and is
gonna need some rights from me in order to utilize my contributions in
this here PR. So here's the deal: I retain all rights, title and
interest in and to my contributions, and by keeping this boilerplate
intact I confirm that Sentry can use, modify, copy, and redistribute my
contributions, under Sentry's choice of terms.
@antonpirker antonpirker marked this pull request as ready for review June 11, 2025 15:09
shellmayr pushed a commit that referenced this pull request Jun 12, 2025
`with sentry_sdk.init` is deprecated and will be removed in Sentry SDK
3.0.

Split off from #92011

<!-- Describe your PR here. -->

<!--

  Sentry employees and contractors can delete or ignore the following.

-->

### Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated
in the State of Delaware in 2015 as Functional Software, Inc. and is
gonna need some rights from me in order to utilize my contributions in
this here PR. So here's the deal: I retain all rights, title and
interest in and to my contributions, and by keeping this boilerplate
intact I confirm that Sentry can use, modify, copy, and redistribute my
contributions, under Sentry's choice of terms.
@JoshFerge
Copy link
Member

there seems to be a lot of unrelated changes in this PR?

@untitaker
Copy link
Member

there seems to be a lot of unrelated changes in this PR?

are there? some new sdk-related tests, other than that it's a mass-replace

andrewshie-sentry pushed a commit that referenced this pull request Jun 19, 2025
`with sentry_sdk.init` is deprecated and will be removed in Sentry SDK
3.0.

Split off from #92011

<!-- Describe your PR here. -->

<!--

  Sentry employees and contractors can delete or ignore the following.

-->

### Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated
in the State of Delaware in 2015 as Functional Software, Inc. and is
gonna need some rights from me in order to utilize my contributions in
this here PR. So here's the deal: I retain all rights, title and
interest in and to my contributions, and by keeping this boilerplate
intact I confirm that Sentry can use, modify, copy, and redistribute my
contributions, under Sentry's choice of terms.
andrewshie-sentry pushed a commit that referenced this pull request Jun 19, 2025
This parameter is deprecated as of Sentry SDK 2.0.0; the default value
is now `True`, so passing this parameter is no longer needed.

Split off from #92011
andrewshie-sentry pushed a commit that referenced this pull request Jun 19, 2025
Using `sentry_sdk.Scope.get_current_scope` has been deprecated in favor
of `sentry_sdk.get_current_scope`.

Going forward, we generally would like SDK users to stick to the
top-level APIs.

Split off from #92011.

Stacked on:
  - #93016

<!-- Describe your PR here. -->

<!--

  Sentry employees and contractors can delete or ignore the following.

-->

### Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated
in the State of Delaware in 2015 as Functional Software, Inc. and is
gonna need some rights from me in order to utilize my contributions in
this here PR. So here's the deal: I retain all rights, title and
interest in and to my contributions, and by keeping this boilerplate
intact I confirm that Sentry can use, modify, copy, and redistribute my
contributions, under Sentry's choice of terms.
andrewshie-sentry pushed a commit that referenced this pull request Jun 19, 2025
Migrate calls of `sentry_sdk.Scope.get_isolation_scope` to
`sentry_sdk.get_isolation_scope`. Calls where `Scope` is first imported
and then where `Scope.get_isolation_scope` is called are left as-is; we
will address those separately.

Split off from #92011.

<!-- Describe your PR here. -->

<!--

  Sentry employees and contractors can delete or ignore the following.

-->

### Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated
in the State of Delaware in 2015 as Functional Software, Inc. and is
gonna need some rights from me in order to utilize my contributions in
this here PR. So here's the deal: I retain all rights, title and
interest in and to my contributions, and by keeping this boilerplate
intact I confirm that Sentry can use, modify, copy, and redistribute my
contributions, under Sentry's choice of terms.
andrewshie-sentry pushed a commit that referenced this pull request Jun 19, 2025
Migrate calls of `sentry_sdk.Scope.get_global_scope` to
`sentry_sdk.get_global_scope`.

Split off from #92011.

<!-- Describe your PR here. -->

<!--

  Sentry employees and contractors can delete or ignore the following.

-->

### Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated
in the State of Delaware in 2015 as Functional Software, Inc. and is
gonna need some rights from me in order to utilize my contributions in
this here PR. So here's the deal: I retain all rights, title and
interest in and to my contributions, and by keeping this boilerplate
intact I confirm that Sentry can use, modify, copy, and redistribute my
contributions, under Sentry's choice of terms.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants