Skip to content

Added long press to click detection#1741

Merged
LikeTheSalad merged 4 commits into
open-telemetry:mainfrom
DavidGrath:issue-1576-long-press
May 26, 2026
Merged

Added long press to click detection#1741
LikeTheSalad merged 4 commits into
open-telemetry:mainfrom
DavidGrath:issue-1576-long-press

Conversation

@DavidGrath

Copy link
Copy Markdown
Contributor

References #1576

@thompson-tomo , are these new attributes fine by you?

@DavidGrath DavidGrath requested a review from a team as a code owner May 13, 2026 19:10
@codecov

codecov Bot commented May 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.54839% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.77%. Comparing base (a26eda2) to head (54688f1).
⚠️ Report is 16 commits behind head on main.

Files with missing lines Patch % Lines
...trumentation/view/click/ViewClickEventGenerator.kt 89.47% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1741      +/-   ##
==========================================
- Coverage   62.06%   61.77%   -0.30%     
==========================================
  Files         159      158       -1     
  Lines        3443     3443              
  Branches      347      348       +1     
==========================================
- Hits         2137     2127      -10     
- Misses       1207     1217      +10     
  Partials       99       99              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread instrumentation/view-click/src/test/kotlin/TestUtils.kt Outdated
Comment thread instrumentation/view-click/src/test/kotlin/TestUtils.kt Outdated
Comment thread instrumentation/view-click/src/test/kotlin/TestUtils.kt Outdated
/**
* @param clicks 0 for other event, 1 for single tap, 2 for double tap
*/
private fun createEvent(name: String, tapEvent: TapEvent, clicks: Int = 0): LogRecordBuilder {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This might be overkill, but I wonder whether it's worth creating an enum that holds TapEvent and clicks and returns the attributes that should be used for each event. IMO it could avoid logic such as if(isTapEvent) growing if we continue to add more touch events to the instrumentation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Would it be something like this?

//TapEvent renamed to TapEventMetadata
sealed class Gesture(
    val tapEventMetadata: TapEventMetadata
) {
    class LongPress(val t: TapEvent): Gesture(t)
    class Click(val t: TapEvent, clicks: Int): Gesture(t)
    class Scale(val t: TapEvent, val scaleFactor: Double): Gesture(t)
    class Scroll(val t: TapEvent, val velocityX: Double, val velocityY: Double): Gesture(t)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yep, something along those lines. Gesture could even define val attributes: Map<String, Any> and generate the attributes that are required for each event.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Noted. I'll apply these changes over the weekend

DavidGrath and others added 2 commits May 14, 2026 20:04

internal sealed class Gesture(val m: MotionEvent) {
private val t = TapEventMetadata(m)
val attributeBuilder = Attributes.builder()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@fractalwrench , so is this alright or should I stick with a plain Map instead of Attributes? I feel the dangling builder object is something I might need to walk back on

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would lean slightly to just returning Attributes rather than a builder but I don't think that needs to block.

@breedx-splk breedx-splk May 19, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think there's much value in holding a mutable object in an immutable val, versus just having a mutable private var. So, my recommendation is to just have

var attributes = Attributes.empty()

...and then in the 3 places where you need to update it, you can do

attributes = attributes.toBuilder().put(xxx, yyy).build().

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Okay, done. Thanks for the review

@fractalwrench fractalwrench left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM


internal sealed class Gesture(val m: MotionEvent) {
private val t = TapEventMetadata(m)
val attributeBuilder = Attributes.builder()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would lean slightly to just returning Attributes rather than a builder but I don't think that needs to block.

Comment on lines +248 to +249


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change

@breedx-splk breedx-splk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Had one small feedback about the attributes builder, but otherwise looking good. Thanks for the contribution!


}

internal sealed class Gesture(val m: MotionEvent) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

sharing as context
eg https://github.com/PostHog/posthog-android/blob/d2cc7f7a9bb715a2902b454e33bc4912cba585b9/posthog-android/src/main/java/com/posthog/android/replay/PostHogReplayIntegration.kt#L303-L323
i've seen errors where acessing MotionEvent may trigger native errors, so its better to call MotionEvent.obtain and later recycle
this was the case if accessing or processing in a background thread, not sure if its the case here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If the change is to simply use an obtain to duplicate it, then I think I can do that. I'd need to take my time to look at your own code so I can reproduce a test case for it, too, so it'll be a bit

@LikeTheSalad LikeTheSalad left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you! 🙏

@LikeTheSalad LikeTheSalad merged commit f808a6a into open-telemetry:main May 26, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants