[$250] Upload logs from Swift code
If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!
Version Number: 1.4.75-1 Reproducible in staging?: Needs reproduction Reproducible in production?: Needs reproduction If this was caught during regression testing, add the test name, ID and link from TestRail: Email or phone of affected tester (no customers): Logs: https://stackoverflow.com/c/expensify/questions/4856 Expensify/Expensify Issue URL: Issue reported by: @arosiclair Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1716825560361569
Action Performed:
User B logged in iOS device and notifications enabled
- Go to staging.new.expensify.com
- Send a message from A to B
Expected Result:
The notification received with the user's avatar
Actual Result:
No avatar displays in the notification
Workaround:
Unknown
Platforms:
Which of our officially supported platforms is this issue occurring on?
- [ ] Android: Native
- [ ] Android: mWeb Chrome
- [x] iOS: Native
- [ ] iOS: mWeb Safari
- [ ] MacOS: Chrome / Safari
- [ ] MacOS: Desktop
Screenshots/Videos
Add any screenshot/video evidence
- reportID
1911951290129650 - reportActionID
5005778300960326136
Relevant logs:
Upwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~018463b08116cdfa88
- Upwork Job ID: 1795181230839853056
- Last Price Increase: 2024-07-02
- Automatic offers:
- abdulrahuman5196 | Reviewer | 102978733
Issue Owner
Current Issue Owner: @
This has been labelled "Needs Reproduction". Follow the steps here: https://stackoverflowteams.com/c/expensify/questions/16989
Triggered auto assignment to @puneetlath (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.
Job added to Upwork: https://www.upwork.com/jobs/~018463b08116cdfa88
Triggered auto assignment to Contributor-plus team member for initial proposal review - @abdulrahuman5196 (External)
@puneetlath, @arosiclair, @abdulrahuman5196 Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
seems to be an internal assigned issue. Seems we don't have a PR yet.
I wasn't able to find the root issue for this when I looked into it though I'm pretty sure it was a transient issue in the NotificationService for iOS.
We do os_log in that lib for most errors but those are not sent to the backend. I think we should find a way to write and upload logs from swift code so we can debug this kind of issue in the future.
No progress on this yet
Focusing on a critical issue atm.
@puneetlath @arosiclair @abdulrahuman5196 this issue was created 2 weeks ago. Are we close to a solution? Let's make sure we're treating this as a top priority. Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!
Since the plan is to just improve logging for swift code, I'm going to switch this to a NewFeature and mark this External.
Current assignee @abdulrahuman5196 is eligible for the External assigner, not assigning anyone new.
Current assignee @puneetlath is eligible for the NewFeature assigner, not assigning anyone new.
:warning: It looks like this issue is labelled as a New Feature but not tied to any GitHub Project. Keep in mind that all new features should be tied to GitHub Projects in order to properly track external CAP software time :warning:
Triggered auto assignment to Design team member for new feature review - @dubielzyk-expensify (NewFeature)
Problem
We have some native iOS swift code that configures notifications here. This code logs errors using os_log but these are local only so it's not possible to debug those issues in production like the one reported in the OP.
Solution Find some way to upload logs from Swift code to our server like we do in React here so that we can debug issues in native code.
@dubielzyk-expensify this is just a logging improvement so no design input needed here.
📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸
Proposal
Please re-state the problem that we are trying to solve in this issue.
Upload logs from Swift code
What is the root cause of that problem?
No Problem, it's a feature request.
What changes do you think we should make in order to solve the problem?
To support reading logs from Swift code we need to add native module to our app.
The implementation that I'm trying doesn't support devices with iOS version less than 15.0 which I think doesn't seem to be a worry for us.
https://gs.statcounter.com/ios-version-market-share/ Seems nobody now using devices with less v15.0 which is a great thing.
The support to read logs from device is done by using OsLogStore class from osLog class provided in swift.
using OsLogStore.getAllEntries will give the all logs happened with the iOS devices (or current process) based on that we can process the log message.
I'm attaching a sample function that I have tested with and working fine.
@objc(withResolver:withRejecter:)
func logs(resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
if #available(iOS 15.0, *) {
let subsystem = Bundle.main.bundleIdentifier!
// Open the log store.
do {
let logStore = try OSLogStore(scope: .currentProcessIdentifier)
// Get all the logs from the last hour.
let oneHourAgo = logStore.position(date: Date().addingTimeInterval(-3600))
// Fetch log objects.
let allEntries = try logStore.getEntries(at: oneHourAgo)
// Filter the log to be relevant for our specific subsystem
// and remove other elements (signposts, etc).
let bundleLogs = allEntries
.compactMap { $0 as? OSLogEntryLog }
.filter { $0.subsystem == subsystem }
.map { $0.formatString }
resolve(bundleLogs);
}catch {
reject("OSVersionError","Error", nil)
}
}else{
reject("OSVersionError","Not possible", nil)
}
}
With the above code we can read the logs and share it with react-native.
We can create a new module and attach this to expensify app, whenever we want logs we can use logs() function exposed from swift inside our JS code and save it along with the existings logs.
What alternative solutions did you explore? (Optional)
NA
Demo
https://github.com/Expensify/App/assets/59088937/cc3b6434-8a2e-4c38-9e46-e35d977423e9
The above demo is showing that inside multiply function I'm doing logs 4 times which I can read later after calling the multiply function all throughout using JS with native swift code.
Update
We can also capture the level of logging i.e either Error or Info or so using the following sinppet changes
let bundleLogs = allEntries
.compactMap { $0 as? OSLogEntryLog }
.filter { $0.subsystem == subsystem }
.map { "[\(logLevelStrings[$0.level.rawValue] ?? "Unknown")] \($0.formatString)" }
logLevelStrings is a map of available types of log levels with string values.
Attaching demo too
@abdulrahuman5196 @arosiclair Soft ping for proposal review, thanks!
Thanks for the proposal @b4s36t4. Is there a way we can actively push logs to our JS logging system rather than fetching logs from Swift after the fact? Put another way, is there a way to implement Log.info() Log.hmmm(), and etc. in Swift and have those logs pushed to JS directly?
No @arosiclair. Basically there's no way to stream the logs directly through code as far as I've researched.
This is the only I was able to extract the logs, I'll try if there's anyway to stream the logs directly.
there's no way to stream the logs directly through code as far as I've researched.
Do you mean logs written to os_log specifically? There's no requirement to keep using os_log if it prevents this. Is there a way we can communicate from Native to React Native to write logs?
📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸
Issue not reproducible during KI retests. (First week)
@mvtglobally no need to reproduce this issue
Looks like we may have some agencies look at this (thread)
I started working on a proposal for this, but first i'd like get some opinions about how we go forward with writing native modules / TurboModules.
Posted a thread here: https://expensify.slack.com/archives/C01GTK53T8Q/p1719311680059169
📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸
@kirillzyusko is going to take this over, because i'm gonna be OOO for the next few weeks.
I did some initial research and shared my findings with @kirillzyusko. Also there was some good traffic in the slack thread, so we should be good to go with (potentially) implementing a native module to solve this problem