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

Doesn"t cut request body with size >= 10000 #1635

Merged
merged 5 commits into from Sep 19, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 15 additions & 4 deletions elasticapm/contrib/starlette/__init__.py
Expand Up @@ -146,6 +146,9 @@ async def wrapped_send(message):
elasticapm.set_transaction_result(result, override=False)
await send(message)

_mocked_receive = None
_request_receive = None

if self.client.config.capture_body != "off":

# When we consume the body from receive, we replace the streaming
Expand All @@ -165,17 +168,25 @@ async def wrapped_send(message):
if message["type"] == "http.disconnect":
break

joined_body = b"".join(body)

async def mocked_receive() -> Message:
await asyncio.sleep(0)
return {"type": "http.request", "body": long_field(b"".join(body))}
return {"type": "http.request", "body": long_field(joined_body)}

_mocked_receive = mocked_receive

async def request_receive() -> Message:
await asyncio.sleep(0)
return {"type": "http.request", "body": joined_body}

receive = mocked_receive
_request_receive = request_receive

request = Request(scope, receive=receive)
request = Request(scope, receive=_mocked_receive or receive)
await self._request_started(request)

try:
await self.app(scope, receive, wrapped_send)
await self.app(scope, _request_receive or receive, wrapped_send)
elasticapm.set_transaction_outcome(constants.OUTCOME.SUCCESS, override=False)
except Exception:
await self.capture_exception(
Expand Down