Skip to content

Commit 1ac4196

Browse files
BYKclaude
andcommitted
fix: Guard isinstance AsyncHttpTransport with ASYNC_TRANSPORT_ENABLED
When httpcore[asyncio] is not installed, AsyncHttpTransport is aliased to HttpTransport. isinstance(transport, AsyncHttpTransport) would then be True for ALL transports, causing close()/flush() to skip the sync flush path. Guard with ASYNC_TRANSPORT_ENABLED flag. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 38f97c2 commit 1ac4196

2 files changed

Lines changed: 25 additions & 7 deletions

File tree

sentry_sdk/client.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@
3131
from sentry_sdk.serializer import serialize
3232
from sentry_sdk.tracing import trace
3333
from sentry_sdk.tracing_utils import has_span_streaming_enabled
34-
from sentry_sdk.transport import HttpTransportCore, make_transport, AsyncHttpTransport
34+
from sentry_sdk.transport import (
35+
ASYNC_TRANSPORT_ENABLED,
36+
HttpTransportCore,
37+
make_transport,
38+
AsyncHttpTransport,
39+
)
3540
from sentry_sdk.consts import (
3641
SPANDATA,
3742
DEFAULT_MAX_VALUE_LENGTH,
@@ -1037,7 +1042,9 @@ def close(
10371042
semantics as :py:meth:`Client.flush`.
10381043
"""
10391044
if self.transport is not None:
1040-
if isinstance(self.transport, AsyncHttpTransport):
1045+
if ASYNC_TRANSPORT_ENABLED and isinstance(
1046+
self.transport, AsyncHttpTransport
1047+
):
10411048
logger.warning(
10421049
"close() used with AsyncHttpTransport. "
10431050
"Prefer close_async() for graceful async shutdown. "
@@ -1060,7 +1067,10 @@ async def close_async(
10601067
semantics as :py:meth:`Client.flush_async`.
10611068
"""
10621069
if self.transport is not None:
1063-
if not isinstance(self.transport, AsyncHttpTransport):
1070+
if not (
1071+
ASYNC_TRANSPORT_ENABLED
1072+
and isinstance(self.transport, AsyncHttpTransport)
1073+
):
10641074
logger.debug(
10651075
"close_async() used with non-async transport, aborting. Please use close() instead."
10661076
)
@@ -1085,7 +1095,9 @@ def flush(
10851095
:param callback: Is invoked with the number of pending events and the configured timeout.
10861096
"""
10871097
if self.transport is not None:
1088-
if isinstance(self.transport, AsyncHttpTransport):
1098+
if ASYNC_TRANSPORT_ENABLED and isinstance(
1099+
self.transport, AsyncHttpTransport
1100+
):
10891101
logger.warning(
10901102
"flush() used with AsyncHttpTransport. Please use flush_async() instead."
10911103
)
@@ -1109,7 +1121,10 @@ async def flush_async(
11091121
:param callback: Is invoked with the number of pending events and the configured timeout.
11101122
"""
11111123
if self.transport is not None:
1112-
if not isinstance(self.transport, AsyncHttpTransport):
1124+
if not (
1125+
ASYNC_TRANSPORT_ENABLED
1126+
and isinstance(self.transport, AsyncHttpTransport)
1127+
):
11131128
logger.debug(
11141129
"flush_async() used with non-async transport, aborting. Please use flush() instead."
11151130
)

sentry_sdk/integrations/asyncio.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
reraise,
1212
is_internal_task,
1313
)
14-
from sentry_sdk.transport import AsyncHttpTransport
14+
from sentry_sdk.transport import ASYNC_TRANSPORT_ENABLED, AsyncHttpTransport
1515

1616
try:
1717
import asyncio
@@ -68,7 +68,10 @@ async def _flush() -> None:
6868
return
6969

7070
try:
71-
if not isinstance(client.transport, AsyncHttpTransport):
71+
if not (
72+
ASYNC_TRANSPORT_ENABLED
73+
and isinstance(client.transport, AsyncHttpTransport)
74+
):
7275
return
7376

7477
await client.close_async()

0 commit comments

Comments
 (0)