DataDog / dd-sdk-android

Datadog SDK for Android (Compatible with Kotlin and Java)
Apache License 2.0
146 stars 59 forks source link

🔋 ⚠️ Datadog sdk heavy battery consumption in background in Android #2206

Open ankur0660 opened 3 weeks ago

ankur0660 commented 3 weeks ago

We are using Datadog as an analytics tool in our Android application. Recently, we’ve observed significant battery drain, which seems to be correlated to the Datadog SDK integration. In order to debug the issue, we’ve asked our users for bug reports but those reports were not conclusive enough to identify the culprit. Hence we enabled custom logging to Firebase to gather information regarding background work which might be causing battery drain. Upon testing and profiling, we’ve found that the Datadog SDK is likely contributing to this issue, particularly during periods of high network activity or when the app is running in the background. I am attaching files which describe the logic that we are using to gather the information regarding background activity happening in our application. In a lot of cases we’ve found that Datadog background upload worker was running beyond 30 minutes, which led us to believe that DD worker might be the culprit in draining the battery in background. Our tracking logic starts when the app becomes active and checks for running workers every 5 minutes. If the same worker has been running for over 30 minutes, it’s logged to Firebase. We also remove jobs that are no longer active to avoid false positives. Even with RUM disabled and only tracing enabled, we’ve found that the Datadog background upload worker frequently runs for extended periods, which is a strong indicator that it might be contributing to the battery drain issue. To resolve this problem, we’ll need to further investigate the Datadog SDK’s behavior and optimize its integration with our app, which is where we are soliciting your help. Additional notes: RUM feature within our Datadog instance on PROD has been disabled, due to numerous user reports of excessive battery consumption, we are currently using only DD Tracing. We are working with the id of the worker to find if the worker is same or not. Going through the BackgroundUploadWorker code, since it uses ‘Replace’ as the ExistingWorkPolicy, the id should ideally change for every new worker instance created.

BgJobTracking_kt.txt SCR-20240813-uaeb (1) SCR-20240813-uaqz (1) FirebaseJobTrackingLogger_kt.txt

jonathanmos commented 3 weeks ago

hi @ankur0660, thanks for reaching out on this issue.

We'll investigate on our end. Do you have any further information that you feel may be helpful in reproducing the issue/pinpointing the cause (device types, os version, sdk version)? Are you seeing any errors from the sdk in the logcat when the battery drain issue is occurring? Does this issue occur when using the latest sdk version?

jonathanmos commented 3 weeks ago

Would it be possible for you to open a support ticket and reference this issue there?

jonathanmos commented 4 days ago

@ankur0660 we released a fix for an upload worker issue in version 2.13.1. Can you please try with the latest version and see if the issue is resolved for you?