Skip to content

Add async task background worker #4591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: srothh/worker-class-hierarchy
Choose a base branch
from

Conversation

srothh
Copy link
Member

@srothh srothh commented Jul 17, 2025

Add a new implementation of the transport background worker based on an async task. This worker mostly mirrors the same functionality as the thread-based worker, with the exception that it exposes a non-blocking async flush. Furthermore, the worker itself is not thread-safe and should be called using run_coroutine_threadsafe or similar when called from another thread.

GH-4581

Copy link

codecov bot commented Jul 17, 2025

Codecov Report

Attention: Patch coverage is 17.02128% with 78 lines in your changes missing coverage. Please review.

Project coverage is 84.54%. Comparing base (2896602) to head (1a129f7).

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
sentry_sdk/worker.py 17.02% 78 Missing ⚠️
Additional details and impacted files
@@                        Coverage Diff                        @@
##           srothh/worker-class-hierarchy    #4591      +/-   ##
=================================================================
- Coverage                          84.95%   84.54%   -0.42%     
=================================================================
  Files                                158      158              
  Lines                              15403    15497      +94     
  Branches                            2432     2443      +11     
=================================================================
+ Hits                               13086    13102      +16     
- Misses                              1564     1642      +78     
  Partials                             753      753              
Files with missing lines Coverage Δ
sentry_sdk/worker.py 51.70% <17.02%> (-29.38%) ⬇️

@srothh srothh force-pushed the srothh/worker-class-hierarchy branch from 1261319 to 2896602 Compare July 21, 2025 09:58
srothh added 9 commits July 21, 2025 12:41
Add a new implementation of the worker interface, implementing the worker as an async task. This is
to be used by the upcoming async transport.

GH-4581
Refactor the flush method in the async worker to use the async_flush coroutine.

GH-4581
…unctions

Add a check to see wheter callbacks are awaitable coroutines or functions, as coroutines need to be awaited.

GH-4581
…coroutines

Coroutines do not return None, therefore it is necessary to consider this in the callback parameter of the worker. Previously,
only callbacks with return Type None were accepted.

GH-4581
Enable concurrent callbacks on async task worker by firing them as a task rather than awaiting them. A done callback handles the necessary queue and exception logic.

GH-4581
Changed kill to also use the _TERMINATOR sentinel, so the queue is still drained to this point on kill instead of cancelled immediately. This should also fix potential race conditions with flush_async.

GH-4581
Add proper type annotation to worker task list to fix linting problems

GH-4581
@srothh srothh force-pushed the srothh/async-task-worker branch from 7ada4b3 to 1a129f7 Compare July 21, 2025 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant