2025-12-01
This commit is contained in:
@@ -158,13 +158,6 @@ class Transport(ABC):
|
||||
# type: (Self) -> bool
|
||||
return True
|
||||
|
||||
def __del__(self):
|
||||
# type: (Self) -> None
|
||||
try:
|
||||
self.kill()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def _parse_rate_limits(header, now=None):
|
||||
# type: (str, Optional[datetime]) -> Iterable[Tuple[Optional[EventDataCategory], datetime]]
|
||||
@@ -178,17 +171,7 @@ def _parse_rate_limits(header, now=None):
|
||||
|
||||
retry_after = now + timedelta(seconds=int(retry_after_val))
|
||||
for category in categories and categories.split(";") or (None,):
|
||||
if category == "metric_bucket":
|
||||
try:
|
||||
namespaces = parameters[4].split(";")
|
||||
except IndexError:
|
||||
namespaces = []
|
||||
|
||||
if not namespaces or "custom" in namespaces:
|
||||
yield category, retry_after # type: ignore
|
||||
|
||||
else:
|
||||
yield category, retry_after # type: ignore
|
||||
yield category, retry_after # type: ignore
|
||||
except (LookupError, ValueError):
|
||||
continue
|
||||
|
||||
@@ -196,6 +179,8 @@ def _parse_rate_limits(header, now=None):
|
||||
class BaseHttpTransport(Transport):
|
||||
"""The base HTTP transport."""
|
||||
|
||||
TIMEOUT = 30 # seconds
|
||||
|
||||
def __init__(self, options):
|
||||
# type: (Self, Dict[str, Any]) -> None
|
||||
from sentry_sdk.consts import VERSION
|
||||
@@ -208,9 +193,7 @@ class BaseHttpTransport(Transport):
|
||||
self._disabled_until = {} # type: Dict[Optional[EventDataCategory], datetime]
|
||||
# We only use this Retry() class for the `get_retry_after` method it exposes
|
||||
self._retry = urllib3.util.Retry()
|
||||
self._discarded_events = defaultdict(
|
||||
int
|
||||
) # type: DefaultDict[Tuple[EventDataCategory, str], int]
|
||||
self._discarded_events = defaultdict(int) # type: DefaultDict[Tuple[EventDataCategory, str], int]
|
||||
self._last_client_report_sent = time.time()
|
||||
|
||||
self._pool = self._make_pool()
|
||||
@@ -424,12 +407,6 @@ class BaseHttpTransport(Transport):
|
||||
# type: (str) -> bool
|
||||
def _disabled(bucket):
|
||||
# type: (Any) -> bool
|
||||
|
||||
# The envelope item type used for metrics is statsd
|
||||
# whereas the rate limit category is metric_bucket
|
||||
if bucket == "statsd":
|
||||
bucket = "metric_bucket"
|
||||
|
||||
ts = self._disabled_until.get(bucket)
|
||||
return ts is not None and ts > datetime.now(timezone.utc)
|
||||
|
||||
@@ -554,7 +531,8 @@ class BaseHttpTransport(Transport):
|
||||
raise NotImplementedError()
|
||||
|
||||
def capture_envelope(
|
||||
self, envelope # type: Envelope
|
||||
self,
|
||||
envelope, # type: Envelope
|
||||
):
|
||||
# type: (...) -> None
|
||||
def send_envelope_wrapper():
|
||||
@@ -621,6 +599,7 @@ class HttpTransport(BaseHttpTransport):
|
||||
options = {
|
||||
"num_pools": 2 if num_pools is None else int(num_pools),
|
||||
"cert_reqs": "CERT_REQUIRED",
|
||||
"timeout": urllib3.Timeout(total=self.TIMEOUT),
|
||||
}
|
||||
|
||||
socket_options = None # type: Optional[List[Tuple[int, int, int | bytes]]]
|
||||
@@ -736,6 +715,8 @@ else:
|
||||
class Http2Transport(BaseHttpTransport): # type: ignore
|
||||
"""The HTTP2 transport based on httpcore."""
|
||||
|
||||
TIMEOUT = 15
|
||||
|
||||
if TYPE_CHECKING:
|
||||
_pool: Union[
|
||||
httpcore.SOCKSProxy, httpcore.HTTPProxy, httpcore.ConnectionPool
|
||||
@@ -765,6 +746,14 @@ else:
|
||||
self._auth.get_api_url(endpoint_type),
|
||||
content=body,
|
||||
headers=headers, # type: ignore
|
||||
extensions={
|
||||
"timeout": {
|
||||
"pool": self.TIMEOUT,
|
||||
"connect": self.TIMEOUT,
|
||||
"write": self.TIMEOUT,
|
||||
"read": self.TIMEOUT,
|
||||
}
|
||||
},
|
||||
)
|
||||
return response
|
||||
|
||||
@@ -856,14 +845,16 @@ class _FunctionTransport(Transport):
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self, func # type: Callable[[Event], None]
|
||||
self,
|
||||
func, # type: Callable[[Event], None]
|
||||
):
|
||||
# type: (...) -> None
|
||||
Transport.__init__(self)
|
||||
self._func = func
|
||||
|
||||
def capture_event(
|
||||
self, event # type: Event
|
||||
self,
|
||||
event, # type: Event
|
||||
):
|
||||
# type: (...) -> None
|
||||
self._func(event)
|
||||
@@ -885,9 +876,7 @@ def make_transport(options):
|
||||
use_http2_transport = options.get("_experiments", {}).get("transport_http2", False)
|
||||
|
||||
# By default, we use the http transport class
|
||||
transport_cls = (
|
||||
Http2Transport if use_http2_transport else HttpTransport
|
||||
) # type: Type[Transport]
|
||||
transport_cls = Http2Transport if use_http2_transport else HttpTransport # type: Type[Transport]
|
||||
|
||||
if isinstance(ref_transport, Transport):
|
||||
return ref_transport
|
||||
|
||||
Reference in New Issue
Block a user