11import sys
22from functools import partial
3- from threading import Timer
43
54import sentry_sdk
65from sentry_sdk ._werkzeug import get_host , _get_headers
@@ -124,18 +123,11 @@ def __call__(self, environ, start_response):
124123 origin = self .span_origin ,
125124 )
126125
127- timer = None
128126 if transaction is not None :
129127 sentry_sdk .start_transaction (
130128 transaction ,
131129 custom_sampling_context = {"wsgi_environ" : environ },
132130 ).__enter__ ()
133- timer = Timer (
134- MAX_TRANSACTION_DURATION_SECONDS ,
135- _finish_long_running_transaction ,
136- args = (current_scope , scope ),
137- )
138- timer .start ()
139131
140132 try :
141133 response = self .app (
@@ -149,7 +141,7 @@ def __call__(self, environ, start_response):
149141 except BaseException :
150142 exc_info = sys .exc_info ()
151143 _capture_exception (exc_info )
152- finish_running_transaction (current_scope , exc_info , timer )
144+ finish_running_transaction (current_scope , exc_info )
153145 reraise (* exc_info )
154146
155147 finally :
@@ -159,7 +151,6 @@ def __call__(self, environ, start_response):
159151 response = response ,
160152 current_scope = current_scope ,
161153 isolation_scope = scope ,
162- timer = timer ,
163154 )
164155
165156
@@ -255,20 +246,18 @@ class _ScopedResponse:
255246 - WSGI servers streaming responses interleaved from the same thread
256247 """
257248
258- __slots__ = ("_response" , "_current_scope" , "_isolation_scope" , "_timer" )
249+ __slots__ = ("_response" , "_current_scope" , "_isolation_scope" )
259250
260251 def __init__ (
261252 self ,
262253 response , # type: Iterator[bytes]
263254 current_scope , # type: sentry_sdk.scope.Scope
264255 isolation_scope , # type: sentry_sdk.scope.Scope
265- timer = None , # type: Optional[Timer]
266256 ):
267257 # type: (...) -> None
268258 self ._response = response
269259 self ._current_scope = current_scope
270260 self ._isolation_scope = isolation_scope
271- self ._timer = timer
272261
273262 def __iter__ (self ):
274263 # type: () -> Iterator[bytes]
@@ -290,14 +279,14 @@ def __iter__(self):
290279 finally :
291280 with use_isolation_scope (self ._isolation_scope ):
292281 with use_scope (self ._current_scope ):
293- finish_running_transaction (timer = self . _timer )
282+ finish_running_transaction ()
294283
295284 def close (self ):
296285 # type: () -> None
297286 with use_isolation_scope (self ._isolation_scope ):
298287 with use_scope (self ._current_scope ):
299288 try :
300- finish_running_transaction (timer = self . _timer )
289+ finish_running_transaction ()
301290 self ._response .close () # type: ignore
302291 except AttributeError :
303292 pass
@@ -346,18 +335,3 @@ def event_processor(event, hint):
346335 return event
347336
348337 return event_processor
349-
350-
351- def _finish_long_running_transaction (current_scope , isolation_scope ):
352- # type: (sentry_sdk.scope.Scope, sentry_sdk.scope.Scope) -> None
353- """
354- Make sure we don't keep transactions open for too long.
355- Triggered after MAX_TRANSACTION_DURATION_SECONDS have passed.
356- """
357- try :
358- with use_isolation_scope (isolation_scope ):
359- with use_scope (current_scope ):
360- finish_running_transaction ()
361- except AttributeError :
362- # transaction is not there anymore
363- pass
0 commit comments