|
7 | 7 | parse_version, |
8 | 8 | ) |
9 | 9 | from sentry_sdk.traces import StreamedSpan, SpanStatus |
| 10 | +from sentry_sdk.tracing import Span |
10 | 11 |
|
11 | 12 | try: |
12 | 13 | from sqlalchemy.engine import Engine # type: ignore |
|
23 | 24 | from typing import Optional |
24 | 25 | from typing import Union |
25 | 26 |
|
26 | | - from sentry_sdk.tracing import Span |
27 | | - |
28 | 27 |
|
29 | 28 | class SqlalchemyIntegration(Integration): |
30 | 29 | identifier = "sqlalchemy" |
@@ -81,15 +80,21 @@ def _after_cursor_execute( |
81 | 80 | ) |
82 | 81 |
|
83 | 82 | # 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): |
86 | 87 | with capture_internal_exceptions(): |
87 | 88 | add_query_source(span) |
88 | 89 |
|
89 | 90 | if ctx_mgr is not None: |
90 | 91 | context._sentry_sql_span_manager = None |
91 | 92 | ctx_mgr.__exit__(None, None, None) |
92 | 93 |
|
| 94 | + if isinstance(span, Span): |
| 95 | + with capture_internal_exceptions(): |
| 96 | + add_query_source(span) |
| 97 | + |
93 | 98 |
|
94 | 99 | def _handle_error(context: "Any", *args: "Any") -> None: |
95 | 100 | execution_context = context.execution_context |
|
0 commit comments