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

RUMM-1765 Handle App Launch crashes - part 4 #695

Conversation

ncreated
Copy link
Member

@ncreated ncreated commented Dec 20, 2021

What and why?

📦 This PR adds the actual handling of application launch crashes. When app crashes before starting the RUM session, the crash is uploaded in a new, artificial session indicated either by "ApplicationLaunch" or "Background" view, depending on the app state during crash.

How?

The RUMOffViewEventsHandlingRule introduced in #690 is now reused in CrashReportingWithRUMIntegration to decided on how to send the crash. The overall logic of processing crashes in RUM looks this:

application-launch-events

To make it work as described in the original RFC, I had to inject sampling logic into CrashReportingWithRUMIntegration. To reuse existing code, I isolated it into single Sampler component (defined in "core").

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

Base automatically changed from ncreated/RUMM-1765-collect-app-launch-crashes to ncreated/RUMM-1765-app-launch-events-tracking December 21, 2021 11:21
…ssion

while there was no Background view started.
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 🚀

@@ -148,7 +277,7 @@ internal struct CrashReportingWithRUMIntegration: CrashReportingIntegration {
application: original.application,
connectivity: original.connectivity,
context: original.context,
date: crashDate.timeIntervalSince1970.toInt64Milliseconds,
date: crashDate.timeIntervalSince1970.toInt64Milliseconds - 1, // -1ms to put the crash after view in RUM session
Copy link
Member

@maxep maxep Dec 22, 2021

Choose a reason for hiding this comment

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

Could we fix it in BE instead? or FE?

Copy link
Member Author

@ncreated ncreated Dec 22, 2021

Choose a reason for hiding this comment

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

I asked on frontend channel, let's see 👌. Until it's solved in FE I think we can keep this workaround - all in all, we're making up this view update by ourself, so IMO it's not a big deal that we choose to send it -1ms before the crash. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good 👍
Indeed, it would be great to cover this on FE!

lastRUMViewEventInPreviousSession lastRUMViewEvent: RUMEvent<RUMViewEvent>,
using crashTimings: AdjustedCrashTimings
) {
if crashTimings.realDateNow.timeIntervalSince(crashTimings.realCrashDate) < Constants.viewEventAvailabilityThreshold {
Copy link
Member

Choose a reason for hiding this comment

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

This threshold is client side?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it's been like this since beginning of crash reporting. Problem is that backend considers all RUM sessions as "closed" after 4h, so sending additional view update to it might introduce inconsistency. It was discussed with BE team, and this is the best we came up with.

Copy link
Member

Choose a reason for hiding this comment

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

Ok 👍 Shouldn't be a big deal in that specific case and totally out of the scope of this PR, but I'm concerned that if we change that value BE side, for any reason, we will have inconsistencies.
Would be great to pull some configuration from BE at some point.

import Foundation

/// Sampler, deciding if events should be sent do Datadog or dropped.
internal struct Sampler {
Copy link
Member

Choose a reason for hiding this comment

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

/nit could be handy to make this ExpressibleByFloatLiteral, we would avoid having to update all tests.

extension Sampler: ExpressibleByFloatLiteral {

    init(floatLiteral value: Float) {
        self.init(samplingRate: value)
    }
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice! I wish I could think of it before doing refactoring in the first place. But now as it is done, I think that having explicit Sampler type passed around just reads better - at least it's less magical.

@ncreated ncreated merged commit 4910a31 into ncreated/RUMM-1765-app-launch-events-tracking Dec 22, 2021
@ncreated ncreated deleted the ncreated/RUMM-1765-send-app-launch-crashes branch December 22, 2021 11:40
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.

2 participants