Skip to content

Commit fce4404

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 0d54354 commit fce4404

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
@@ -173,7 +173,7 @@ def __init__(self: Self, options: Dict[str, Any]) -> None:
173173
Transport.__init__(self, options)
174174
assert self.parsed_dsn is not None
175175
self.options: Dict[str, Any] = options
176-
self._worker = BackgroundWorker(queue_size=options["transport_queue_size"])
176+
self._worker = self._create_worker(options)
177177
self._auth = self.parsed_dsn.to_auth("sentry.python/%s" % VERSION)
178178
self._disabled_until: Dict[Optional[str], datetime] = {}
179179
# We only use this Retry() class for the `get_retry_after` method it exposes
@@ -224,6 +224,10 @@ def __init__(self: Self, options: Dict[str, Any]) -> None:
224224
elif self._compression_algo == "br":
225225
self._compression_level = 4
226226

227+
def _create_worker(self: Self, options: Dict[str, Any]) -> Worker:
228+
# For now, we only support the threaded sync background worker.
229+
return BackgroundWorker(queue_size=options["transport_queue_size"])
230+
227231
def record_lost_event(
228232
self: Self,
229233
reason: str,

0 commit comments

Comments
 (0)