@@ -17,7 +17,7 @@ def __init__(self, app, recorder):
17
17
self ._recorder = recorder
18
18
self .app .before_request (self ._before_request )
19
19
self .app .after_request (self ._after_request )
20
- self .app .teardown_request (self ._handle_exception )
20
+ self .app .teardown_request (self ._teardown_request )
21
21
self .in_lambda_ctx = False
22
22
23
23
if check_in_lambda () and type (self ._recorder .context ) == LambdaContext :
@@ -81,18 +81,9 @@ def _after_request(self, response):
81
81
if cont_len :
82
82
segment .put_http_meta (http .CONTENT_LENGTH , int (cont_len ))
83
83
84
- if response .status_code >= 500 :
85
- return response
86
-
87
- if self .in_lambda_ctx :
88
- self ._recorder .end_subsegment ()
89
- else :
90
- self ._recorder .end_segment ()
91
84
return response
92
85
93
- def _handle_exception (self , exception ):
94
- if not exception :
95
- return
86
+ def _teardown_request (self , exception ):
96
87
segment = None
97
88
try :
98
89
if self .in_lambda_ctx :
@@ -104,9 +95,11 @@ def _handle_exception(self, exception):
104
95
if not segment :
105
96
return
106
97
107
- segment .put_http_meta (http .STATUS , 500 )
108
- stack = stacktrace .get_stacktrace (limit = self ._recorder ._max_trace_back )
109
- segment .add_exception (exception , stack )
98
+ if exception :
99
+ segment .put_http_meta (http .STATUS , 500 )
100
+ stack = stacktrace .get_stacktrace (limit = self ._recorder ._max_trace_back )
101
+ segment .add_exception (exception , stack )
102
+
110
103
if self .in_lambda_ctx :
111
104
self ._recorder .end_subsegment ()
112
105
else :
0 commit comments