Skip to content

Commit 8f2463b

Browse files
committed
Revert "Keep transaction open until all streaming responses are finished."
This reverts commit 1fe8679.
1 parent ef90c73 commit 8f2463b

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

sentry_sdk/integrations/wsgi.py

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -119,30 +119,30 @@ def __call__(self, environ, start_response):
119119
origin=self.span_origin,
120120
)
121121

122-
if transaction is not None:
123-
transaction = sentry_sdk.start_transaction(
122+
with (
123+
sentry_sdk.start_transaction(
124124
transaction,
125125
custom_sampling_context={"wsgi_environ": environ},
126126
)
127-
transaction.__enter__()
128-
129-
try:
130-
response = self.app(
131-
environ,
132-
partial(
133-
_sentry_start_response, start_response, transaction
134-
),
135-
)
136-
except BaseException:
137-
reraise(*_capture_exception())
127+
if transaction is not None
128+
else nullcontext()
129+
):
130+
try:
131+
response = self.app(
132+
environ,
133+
partial(
134+
_sentry_start_response, start_response, transaction
135+
),
136+
)
137+
except BaseException:
138+
reraise(*_capture_exception())
138139
finally:
139140
_wsgi_middleware_applied.set(False)
140141

141142
return _ScopedResponse(
142143
response=response,
143144
current_scope=current_scope,
144145
isolation_scope=scope,
145-
transaction=transaction,
146146
)
147147

148148

@@ -238,7 +238,7 @@ class _ScopedResponse:
238238
- WSGI servers streaming responses interleaved from the same thread
239239
"""
240240

241-
__slots__ = ("_response", "_current_scope", "_isolation_scope", "_transaction")
241+
__slots__ = ("_response", "_current_scope", "_isolation_scope")
242242

243243
def __init__(
244244
self,
@@ -275,13 +275,6 @@ def close(self):
275275
with sentry_sdk.use_scope(self._current_scope):
276276
try:
277277
self._response.close() # type: ignore
278-
279-
# Close the Sentry transaction
280-
# This is done here to make sure the Transaction stays
281-
# open until all streaming responses are done.
282-
# Of course this here works also for non streaming responses.
283-
if self._transaction is not None:
284-
self._transaction.__exit__(None, None, None)
285278
except AttributeError:
286279
pass
287280
except BaseException:

0 commit comments

Comments
 (0)