Skip to content

Commit 0e4158c

Browse files
antonpirkergetsantry[bot]szokeasaurusrexsentrivanasl0thentr0py
authored andcommitted
Support Python SDK 3.0.0 (#92011)
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]>
1 parent 3dc448a commit 0e4158c

File tree

82 files changed

+285
-206
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+285
-206
lines changed

requirements-base.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ sentry-ophio>=1.1.3
6969
sentry-protos==0.2.1
7070
sentry-redis-tools>=0.5.0
7171
sentry-relay>=0.9.9
72-
sentry-sdk[http2]>=2.29.1
72+
sentry-sdk[http2]==3.0.0a2
7373
slack-sdk>=3.27.2
7474
snuba-sdk>=3.0.43
7575
simplejson>=3.17.6

requirements-dev-frozen.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ cryptography==44.0.1
3737
cssselect==1.0.3
3838
cssutils==2.9.0
3939
datadog==0.49.1
40+
deprecated==1.2.18
4041
devservices==1.2.1
4142
distlib==0.3.8
4243
distro==1.8.0
@@ -83,6 +84,7 @@ httpx==0.25.2
8384
hyperframe==6.1.0
8485
identify==2.6.1
8586
idna==3.7
87+
importlib-metadata==8.6.1
8688
inflection==0.5.1
8789
iniconfig==1.1.1
8890
iso3166==2.1.1
@@ -115,6 +117,9 @@ openapi-core==0.18.2
115117
openapi-pydantic==0.4.0
116118
openapi-schema-validator==0.6.2
117119
openapi-spec-validator==0.7.1
120+
opentelemetry-api==1.33.1
121+
opentelemetry-sdk==1.33.1
122+
opentelemetry-semantic-conventions==0.54b1
118123
orjson==3.10.10
119124
outcome==1.2.0
120125
packaging==24.1
@@ -152,7 +157,7 @@ pytest-fail-slow==0.3.0
152157
pytest-json-report==1.5.0
153158
pytest-metadata==3.1.1
154159
pytest-rerunfailures==15.0
155-
pytest-sentry==0.3.0
160+
pytest-sentry==0.5.1
156161
pytest-workaround-12888==1.0.0
157162
pytest-xdist==3.0.2
158163
python-dateutil==2.9.0.post0
@@ -191,7 +196,7 @@ sentry-ophio==1.1.3
191196
sentry-protos==0.2.1
192197
sentry-redis-tools==0.5.0
193198
sentry-relay==0.9.9
194-
sentry-sdk==2.29.1
199+
sentry-sdk==3.0.0a2
195200
sentry-usage-accountant==0.0.10
196201
simplejson==3.17.6
197202
six==1.17.0
@@ -247,6 +252,7 @@ wheel==0.38.4
247252
wrapt==1.17.0
248253
wsproto==1.1.0
249254
xmlsec==1.3.14
255+
zipp==3.21.0
250256
zstandard==0.18.0
251257

252258
# The following packages are considered to be unsafe in a requirements file:

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pytest-django>=4.9.0
1717
pytest-fail-slow>=0.3.0
1818
pytest-json-report>=1.5.0
1919
pytest-rerunfailures>=15
20-
pytest-sentry>=0.3.0,<0.4.0
20+
pytest-sentry>=0.5.1
2121
pytest-workaround-12888
2222
pytest-xdist>=3
2323
responses>=0.23.1

requirements-frozen.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ cryptography==44.0.1
3232
cssselect==1.0.3
3333
cssutils==2.9.0
3434
datadog==0.49.1
35+
deprecated==1.2.18
3536
distro==1.8.0
3637
django==5.2.1
3738
django-crispy-forms==1.14.0
@@ -67,6 +68,7 @@ httpcore==1.0.2
6768
httpx==0.25.2
6869
hyperframe==6.1.0
6970
idna==3.7
71+
importlib-metadata==8.6.1
7072
inflection==0.5.1
7173
iso3166==2.1.1
7274
isodate==0.6.1
@@ -82,6 +84,9 @@ mmh3==4.0.0
8284
msgpack==1.1.0
8385
oauthlib==3.1.0
8486
openai==1.3.5
87+
opentelemetry-api==1.33.1
88+
opentelemetry-sdk==1.33.1
89+
opentelemetry-semantic-conventions==0.54b1
8590
orjson==3.10.10
8691
packaging==24.1
8792
parsimonious==0.10.0
@@ -128,7 +133,7 @@ sentry-ophio==1.1.3
128133
sentry-protos==0.2.1
129134
sentry-redis-tools==0.5.0
130135
sentry-relay==0.9.9
131-
sentry-sdk==2.29.1
136+
sentry-sdk==3.0.0a2
132137
sentry-usage-accountant==0.0.10
133138
simplejson==3.17.6
134139
six==1.17.0
@@ -154,7 +159,9 @@ urllib3==2.2.2
154159
vine==5.1.0
155160
vroomrs==0.1.6
156161
wcwidth==0.2.13
162+
wrapt==1.17.2
157163
xmlsec==1.3.14
164+
zipp==3.21.0
158165
zstandard==0.18.0
159166

160167
# The following packages are considered to be unsafe in a requirements file:

src/sentry/api/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,9 @@ def dispatch(self, request: Request, *args, **kwargs) -> Response:
445445
op="base.dispatch.sleep",
446446
name=type(self).__name__,
447447
) as span:
448-
span.set_data("SENTRY_API_RESPONSE_DELAY", settings.SENTRY_API_RESPONSE_DELAY)
448+
span.set_attribute(
449+
"SENTRY_API_RESPONSE_DELAY", settings.SENTRY_API_RESPONSE_DELAY
450+
)
449451
time.sleep(settings.SENTRY_API_RESPONSE_DELAY / 1000.0 - duration)
450452

451453
# Only enforced in dev environment

src/sentry/api/bases/organization.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ def get_projects(
408408

409409
with sentry_sdk.start_span(op="fetch_organization_projects") as span:
410410
projects = list(qs)
411-
span.set_data("Project Count", len(projects))
411+
span.set_attribute("Project Count", len(projects))
412412

413413
filter_by_membership = not bool(ids) and not bool(slugs)
414414
filtered_projects = self._filter_projects_by_permissions(
@@ -434,7 +434,7 @@ def _filter_projects_by_permissions(
434434
include_all_accessible: bool = False,
435435
) -> list[Project]:
436436
with sentry_sdk.start_span(op="apply_project_permissions") as span:
437-
span.set_data("Project Count", len(projects))
437+
span.set_attribute("Project Count", len(projects))
438438
if force_global_perms:
439439
span.set_tag("mode", "force_global_perms")
440440
return projects

src/sentry/api/endpoints/group_current_release.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ def get(self, request: Request, group) -> Response:
6565
environments = get_environments(request, group.project.organization)
6666

6767
with sentry_sdk.start_span(op="CurrentReleaseEndpoint.get.current_release") as span:
68-
span.set_data("Environment Count", len(environments))
69-
span.set_data(
68+
span.set_attribute("Environment Count", len(environments))
69+
span.set_attribute(
7070
"Raw Parameters",
7171
{
7272
"group.id": group.id,

src/sentry/api/endpoints/organization_events_facets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def data_fn(offset, limit):
5656
)
5757

5858
with sentry_sdk.start_span(op="discover.endpoint", name="populate_results") as span:
59-
span.set_data("facet_count", len(facets or []))
59+
span.set_attribute("facet_count", len(facets or []))
6060
resp: dict[str, _KeyTopValues]
6161
resp = defaultdict(lambda: {"key": "", "topValues": []})
6262
for row in facets:

src/sentry/api/endpoints/organization_events_facets_performance.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def query_tag_data(
262262
Returns None if query was not successful which causes the endpoint to return early
263263
"""
264264
with sentry_sdk.start_span(op="discover.discover", name="facets.filter_transform") as span:
265-
span.set_data("query", filter_query)
265+
span.set_attribute("query", filter_query)
266266
tag_query = DiscoverQueryBuilder(
267267
dataset=Dataset.Discover,
268268
params={},
@@ -391,7 +391,7 @@ def query_facet_performance(
391391
tag_key_limit = limit if tag_key else 1
392392

393393
with sentry_sdk.start_span(op="discover.discover", name="facets.filter_transform") as span:
394-
span.set_data("query", filter_query)
394+
span.set_attribute("query", filter_query)
395395
tag_query = DiscoverQueryBuilder(
396396
dataset=Dataset.Discover,
397397
params={},
@@ -417,8 +417,8 @@ def query_facet_performance(
417417
)
418418

419419
with sentry_sdk.start_span(op="discover.discover", name="facets.aggregate_tags"):
420-
span.set_data("sample_rate", sample_rate)
421-
span.set_data("target_sample", target_sample)
420+
span.set_attribute("sample_rate", sample_rate)
421+
span.set_attribute("target_sample", target_sample)
422422
aggregate_comparison = transaction_aggregate * 1.005 if transaction_aggregate else 0
423423
aggregate_column = Function("avg", [translated_aggregate_column], "aggregate")
424424
tag_query.where.append(excluded_tags)

src/sentry/api/endpoints/organization_events_meta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def get(self, request: Request, organization) -> Response:
170170

171171
with sentry_sdk.start_span(op="discover.endpoint", name="serialize_results") as span:
172172
results = list(results_cursor)
173-
span.set_data("result_length", len(results))
173+
span.set_attribute("result_length", len(results))
174174
context = serialize(
175175
results,
176176
request.user,

0 commit comments

Comments
 (0)