Skip to content

Commit c277ed5

Browse files
mitsuhikountitaker
andauthored
feat: Expose transport queue size to options and bump queue size (#942)
Co-authored-by: Markus Unterwaditzer <[email protected]>
1 parent 7dad958 commit c277ed5

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

sentry_sdk/consts.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from sentry_sdk._types import MYPY
22

33
if MYPY:
4+
import sentry_sdk
5+
46
from typing import Optional
57
from typing import Callable
68
from typing import Union
@@ -11,7 +13,6 @@
1113
from typing import Sequence
1214
from typing_extensions import TypedDict
1315

14-
from sentry_sdk.transport import Transport
1516
from sentry_sdk.integrations import Integration
1617

1718
from sentry_sdk._types import (
@@ -36,6 +37,7 @@
3637
total=False,
3738
)
3839

40+
DEFAULT_QUEUE_SIZE = 100
3941
DEFAULT_MAX_BREADCRUMBS = 100
4042

4143

@@ -56,7 +58,8 @@ def __init__(
5658
in_app_exclude=[], # type: List[str] # noqa: B006
5759
default_integrations=True, # type: bool
5860
dist=None, # type: Optional[str]
59-
transport=None, # type: Optional[Union[Transport, Type[Transport], Callable[[Event], None]]]
61+
transport=None, # type: Optional[Union[sentry_sdk.transport.Transport, Type[sentry_sdk.transport.Transport], Callable[[Event], None]]]
62+
transport_queue_size=DEFAULT_QUEUE_SIZE, # type: int
6063
sample_rate=1.0, # type: float
6164
send_default_pii=False, # type: bool
6265
http_proxy=None, # type: Optional[str]

sentry_sdk/transport.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ def __init__(
126126

127127
Transport.__init__(self, options)
128128
assert self.parsed_dsn is not None
129-
self._worker = BackgroundWorker()
129+
self.options = options
130+
self._worker = BackgroundWorker(queue_size=options["transport_queue_size"])
130131
self._auth = self.parsed_dsn.to_auth("sentry.python/%s" % VERSION)
131132
self._disabled_until = {} # type: Dict[DataCategory, datetime]
132133
self._retry = urllib3.util.Retry()
133-
self.options = options
134134

135135
self._pool = self._make_pool(
136136
self.parsed_dsn,

sentry_sdk/worker.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from sentry_sdk._compat import check_thread_support
66
from sentry_sdk._queue import Queue, Full
77
from sentry_sdk.utils import logger
8+
from sentry_sdk.consts import DEFAULT_QUEUE_SIZE
89

910
from sentry_sdk._types import MYPY
1011

@@ -18,7 +19,7 @@
1819

1920

2021
class BackgroundWorker(object):
21-
def __init__(self, queue_size=30):
22+
def __init__(self, queue_size=DEFAULT_QUEUE_SIZE):
2223
# type: (int) -> None
2324
check_thread_support()
2425
self._queue = Queue(queue_size) # type: Queue
@@ -110,7 +111,11 @@ def submit(self, callback):
110111
try:
111112
self._queue.put_nowait(callback)
112113
except Full:
113-
logger.debug("background worker queue full, dropping event")
114+
self.on_full_queue(callback)
115+
116+
def on_full_queue(self, callback):
117+
# type: (Optional[Any]) -> None
118+
logger.debug("background worker queue full, dropping event")
114119

115120
def _target(self):
116121
# type: () -> None

0 commit comments

Comments
 (0)