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-2606 Launch Time Publisher #1030

Merged
merged 5 commits into from
Nov 2, 2022

Conversation

maxep
Copy link
Member

@maxep maxep commented Oct 20, 2022

What and why?

Replace the LaunchTimeReader by the LaunchTimePublisher.

How?

The _Datadog_Private expose a __dd_private_AppLaunchHandler interface for providing and listening to Application Launch time information.
The __dd_private_AppLaunchHandler provide a shared instance with atomic properties. Therefor, thread-safety is now ensured by instance lock and the pthread_rwlock_t has been removed.

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

Custom CI job configuration (optional)

  • Run unit tests
  • Run integration tests
  • Run smoke tests

@maxep maxep self-assigned this Oct 20, 2022
@maxep maxep force-pushed the maxep/RUMM-2606/launch-time-publisher branch from 3798560 to 60a8aff Compare October 20, 2022 15:35
@datadog-datadog-prod-us1
Copy link

datadog-datadog-prod-us1 bot commented Oct 20, 2022

Datadog Report

Branch report: maxep/RUMM-2606/launch-time-publisher
Commit report: 3be6dc8

dd-sdk-ios 0 Failed, 0 New Flaky, 1955 Passed, 0 Skipped, 17m57.87s Wall Time

@maxep maxep force-pushed the maxep/RUMM-2606/launch-time-publisher branch from fb4a0c2 to fbc11e4 Compare October 21, 2022 11:03
@maxep maxep marked this pull request as ready for review October 21, 2022 11:03
@maxep maxep requested a review from a team as a code owner October 21, 2022 11:03
Comment on lines 325 to 332
// The launchTime can be `nil` if the application is not yet
// active (UIApplicationDidBecomeActiveNotification). That is
// the case when instrumenting a SwiftUI application that start
// a RUM view on `SwiftUI.View.onAppear`.
//
// In that case, we consider the time between the application
// launch and the view start as the application loadint time.
loadingTime = viewStartTime.timeIntervalSince(launchDate).toInt64Nanoseconds
Copy link
Member Author

Choose a reason for hiding this comment

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

This logic was previously enabled here: https://github.com/DataDog/dd-sdk-ios/blob/develop/Sources/_Datadog_Private/ObjcAppLaunchHandler.m#L92

In a SwiftUI application, the first SwiftUI.View/onAppear is called before the UIApplicationDidBecomeActiveNotification, so we consider the startView as the end of the launch sequence. It is best to have this logic explicitly stated in RUM.

Copy link
Member

@ncreated ncreated left a comment

Choose a reason for hiding this comment

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

Nice work 👌! I left some feedback - mostly on ambiguities around launchDate optionality. LTMWDYT @maxep

Sources/Datadog/RUM/RUMMonitor/Scopes/RUMViewScope.swift Outdated Show resolved Hide resolved
Comment on lines 14 to 18
/// If the `UIApplication.didBecomeActiveNotification` has not yet been received by the
/// time this value is provided, it will represent the time interval between now and the process start time.
/* public */ let launchTime: TimeInterval
/* public */ let launchTime: TimeInterval?

/* public */ let launchDate: Date?
Copy link
Member

Choose a reason for hiding this comment

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

Needs docstrings explaining why launchTime and launchDate are optional.

Does launchDate need to be optional at all? Its obj-c counterpart seems to be not:

NS_ASSUME_NONNULL_BEGIN

/// Returns the Application process launch date.
@property (atomic, readonly) NSDate* launchDate;

Copy link
Member Author

Choose a reason for hiding this comment

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

Both interfaces are similar but decorrelated, LaunchTime is publicly exposed by DatadogInternal while the __dd_private_AppLaunchHandler is used internally by the publisher.

DatadogInternal allow nil for the launch date because it needs to defined a .zero value. So we either make DatadogContext/launchTime optional, are we keep DatadogContext/launchTime/launchDate optional 🤔
I think it makes more sense to make DatadogContext/launchTime optional, I will see what's the impact of this changes.

//
// In that case, we consider the time between the application
// launch and the view start as the application loadint time.
loadingTime = viewStartTime.timeIntervalSince(launchDate).toInt64Nanoseconds
}
Copy link
Member

Choose a reason for hiding this comment

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

Don't we introduce a regression now? Previously there was no unhandled control flow:

// before:

} else {
   loadingTime = context.launchTime.launchTime.toInt64Nanoseconds
}

and now there is:

// now:

} else if let launchDate = context.launchTime.launchDate {
   // ...
} // <--- unhandled

Copy link
Member

Choose a reason for hiding this comment

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

Seems that non-optional launchDate could solve it (ref. to above: #1030 (comment)).

Copy link
Member Author

Choose a reason for hiding this comment

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

Previously, the context.launchTime was 0 when not evaluated. I think it's more correct to have loadingTime == nil instead of 0. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, now it describes much better with the nil 👌.

Sources/_Datadog_Private/ObjcAppLaunchHandler.m Outdated Show resolved Hide resolved
@maxep maxep force-pushed the maxep/RUMM-2606/launch-time-publisher branch 2 times, most recently from 01f56ef to 1277817 Compare October 24, 2022 13:06
Co-Authored-By: Maciek Grzybowski <maciek.grzybowski@datadoghq.com>
@maxep maxep force-pushed the maxep/RUMM-2606/launch-time-publisher branch 2 times, most recently from 806d091 to fd55617 Compare October 24, 2022 13:17
@maxep maxep force-pushed the maxep/RUMM-2606/launch-time-publisher branch from fd55617 to 3be6dc8 Compare October 24, 2022 13:38
@maxep maxep requested a review from ncreated October 24, 2022 15:59
Copy link
Member

@ncreated ncreated left a comment

Choose a reason for hiding this comment

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

It looks good 👌🎯. I asked some clarification questions - sorry for being picky 😞🙌, I want to make sure "launch time" logic is obvious and well described to everyone (as it is quite popular topic).

//
// In that case, we consider the time between the application
// launch and the view start as the application loadint time.
loadingTime = viewStartTime.timeIntervalSince(launchDate).toInt64Nanoseconds
}
Copy link
Member

Choose a reason for hiding this comment

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

Agreed, now it describes much better with the nil 👌.

Sources/Datadog/DatadogInternal/Context/LaunchTime.swift Outdated Show resolved Hide resolved
Comment on lines +64 to +65
/// Can be `nil` if the launch could not yet been evaluated.
var launchTime: LaunchTime?
Copy link
Member

Choose a reason for hiding this comment

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

So the nil value is quite unexpected and will be there only for a short while when SDK is being warmed up (this is what we mean by "evaluated"), right?

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, exactly. In practice, this value will be evaluated when we subscribe to the publisher, it will be done when initialising the core.

Co-authored-by: Maciek Grzybowski <maciek.grzybowski@datadoghq.com>
@datadog-datadog-prod-us1
Copy link

datadog-datadog-prod-us1 bot commented Nov 2, 2022

Datadog Report

Branch report: maxep/RUMM-2606/launch-time-publisher
Commit report: e747497

dd-sdk-ios 0 Failed, 0 New Flaky, 1955 Passed, 0 Skipped, 18m13.92s Wall Time

@maxep maxep merged commit d620fe0 into feature/v2 Nov 2, 2022
@maxep maxep deleted the maxep/RUMM-2606/launch-time-publisher branch November 2, 2022 13:24
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