Skip to content
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

UI Button click creates unexpected trace #4129

Open
armcknight opened this issue Jun 27, 2024 · 3 comments
Open

UI Button click creates unexpected trace #4129

armcknight opened this issue Jun 27, 2024 · 3 comments

Comments

@armcknight
Copy link
Member

armcknight commented Jun 27, 2024

Description

I tried testing how to get from an ANR issue to a profile. But the sample app UX and client behavior combined to produce an unexpected result.

Repro steps

  1. Run iOS-Swift with trace-based profiling enabled, no debugger attached (ANR reporting is disabled while debugging)
  2. start a manual transaction by tapping the button to do so
  3. trigger an ANR by tapping that button
  4. tap the button to stop the transaction so it and the associated profile data can be uploaded

Expected result

Ideally, the profile should be linked right from the ANR. There is a field for us to do so, but I haven't been able to get an actual profile link to show up there yet.

Barring that, I should be able to go from the ANR issue (https://sentry-sdks.sentry.io/issues/5485507710/?project=5428557&query=is%3Aunresolved+issue.priority%3A%5Bhigh%2C+medium%5D&referrer=issue-stream&statsPeriod=1m&stream_index=0) to the trace, which would then have profiling data displayed inline or a link to the profile (here's the actual profile it should've been associated with: https://sentry-sdks.sentry.io/profiling/profile/sentry-cocoa/2bba13dac5a044fba93eaff0c19b8266/flamegraph/?colorCoding=by+system+vs+application+frame&query=&sorting=call+order&tid=259&view=top+down)

I expected this structure:

|-------------------manual transaction----------------------|  trace ID: A
 |--------------------profile------------------------------|
                              |----------ANR----------|      

Observed result

No profile is linked directly on the ANR.

But, for the actual point of this ticket, when I went to the trace for the ANR, it was not the trace for the manual transaction I'd started. It was for a separate trace for the automatic UIButton click. I would've expected that to at least be a child span on the manual transaction that I started. But I can't find a way to traverse from one to the other to connect the pathway from the ANR to the profile.

It appears what actually happened is something more like this:

|-------------------manual transaction----------------------|  trace ID: A
 |--------------------profile------------------------------|


                             |--button click--|                trace ID: B
                              |----------ANR----------|        
@kahest
Copy link
Member

kahest commented Jun 28, 2024

Thanks for testing and documenting this scenario, this doesn't seem intuitive. Though there might be a historic/technical reason for that behaviour I'm not aware of.

My gut feeling is - this might be related to the way we instrument user UI interactions, i.e. the button click. We need to create an idle transaction for this because the action doesn't have a clear end (like a navigation would have), so we might not be able to use the manual tx (or another automatic tx) to instrument that.

To narrow down the problem field, did/can you try what happens if you trigger the ANR via e.g. a navigation or something else that starts an auto tx? Also, what would happen if the initial manual tx is instead an auto tx?

@armcknight
Copy link
Member Author

the way we instrument user UI interactions, i.e. the button click. We need to create an idle transaction

I wonder if this comes out of the fact that SentryTracer was originally used for managing the idle timeout, and then only later did we refactor SentryTracer to be a subclass of SentrySpan.

In my mind, every automatic UI interaction should be a span. I'm not sure where we're at with performanceV2, but that simplifies things a bunch for this: in V1, maybe it's the case that such a span wouldn't be recorded if there's no current trace. But in V2 we would record every such span.

I guess maybe I should also try this with the perfV2 option enabled, as well as what you suggested.

@brustolin brustolin moved this from Needs Discussion to Backlog in Mobile & Cross Platform SDK Jul 10, 2024
@philipphofmann
Copy link
Member

I think the reason is that the manual transaction started here isn't bound to the scope.

spans.append(SentrySDK.startTransaction(name: "Manual Transaction", operation: "Manual Operation"))

You can do this by changing the code to

spans.append(SentrySDK.startTransaction(name: "Manual Transaction", operation: "Manual Operation", bindToScope: true))

Then, the ANR should be linked to the manual transaction as the SDK doesn't bind the UI event transaction to the scope.

func test_ManualTransactionOnScope_StartNewUIEventTransaction_NotBoundToScope() {
let manualTransaction = SentrySDK.startTransaction(name: "test", operation: "my.operation", bindToScope: true)
callExecuteAction(action: action, target: fixture.target, sender: fixture.button, event: TestUIEvent())
XCTAssertTrue(manualTransaction === SentrySDK.span)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Backlog
Development

No branches or pull requests

3 participants