-
Notifications
You must be signed in to change notification settings - Fork 133
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
RUM-3284 Extension background upload #1803
Conversation
Datadog ReportBranch report: ✅ 0 Failed, 3044 Passed, 0 Skipped, 3m 57.51s Total Time 🔻 Code Coverage Decreases vs Default Branch (10)
|
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.
I have couple of question on the approach here.
- When a batch is written - there can only be one and only one writer, because the way we name it. Once the file is written to the disk it is immutable.
- in this process, the lock must be on the file, not on the directory, if we need.
- Now reading the file from multiple sources must not make a difference.
While working on a personal project, I realized the programming model of widgets is quite different from lifecycle point of view. Hence I wonder if it even makes sense to upload batches from extension itself.
https://developer.apple.com/documentation/widgetkit/making-network-requests-in-a-widget-extension
6f17a40
to
2ae71ba
Compare
Problem is we don't have access to app's directory from the extension. For example I get path like this:
Extension:
For sharing the storage we could think of using app groups for instance, but this requires bigger planning and probably an RFC. This PR helps but doesn't fully resolves the |
internal func beginBackgroundTask() { | ||
endBackgroundTask() | ||
currentActivity = processInfo.beginActivity(options: [.background], reason: "Datadog SDK background upload") | ||
} |
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.
question/ Because beginBackgroundTask()
is called right before the SDK starts uploading data, how does it correspond to the explanation of 0xdead10cc
?
(...) Make this request well before starting to write to the file in order to complete those operations and relinquish the lock before the app suspends.
Apple suggestion is to wrap "file write" operations with .beginActivity()
and .endActivity()
. What we seem to do instead is wrapping data uploads. Considering that upload starts after the file was read and it has nothing to do with file writes (which are decoupled SDK routine), I'm not seeing clearly how this solves the 0xdead10cc
problem.
Shouldn't we instead use .beginActivity()
and .endActivity()
when writing to files, instead of when performing data upload 🤔💭?
Co-authored-by: Maciek Grzybowski <maciek.grzybowski@datadoghq.com>
1b1e04d
to
1c2c466
Compare
As described in #1690 we ruled out some potential root causes in the SDK code. Now, this PR is still relevant, but it acts more as a fix of background tasks for extension targets. I updated the description accordingly. Please review again :) |
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.
Looks good 👌, thanks for doing an extra iteration on this 💪
What and why?
This PR makes extension targets use
beginActivity(options:reason:)
andendActivity(_:)
APIs whenbackgroundTasksEnabled
configuration is enabled. This allows slightly extending the lifetime of the extension in order to upload all the necessary data.https://developer.apple.com/documentation/foundation/processinfo/1415995-beginactivity
https://developer.apple.com/documentation/foundation/processinfo/1411321-endactivity
It is recommended to use this configuration of the SDK when initialising from extensions:
How?
This PR adds extension compatible mechanism for background upload as well as mentions the recommended configuration setup when using the SDK from within extensions. Currently adopted mechanism only works from app targets.
Review checklist
Custom CI job configuration (optional)
tools/