Can't Get Raw Request Payload in Flask with APM

Normally, I'm able to access the raw request payload in my Flask app using request.get_data() but I get an empty string when the APM agent is used. In Flask, I would need to call request.get_data() before accessing anything from the request object otherwise payload parsing would be triggered based on the content-type header. However, it seems like the python APM agent accesses the request object before I'm able to do so which triggers the payloads parsing and prevents me from accessing the raw request payload.

Currently, I have the APM agent turned off since retrieving the raw payload is crucial for my own use case to compute payload hashes but I'm wondering if anyone has any suggested solution to keep the APM on and still be able to get the raw payload?

Thanks!

NOTE: APM agent version: elastic-apm[flask]==5.4.3

Hey @Alsheh

Can you check if you have the capture_body config value set to false? We only look at the request body if that config option is set to transactions, errors or all. In your case where your code depends on the request body not being touched, I'd set it to false.

@beniwohli Thanks for your response! I'm unable to reproduce this issue since upgrading to elastic-apm[flask]==5.9.0 .

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.