Skip to content

Support for 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 36 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.

Still ToDo (not an exhaustive list):

  • 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)

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()

@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

❌ 2 Tests Failed:

Tests completed Failed Passed Skipped
26038 2 26036 207
View the top 2 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.284s 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...67507c259fbe'} == {'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: 3b283809fafd403d8e9067507c259fbe'} != {'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: 3b283809fafd403d8e9067507c259fbe',#x1B[0m
#x1B[1m#x1B[31mE       }#x1B[0m
tests.sentry.sentry_apps.api.endpoints.test_sentry_app_installation_external_issues.SentryAppInstallationExternalIssuesEndpointTest::test_external_issue_creation_fails_with_db_error
Stack Traces | 8.34s run time
#x1B[1m#x1B[.../api/endpoints/test_sentry_app_installation_external_issues.py#x1B[0m:120: in test_external_issue_creation_fails_with_db_error
    assert response.data == {
#x1B[1m#x1B[31mE   AssertionError: assert {'detail': 'A...795ea6a874e2'} == {'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: 0cd0fa12e0d44acba63e795ea6a874e2'} != {'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: 0cd0fa12e0d44acba63e795ea6a874e2',#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.

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