12
12
import urllib3
13
13
import certifi
14
14
15
+ import sentry_sdk
15
16
from sentry_sdk .consts import EndpointType
16
17
from sentry_sdk .utils import Dsn , logger , capture_internal_exceptions
17
18
from sentry_sdk .worker import BackgroundWorker
33
34
from urllib3 .poolmanager import PoolManager
34
35
from urllib3 .poolmanager import ProxyManager
35
36
36
- from sentry_sdk ._types import Event
37
-
38
- DataCategory = Optional [str ]
39
-
37
+ from sentry_sdk ._types import Event , EventDataCategory
40
38
41
39
KEEP_ALIVE_SOCKET_OPTIONS = []
42
40
for option in [
@@ -133,7 +131,7 @@ def kill(self):
133
131
def record_lost_event (
134
132
self ,
135
133
reason , # type: str
136
- data_category = None , # type: Optional[str ]
134
+ data_category = None , # type: Optional[EventDataCategory ]
137
135
item = None , # type: Optional[Item]
138
136
):
139
137
# type: (...) -> None
@@ -155,7 +153,7 @@ def __del__(self):
155
153
156
154
157
155
def _parse_rate_limits (header , now = None ):
158
- # type: (Any, Optional[datetime]) -> Iterable[Tuple[DataCategory , datetime]]
156
+ # type: (Any, Optional[datetime]) -> Iterable[Tuple[Optional[EventDataCategory] , datetime]]
159
157
if now is None :
160
158
now = datetime .now (timezone .utc )
161
159
@@ -195,11 +193,11 @@ def __init__(
195
193
self .options = options # type: Dict[str, Any]
196
194
self ._worker = BackgroundWorker (queue_size = options ["transport_queue_size" ])
197
195
self ._auth = self .parsed_dsn .to_auth ("sentry.python/%s" % VERSION )
198
- self ._disabled_until = {} # type: Dict[DataCategory , datetime]
196
+ self ._disabled_until = {} # type: Dict[Optional[EventDataCategory] , datetime]
199
197
self ._retry = urllib3 .util .Retry ()
200
198
self ._discarded_events = defaultdict (
201
199
int
202
- ) # type: DefaultDict[Tuple[str , str], int]
200
+ ) # type: DefaultDict[Tuple[EventDataCategory , str], int]
203
201
self ._last_client_report_sent = time .time ()
204
202
205
203
compresslevel = options .get ("_experiments" , {}).get (
@@ -218,14 +216,13 @@ def __init__(
218
216
proxy_headers = options ["proxy_headers" ],
219
217
)
220
218
221
- from sentry_sdk import Hub
222
-
223
- self .hub_cls = Hub
219
+ # Backwards compatibility for deprecated `self.hub_class` attribute
220
+ self ._hub_cls = sentry_sdk .Hub
224
221
225
222
def record_lost_event (
226
223
self ,
227
224
reason , # type: str
228
- data_category = None , # type: Optional[str ]
225
+ data_category = None , # type: Optional[EventDataCategory ]
229
226
item = None , # type: Optional[Item]
230
227
):
231
228
# type: (...) -> None
@@ -548,14 +545,11 @@ def capture_envelope(
548
545
self , envelope # type: Envelope
549
546
):
550
547
# type: (...) -> None
551
- hub = self .hub_cls .current
552
-
553
548
def send_envelope_wrapper ():
554
549
# type: () -> None
555
- with hub :
556
- with capture_internal_exceptions ():
557
- self ._send_envelope (envelope )
558
- self ._flush_client_reports ()
550
+ with capture_internal_exceptions ():
551
+ self ._send_envelope (envelope )
552
+ self ._flush_client_reports ()
559
553
560
554
if not self ._worker .submit (send_envelope_wrapper ):
561
555
self .on_dropped_event ("full_queue" )
@@ -579,6 +573,30 @@ def kill(self):
579
573
logger .debug ("Killing HTTP transport" )
580
574
self ._worker .kill ()
581
575
576
+ @staticmethod
577
+ def _warn_hub_cls ():
578
+ # type: () -> None
579
+ """Convenience method to warn users about the deprecation of the `hub_cls` attribute."""
580
+ warnings .warn (
581
+ "The `hub_cls` attribute is deprecated and will be removed in a future release." ,
582
+ DeprecationWarning ,
583
+ stacklevel = 3 ,
584
+ )
585
+
586
+ @property
587
+ def hub_cls (self ):
588
+ # type: () -> type[sentry_sdk.Hub]
589
+ """DEPRECATED: This attribute is deprecated and will be removed in a future release."""
590
+ HttpTransport ._warn_hub_cls ()
591
+ return self ._hub_cls
592
+
593
+ @hub_cls .setter
594
+ def hub_cls (self , value ):
595
+ # type: (type[sentry_sdk.Hub]) -> None
596
+ """DEPRECATED: This attribute is deprecated and will be removed in a future release."""
597
+ HttpTransport ._warn_hub_cls ()
598
+ self ._hub_cls = value
599
+
582
600
583
601
class _FunctionTransport (Transport ):
584
602
"""
0 commit comments