Skip to content

feat(async transport): Add Async Transport implementation #4654

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 161 commits into
base: potel-base
Choose a base branch
from

Conversation

srothh
Copy link
Member

@srothh srothh commented Jul 31, 2025

Contains the complete implementation of the async transport, with potel-base merged into it again.

The async transport was initially implemented in the following PR's:

Transport Class Abstraction
Worker Class Abstraction
Async Task Worker
Async Transport Implementation
Async Transport SDK Integration

srothh added 30 commits July 21, 2025 11:44
…ted a sync transport HTTP subclass

Moved shared sync/async logic into a new superclass (HttpTransportCore), and moved sync transport specific code into a new subclass(BaseSyncHttpTransport), from which the current transport implementations inherit

Fixes GH-4568
Removed an unnecessary TODO message and reverted a class name change for BaseHTTPTransport.

GH-4568
Adds test coverage for the error handling path when HTTP requests return
error status codes.

GH-4568
Restore comments accidentally removed during a previous commit.
Refactored class names such that BaseHttpTransport now has the same functionality as before the hierarchy refactor

GH-4568
Add a new flush_async method in the Transport ABC. This is needed for the async transport, as calling it from the client
while preserving execution order in close will require flush to be a coroutine, not a function.

GH-4568
Move flush_async down to the specific async transport subclass. This makes more sense anyway, as
this will only be required by the async transport. If more async transports are expected,
another shared superclass can be created.

GH-4568
Add necessary type annotations to the core HttpTransport to accomodate for async transport.

GH-4568
Add an abstract bass class for implementation of the background worker. This was done to provide a shared interface for the current
implementation of a threaded worker in the sync context as well as the upcoming async task-based worker implementation.

GH-4578
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
Add a new flush_async method to worker ABC. This is necessary because the async transport cannot use a
synchronous blocking flush.

GH-4578
Move the flush_async down to the concrete subclass to not break existing testing. This makes sense,
as this will only really be needed by the async worker anyway and therefore is not shared logic.

GH-4578
Coroutines have a return value, however the current function signature for the worker methods does not
accomodate for this. Therefore, this signature was changed.

GH-4578
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
Add an implementation of Transport to work with the async background worker and HTTPCore async.

GH-4582
Async Transport now properly checks for the presence of the event loop in capture_envelop, and drops items
in case the event loop is no longer running for some reason.

GH-4582
Implement a kill method that properly shuts down the async transport. The httpcore async connection pool needs
to be explicitly shutdown at the end of its usage.

GH-4582
Fix type errors resulting from async override and missing type definition in the async transport.

GH-4582
Add a try/catch to ensure silent fail on kill in case the event loop shuts down.

GH-4582
Fix the event loop check in make_transport so that it does not throw a runtime error but rather falls back correctly.

GH-4582
srothh added 24 commits July 31, 2025 14:01
The callbacks passed to the worker from the transport are all async now, so this is currently not needed.

GH-4581
Add an implementation of Transport to work with the async background worker and HTTPCore async.

GH-4582
Async Transport now properly checks for the presence of the event loop in capture_envelop, and drops items
in case the event loop is no longer running for some reason.

GH-4582
Implement a kill method that properly shuts down the async transport. The httpcore async connection pool needs
to be explicitly shutdown at the end of its usage.

GH-4582
Fix type errors resulting from async override and missing type definition in the async transport.

GH-4582
Add a try/catch to ensure silent fail on kill in case the event loop shuts down.

GH-4582
Fix the event loop check in make_transport so that it does not throw a runtime error but rather falls back correctly.

GH-4582
Make kill optionally return a task for async transport. This allows for a blocking kill operation if the caller is in an async context.

GH-4582
@srothh srothh changed the base branch from master to potel-base July 31, 2025 14:00
Copy link

codecov bot commented Jul 31, 2025

❌ 1310 Tests Failed:

Tests completed Failed Passed Skipped
22067 1310 20757 1248
View the top 3 failed test(s) by shortest run time
tests.test_client::test_async_proxy[testcase0]
Stack Traces | 0.088s run time
tests/test_client.py:1700: in test_async_proxy
    assert isinstance(client.transport, AsyncHttpTransport)
E   assert False
E    +  where False = isinstance(<sentry_sdk.transport.HttpTransport object at 0x7f0c8c31df10>, AsyncHttpTransport)
E    +    where <sentry_sdk.transport.HttpTransport object at 0x7f0c8c31df10> = <sentry_sdk.client._Client object at 0x7f0ca08cd7f0>.transport
tests.test_client::test_async_proxy[testcase3]
Stack Traces | 0.089s run time
tests/test_client.py:1700: in test_async_proxy
    assert isinstance(client.transport, AsyncHttpTransport)
E   assert False
E    +  where False = isinstance(<sentry_sdk.transport.HttpTransport object at 0x7f0c8c311850>, AsyncHttpTransport)
E    +    where <sentry_sdk.transport.HttpTransport object at 0x7f0c8c311850> = <sentry_sdk.client._Client object at 0x7f0c8c311a30>.transport
tests.test_client::test_async_socks_proxy[testcase3]
Stack Traces | 0.089s run time
tests/test_client.py:1800: in test_async_socks_proxy
    assert isinstance(client.transport, AsyncHttpTransport)
E   assert False
E    +  where False = isinstance(<sentry_sdk.transport.HttpTransport object at 0x7f0ca0550520>, AsyncHttpTransport)
E    +    where <sentry_sdk.transport.HttpTransport object at 0x7f0ca0550520> = <sentry_sdk.client._Client object at 0x7f0ca0550c70>.transport

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@antonpirker antonpirker changed the title Complete Async Transport implementation feat(async transport): Add Async Transport implementation Aug 5, 2025
srothh added 2 commits August 5, 2025 13:52
Previously, the Async Transport fallback pointed to the sync superclass, which does not implment core methods. This now falls back to the correct, implemented sync transport

GH-4601
AsyncIO integration is necessary for the Async Transport to work properly. This adds a check that makes AsyncTransport fall back to Sync Transport if this is not configured.

GH-4601
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