App icon indicating copy to clipboard operation
App copied to clipboard

[$250] Upload logs from Swift code

Open m-natarajan opened this issue 1 year ago • 33 comments

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

  1. Go to staging.new.expensify.com
  2. 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:

View all open jobs on GitHub

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 OwnerCurrent Issue Owner: @

m-natarajan avatar May 27 '24 19:05 m-natarajan

This has been labelled "Needs Reproduction". Follow the steps here: https://stackoverflowteams.com/c/expensify/questions/16989

MelvinBot avatar May 27 '24 19:05 MelvinBot

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.

melvin-bot[bot] avatar May 27 '24 19:05 melvin-bot[bot]

Job added to Upwork: https://www.upwork.com/jobs/~018463b08116cdfa88

melvin-bot[bot] avatar May 27 '24 19:05 melvin-bot[bot]

Triggered auto assignment to Contributor-plus team member for initial proposal review - @abdulrahuman5196 (External)

melvin-bot[bot] avatar May 27 '24 19:05 melvin-bot[bot]

@puneetlath, @arosiclair, @abdulrahuman5196 Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

melvin-bot[bot] avatar May 31 '24 18:05 melvin-bot[bot]

seems to be an internal assigned issue. Seems we don't have a PR yet.

abdulrahuman5196 avatar May 31 '24 19:05 abdulrahuman5196

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.

arosiclair avatar May 31 '24 19:05 arosiclair

No progress on this yet

arosiclair avatar Jun 03 '24 15:06 arosiclair

Focusing on a critical issue atm.

arosiclair avatar Jun 06 '24 15:06 arosiclair

@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!

melvin-bot[bot] avatar Jun 10 '24 18:06 melvin-bot[bot]

Since the plan is to just improve logging for swift code, I'm going to switch this to a NewFeature and mark this External.

arosiclair avatar Jun 11 '24 13:06 arosiclair

Current assignee @abdulrahuman5196 is eligible for the External assigner, not assigning anyone new.

melvin-bot[bot] avatar Jun 11 '24 13:06 melvin-bot[bot]

Current assignee @puneetlath is eligible for the NewFeature assigner, not assigning anyone new.

melvin-bot[bot] avatar Jun 11 '24 13:06 melvin-bot[bot]

: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:

melvin-bot[bot] avatar Jun 11 '24 13:06 melvin-bot[bot]

Triggered auto assignment to Design team member for new feature review - @dubielzyk-expensify (NewFeature)

melvin-bot[bot] avatar Jun 11 '24 13:06 melvin-bot[bot]

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.

arosiclair avatar Jun 11 '24 14:06 arosiclair

@dubielzyk-expensify this is just a logging improvement so no design input needed here.

arosiclair avatar Jun 11 '24 14:06 arosiclair

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

melvin-bot[bot] avatar Jun 11 '24 16:06 melvin-bot[bot]

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

Screenshot 2024-06-13 at 3 49 48 AM

b4s36t4 avatar Jun 12 '24 22:06 b4s36t4

@abdulrahuman5196 @arosiclair Soft ping for proposal review, thanks!

b4s36t4 avatar Jun 12 '24 22:06 b4s36t4

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?

arosiclair avatar Jun 17 '24 13:06 arosiclair

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.

b4s36t4 avatar Jun 17 '24 14:06 b4s36t4

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?

arosiclair avatar Jun 17 '24 21:06 arosiclair

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

melvin-bot[bot] avatar Jun 18 '24 16:06 melvin-bot[bot]

Issue not reproducible during KI retests. (First week)

mvtglobally avatar Jun 20 '24 14:06 mvtglobally

@mvtglobally no need to reproduce this issue

arosiclair avatar Jun 20 '24 16:06 arosiclair

Looks like we may have some agencies look at this (thread)

arosiclair avatar Jun 24 '24 19:06 arosiclair

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

chrispader avatar Jun 25 '24 11:06 chrispader

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

melvin-bot[bot] avatar Jun 25 '24 16:06 melvin-bot[bot]

@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

chrispader avatar Jun 26 '24 09:06 chrispader