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

Remove init context manager #3730

Merged
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
3 changes: 1 addition & 2 deletions MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Sentry SDK Migration Guide


## Upgrading to 3.0

Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of what's changed. Looking for a more digestible summary? See the [guide in the docs](https://docs.sentry.io/platforms/python/migration/2.x-to-3.x) with the most common migration patterns.
Expand All @@ -19,6 +18,7 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
- `sentry_sdk.continue_trace` no longer returns a `Transaction` and is now a context manager.
- Redis integration: In Redis pipeline spans there is no `span["data"]["redis.commands"]` that contains a dict `{"count": 3, "first_ten": ["cmd1", "cmd2", ...]}` but instead `span["data"]["redis.commands.count"]` (containing `3`) and `span["data"]["redis.commands.first_ten"]` (containing `["cmd1", "cmd2", ...]`).
- clickhouse-driver integration: The query is now available under the `db.query.text` span attribute (only if `send_default_pii` is `True`).
- `sentry_sdk.init` now returns `None` instead of a context manager.

### Removed

Expand All @@ -40,7 +40,6 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
- `continue_from_headers`, `continue_from_environ` and `from_traceparent` have been removed, please use top-level API `sentry_sdk.continue_trace` instead.
- `PropagationContext` constructor no longer takes a `dynamic_sampling_context` but takes a `baggage` object instead.


### Deprecated

- `sentry_sdk.start_transaction` is deprecated. Use `sentry_sdk.start_span` instead.
Expand Down
24 changes: 3 additions & 21 deletions sentry_sdk/_init_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,11 @@
import sentry_sdk

if TYPE_CHECKING:
from typing import Any, ContextManager, Optional
from typing import Any, Optional

import sentry_sdk.consts


class _InitGuard:
def __init__(self, client):
# type: (sentry_sdk.Client) -> None
self._client = client

def __enter__(self):
# type: () -> _InitGuard
return self

def __exit__(self, exc_type, exc_value, tb):
# type: (Any, Any, Any) -> None
c = self._client
if c is not None:
c.close()


def _check_python_deprecations():
# type: () -> None
# Since we're likely to deprecate Python versions in the future, I'm keeping
Expand All @@ -33,16 +17,14 @@ def _check_python_deprecations():


def _init(*args, **kwargs):
# type: (*Optional[str], **Any) -> ContextManager[Any]
# type: (*Optional[str], **Any) -> None
"""Initializes the SDK and optionally integrations.

This takes the same arguments as the client constructor.
"""
client = sentry_sdk.Client(*args, **kwargs)
sentry_sdk.get_global_scope().set_client(client)
_check_python_deprecations()
rv = _InitGuard(client)
return rv


if TYPE_CHECKING:
Expand All @@ -52,7 +34,7 @@ def _init(*args, **kwargs):
# Use `ClientConstructor` to define the argument types of `init` and
# `ContextManager[Any]` to tell static analyzers about the return type.

class init(sentry_sdk.consts.ClientConstructor, _InitGuard): # noqa: N801
class init(sentry_sdk.consts.ClientConstructor): # noqa: N801
pass

else:
Expand Down
Loading