bugsnag / bugsnag-cocoa

BugSnag error monitoring & exception reporter for iOS, macOS, tvOS and watchOS
https://docs.bugsnag.com/platforms/ios
MIT License
236 stars 129 forks source link

Add app memory information to BugsnagAppWithState #1691

Open prabhuamol opened 2 months ago

prabhuamol commented 2 months ago

Description

Add freeMemory, memoryLimit and memoryUsage that is found on Bugsnag to BugsnagAppWithState. This will help analyze error events before sending them to bugsnag via addOnSendErrorBlock

Screenshot 2024-08-15 at 11 19 32 AM

Describe the solution you'd like More memory related data in BugsnagAppWithState

Describe alternatives you've considered Tried to get app memory information via BugsnagEvent using other means

prabhuamol commented 2 months ago

related to this https://github.com/bugsnag/bugsnag-cocoa/issues/1687

clr182 commented 2 months ago

Hi @prabhuamol

The fields in the BugsnagApp/BugsnagAppWithState classes deliberately mirror the API fields of the BugSnag Reporting endpoint. These memory fields are not first class fields but simply platform-specific metadata that the SDK reports, they are not in the class but can be manipulated in callbacks using the addMetadata or clearMetadata methods on the event with a key such as "app.memoryLimit".

However, it should be noted that the on send callback you are proposing to use is not run at the time of a the crash, but when the report is sent on a subsequent launch so it can be minutes, hours, days or months after the crash occurred. So adding memory stats at this stage is of questionable use in the event. I see you have linked to the query about the lack of these stats in OOMs and that is due to the fact that the app is terminated without the ability to run any sort of diagnostic code.

prabhuamol commented 2 months ago

Sounds good. I was hoping to get access to app memory at the time of crash so we could check it before we send the report. but I see what you are saying

prabhuamol commented 1 month ago

Also now i wonder is the device memory/app memory that you see in bugnsag is reported at the time of the OOM event or is that the memory when the event is sent? Talking about the data shown here. I am guessing thats at the time of the crash

Screenshot 2024-08-26 at 10 58 33 AM Screenshot 2024-08-26 at 10 58 38 AM

And how does that correlate to event.device.freeMemory at the time of sending the event

toniewypada commented 1 month ago

Hi @prabhuamol 👋🏻, BugSnag is collecting the data at the moment of the crash. Regarding the fields you’ve highlighted:

freeMemory is showing ow much additional memory the app may allocate before reaching its memory limit, as reported by, and memoryUsage is showing app’s memory footprint.

You can check our docs to find information about data automatically captured by BugSnag.