|
5 | 5 | from sentry_sdk.integrations._wsgi_common import ( |
6 | 6 | DEFAULT_HTTP_METHODS_TO_CAPTURE, |
7 | 7 | RequestExtractor, |
8 | | - _serialize_request_body_data, |
9 | | - request_body_within_bounds, |
10 | 8 | ) |
11 | 9 | from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware |
12 | 10 | from sentry_sdk.scope import should_send_default_pii |
13 | | -from sentry_sdk.traces import StreamedSpan, _get_current_streamed_span |
14 | 11 | from sentry_sdk.tracing import SOURCE_FOR_STYLE |
15 | | -from sentry_sdk.tracing_utils import has_span_streaming_enabled |
16 | 12 | from sentry_sdk.utils import ( |
17 | | - AnnotatedValue, |
18 | 13 | capture_internal_exceptions, |
19 | 14 | ensure_integration_enabled, |
20 | 15 | event_from_exception, |
|
41 | 36 | from flask.signals import ( |
42 | 37 | before_render_template, |
43 | 38 | got_request_exception, |
44 | | - request_finished, |
45 | 39 | request_started, |
46 | 40 | ) |
47 | 41 | from markupsafe import Markup |
48 | | - from werkzeug.exceptions import ClientDisconnected |
49 | 42 | except ImportError: |
50 | 43 | raise DidNotEnable("Flask is not installed") |
51 | 44 |
|
@@ -95,7 +88,6 @@ def setup_once() -> None: |
95 | 88 |
|
96 | 89 | before_render_template.connect(_add_sentry_trace) |
97 | 90 | request_started.connect(_request_started) |
98 | | - request_finished.connect(_request_finished) |
99 | 91 | got_request_exception.connect(_capture_exception) |
100 | 92 |
|
101 | 93 | old_app = Flask.__call__ |
@@ -167,72 +159,6 @@ def _request_started(app: "Flask", **kwargs: "Any") -> None: |
167 | 159 | scope.add_event_processor(evt_processor) |
168 | 160 |
|
169 | 161 |
|
170 | | -def _request_finished(sender: "Flask", response: "Any", **kwargs: "Any") -> None: |
171 | | - integration = sentry_sdk.get_client().get_integration(FlaskIntegration) |
172 | | - if integration is None: |
173 | | - return |
174 | | - |
175 | | - client = sentry_sdk.get_client() |
176 | | - if has_span_streaming_enabled(client.options): |
177 | | - request = flask_request._get_current_object() |
178 | | - _set_request_body_data_on_streaming_segment(request, client) |
179 | | - |
180 | | - |
181 | | -def _set_request_body_data_on_streaming_segment( |
182 | | - request: "Request", client: "sentry_sdk.client.BaseClient" |
183 | | -) -> None: |
184 | | - current_span = _get_current_streamed_span() |
185 | | - if type(current_span) is not StreamedSpan: |
186 | | - return |
187 | | - |
188 | | - with capture_internal_exceptions(): |
189 | | - content_length = int(request.content_length or 0) |
190 | | - |
191 | | - # Proceeding without a content length means that we may be consuming the request |
192 | | - # without respecting the bounds specified by the user via `max_request_body_size` |
193 | | - # option in the SDK. |
194 | | - if not content_length: |
195 | | - return |
196 | | - |
197 | | - if not request_body_within_bounds(client, content_length): |
198 | | - data = AnnotatedValue.substituted_because_over_size_limit() |
199 | | - else: |
200 | | - raw_data = getattr(request, "_cached_data", None) |
201 | | - parsed_body = None |
202 | | - if "form" in request.__dict__: |
203 | | - extractor = FlaskRequestExtractor(request) |
204 | | - parsed_body = extractor.parsed_body() |
205 | | - elif raw_data is not None: |
206 | | - extractor = FlaskRequestExtractor(request) |
207 | | - if extractor.is_json(): |
208 | | - parsed_body = extractor.json() |
209 | | - else: |
210 | | - # The route never read the body via Werkzeug, but it |
211 | | - # may have consumed wsgi.input directly. get_data() |
212 | | - # raises ClientDisconnected if the stream is exhausted. |
213 | | - try: |
214 | | - raw_data = request.get_data() |
215 | | - except ClientDisconnected: |
216 | | - raw_data = None |
217 | | - |
218 | | - if raw_data: |
219 | | - extractor = FlaskRequestExtractor(request) |
220 | | - if extractor.is_json(): |
221 | | - parsed_body = extractor.json() |
222 | | - |
223 | | - if parsed_body is not None: |
224 | | - data = parsed_body |
225 | | - elif raw_data: |
226 | | - data = AnnotatedValue.substituted_because_raw_data() |
227 | | - else: |
228 | | - return |
229 | | - |
230 | | - current_span._segment.set_attribute( |
231 | | - "http.request.body.data", |
232 | | - _serialize_request_body_data(data), |
233 | | - ) |
234 | | - |
235 | | - |
236 | 162 | class FlaskRequestExtractor(RequestExtractor): |
237 | 163 | def env(self) -> "Dict[str, str]": |
238 | 164 | return self.request.environ |
|
0 commit comments