1010 RequestExtractor ,
1111 _filter_headers ,
1212 _is_json_content_type ,
13+ request_body_within_bounds ,
1314)
1415from sentry_sdk .integrations .logging import ignore_logger
1516from sentry_sdk .scope import should_send_default_pii
1920from sentry_sdk .utils import (
2021 CONTEXTVARS_ERROR_MESSAGE ,
2122 HAS_REAL_CONTEXTVARS ,
23+ AnnotatedValue ,
2224 capture_internal_exceptions ,
2325 ensure_integration_enabled ,
2426 event_from_exception ,
@@ -162,7 +164,7 @@ def _handle_request_impl(self: "RequestHandler") -> "Generator[None, None, None]
162164
163165 method = getattr (self , self .request .method .lower (), None )
164166 if method is not None :
165- span_name = transaction_from_function (method ) or ""
167+ span_name = transaction_from_function (method )
166168 if span_name :
167169 span .name = span_name
168170 span .set_attribute (
@@ -188,7 +190,7 @@ def _get_request_attributes(request: "Any") -> "Dict[str, Any]":
188190
189191 headers = _filter_headers (dict (request .headers ), use_annotated_value = False )
190192 for header , value in headers .items ():
191- attributes [f"http.request.header .{ header .lower ()} " ] = value
193+ attributes [f"{ SPANDATA . HTTP_REQUEST_HEADER } .{ header .lower ()} " ] = value
192194
193195 if request .query :
194196 attributes [SPANDATA .HTTP_QUERY ] = request .query
@@ -200,15 +202,34 @@ def _get_request_attributes(request: "Any") -> "Dict[str, Any]":
200202 )
201203
202204 if request .protocol :
203- attributes ["network.protocol.name" ] = request .protocol
205+ attributes [SPANDATA . NETWORK_PROTOCOL_NAME ] = request .protocol
204206
205207 if should_send_default_pii () and request .remote_ip :
206- attributes ["client.address" ] = request .remote_ip
207- attributes ["user.ip_address" ] = request .remote_ip
208+ attributes [SPANDATA .CLIENT_ADDRESS ] = request .remote_ip
209+ attributes [SPANDATA .USER_IP_ADDRESS ] = request .remote_ip
210+
211+ with capture_internal_exceptions ():
212+ raw_data = _get_tornado_request_data (request )
213+ body_data = raw_data .value if isinstance (raw_data , AnnotatedValue ) else raw_data
214+ if body_data is not None :
215+ attributes [SPANDATA .HTTP_REQUEST_BODY_DATA ] = body_data
208216
209217 return attributes
210218
211219
220+ def _get_tornado_request_data (
221+ request : "Any" ,
222+ ) -> "Union[Optional[str], AnnotatedValue]" :
223+ body = request .body
224+ if not body :
225+ return None
226+
227+ if not request_body_within_bounds (sentry_sdk .get_client (), len (body )):
228+ return AnnotatedValue .substituted_because_over_size_limit ()
229+
230+ return body .decode ("utf-8" , "replace" )
231+
232+
212233@ensure_integration_enabled (TornadoIntegration )
213234def _capture_exception (ty : type , value : BaseException , tb : "Any" ) -> None :
214235 if isinstance (value , HTTPError ):
0 commit comments