Skip to content

RUM-10378 Collect battery attributes #2351

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

Merged

Conversation

barboraplasovska
Copy link
Contributor

What and why?

This PR adds support for collecting battery-related attributes in the RUM event model:

  • battery_level: The current battery charge level, expressed as a float from 0.0 (empty) to 1.0 (full).
  • low_power_mode: A boolean indicating whether the device is currently in Low Power Mode.
  • brightness_level: The current screen brightness, normalized as a float between 0.0 (darkest) and 1.0 (brightest).

These attributes provide crucial context for analyzing app performance and behavior under different power conditions. They help teams understand usage patterns on low-battery devices, identify potential regressions caused by power-saving configurations, and optimize experiences for energy-constrained environments

Review checklist

  • Feature or bugfix MUST have appropriate tests (unit, integration)
  • Make sure each commit and the PR mention the Issue number or JIRA reference
  • Add CHANGELOG entry for user facing changes
  • Add Objective-C interface for public APIs (see our guidelines (internal) and run make api-surface)

@barboraplasovska barboraplasovska self-assigned this Jun 20, 2025
@barboraplasovska barboraplasovska force-pushed the bplasovska/RUM-10378/collect-battery-attributes branch from da7046c to b783e3d Compare June 20, 2025 08:55
@datadog-datadog-prod-us1
Copy link

datadog-datadog-prod-us1 bot commented Jun 20, 2025

Datadog Report

Branch report: bplasovska/RUM-10378/collect-battery-attributes
Commit report: b49fbbc
Test service: dd-sdk-ios

✅ 0 Failed, 3123 Passed, 859 Skipped, 5m 32.88s Total duration (41.37s time saved)
❄️ 1 New Flaky

New Flaky Tests (1)

  • testWhenEnabled_itSendsConfigurationTelemetry_withNewApi - SessionReplayTests - Last Failure

    Expand for error
     Assertion Failure at SessionReplayTests.swift:249: XCTUnwrap failed: expected non-nil value of type "ConfigurationTelemetry"
    

@barboraplasovska barboraplasovska force-pushed the bplasovska/RUM-10378/collect-battery-attributes branch 5 times, most recently from 58c28c1 to 725c8c6 Compare June 20, 2025 11:53
@barboraplasovska barboraplasovska marked this pull request as ready for review June 20, 2025 12:37
@barboraplasovska barboraplasovska requested review from a team as code owners June 20, 2025 12:37
maciejburda
maciejburda previously approved these changes Jun 23, 2025
Copy link
Member

@maciejburda maciejburda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - left some minor questions/suggestions

/// Describe the battery state for mobile devices.
public struct BrightnessStatus: Codable, Equatable {
/// The brightness level
public let level: Float
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't expect more properties - could it be flattened to use float directly?

We could typealias BrightnessLevel = Float for readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right ! I've made the changes.

@@ -525,6 +525,10 @@ extension DatadogContextProvider {
subscribe(\.isLowPowerModeEnabled, to: LowPowerModePublisher(notificationCenter: notificationCenter, processInfo: processInfo))
#endif

#if os(iOS)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything for tvOS on that front?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this should be available on tvOS as well!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! Actually I checked on the documentation and it's not available for tvOS.

Copy link
Member

@maxep maxep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!! As @maciejburda mention, I think the brightness could be available on tvOS

@@ -525,6 +525,10 @@ extension DatadogContextProvider {
subscribe(\.isLowPowerModeEnabled, to: LowPowerModePublisher(notificationCenter: notificationCenter, processInfo: processInfo))
#endif

#if os(iOS)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this should be available on tvOS as well!

maxep
maxep previously approved these changes Jun 23, 2025
Copy link
Member

@maxep maxep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disregard my previous comment, brightness is not available on tvOS

@barboraplasovska barboraplasovska dismissed stale reviews from maxep and maciejburda via b49fbbc June 23, 2025 12:18
@barboraplasovska barboraplasovska force-pushed the bplasovska/RUM-10378/collect-battery-attributes branch from 725c8c6 to b49fbbc Compare June 23, 2025 12:18
@barboraplasovska
Copy link
Contributor Author

/merge

@dd-devflow
Copy link

dd-devflow bot commented Jun 24, 2025

View all feedbacks in Devflow UI.

2025-06-24 08:56:43 UTC ℹ️ Start processing command /merge


2025-06-24 08:57:10 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in develop is approximately 54m (p90).


2025-06-24 08:57:23 UTC ⚠️ MergeQueue: This merge request build was cancelled

[email protected] cancelled this merge request build

@barboraplasovska
Copy link
Contributor Author

/remove

@dd-devflow
Copy link

dd-devflow bot commented Jun 24, 2025

View all feedbacks in Devflow UI.

2025-06-24 08:57:18 UTC ℹ️ Start processing command /remove


2025-06-24 08:57:21 UTC ℹ️ Devflow: /remove

@barboraplasovska
Copy link
Contributor Author

/merge

@dd-devflow
Copy link

dd-devflow bot commented Jun 24, 2025

View all feedbacks in Devflow UI.

2025-06-24 12:13:58 UTC ℹ️ Start processing command /merge


2025-06-24 12:14:08 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in develop is approximately 54m (p90).


2025-06-24 12:39:41 UTCMergeQueue: The checks failed on this merge request

Tests failed on this commit 1d6c514:

What to do next?

  • Investigate the failures and when ready, re-add your pull request to the queue!
  • If your PR checks are green, try to rebase/merge. It might be because the CI run is a bit old.
  • Any question, go check the FAQ.

@barboraplasovska
Copy link
Contributor Author

/merge

@dd-devflow
Copy link

dd-devflow bot commented Jun 24, 2025

View all feedbacks in Devflow UI.

2025-06-24 13:12:52 UTC ℹ️ Start processing command /merge


2025-06-24 13:13:00 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in develop is approximately 54m (p90).


2025-06-24 13:37:34 UTCMergeQueue: The checks failed on this merge request

Tests failed on this commit 7155548:

What to do next?

  • Investigate the failures and when ready, re-add your pull request to the queue!
  • If your PR checks are green, try to rebase/merge. It might be because the CI run is a bit old.
  • Any question, go check the FAQ.

@barboraplasovska
Copy link
Contributor Author

/merge

@dd-devflow
Copy link

dd-devflow bot commented Jun 24, 2025

View all feedbacks in Devflow UI.

2025-06-24 14:25:15 UTC ℹ️ Start processing command /merge


2025-06-24 14:25:34 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in develop is approximately 54m (p90).


2025-06-24 15:22:51 UTC ℹ️ MergeQueue: This merge request was merged

@dd-mergequeue dd-mergequeue bot merged commit f86e00d into develop Jun 24, 2025
16 checks passed
@dd-mergequeue dd-mergequeue bot deleted the bplasovska/RUM-10378/collect-battery-attributes branch June 24, 2025 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants