---
title: "Scopes"
description: "The SDK will in most cases automatically manage the scopes for you in the framework integrations. Learn what a scope is and how you can use it to your advantage."
url: https://docs.sentry.io/platforms/python/enriching-events/scopes/
---

# Scopes | Sentry for Python

Scopes store extra data that the SDK adds to your event when sending the event to Sentry. While the SDKs typically manage the scope automatically, understanding how scopes work and how you can manage them manually can be helpful.

## [What is a Scope?](https://docs.sentry.io/platforms/python/enriching-events/scopes.md#what-is-a-scope)

A scope manages an event's data. For instance, the SDK stores [contexts](https://docs.sentry.io/platforms/python/enriching-events/context.md) and [breadcrumbs](https://docs.sentry.io/platforms/python/enriching-events/breadcrumbs.md) on the scope.

There are three types of scopes. Exactly one scope of each type will be active at a specific point in time.

* *Global scope*: A single globally-shared scope storing data relevant for the whole app (such as the release).
* *Isolation scope*: Thread-local scope created for each request-response lifecycle to store data relevant to the request.
* *Current scope*: Thread-local scope created for each span to store data relevant to the span.

The SDK and the SDK's built-in integrations automatically manage the scopes. For example, web framework integrations create an isolation scope for each request handled. When you call a top-level API function, such as `set_tag`, the SDK determines the correct scope on which to operate.

When sending an event to Sentry, the final data applied to the event is the result of merging the three scopes, applying data from each in turn. The global scope is applied first, followed by the isolation scope, and then the current scope.

## [Changing the Scope](https://docs.sentry.io/platforms/python/enriching-events/scopes.md#changing-the-scope)

We generally recommend using the top-level API to manage your scopes, since the SDK's automatic scope management handles most use cases.

However, if your use case requires direct access to the scope object, you can use the `new_scope` context manager. `new_scope` forks the current scope, allows you to modify the new scope while the context manager is active, and restores the original scope afterwards. Using `new_scope` allows you to send data for only one specific event, such as [modifying the context](https://docs.sentry.io/platforms/python/enriching-events/context.md). It is roughly equivalent to the `push_scope` context manager in earlier (1.x) versions of the SDK.

Avoid calling top-level APIs inside the `new_scope` context manager. The top-level API might interact with a different scope from what `new_scope` yields, causing unintended results. While within the `new_scope` context manager, please call methods directly on the scope that `new_scope` yields!

Using `new_scope` allows you to attach additional information, such as adding custom tags.

```python
import sentry_sdk

sentry_sdk.init(...)

with sentry_sdk.new_scope() as scope:
    scope.set_tag("inside-new-scope", "yes")
    try:
        raise RuntimeError("With new_scope")
    except:
        # This exception will have the tag set
        sentry_sdk.capture_exception()

# The scope is automatically cleared and the previous scope
# is restored after the `with` block
try:
    raise RuntimeError("Outside of new_scope")
except:
    # This exception won't have the custom tag set
    sentry_sdk.capture_exception()
```

To learn what useful information can be associated with scopes see [the context documentation](https://docs.sentry.io/platforms/python/enriching-events/context.md).
