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

Expose the scope getters to top level API and use them everywhere #3357

Merged
merged 6 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
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
30 changes: 15 additions & 15 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
```python
import sentry_sdk
from sentry_sdk.integrations.flask import FlaskIntegration

sentry_sdk.init(
# Do not use the Flask integration even if Flask is installed.
disabled_integrations=[
Expand Down Expand Up @@ -68,7 +68,7 @@
LangchainIntegration(tiktoken_encoding_name="cl100k_base"),
],
)
```
```

- PyMongo: Send query description as valid JSON (#3291) by @0Calories
- Remove Python 2 compatibility code (#3284) by @szokeasaurusrex
Expand Down Expand Up @@ -183,7 +183,7 @@ This change fixes a regression in our cron monitoring feature, which caused cron
```python
from sentry_sdk.integrations.starlette import StarletteIntegration
from sentry_sdk.integrations.fastapi import FastApiIntegration

sentry_sdk.init(
# ...
integrations=[
Expand Down Expand Up @@ -312,9 +312,9 @@ This change fixes a regression in our cron monitoring feature, which caused cron
integrations=[AnthropicIntegration()],
)

client = Anthropic()
client = Anthropic()
```
Check out [the Anthropic docs](https://docs.sentry.io/platforms/python/integrations/anthropic/) for details.
Check out [the Anthropic docs](https://docs.sentry.io/platforms/python/integrations/anthropic/) for details.

- **New integration:** [Huggingface Hub](https://docs.sentry.io/platforms/python/integrations/huggingface/) (#3033) by @colin-sentry

Expand Down Expand Up @@ -369,13 +369,13 @@ This change fixes a regression in our cron monitoring feature, which caused cron

## 2.0.0

This is the first major update in a *long* time!
This is the first major update in a *long* time!

We dropped support for some ancient languages and frameworks (Yes, Python 2.7 is no longer supported). Additionally we refactored a big part of the foundation of the SDK (how data inside the SDK is handled).

We hope you like it!

For a shorter version of what you need to do, to upgrade to Sentry SDK 2.0 see: https://docs.sentry.io/platforms/python/migration/1.x-to-2.x
For a shorter version of what you need to do, to upgrade to Sentry SDK 2.0 see: https://docs.sentry.io/platforms/python/migration/1.x-to-2.x

### New Features

Expand Down Expand Up @@ -415,7 +415,7 @@ For a shorter version of what you need to do, to upgrade to Sentry SDK 2.0 see:

# later in the code execution:

scope = sentry_sdk.Scope.get_current_scope()
scope = sentry_sdk.get_current_scope()
scope.set_transaction_name("new-transaction-name")
```
- The classes listed in the table below are now abstract base classes. Therefore, they can no longer be instantiated. Subclasses can only be instantiated if they implement all of the abstract methods.
Expand Down Expand Up @@ -492,7 +492,7 @@ For a shorter version of what you need to do, to upgrade to Sentry SDK 2.0 see:
# do something with the forked scope
```

- `configure_scope` is deprecated. Use the new isolation scope directly via `Scope.get_isolation_scope()` instead.
- `configure_scope` is deprecated. Use the new isolation scope directly via `get_isolation_scope()` instead.

Before:

Expand All @@ -504,9 +504,9 @@ For a shorter version of what you need to do, to upgrade to Sentry SDK 2.0 see:
After:

```python
from sentry_sdk.scope import Scope
from sentry_sdk import get_isolation_scope

scope = Scope.get_isolation_scope()
scope = get_isolation_scope()
# do something with `scope`
```

Expand Down Expand Up @@ -563,7 +563,7 @@ This is the final 1.x release for the forseeable future. Development will contin
"failure_issue_threshold": 5,
"recovery_threshold": 5,
}

@monitor(monitor_slug='<monitor-slug>', monitor_config=monitor_config)
def tell_the_world():
print('My scheduled task...')
Expand All @@ -578,14 +578,14 @@ This is the final 1.x release for the forseeable future. Development will contin
```python
import django.db.models.signals
import sentry_sdk

sentry_sdk.init(
...
integrations=[
DjangoIntegration(
...
signals_denylist=[
django.db.models.signals.pre_init,
django.db.models.signals.pre_init,
django.db.models.signals.post_init,
],
),
Expand All @@ -608,7 +608,7 @@ This is the final 1.x release for the forseeable future. Development will contin
tags["extra"] = "foo"
del tags["release"]
return True

sentry_sdk.init(
...
_experiments={
Expand Down
10 changes: 5 additions & 5 deletions MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Looking to upgrade from Sentry SDK 1.x to 2.x? Here's a comprehensive list of wh

# later in the code execution:

scope = sentry_sdk.Scope.get_current_scope()
scope = sentry_sdk.get_current_scope()
scope.set_transaction_name("new-transaction-name")
```

Expand Down Expand Up @@ -132,18 +132,18 @@ Looking to upgrade from Sentry SDK 1.x to 2.x? Here's a comprehensive list of wh
After:

```python
from sentry_sdk.scope import Scope
from sentry_sdk import get_current_scope

scope = Scope.get_current_scope()
scope = get_current_scope()
# do something with `scope`
```

Or:

```python
from sentry_sdk.scope import Scope
from sentry_sdk import get_isolation_scope

scope = Scope.get_isolation_scope()
scope = get_isolation_scope()
# do something with `scope`
```

Expand Down
16 changes: 9 additions & 7 deletions sentry_sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
from sentry_sdk.hub import Hub
from sentry_sdk.scope import Scope
from sentry_sdk.transport import Transport, HttpTransport
from sentry_sdk.client import Client
from sentry_sdk._init_implementation import init

from sentry_sdk.api import * # noqa

from sentry_sdk.consts import VERSION # noqa

from sentry_sdk.crons import monitor # noqa
from sentry_sdk.tracing import trace # noqa

__all__ = [ # noqa
"Hub",
"Scope",
"Client",
"Transport",
"HttpTransport",
"init",
"integrations",
"trace",
# From sentry_sdk.api
"init",
"add_breadcrumb",
"capture_event",
"capture_exception",
Expand All @@ -30,6 +24,9 @@
"flush",
"get_baggage",
"get_client",
"get_global_scope",
"get_isolation_scope",
"get_current_scope",
"get_current_span",
"get_traceparent",
"is_initialized",
Expand All @@ -46,10 +43,15 @@
"set_user",
"start_span",
"start_transaction",
"trace",
"monitor",
]

# Initialize the debug support after everything is loaded
from sentry_sdk.debug import init_debug_support

init_debug_support()
del init_debug_support

# circular imports
from sentry_sdk.hub import Hub
2 changes: 1 addition & 1 deletion sentry_sdk/_init_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _init(*args, **kwargs):
This takes the same arguments as the client constructor.
"""
client = sentry_sdk.Client(*args, **kwargs)
sentry_sdk.Scope.get_global_scope().set_client(client)
sentry_sdk.get_global_scope().set_client(client)
_check_python_deprecations()
rv = _InitGuard(client)
return rv
Expand Down
Loading
Loading