-
Notifications
You must be signed in to change notification settings - Fork 134
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
Conversation
3798560
to
60a8aff
Compare
Datadog ReportBranch report: ✅ |
fb4a0c2
to
fbc11e4
Compare
// 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this 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
Datadog/Datadog.xcodeproj/xcshareddata/xcschemes/DatadogIntegrationTests.xcscheme
Outdated
Show resolved
Hide resolved
/// 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? |
There was a problem hiding this comment.
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;
There was a problem hiding this comment.
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 | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)).
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
👌.
Tests/DatadogTests/Datadog/RUM/RUMMonitor/Scopes/RUMViewScopeTests.swift
Outdated
Show resolved
Hide resolved
Tests/DatadogTests/Datadog/RUM/RUMMonitor/Scopes/RUMViewScopeTests.swift
Outdated
Show resolved
Hide resolved
01f56ef
to
1277817
Compare
Co-Authored-By: Maciek Grzybowski <maciek.grzybowski@datadoghq.com>
806d091
to
fd55617
Compare
fd55617
to
3be6dc8
Compare
There was a problem hiding this 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 | ||
} |
There was a problem hiding this comment.
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
👌.
/// Can be `nil` if the launch could not yet been evaluated. | ||
var launchTime: LaunchTime? |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 ReportBranch report: ✅ |
What and why?
Replace the
LaunchTimeReader
by theLaunchTimePublisher
.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 withatomic
properties. Therefor, thread-safety is now ensured by instance lock and thepthread_rwlock_t
has been removed.Review checklist
Custom CI job configuration (optional)