Skip to content

Commit 1ca6a02

Browse files
authored
docs: Tweak migration guide (#2979)
1 parent 66f3fe7 commit 1ca6a02

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

MIGRATION_GUIDE.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Sentry SDK 2.0 Migration Guide
22

3-
Looking to upgrade from Sentry SDK 1.x to 2.x? Here's a comprehensive list of what's changed.
3+
Looking to upgrade from Sentry SDK 1.x to 2.x? Here's a comprehensive list of what's changed. Looking for a more digestable summary? See the [guide in the docs](https://docs.sentry.io/platforms/python/migration/1.x-to-2.x) with the most common migration patterns.
44

55
## New Features
66

77
- Additional integrations will now be activated automatically if the SDK detects the respective package is installed: Ariadne, ARQ, asyncpg, Chalice, clickhouse-driver, GQL, Graphene, huey, Loguru, PyMongo, Quart, Starlite, Strawberry.
8-
- Added new API for custom instrumentation: `new_scope`, `isolation_scope`. See the [Deprecated](#deprecated) section to see how they map to the existing APIs.
8+
- While refactoring the [inner workings](https://docs.sentry.io/platforms/python/enriching-events/scopes/) of the SDK we added new top-level APIs for custom instrumentation called `new_scope` and `isolation_scope`. See the [Deprecated](#deprecated) section to see how they map to the existing APIs.
99

1010
## Changed
1111

@@ -118,7 +118,7 @@ Looking to upgrade from Sentry SDK 1.x to 2.x? Here's a comprehensive list of wh
118118
# do something with the forked scope
119119
```
120120

121-
- `configure_scope` is deprecated. Use the new isolation scope directly via `Scope.get_isolation_scope()` instead.
121+
- `configure_scope` is deprecated. Modify the current or isolation scope directly instead.
122122

123123
Before:
124124

@@ -132,11 +132,22 @@ Looking to upgrade from Sentry SDK 1.x to 2.x? Here's a comprehensive list of wh
132132
```python
133133
from sentry_sdk.scope import Scope
134134

135+
scope = Scope.get_current_scope()
136+
# do something with `scope`
137+
```
138+
139+
Or:
140+
141+
```python
142+
from sentry_sdk.scope import Scope
143+
135144
scope = Scope.get_isolation_scope()
136145
# do something with `scope`
137146
```
138147

139-
- `push_scope` is deprecated. Use the new `new_scope` context manager to fork the necessary scopes.
148+
When to use `get_current_scope()` and `get_isolation_scope()` depends on how long the change to the scope should be in effect. If you want the changed scope to affect the whole request-response cycle or the whole execution of task, use the isolation scope. If it's more localized, use the current scope.
149+
150+
- `push_scope` is deprecated. Fork the current or the isolation scope instead.
140151

141152
Before:
142153

@@ -154,6 +165,17 @@ Looking to upgrade from Sentry SDK 1.x to 2.x? Here's a comprehensive list of wh
154165
# do something with `scope`
155166
```
156167

168+
Or:
169+
170+
```python
171+
import sentry_sdk
172+
173+
with sentry_sdk.isolation_scope() as scope:
174+
# do something with `scope`
175+
```
176+
177+
`new_scope()` will fork the current scope, while `isolation_scope()` will fork the isolation scope. The lifecycle of a single isolation scope roughly translates to the lifecycle of a transaction in most cases, so if you're looking to create a new separated scope for a whole request-response cycle or task execution, go for `isolation_scope()`. If you want to wrap a smaller unit code, fork the current scope instead with `new_scope()`.
178+
157179
- Accessing the client via the hub has been deprecated. Use the top-level `sentry_sdk.get_client()` to get the current client.
158180
- `profiler_mode` and `profiles_sample_rate` have been deprecated as `_experiments` options. Use them as top level options instead:
159181
```python

0 commit comments

Comments
 (0)