8000 ref(beam): Use new scopes API (#2879) · au79stein/sentry-python@aa92e2e · GitHub
[go: up one dir, main page]

Skip to content

Commit aa92e2e

Browse files
authored
ref(beam): Use new scopes API (getsentry#2879)
1 parent 75b33d2 commit aa92e2e

File tree

1 file changed

+21
-28
lines changed

1 file changed

+21
-28
lines changed

sentry_sdk/integrations/beam.py

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@
22
import types
33
from functools import wraps
44

5-
from sentry_sdk.hub import Hub
6-
from sentry_sdk.utils import capture_internal_exceptions, event_from_exception, reraise
5+
import sentry_sdk
76
from sentry_sdk.integrations import Integration
87
from sentry_sdk.integrations.logging import ignore_logger
8+
from sentry_sdk.utils import (
9+
capture_internal_exceptions,
10+
ensure_integration_enabled,
11+
event_from_exception,
12+
reraise,
13+
)
914
from sentry_sdk._types import TYPE_CHECKING
1015

1116
if TYPE_CHECKING:
1217
from typing import Any
1318
from typing import Iterator
1419
from typing import TypeVar
15-
from typing import Optional
1620
from typing import Callable
1721

18-
from sentry_sdk.client import BaseClient
1922
from sentry_sdk._types import ExcInfo
2023

2124
T = TypeVar("T")
@@ -113,63 +116,53 @@ def _wrap_task_call(func):
113116
# type: (F) -> F
114117
"""
115118
Wrap task call with a try catch to get exceptions.
116-
Pass the client on to raise_exception so it can get rebinded.
117119
"""
118-
client = Hub.current.client
119120

120121
@wraps(func)
121122
def _inner(*args, **kwargs):
122123
# type: (*Any, **Any) -> Any
123124
try:
124125
gen = func(*args, **kwargs)
125126
except Exception:
126-
raise_exception(client)
127+
raise_exception()
127128

128129
if not isinstance(gen, types.GeneratorType):
129130
return gen
130-
return _wrap_generator_call(gen, client)
131+
return _wrap_generator_call(gen)
131132

132133
setattr(_inner, USED_FUNC, True)
133134
return _inner # type: ignore
134135

135136

136-
def _capture_exception(exc_info, hub):
137-
# type: (ExcInfo, Hub) -> None
137+
@ensure_integration_enabled(BeamIntegration)
138+
def _capture_exception(exc_info):
139+
# type: (ExcInfo) -> None
138140
"""
139141
Send Beam exception to Sentry.
140142
"""
141-
integration = hub.get_integration(BeamIntegration)
142-
if integration is None:
143-
return
144-
145-
client = hub.client
146-
if client is None:
147-
return
143+
client = sentry_sdk.get_client()
148144

149145
event, hint = event_from_exception(
150146
exc_info,
151147
client_options=client.options,
152148
mechanism={"type": "beam", "handled": False},
153149
)
154-
hub.capture_event(event, hint=hint)
150+
sentry_sdk.capture_event(event, hint=hint)
155151

156152

157-
def raise_exception(client):
158-
# type: (Optional[BaseClient]) -> None
153+
def raise_exception():
154+
# type: () -> None
159155
"""
160-
Raise an exception. If the client is not in the hub, rebind it.
156+
Raise an exception.
161157
"""
162-
hub = Hub.current
163-
if hub.client is None:
164-
hub.bind_client(client)
165158
exc_info = sys.exc_info()
166159
with capture_internal_exceptions():
167-
_capture_exception(exc_info, hub)
160+
_capture_exception(exc_info)
168161
reraise(*exc_info)
169162

170163

171-
def _wrap_generator_call(gen, client):
172-
# type: (Iterator[T], Optional[BaseClient]) -> Iterator[T]
164+
def _wrap_generator_call(gen):
165+
# type: (Iterator[T]) -> Iterator[T]
173166
"""
174167
Wrap the generator to handle any failures.
175168
"""
@@ -179,4 +172,4 @@ def _wrap_generator_call(gen, client):
179172
except StopIteration:
180173
break
181174
except Exception:
182-
raise_exception(client)
175+
raise_exception()

0 commit comments

Comments
 (0)
0