Skip to content

Commit 656ac9d

Browse files
authored
Scope refactoring (merge Hubs and Scopes) (#2610)
This refactors the SDK to move away from the Hub and have all the functionality in the Scope. Introducing different types of scopes. This aligns the SDK with how Opentelementry (OTel) handles data bringing us closer to be 100% OTel compatible. This change was discussed in this RFC: getsentry/rfcs#122 There is also a small FAQ: https://gist.github.com/mitsuhiko/1bc78d04ea7d08e5b50d27e42676db80 And a Miro board showing how the new scopes manage data: https://miro.com/app/board/uXjVNtPiOfI=/?share_link_id=216270218892 ### This RP contains - Introduction of global, isolation, and current scope - Deprecation of the Hub - All existing Hub based API still works and is still used by most of our integrations. Under the hood the new Scopes are used. - (this PR now includes all the changes made in the [first PR](#2609) introducing the new API) ### Breaking changes - The Pyramid integration will not capture errors that might happen in `authenticated_userid()` in a custom `AuthenticationPolicy` class. - The parameter `propagate_hub` in `ThreadingIntegration()` was deprecated and renamed to `propagate_scope`.
1 parent 888ee4c commit 656ac9d

Some content is hidden

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

67 files changed

+2499
-902
lines changed

.github/workflows/test-integrations-web-frameworks-1.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ jobs:
6767
run: |
6868
set -x # print commands that are executed
6969
./scripts/runtox.sh "py${{ matrix.python-version }}-django-latest" --cov=tests --cov=sentry_sdk --cov-report= --cov-branch
70-
- name: Test fastapi latest
71-
run: |
72-
set -x # print commands that are executed
73-
./scripts/runtox.sh "py${{ matrix.python-version }}-fastapi-latest" --cov=tests --cov=sentry_sdk --cov-report= --cov-branch
7470
- name: Test flask latest
7571
run: |
7672
set -x # print commands that are executed
@@ -79,6 +75,10 @@ jobs:
7975
run: |
8076
set -x # print commands that are executed
8177
./scripts/runtox.sh "py${{ matrix.python-version }}-starlette-latest" --cov=tests --cov=sentry_sdk --cov-report= --cov-branch
78+
- name: Test fastapi latest
79+
run: |
80+
set -x # print commands that are executed
81+
./scripts/runtox.sh "py${{ matrix.python-version }}-fastapi-latest" --cov=tests --cov=sentry_sdk --cov-report= --cov-branch
8282
- name: Generate coverage XML
8383
run: |
8484
coverage combine .coverage*
@@ -136,10 +136,6 @@ jobs:
136136
run: |
137137
set -x # print commands that are executed
138138
./scripts/runtox.sh --exclude-latest "py${{ matrix.python-version }}-django" --cov=tests --cov=sentry_sdk --cov-report= --cov-branch
139-
- name: Test fastapi pinned
140-
run: |
141-
set -x # print commands that are executed
142-
./scripts/runtox.sh --exclude-latest "py${{ matrix.python-version }}-fastapi" --cov=tests --cov=sentry_sdk --cov-report= --cov-branch
143139
- name: Test flask pinned
144140
run: |
145141
set -x # print commands that are executed
@@ -148,6 +144,10 @@ jobs:
148144
run: |
149145
set -x # print commands that are executed
150146
./scripts/runtox.sh --exclude-latest "py${{ matrix.python-version }}-starlette" --cov=tests --cov=sentry_sdk --cov-report= --cov-branch
147+
- name: Test fastapi pinned
148+
run: |
149+
set -x # print commands that are executed
150+
./scripts/runtox.sh --exclude-latest "py${{ matrix.python-version }}-fastapi" --cov=tests --cov=sentry_sdk --cov-report= --cov-branch
151151
- name: Generate coverage XML
152152
run: |
153153
coverage combine .coverage*

docs/api.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,18 @@ Distributed Tracing
4141
.. autofunction:: sentry_sdk.api.get_traceparent
4242

4343

44+
Client Management
45+
=================
46+
47+
.. autofunction:: sentry_sdk.api.is_initialized
48+
.. autofunction:: sentry_sdk.api.get_client
49+
50+
4451
Managing Scope (advanced)
4552
=========================
4653

4754
.. autofunction:: sentry_sdk.api.configure_scope
4855
.. autofunction:: sentry_sdk.api.push_scope
4956

57+
.. autofunction:: sentry_sdk.api.new_scope
5058

51-
.. Not documented (On purpose. Not sure if anyone should use those)
52-
.. last_event_id()
53-
.. flush()

docs/apidocs.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ API Docs
1111
.. autoclass:: sentry_sdk.Client
1212
:members:
1313

14+
.. autoclass:: sentry_sdk.client.BaseClient
15+
:members:
16+
17+
.. autoclass:: sentry_sdk.client.NonRecordingClient
18+
:members:
19+
1420
.. autoclass:: sentry_sdk.client._Client
1521
:members:
1622

scripts/split-tox-gh-actions/split-tox-gh-actions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@
9494
],
9595
"Web Frameworks 1": [
9696
"django",
97-
"fastapi",
9897
"flask",
9998
"starlette",
99+
"fastapi",
100100
],
101101
"Web Frameworks 2": [
102102
"aiohttp",

sentry_sdk/__init__.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,31 @@
1818
"HttpTransport",
1919
"init",
2020
"integrations",
21+
"trace",
2122
# From sentry_sdk.api
23+
"add_breadcrumb",
2224
"capture_event",
23-
"capture_message",
2425
"capture_exception",
25-
"add_breadcrumb",
26+
"capture_message",
2627
"configure_scope",
27-
"push_scope",
28+
"continue_trace",
2829
"flush",
29-
"last_event_id",
30-
"start_span",
31-
"start_transaction",
32-
"set_tag",
30+
"get_baggage",
31+
"get_client",
32+
"get_current_span",
33+
"get_traceparent",
34+
"is_initialized",
35+
"isolation_scope",
36+
"new_scope",
37+
"push_scope",
3338
"set_context",
3439
"set_extra",
35-
"set_user",
3640
"set_level",
3741
"set_measurement",
38-
"get_current_span",
39-
"get_traceparent",
40-
"get_baggage",
41-
"continue_trace",
42-
"trace",
42+
"set_tag",
43+
"set_user",
44+
"start_span",
45+
"start_transaction",
4346
]
4447

4548
# Initialize the debug support after everything is loaded

0 commit comments

Comments
 (0)