1212import urllib3
1313import certifi
1414
15+ import sentry_sdk
1516from sentry_sdk .consts import EndpointType
1617from sentry_sdk .utils import Dsn , logger , capture_internal_exceptions
1718from sentry_sdk .worker import BackgroundWorker
3738
3839 DataCategory = Optional [str ]
3940
40-
4141KEEP_ALIVE_SOCKET_OPTIONS = []
4242for option in [
4343 (socket .SOL_SOCKET , lambda : getattr (socket , "SO_KEEPALIVE" ), 1 ), # noqa: B009
@@ -218,9 +218,8 @@ def __init__(
218218 proxy_headers = options ["proxy_headers" ],
219219 )
220220
221- from sentry_sdk import Hub
222-
223- self .hub_cls = Hub
221+ # Backwards compatibility for deprecated `self.hub_class` attribute
222+ self ._hub_cls = sentry_sdk .Hub
224223
225224 def record_lost_event (
226225 self ,
@@ -548,14 +547,11 @@ def capture_envelope(
548547 self , envelope # type: Envelope
549548 ):
550549 # type: (...) -> None
551- hub = self .hub_cls .current
552-
553550 def send_envelope_wrapper ():
554551 # type: () -> None
555- with hub :
556- with capture_internal_exceptions ():
557- self ._send_envelope (envelope )
558- self ._flush_client_reports ()
552+ with capture_internal_exceptions ():
553+ self ._send_envelope (envelope )
554+ self ._flush_client_reports ()
559555
560556 if not self ._worker .submit (send_envelope_wrapper ):
561557 self .on_dropped_event ("full_queue" )
@@ -579,6 +575,30 @@ def kill(self):
579575 logger .debug ("Killing HTTP transport" )
580576 self ._worker .kill ()
581577
578+ @staticmethod
579+ def _warn_hub_cls ():
580+ # type: () -> None
581+ """Convenience method to warn users about the deprecation of the `hub_cls` attribute."""
582+ warnings .warn (
583+ "The `hub_cls` attribute is deprecated and will be removed in a future release." ,
584+ DeprecationWarning ,
585+ stacklevel = 3 ,
586+ )
587+
588+ @property
589+ def hub_cls (self ):
590+ # type: () -> type[sentry_sdk.Hub]
591+ """DEPRECATED: This attribute is deprecated and will be removed in a future release."""
592+ HttpTransport ._warn_hub_cls ()
593+ return self ._hub_cls
594+
595+ @hub_cls .setter
596+ def hub_cls (self , value ):
597+ # type: (type[sentry_sdk.Hub]) -> None
598+ """DEPRECATED: This attribute is deprecated and will be removed in a future release."""
599+ HttpTransport ._warn_hub_cls ()
600+ self ._hub_cls = value
601+
582602
583603class _FunctionTransport (Transport ):
584604 """
0 commit comments