Skip to content

Commit f9faa2f

Browse files
.
1 parent 2c22c16 commit f9faa2f

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

sentry_sdk/integrations/sqlalchemy.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
parse_version,
88
)
99
from sentry_sdk.traces import StreamedSpan, SpanStatus
10+
from sentry_sdk.tracing import Span
1011

1112
try:
1213
from sqlalchemy.engine import Engine # type: ignore
@@ -23,8 +24,6 @@
2324
from typing import Optional
2425
from typing import Union
2526

26-
from sentry_sdk.tracing import Span
27-
2827

2928
class SqlalchemyIntegration(Integration):
3029
identifier = "sqlalchemy"
@@ -81,15 +80,21 @@ def _after_cursor_execute(
8180
)
8281

8382
# Record query source immediately before span is finished: accurate end timestamp and before the span is flushed.
84-
span: "Optional[Span]" = getattr(context, "_sentry_sql_span", None)
85-
if span is not None:
83+
span: "Optional[Union[Span, StreamedSpan]]" = getattr(
84+
context, "_sentry_sql_span", None
85+
)
86+
if isinstance(span, StreamedSpan):
8687
with capture_internal_exceptions():
8788
add_query_source(span)
8889

8990
if ctx_mgr is not None:
9091
context._sentry_sql_span_manager = None
9192
ctx_mgr.__exit__(None, None, None)
9293

94+
if isinstance(span, Span):
95+
with capture_internal_exceptions():
96+
add_query_source(span)
97+
9398

9499
def _handle_error(context: "Any", *args: "Any") -> None:
95100
execution_context = context.execution_context

0 commit comments

Comments
 (0)