66
77from time import sleep , time
88from sentry_sdk ._queue import Queue , FullError
9- from sentry_sdk .utils import logger
9+ from sentry_sdk .utils import logger , mark_sentry_task_internal
1010from sentry_sdk .consts import DEFAULT_QUEUE_SIZE
1111
1212from typing import TYPE_CHECKING
@@ -231,7 +231,10 @@ def start(self) -> None:
231231 self ._loop = asyncio .get_running_loop ()
232232 if self ._queue is None :
233233 self ._queue = asyncio .Queue (maxsize = self ._queue_size )
234- self ._task = self ._loop .create_task (self ._target ())
234+ with mark_sentry_task_internal ():
235+ self ._task = self ._loop .create_task (
236+ self ._target (), name = "sentry_sdk_async_worker"
237+ )
235238 self ._task_for_pid = os .getpid ()
236239 except RuntimeError :
237240 # There is no event loop running
@@ -273,7 +276,11 @@ async def _wait_flush(self, timeout: float, callback: Optional[Any] = None) -> N
273276
274277 def flush (self , timeout : float , callback : Optional [Any ] = None ) -> Optional [asyncio .Task [None ]]: # type: ignore[override]
275278 if self .is_alive and timeout > 0.0 and self ._loop and self ._loop .is_running ():
276- return self ._loop .create_task (self ._wait_flush (timeout , callback ))
279+ with mark_sentry_task_internal ():
280+ return self ._loop .create_task (
281+ self ._wait_flush (timeout , callback ),
282+ name = "sentry_sdk_async_worker_flush" ,
283+ )
277284 return None
278285
279286 def submit (self , callback : Callable [[], Any ]) -> bool :
@@ -295,7 +302,11 @@ async def _target(self) -> None:
295302 self ._queue .task_done ()
296303 break
297304 # Firing tasks instead of awaiting them allows for concurrent requests
298- task = asyncio .create_task (self ._process_callback (callback ))
305+ with mark_sentry_task_internal ():
306+ task = asyncio .create_task (
307+ self ._process_callback (callback ),
308+ name = "sentry_sdk_async_worker_process_callback" ,
309+ )
299310 # Create a strong reference to the task so it can be cancelled on kill
300311 # and does not get garbage collected while running
301312 self ._active_tasks .add (task )
0 commit comments