Add thermal status instrumentation (#1799)#1801
Conversation
|
|
6fb9f7c to
0ac4f7e
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1801 +/- ##
==========================================
+ Coverage 62.88% 63.13% +0.25%
==========================================
Files 158 160 +2
Lines 3451 3494 +43
Branches 355 360 +5
==========================================
+ Hits 2170 2206 +36
- Misses 1179 1182 +3
- Partials 102 106 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Add a new opt-in instrumentation module that listens for device thermal-status changes via PowerManager.addThermalStatusListener (no polling) and emits one log event per status change. The thermal APIs are API 29+, so install() gates on Build.VERSION.SDK_INT and no-ops on older devices. The module is not bundled with the android-agent; it must be installed explicitly. Signed-off-by: Hitesh Kalluru <kalluruhitesh3@gmail.com>
0ac4f7e to
3137bb4
Compare
breedx-splk
left a comment
There was a problem hiding this comment.
Thanks @hitkall this is great. I offered a few remarks, but this is definitely on track.
I also think you might have missed adding this module to the settings.gradle.kts in the root of the project. I don't think it'll be included and compiled until you do that.
| .loggerBuilder("io.opentelemetry.$name") | ||
| .build() | ||
|
|
||
| val executor = Executors.newSingleThreadExecutor() |
There was a problem hiding this comment.
A bit of a drag to burn an entire thread on something that is probably rarely used. I'm not entirely sure what best practice around this is. We have a few other instrumentations that create their own, so it's not a show-stopper. We might want to consider a future mechanism for sharing these so that it's a little more scalable.
| } | ||
| } | ||
|
|
||
| override fun onThermalStatusChanged(status: Int) { |
There was a problem hiding this comment.
nitpick: prefer to have the interface method above the private methods that it calls into.
| <manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
|
||
| </manifest> No newline at end of file |
There was a problem hiding this comment.
I think this can be removed, unless you have a reason for needing it? I see that the screen orientation also has an empty one, but maybe that can be removed as well (separately from this PR tho).
| import org.junit.Test | ||
|
|
||
| class ThermalDetectorTest { | ||
| private lateinit var sut: ThermalDetector |
There was a problem hiding this comment.
I'm not sure what sut is a convention for or shortening of ("[s]omething [u]nder [t]est"?), but it's not something we really use. Maybe just call it detector instead?
| ### Thermal State | ||
|
|
||
| * Type: Event | ||
| * Name: `device.thermal_state` |
There was a problem hiding this comment.
reminder to change readme to match the name change suggested above (or whatever it lands on).
|
Thanks for the thorough review, really appreciate it! |
…/instrumentation/thermal/ThermalDetector.kt Co-authored-by: jason plumb <75337021+breedx-splk@users.noreply.github.com>
…tation test Signed-off-by: Hitesh Kalluru <kalluruhitesh3@gmail.com>
breedx-splk
left a comment
There was a problem hiding this comment.
Looking good! Thanks for the help and for the quick responses.
The thermal API reports throttling severity rather than temperature, so android.thermal.throttling_status more accurately describes the value (per maintainer review feedback). Signed-off-by: Hitesh Kalluru <kalluruhitesh3@gmail.com>
|
Thanks for the review @breedx-splk! All feedback is addressed in the latest commits:
Re: The event/attribute names are still open to whatever the semantic-conventions discussion lands on. Let me know if you'd like anything else. |
What
Adds a new, opt-in instrumentation module (
instrumentation/thermal) that listens for device thermal-status changes and emits one log event per change.Fixes #1799
Approach
ThermalInstrumentation.install()registers aPowerManager.OnThermalStatusChangedListenerviaPowerManager.addThermalStatusListener(executor, listener)on a single-thread executor.uninstall()callsremoveThermalStatusListenerand shuts the executor down.addThermalStatusListener,THERMAL_STATUS_*) are only available on API level 29 (Android Q). Since the projectminSdkis 23,install()gates onBuild.VERSION.SDK_INT >= Build.VERSION_CODES.Qand no-ops on older devices. The API-29 call sites are annotated@RequiresApi(29)so Animal Sniffer is satisfied.android-agent, so it is not bundled by default — consumers add the dependency and install it explicitly. The README documents this.ThermalDetectormaps the integer status codes to readable strings (none,light,moderate,severe,critical,emergency,shutdown, with anunknownfallback) and emits via the logs bridge.This module closely mirrors the existing
instrumentation/screen-orientationmodule in structure, style, and conventions.Telemetry
io.opentelemetry.thermaldevice.thermal_stateandroid.thermal.state(string)Tests
ThermalDetectorTest(JUnit 4 + MockK + AssertJ +OpenTelemetryRule) covers:unknownfallback for an unrecognized code.Verification
Run locally against JDK 17 + Android SDK 36:
./gradlew spotlessApply./gradlew :instrumentation:thermal:test(3 tests pass)./gradlew apiDump(generatedapi/thermal.api)./gradlew apiCheck./gradlew :instrumentation:thermal:assembledetekt+lintDebugfor the module)🤖 Generated with Claude Code