We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 56ee084 commit 2c22c16Copy full SHA for 2c22c16
1 file changed
sentry_sdk/integrations/sqlalchemy.py
@@ -80,15 +80,16 @@ def _after_cursor_execute(
80
context, "_sentry_sql_span_manager", None
81
)
82
83
- if ctx_mgr is not None:
84
- context._sentry_sql_span_manager = None
85
- ctx_mgr.__exit__(None, None, None)
86
-
+ # Record query source immediately before span is finished: accurate end timestamp and before the span is flushed.
87
span: "Optional[Span]" = getattr(context, "_sentry_sql_span", None)
88
if span is not None:
89
with capture_internal_exceptions():
90
add_query_source(span)
91
+ if ctx_mgr is not None:
+ context._sentry_sql_span_manager = None
+ ctx_mgr.__exit__(None, None, None)
92
+
93
94
def _handle_error(context: "Any", *args: "Any") -> None:
95
execution_context = context.execution_context
0 commit comments