You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

740 regels
25 KiB

  1. import warnings
  2. from contextlib import contextmanager
  3. from sentry_sdk import (
  4. get_client,
  5. get_global_scope,
  6. get_isolation_scope,
  7. get_current_scope,
  8. )
  9. from sentry_sdk._compat import with_metaclass
  10. from sentry_sdk.consts import INSTRUMENTER
  11. from sentry_sdk.scope import _ScopeManager
  12. from sentry_sdk.client import Client
  13. from sentry_sdk.tracing import (
  14. NoOpSpan,
  15. Span,
  16. Transaction,
  17. )
  18. from sentry_sdk.utils import (
  19. logger,
  20. ContextVar,
  21. )
  22. from typing import TYPE_CHECKING
  23. if TYPE_CHECKING:
  24. from typing import Any
  25. from typing import Callable
  26. from typing import ContextManager
  27. from typing import Dict
  28. from typing import Generator
  29. from typing import List
  30. from typing import Optional
  31. from typing import overload
  32. from typing import Tuple
  33. from typing import Type
  34. from typing import TypeVar
  35. from typing import Union
  36. from typing_extensions import Unpack
  37. from sentry_sdk.scope import Scope
  38. from sentry_sdk.client import BaseClient
  39. from sentry_sdk.integrations import Integration
  40. from sentry_sdk._types import (
  41. Event,
  42. Hint,
  43. Breadcrumb,
  44. BreadcrumbHint,
  45. ExcInfo,
  46. LogLevelStr,
  47. SamplingContext,
  48. )
  49. from sentry_sdk.tracing import TransactionKwargs
  50. T = TypeVar("T")
  51. else:
  52. def overload(x):
  53. # type: (T) -> T
  54. return x
  55. class SentryHubDeprecationWarning(DeprecationWarning):
  56. """
  57. A custom deprecation warning to inform users that the Hub is deprecated.
  58. """
  59. _MESSAGE = (
  60. "`sentry_sdk.Hub` is deprecated and will be removed in a future major release. "
  61. "Please consult our 1.x to 2.x migration guide for details on how to migrate "
  62. "`Hub` usage to the new API: "
  63. "https://docs.sentry.io/platforms/python/migration/1.x-to-2.x"
  64. )
  65. def __init__(self, *_):
  66. # type: (*object) -> None
  67. super().__init__(self._MESSAGE)
  68. @contextmanager
  69. def _suppress_hub_deprecation_warning():
  70. # type: () -> Generator[None, None, None]
  71. """Utility function to suppress deprecation warnings for the Hub."""
  72. with warnings.catch_warnings():
  73. warnings.filterwarnings("ignore", category=SentryHubDeprecationWarning)
  74. yield
  75. _local = ContextVar("sentry_current_hub")
  76. class HubMeta(type):
  77. @property
  78. def current(cls):
  79. # type: () -> Hub
  80. """Returns the current instance of the hub."""
  81. warnings.warn(SentryHubDeprecationWarning(), stacklevel=2)
  82. rv = _local.get(None)
  83. if rv is None:
  84. with _suppress_hub_deprecation_warning():
  85. # This will raise a deprecation warning; suppress it since we already warned above.
  86. rv = Hub(GLOBAL_HUB)
  87. _local.set(rv)
  88. return rv
  89. @property
  90. def main(cls):
  91. # type: () -> Hub
  92. """Returns the main instance of the hub."""
  93. warnings.warn(SentryHubDeprecationWarning(), stacklevel=2)
  94. return GLOBAL_HUB
  95. class Hub(with_metaclass(HubMeta)): # type: ignore
  96. """
  97. .. deprecated:: 2.0.0
  98. The Hub is deprecated. Its functionality will be merged into :py:class:`sentry_sdk.scope.Scope`.
  99. The hub wraps the concurrency management of the SDK. Each thread has
  100. its own hub but the hub might transfer with the flow of execution if
  101. context vars are available.
  102. If the hub is used with a with statement it's temporarily activated.
  103. """
  104. _stack = None # type: List[Tuple[Optional[Client], Scope]]
  105. _scope = None # type: Optional[Scope]
  106. # Mypy doesn't pick up on the metaclass.
  107. if TYPE_CHECKING:
  108. current = None # type: Hub
  109. main = None # type: Hub
  110. def __init__(
  111. self,
  112. client_or_hub=None, # type: Optional[Union[Hub, Client]]
  113. scope=None, # type: Optional[Any]
  114. ):
  115. # type: (...) -> None
  116. warnings.warn(SentryHubDeprecationWarning(), stacklevel=2)
  117. current_scope = None
  118. if isinstance(client_or_hub, Hub):
  119. client = get_client()
  120. if scope is None:
  121. # hub cloning is going on, we use a fork of the current/isolation scope for context manager
  122. scope = get_isolation_scope().fork()
  123. current_scope = get_current_scope().fork()
  124. else:
  125. client = client_or_hub # type: ignore
  126. get_global_scope().set_client(client)
  127. if scope is None: # so there is no Hub cloning going on
  128. # just the current isolation scope is used for context manager
  129. scope = get_isolation_scope()
  130. current_scope = get_current_scope()
  131. if current_scope is None:
  132. # just the current current scope is used for context manager
  133. current_scope = get_current_scope()
  134. self._stack = [(client, scope)] # type: ignore
  135. self._last_event_id = None # type: Optional[str]
  136. self._old_hubs = [] # type: List[Hub]
  137. self._old_current_scopes = [] # type: List[Scope]
  138. self._old_isolation_scopes = [] # type: List[Scope]
  139. self._current_scope = current_scope # type: Scope
  140. self._scope = scope # type: Scope
  141. def __enter__(self):
  142. # type: () -> Hub
  143. self._old_hubs.append(Hub.current)
  144. _local.set(self)
  145. current_scope = get_current_scope()
  146. self._old_current_scopes.append(current_scope)
  147. scope._current_scope.set(self._current_scope)
  148. isolation_scope = get_isolation_scope()
  149. self._old_isolation_scopes.append(isolation_scope)
  150. scope._isolation_scope.set(self._scope)
  151. return self
  152. def __exit__(
  153. self,
  154. exc_type, # type: Optional[type]
  155. exc_value, # type: Optional[BaseException]
  156. tb, # type: Optional[Any]
  157. ):
  158. # type: (...) -> None
  159. old = self._old_hubs.pop()
  160. _local.set(old)
  161. old_current_scope = self._old_current_scopes.pop()
  162. scope._current_scope.set(old_current_scope)
  163. old_isolation_scope = self._old_isolation_scopes.pop()
  164. scope._isolation_scope.set(old_isolation_scope)
  165. def run(
  166. self, callback # type: Callable[[], T]
  167. ):
  168. # type: (...) -> T
  169. """
  170. .. deprecated:: 2.0.0
  171. This function is deprecated and will be removed in a future release.
  172. Runs a callback in the context of the hub. Alternatively the
  173. with statement can be used on the hub directly.
  174. """
  175. with self:
  176. return callback()
  177. def get_integration(
  178. self, name_or_class # type: Union[str, Type[Integration]]
  179. ):
  180. # type: (...) -> Any
  181. """
  182. .. deprecated:: 2.0.0
  183. This function is deprecated and will be removed in a future release.
  184. Please use :py:meth:`sentry_sdk.client._Client.get_integration` instead.
  185. Returns the integration for this hub by name or class. If there
  186. is no client bound or the client does not have that integration
  187. then `None` is returned.
  188. If the return value is not `None` the hub is guaranteed to have a
  189. client attached.
  190. """
  191. return get_client().get_integration(name_or_class)
  192. @property
  193. def client(self):
  194. # type: () -> Optional[BaseClient]
  195. """
  196. .. deprecated:: 2.0.0
  197. This property is deprecated and will be removed in a future release.
  198. Please use :py:func:`sentry_sdk.api.get_client` instead.
  199. Returns the current client on the hub.
  200. """
  201. client = get_client()
  202. if not client.is_active():
  203. return None
  204. return client
  205. @property
  206. def scope(self):
  207. # type: () -> Scope
  208. """
  209. .. deprecated:: 2.0.0
  210. This property is deprecated and will be removed in a future release.
  211. Returns the current scope on the hub.
  212. """
  213. return get_isolation_scope()
  214. def last_event_id(self):
  215. # type: () -> Optional[str]
  216. """
  217. Returns the last event ID.
  218. .. deprecated:: 1.40.5
  219. This function is deprecated and will be removed in a future release. The functions `capture_event`, `capture_message`, and `capture_exception` return the event ID directly.
  220. """
  221. logger.warning(
  222. "Deprecated: last_event_id is deprecated. This will be removed in the future. The functions `capture_event`, `capture_message`, and `capture_exception` return the event ID directly."
  223. )
  224. return self._last_event_id
  225. def bind_client(
  226. self, new # type: Optional[BaseClient]
  227. ):
  228. # type: (...) -> None
  229. """
  230. .. deprecated:: 2.0.0
  231. This function is deprecated and will be removed in a future release.
  232. Please use :py:meth:`sentry_sdk.Scope.set_client` instead.
  233. Binds a new client to the hub.
  234. """
  235. get_global_scope().set_client(new)
  236. def capture_event(self, event, hint=None, scope=None, **scope_kwargs):
  237. # type: (Event, Optional[Hint], Optional[Scope], Any) -> Optional[str]
  238. """
  239. .. deprecated:: 2.0.0
  240. This function is deprecated and will be removed in a future release.
  241. Please use :py:meth:`sentry_sdk.Scope.capture_event` instead.
  242. Captures an event.
  243. Alias of :py:meth:`sentry_sdk.Scope.capture_event`.
  244. :param event: A ready-made event that can be directly sent to Sentry.
  245. :param hint: Contains metadata about the event that can be read from `before_send`, such as the original exception object or a HTTP request object.
  246. :param scope: An optional :py:class:`sentry_sdk.Scope` to apply to events.
  247. The `scope` and `scope_kwargs` parameters are mutually exclusive.
  248. :param scope_kwargs: Optional data to apply to event.
  249. For supported `**scope_kwargs` see :py:meth:`sentry_sdk.Scope.update_from_kwargs`.
  250. The `scope` and `scope_kwargs` parameters are mutually exclusive.
  251. """
  252. last_event_id = get_current_scope().capture_event(
  253. event, hint, scope=scope, **scope_kwargs
  254. )
  255. is_transaction = event.get("type") == "transaction"
  256. if last_event_id is not None and not is_transaction:
  257. self._last_event_id = last_event_id
  258. return last_event_id
  259. def capture_message(self, message, level=None, scope=None, **scope_kwargs):
  260. # type: (str, Optional[LogLevelStr], Optional[Scope], Any) -> Optional[str]
  261. """
  262. .. deprecated:: 2.0.0
  263. This function is deprecated and will be removed in a future release.
  264. Please use :py:meth:`sentry_sdk.Scope.capture_message` instead.
  265. Captures a message.
  266. Alias of :py:meth:`sentry_sdk.Scope.capture_message`.
  267. :param message: The string to send as the message to Sentry.
  268. :param level: If no level is provided, the default level is `info`.
  269. :param scope: An optional :py:class:`sentry_sdk.Scope` to apply to events.
  270. The `scope` and `scope_kwargs` parameters are mutually exclusive.
  271. :param scope_kwargs: Optional data to apply to event.
  272. For supported `**scope_kwargs` see :py:meth:`sentry_sdk.Scope.update_from_kwargs`.
  273. The `scope` and `scope_kwargs` parameters are mutually exclusive.
  274. :returns: An `event_id` if the SDK decided to send the event (see :py:meth:`sentry_sdk.client._Client.capture_event`).
  275. """
  276. last_event_id = get_current_scope().capture_message(
  277. message, level=level, scope=scope, **scope_kwargs
  278. )
  279. if last_event_id is not None:
  280. self._last_event_id = last_event_id
  281. return last_event_id
  282. def capture_exception(self, error=None, scope=None, **scope_kwargs):
  283. # type: (Optional[Union[BaseException, ExcInfo]], Optional[Scope], Any) -> Optional[str]
  284. """
  285. .. deprecated:: 2.0.0
  286. This function is deprecated and will be removed in a future release.
  287. Please use :py:meth:`sentry_sdk.Scope.capture_exception` instead.
  288. Captures an exception.
  289. Alias of :py:meth:`sentry_sdk.Scope.capture_exception`.
  290. :param error: An exception to capture. If `None`, `sys.exc_info()` will be used.
  291. :param scope: An optional :py:class:`sentry_sdk.Scope` to apply to events.
  292. The `scope` and `scope_kwargs` parameters are mutually exclusive.
  293. :param scope_kwargs: Optional data to apply to event.
  294. For supported `**scope_kwargs` see :py:meth:`sentry_sdk.Scope.update_from_kwargs`.
  295. The `scope` and `scope_kwargs` parameters are mutually exclusive.
  296. :returns: An `event_id` if the SDK decided to send the event (see :py:meth:`sentry_sdk.client._Client.capture_event`).
  297. """
  298. last_event_id = get_current_scope().capture_exception(
  299. error, scope=scope, **scope_kwargs
  300. )
  301. if last_event_id is not None:
  302. self._last_event_id = last_event_id
  303. return last_event_id
  304. def add_breadcrumb(self, crumb=None, hint=None, **kwargs):
  305. # type: (Optional[Breadcrumb], Optional[BreadcrumbHint], Any) -> None
  306. """
  307. .. deprecated:: 2.0.0
  308. This function is deprecated and will be removed in a future release.
  309. Please use :py:meth:`sentry_sdk.Scope.add_breadcrumb` instead.
  310. Adds a breadcrumb.
  311. :param crumb: Dictionary with the data as the sentry v7/v8 protocol expects.
  312. :param hint: An optional value that can be used by `before_breadcrumb`
  313. to customize the breadcrumbs that are emitted.
  314. """
  315. get_isolation_scope().add_breadcrumb(crumb, hint, **kwargs)
  316. def start_span(self, instrumenter=INSTRUMENTER.SENTRY, **kwargs):
  317. # type: (str, Any) -> Span
  318. """
  319. .. deprecated:: 2.0.0
  320. This function is deprecated and will be removed in a future release.
  321. Please use :py:meth:`sentry_sdk.Scope.start_span` instead.
  322. Start a span whose parent is the currently active span or transaction, if any.
  323. The return value is a :py:class:`sentry_sdk.tracing.Span` instance,
  324. typically used as a context manager to start and stop timing in a `with`
  325. block.
  326. Only spans contained in a transaction are sent to Sentry. Most
  327. integrations start a transaction at the appropriate time, for example
  328. for every incoming HTTP request. Use
  329. :py:meth:`sentry_sdk.start_transaction` to start a new transaction when
  330. one is not already in progress.
  331. For supported `**kwargs` see :py:class:`sentry_sdk.tracing.Span`.
  332. """
  333. scope = get_current_scope()
  334. return scope.start_span(instrumenter=instrumenter, **kwargs)
  335. def start_transaction(
  336. self,
  337. transaction=None,
  338. instrumenter=INSTRUMENTER.SENTRY,
  339. custom_sampling_context=None,
  340. **kwargs
  341. ):
  342. # type: (Optional[Transaction], str, Optional[SamplingContext], Unpack[TransactionKwargs]) -> Union[Transaction, NoOpSpan]
  343. """
  344. .. deprecated:: 2.0.0
  345. This function is deprecated and will be removed in a future release.
  346. Please use :py:meth:`sentry_sdk.Scope.start_transaction` instead.
  347. Start and return a transaction.
  348. Start an existing transaction if given, otherwise create and start a new
  349. transaction with kwargs.
  350. This is the entry point to manual tracing instrumentation.
  351. A tree structure can be built by adding child spans to the transaction,
  352. and child spans to other spans. To start a new child span within the
  353. transaction or any span, call the respective `.start_child()` method.
  354. Every child span must be finished before the transaction is finished,
  355. otherwise the unfinished spans are discarded.
  356. When used as context managers, spans and transactions are automatically
  357. finished at the end of the `with` block. If not using context managers,
  358. call the `.finish()` method.
  359. When the transaction is finished, it will be sent to Sentry with all its
  360. finished child spans.
  361. For supported `**kwargs` see :py:class:`sentry_sdk.tracing.Transaction`.
  362. """
  363. scope = get_current_scope()
  364. # For backwards compatibility, we allow passing the scope as the hub.
  365. # We need a major release to make this nice. (if someone searches the code: deprecated)
  366. # Type checking disabled for this line because deprecated keys are not allowed in the type signature.
  367. kwargs["hub"] = scope # type: ignore
  368. return scope.start_transaction(
  369. transaction, instrumenter, custom_sampling_context, **kwargs
  370. )
  371. def continue_trace(self, environ_or_headers, op=None, name=None, source=None):
  372. # type: (Dict[str, Any], Optional[str], Optional[str], Optional[str]) -> Transaction
  373. """
  374. .. deprecated:: 2.0.0
  375. This function is deprecated and will be removed in a future release.
  376. Please use :py:meth:`sentry_sdk.Scope.continue_trace` instead.
  377. Sets the propagation context from environment or headers and returns a transaction.
  378. """
  379. return get_isolation_scope().continue_trace(
  380. environ_or_headers=environ_or_headers, op=op, name=name, source=source
  381. )
  382. @overload
  383. def push_scope(
  384. self, callback=None # type: Optional[None]
  385. ):
  386. # type: (...) -> ContextManager[Scope]
  387. pass
  388. @overload
  389. def push_scope( # noqa: F811
  390. self, callback # type: Callable[[Scope], None]
  391. ):
  392. # type: (...) -> None
  393. pass
  394. def push_scope( # noqa
  395. self,
  396. callback=None, # type: Optional[Callable[[Scope], None]]
  397. continue_trace=True, # type: bool
  398. ):
  399. # type: (...) -> Optional[ContextManager[Scope]]
  400. """
  401. .. deprecated:: 2.0.0
  402. This function is deprecated and will be removed in a future release.
  403. Pushes a new layer on the scope stack.
  404. :param callback: If provided, this method pushes a scope, calls
  405. `callback`, and pops the scope again.
  406. :returns: If no `callback` is provided, a context manager that should
  407. be used to pop the scope again.
  408. """
  409. if callback is not None:
  410. with self.push_scope() as scope:
  411. callback(scope)
  412. return None
  413. return _ScopeManager(self)
  414. def pop_scope_unsafe(self):
  415. # type: () -> Tuple[Optional[Client], Scope]
  416. """
  417. .. deprecated:: 2.0.0
  418. This function is deprecated and will be removed in a future release.
  419. Pops a scope layer from the stack.
  420. Try to use the context manager :py:meth:`push_scope` instead.
  421. """
  422. rv = self._stack.pop()
  423. assert self._stack, "stack must have at least one layer"
  424. return rv
  425. @overload
  426. def configure_scope(
  427. self, callback=None # type: Optional[None]
  428. ):
  429. # type: (...) -> ContextManager[Scope]
  430. pass
  431. @overload
  432. def configure_scope( # noqa: F811
  433. self, callback # type: Callable[[Scope], None]
  434. ):
  435. # type: (...) -> None
  436. pass
  437. def configure_scope( # noqa
  438. self,
  439. callback=None, # type: Optional[Callable[[Scope], None]]
  440. continue_trace=True, # type: bool
  441. ):
  442. # type: (...) -> Optional[ContextManager[Scope]]
  443. """
  444. .. deprecated:: 2.0.0
  445. This function is deprecated and will be removed in a future release.
  446. Reconfigures the scope.
  447. :param callback: If provided, call the callback with the current scope.
  448. :returns: If no callback is provided, returns a context manager that returns the scope.
  449. """
  450. scope = get_isolation_scope()
  451. if continue_trace:
  452. scope.generate_propagation_context()
  453. if callback is not None:
  454. # TODO: used to return None when client is None. Check if this changes behavior.
  455. callback(scope)
  456. return None
  457. @contextmanager
  458. def inner():
  459. # type: () -> Generator[Scope, None, None]
  460. yield scope
  461. return inner()
  462. def start_session(
  463. self, session_mode="application" # type: str
  464. ):
  465. # type: (...) -> None
  466. """
  467. .. deprecated:: 2.0.0
  468. This function is deprecated and will be removed in a future release.
  469. Please use :py:meth:`sentry_sdk.Scope.start_session` instead.
  470. Starts a new session.
  471. """
  472. get_isolation_scope().start_session(
  473. session_mode=session_mode,
  474. )
  475. def end_session(self):
  476. # type: (...) -> None
  477. """
  478. .. deprecated:: 2.0.0
  479. This function is deprecated and will be removed in a future release.
  480. Please use :py:meth:`sentry_sdk.Scope.end_session` instead.
  481. Ends the current session if there is one.
  482. """
  483. get_isolation_scope().end_session()
  484. def stop_auto_session_tracking(self):
  485. # type: (...) -> None
  486. """
  487. .. deprecated:: 2.0.0
  488. This function is deprecated and will be removed in a future release.
  489. Please use :py:meth:`sentry_sdk.Scope.stop_auto_session_tracking` instead.
  490. Stops automatic session tracking.
  491. This temporarily session tracking for the current scope when called.
  492. To resume session tracking call `resume_auto_session_tracking`.
  493. """
  494. get_isolation_scope().stop_auto_session_tracking()
  495. def resume_auto_session_tracking(self):
  496. # type: (...) -> None
  497. """
  498. .. deprecated:: 2.0.0
  499. This function is deprecated and will be removed in a future release.
  500. Please use :py:meth:`sentry_sdk.Scope.resume_auto_session_tracking` instead.
  501. Resumes automatic session tracking for the current scope if
  502. disabled earlier. This requires that generally automatic session
  503. tracking is enabled.
  504. """
  505. get_isolation_scope().resume_auto_session_tracking()
  506. def flush(
  507. self,
  508. timeout=None, # type: Optional[float]
  509. callback=None, # type: Optional[Callable[[int, float], None]]
  510. ):
  511. # type: (...) -> None
  512. """
  513. .. deprecated:: 2.0.0
  514. This function is deprecated and will be removed in a future release.
  515. Please use :py:meth:`sentry_sdk.client._Client.flush` instead.
  516. Alias for :py:meth:`sentry_sdk.client._Client.flush`
  517. """
  518. return get_client().flush(timeout=timeout, callback=callback)
  519. def get_traceparent(self):
  520. # type: () -> Optional[str]
  521. """
  522. .. deprecated:: 2.0.0
  523. This function is deprecated and will be removed in a future release.
  524. Please use :py:meth:`sentry_sdk.Scope.get_traceparent` instead.
  525. Returns the traceparent either from the active span or from the scope.
  526. """
  527. current_scope = get_current_scope()
  528. traceparent = current_scope.get_traceparent()
  529. if traceparent is None:
  530. isolation_scope = get_isolation_scope()
  531. traceparent = isolation_scope.get_traceparent()
  532. return traceparent
  533. def get_baggage(self):
  534. # type: () -> Optional[str]
  535. """
  536. .. deprecated:: 2.0.0
  537. This function is deprecated and will be removed in a future release.
  538. Please use :py:meth:`sentry_sdk.Scope.get_baggage` instead.
  539. Returns Baggage either from the active span or from the scope.
  540. """
  541. current_scope = get_current_scope()
  542. baggage = current_scope.get_baggage()
  543. if baggage is None:
  544. isolation_scope = get_isolation_scope()
  545. baggage = isolation_scope.get_baggage()
  546. if baggage is not None:
  547. return baggage.serialize()
  548. return None
  549. def iter_trace_propagation_headers(self, span=None):
  550. # type: (Optional[Span]) -> Generator[Tuple[str, str], None, None]
  551. """
  552. .. deprecated:: 2.0.0
  553. This function is deprecated and will be removed in a future release.
  554. Please use :py:meth:`sentry_sdk.Scope.iter_trace_propagation_headers` instead.
  555. Return HTTP headers which allow propagation of trace data. Data taken
  556. from the span representing the request, if available, or the current
  557. span on the scope if not.
  558. """
  559. return get_current_scope().iter_trace_propagation_headers(
  560. span=span,
  561. )
  562. def trace_propagation_meta(self, span=None):
  563. # type: (Optional[Span]) -> str
  564. """
  565. .. deprecated:: 2.0.0
  566. This function is deprecated and will be removed in a future release.
  567. Please use :py:meth:`sentry_sdk.Scope.trace_propagation_meta` instead.
  568. Return meta tags which should be injected into HTML templates
  569. to allow propagation of trace information.
  570. """
  571. if span is not None:
  572. logger.warning(
  573. "The parameter `span` in trace_propagation_meta() is deprecated and will be removed in the future."
  574. )
  575. return get_current_scope().trace_propagation_meta(
  576. span=span,
  577. )
  578. with _suppress_hub_deprecation_warning():
  579. # Suppress deprecation warning for the Hub here, since we still always
  580. # import this module.
  581. GLOBAL_HUB = Hub()
  582. _local.set(GLOBAL_HUB)
  583. # Circular imports
  584. from sentry_sdk import scope