Skip to content
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

docs(python): Document how to migrate Hub clones #10531

Open
wants to merge 3 commits into
base: szokeasaurusrex/use_isolation_scope-migration
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docs/platforms/python/migration/1.x-to-2.x.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ If you were using a custom hub to isolate event data, we recommend using a custo
sentry_sdk.capture_message("I am isolated")
```

### Cloning a Hub

If you previously cloned a hub by passing a hub to the `Hub` constructor, you should now fork an isolation scope by calling the scope's `fork()` method, like this:

```python diff
- import sentry_sdk

- my_cloned_hub = sentry_sdk.Hub(my_hub)
+ my_cloned_isolation_scope = my_isolation_scope.fork()
```

You can follow the previous section's instructions to activate the cloned isolation scope.

### Activating Current Hub Clone

If you previously used `with sentry_sdk.Hub(sentry_sdk.Hub.current)` to clone the current hub and activate the clone, you should now use `with sentry_sdk.isolation_scope()`, like so:
Expand All @@ -93,6 +106,8 @@ If you previously used `with sentry_sdk.Hub(sentry_sdk.Hub.current)` to clone th

`sentry_sdk.isolation_scope` is a context manager that creates a new isolation scope by forking the current isolation scope. The forked isolation scope is activated during the context manager's lifetime, providing a similar level of isolation within the context manager as the previous `Hub`-based approach.

Note that using `sentry_sdk.isolation_scope()` is equivalent to `sentry_sdk.scope.use_isolation_scope(sentry_sdk.Scope.get_isolation_scope().fork())`.

### Scope Configuring

In case of `configure_scope()`, you will need to modify either the isolation scope
Expand Down