Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap StarletteRequestExtractor in capture_internal_exceptions #1551

Merged
merged 1 commit into from
Aug 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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