Skip to content
Closed
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion sentry_sdk/integrations/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,14 @@ async def _sentry_app(*args, **kwargs):
)
sentry_scope = sentry_sdk.get_isolation_scope()
extractor = StarletteRequestExtractor(request)
info = await extractor.extract_request_info()

request_scope = request.scope
if "endpoint" in request_scope:
qualname = getattr(request_scope["endpoint"], "__qualname__", None)
read_body = qualname is None or "FastApiMCP" not in qualname
info = await extractor.extract_request_info(read_body)
else:
info = await extractor.extract_request_info(True)

def _make_request_event_processor(req, integration):
# type: (Any, Any) -> Callable[[Event, Dict[str, Any]], Event]
Expand Down
7 changes: 5 additions & 2 deletions sentry_sdk/integrations/starlette.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,8 @@ def extract_cookies_from_request(self):

return cookies

async def extract_request_info(self):
# type: (StarletteRequestExtractor) -> Optional[Dict[str, Any]]
async def extract_request_info(self, read_body=True):
# type: (StarletteRequestExtractor, bool) -> Optional[Dict[str, Any]]
client = sentry_sdk.get_client()

request_info = {} # type: Dict[str, Any]
Expand All @@ -623,6 +623,9 @@ async def extract_request_info(self):
request_info["data"] = AnnotatedValue.removed_because_over_size_limit()
return request_info

if not read_body:
return request_info

# Add JSON body, if it is a JSON request
json = await self.json()
if json:
Expand Down