Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 12 additions & 25 deletions sentry_sdk/integrations/asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
import sentry_sdk
from sentry_sdk.consts import OP
from sentry_sdk.integrations import DidNotEnable, Integration
from sentry_sdk.traces import StreamedSpan
from sentry_sdk.tracing import Span
from sentry_sdk.tracing_utils import has_span_streaming_enabled
from sentry_sdk.transport import AsyncHttpTransport
from sentry_sdk.utils import (
event_from_exception,
Expand All @@ -22,7 +19,7 @@
except ImportError:
raise DidNotEnable("asyncio not available")

from typing import TYPE_CHECKING, Optional, Union
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from collections.abc import Coroutine
Expand Down Expand Up @@ -149,28 +146,18 @@ async def _task_with_sentry_span_creation() -> "Any":
integration = client.get_integration(AsyncioIntegration)
task_spans = integration.task_spans if integration else False

span_ctx: "Optional[Union[StreamedSpan, Span]]" = None
is_span_streaming_enabled = has_span_streaming_enabled(client.options)

with sentry_sdk.isolation_scope():
if task_spans:
if is_span_streaming_enabled:
if sentry_sdk.traces.get_current_span() is not None:
span_ctx = sentry_sdk.traces.start_span(
name=get_name(coro),
attributes={
"sentry.op": OP.FUNCTION,
"sentry.origin": AsyncioIntegration.origin,
},
)
else:
span_ctx = sentry_sdk.start_span(
op=OP.FUNCTION,
name=get_name(coro),
origin=AsyncioIntegration.origin,
)

with span_ctx if span_ctx else nullcontext():
span_ctx = nullcontext()
if task_spans and sentry_sdk.traces.get_current_span() is not None:
span_ctx = sentry_sdk.traces.start_span(
name=get_name(coro),
attributes={
"sentry.op": OP.FUNCTION,
"sentry.origin": AsyncioIntegration.origin,
},
)

with span_ctx:
try:
result = await coro
except StopAsyncIteration:
Expand Down
Loading
Loading