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

Draft
wants to merge 40 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.

Todo:

  • set_attribute type NOT a dict. (search for TODO-anton in PR files changed)
  • attributes in start_span can NOT be a dict.
  • change set_span_data() to set_span_attribute() but check for value NOT be a dict.
  • make sure traces_sampler works the same as before (check for sample_rate)
  • check event["measurements"] places if those can be removed (because SDK does not support measurements anymore)

What this PR does:

  • replaced custom_sampling_context with attributes parameter in @trace_func
  • replaced 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
  • Ignored the access to event["measurements"] in the mypy type checking.
  • remove custom_sampling_context everywhere in code base (given to spans)
  • removed propagate_hub=True from ThreadingIntegration
  • removed the @mmetrics_noop decorator, because there are no metrics anymore only span.data, so we do not need it.
  • moved sampled=False from assigning to a span into the start_span() call.
  • replaces span.set_data with span.set_attribute with the same params
  • changed one scope.add_attachment to sentry_sdk.add_attachment
  • changed all .start_transaction() to .start_span() (without ever setting only_if_parent)
  • changed custom_sampling_context param in .start_span() to attributes
  • changed one continue_trace to the new context manager.
  • removed helper src/sentry/utils/sdk.py::set_measurement() because it is not used in sentry.
  • replaced scope.transaction with scope.root_span
  • replaced sentry_sdk.Scope.get_*_scope() with sentry_sdk.get_*_scope()

Requires https://github.com/getsentry/getsentry/pull/17553

@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

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
26048 1 26047 207
View the top 1 failed test(s) by shortest run time
tests.sentry.sentry_apps.api.bases.test_sentryapps.IntegrationPlatformEndpointTest::test_handle_sentry_app_sentry_error
Stack Traces | 0.274s run time
#x1B[1m#x1B[.../api/bases/test_sentryapps.py#x1B[0m:268: in test_handle_sentry_app_sentry_error
    assert response.data == error.to_public_dict()
#x1B[1m#x1B[31mE   AssertionError: assert {'detail': 'A...1226c751ba60'} == {'detail': 'A...ror ID: None'}#x1B[0m
#x1B[1m#x1B[31mE     #x1B[0m
#x1B[1m#x1B[31mE     Differing items:#x1B[0m
#x1B[1m#x1B[31mE     {'detail': 'An issue occured during the integration platform process. Sentry error ID: fccad4d08e024c7990fd1226c751ba60'} != {'detail': 'An issue occured during the integration platform process. Sentry error ID: None'}#x1B[0m
#x1B[1m#x1B[31mE     #x1B[0m
#x1B[1m#x1B[31mE     Full diff:#x1B[0m
#x1B[1m#x1B[31mE       {#x1B[0m
#x1B[1m#x1B[31mE           'detail': 'An issue occured during the integration platform process. Sentry error '#x1B[0m
#x1B[1m#x1B[31mE     -     'ID: None',#x1B[0m
#x1B[1m#x1B[31mE     +     'ID: fccad4d08e024c7990fd1226c751ba60',#x1B[0m
#x1B[1m#x1B[31mE       }#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.

@antonpirker antonpirker changed the title Support for Python SDK 3.0.0 Support Python SDK 3.0.0 May 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant