Skip to content

Commit 5699c67

Browse files
committed
fix(transport): Add Async transport check for AsyncIO integration
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
1 parent b09186f commit 5699c67

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

sentry_sdk/transport.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,16 +1074,28 @@ def make_transport(options: Dict[str, Any]) -> Optional[Transport]:
10741074
use_http2_transport = options.get("_experiments", {}).get("transport_http2", False)
10751075
use_async_transport = options.get("_experiments", {}).get("transport_async", False)
10761076
# By default, we use the http transport class
1077+
sync_transport_cls = Http2Transport if use_http2_transport else HttpTransport
10771078
if use_async_transport:
10781079
try:
10791080
asyncio.get_running_loop()
1080-
transport_cls: Type[Transport] = AsyncHttpTransport
1081+
1082+
# Asyncio Integration is necessary for AsyncHttpTransport, as it patches the event loop close for this transport.
1083+
if any(
1084+
integration.__class__.__name__ == "AsyncioIntegration"
1085+
for integration in options.get("integrations", [])
1086+
):
1087+
transport_cls: Type[Transport] = AsyncHttpTransport
1088+
else:
1089+
logger.warning(
1090+
"AsyncHttpTransport requires the AsyncioIntegration to be enabled, falling back to sync transport."
1091+
)
1092+
transport_cls = sync_transport_cls
10811093
except RuntimeError:
10821094
# No event loop running, fall back to sync transport
10831095
logger.warning("No event loop running, falling back to sync transport.")
1084-
transport_cls = Http2Transport if use_http2_transport else HttpTransport
1096+
transport_cls = sync_transport_cls
10851097
else:
1086-
transport_cls = Http2Transport if use_http2_transport else HttpTransport
1098+
transport_cls = sync_transport_cls
10871099

10881100
if isinstance(ref_transport, Transport):
10891101
return ref_transport

0 commit comments

Comments
 (0)