Skip to content

Commit

Permalink
Wrap StarletteRequestExtractor in capture_internal_exceptions (#1551)
Browse files Browse the repository at this point in the history
Fixes #1550
  • Loading branch information
sl0thentr0py authored Aug 8, 2022
1 parent a240248 commit 89c800b
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions sentry_sdk/integrations/starlette.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from sentry_sdk.utils import (
TRANSACTION_SOURCE_ROUTE,
AnnotatedValue,
capture_internal_exceptions,
event_from_exception,
transaction_from_function,
)
Expand Down Expand Up @@ -437,28 +438,35 @@ async def extract_request_info(self):
content_length = await self.content_length()
request_info = {} # type: Dict[str, Any]

if _should_send_default_pii():
request_info["cookies"] = self.cookies()
with capture_internal_exceptions():
if _should_send_default_pii():
request_info["cookies"] = self.cookies()

if not request_body_within_bounds(client, content_length):
data = AnnotatedValue(
"",
{"rem": [["!config", "x", 0, content_length]], "len": content_length},
)
else:
parsed_body = await self.parsed_body()
if parsed_body is not None:
data = parsed_body
elif await self.raw_data():
if not request_body_within_bounds(client, content_length):
data = AnnotatedValue(
"",
{"rem": [["!raw", "x", 0, content_length]], "len": content_length},
{
"rem": [["!config", "x", 0, content_length]],
"len": content_length,
},
)
else:
data = None
parsed_body = await self.parsed_body()
if parsed_body is not None:
data = parsed_body
elif await self.raw_data():
data = AnnotatedValue(
"",
{
"rem": [["!raw", "x", 0, content_length]],
"len": content_length,
},
)
else:
data = None

if data is not None:
request_info["data"] = data
if data is not None:
request_info["data"] = data

return request_info

Expand Down

0 comments on commit 89c800b

Please sign in to comment.