Skip to content

Middleware: Log request payload size #1161

Description

@vprashrex

Is your feature request related to a problem?

In Sentry, we observed slow transactions running for up to ~1 minute that then failed with 400 Bad Request. We suspect these are caused by unusually large request payloads, but the HTTP request logger middleware currently does not log request payload size — so there is no way to confirm this by correlating payload size with a specific request (via its correlation ID) in Sentry or AWS CloudWatch.

Describe the solution you'd like

Modify app/core/middleware.py (_log_http_request) to:

  • Capture the request body size from the Content-Length header (0 when absent/malformed).
  • Add it as the http.request.body.size span attribute (OTel semantic convention) so it reaches Sentry via the OTel instrumenter.
  • Include request_body_size and correlation_id in the access log line, which flows to both Sentry (LoggingIntegration) and AWS CloudWatch (stdout log shipping).
  • Emit a http.server.request.body.size distribution metric to Sentry alongside the existing request count/duration metrics.

This will let us confirm (or rule out) the large-payload hypothesis for the slow 400 transactions.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

  • Status
    Closed

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions