Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion sentry_sdk/integrations/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,13 @@ 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
is_fastapi_mcp = (
request_scope.get("endpoint")
and "FastApiMCP" in request_scope["endpoint"].__qualname__
)
info = await extractor.extract_request_info(read_body=not is_fastapi_mcp)

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