Skip to content

Commit a6be4a3

Browse files
committed
ref(transport): Add _create_worker factory method to Transport
Add a new factory method instead of direct instatiation of the threaded background worker. This allows for easy extension to other types of workers, such as the upcoming task-based async worker. GH-4578
1 parent 5b68b31 commit a6be4a3

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

sentry_sdk/transport.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
from sentry_sdk.consts import EndpointType
3030
from sentry_sdk.utils import Dsn, logger, capture_internal_exceptions
31-
from sentry_sdk.worker import BackgroundWorker
31+
from sentry_sdk.worker import BackgroundWorker, Worker
3232
from sentry_sdk.envelope import Envelope, Item, PayloadRef
3333

3434
from typing import TYPE_CHECKING
@@ -179,7 +179,7 @@ def __init__(self: Self, options: Dict[str, Any]) -> None:
179179
Transport.__init__(self, options)
180180
assert self.parsed_dsn is not None
181181
self.options: Dict[str, Any] = options
182-
self._worker = BackgroundWorker(queue_size=options["transport_queue_size"])
182+
self._worker = self._create_worker(options)
183183
self._auth = self.parsed_dsn.to_auth("sentry.python/%s" % VERSION)
184184
self._disabled_until: Dict[Optional[str], datetime] = {}
185185
# We only use this Retry() class for the `get_retry_after` method it exposes
@@ -230,6 +230,10 @@ def __init__(self: Self, options: Dict[str, Any]) -> None:
230230
elif self._compression_algo == "br":
231231
self._compression_level = 4
232232

233+
def _create_worker(self: Self, options: Dict[str, Any]) -> Worker:
234+
# For now, we only support the threaded sync background worker.
235+
return BackgroundWorker(queue_size=options["transport_queue_size"])
236+
233237
def record_lost_event(
234238
self: Self,
235239
reason: str,

0 commit comments

Comments
 (0)