Skip to content

Include source maps for staging apps #9293

Closed

Description

@roryabraham

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Problem

We are starting to automatically create GitHub issues from mobile crash reports produced by Firebase Crashlytics for the staging and production mobile apps. These crash reports include stacktraces that are difficult or impossible to follow, because they reference lines in a bundled application, not lines in the source code.

Solution

Generate and include source maps for the staging apps so that stacktraces can reference lines in source code rather than lines from a massive minified bundle. Investigate the drawbacks of including these source maps in the staging app, and consider whether we could also include them in the production app.

View all open jobs on GitHub

Activity

  1. added
    Improvement
    on Jun 2, 2022
  2. roryabraham commented on Jun 2, 2022

    @roryabraham
    ContributorAuthor
  3. roryabraham commented on Jun 2, 2022

    @roryabraham
    ContributorAuthor

    Full-transparency: I really don't know much about the topic of source maps, how they work, or their benefits and drawbacks. But I believe having better stacktraces in crash reports would help us to more quickly and successfully trace and fix crashes.

  4. roryabraham commented on Jun 2, 2022

    @roryabraham
    ContributorAuthor

    cc @kidroca too, since this seems like something you might be knowledgable about

  5. kidroca commented on Jun 2, 2022

    @kidroca
    Contributor

    I think since the code is already open source we should be fine including source maps along the bundled code

    There should be a way to tell crashlytics to use source maps. I can work on this and investigate what's needed


    Full-transparency: I really don't know much about the topic of source maps, how they work, or their benefits and drawbacks.

    No one does 😁

    Benefits

    • seeing real source while debugging
    • refference real lines in stack traces

    Drawbacks

    • people can easily see your source
  6. AndrewGable commented on Jun 2, 2022

    @AndrewGable
    Contributor

    Agree no concern because it's open source, this would be great to look into.

  7. roryabraham commented on Jun 3, 2022

    @roryabraham
    ContributorAuthor

    It might be tough for @kidroca to look into the crashlytics piece, because he won't have access to Firebase.

  8. AndrewGable commented on Jun 3, 2022

    @AndrewGable
    Contributor

    Once we get the source maps in place, I'd be happy to check Firebase

  9. kidroca commented on Jun 14, 2022

    @kidroca
    Contributor

    web and desktop already include source maps
    you can find them this way:

    1. find bundle name
    2. append .map to it

    Here's the current one for staging: https://staging.new.expensify.com/app-cc32624656c52b1a56be.bundle.js.map
    image

    • Select the ...bundle.js file, then "Open in new tab", then append .map to url
  10. roryabraham commented on Jun 14, 2022

    @roryabraham
    ContributorAuthor

    Nice! Crashlytics is only relevant to iOS/Android for now. Do you know if those apps ship with a source map?

  11. kidroca commented on Jun 14, 2022

    @kidroca
    Contributor

    Source maps for iOS/Android should already be generated, the problem is even with source maps Firebase does not accept uploading a source map file, though stack traces can be decoded manually: invertase/react-native-firebase#2327 (comment)

    So instead of trying to make Firebase work with source maps (show mapped sources) we can decode the stack trace and create a github issue mapped to original source

    If sending/using source maps was possible it would have been explained here: https://rnfirebase.io/crashlytics/usage

    Generating source maps

    As mentioned they should already be generated, but since creating an issue will happen in a different context it should

    1. When an error happens - extract error, stack trace and app version
    2. Use app version so that we can map to the given version source
      • Update release scripts so they capture source-maps as artifacts. E.g. capture v1.1.77-0.ios/android/web.source.js.map in job artifacts to allow a future pipeline to use them
      • Alternatively the job should checkout the repository at the given version and generate source maps each time

    To generate source maps for iOS/Android we can run the following commands:

    iOS

    react-native bundle \
      --dev false \
      --platform ios \
      --entry-file index.ios.js \
      --bundle-output main.jsbundle \
      --sourcemap-output main.jsbundle.map

    Android

    react-native bundle \
      --dev false \
      --platform android \
      --entry-file index.android.js \
      --bundle-output index.android.bundle \
      --sourcemap-output index.android.bundle.map

    The build process probably already generates these so we should just find where and expose them as build artifacts

    Symbolicating - decoding minified stack trace to original source

    Covered in: https://reactnative.dev/docs/symbolication

    Given a piece of text containing minified stack trace (we'll be getting this from Firebase somehow)
    We run

    npx metro-symbolicate android/app/build/generated/sourcemaps/react/release/index.android.bundle.map < stacktrace.txt

    to convert it to original source that we can use to create the Github issue


    I think Firebase does not support js source maps (in iOS/Android), because in the Firebase Console we have Web/iOS/Android apps and each source is mapped to the underlying architecture, so iOS sources are mapped to iOS code (which is mapped at compile time) and the service knows how to decode that, while with js sources it would be up to react-native-firebase to remap js stack traces before posting crashlytics to Firebase and I guess that's an extra step they don't want to do for various reasons (just my thoughts though, not a fact)

  12. kidroca commented on Jun 14, 2022

    @kidroca
    Contributor

    Feature request for react-native-firebase to use source maps for Crashlytics: https://invertase.canny.io/react-native-firebase/p/crashlytics-to-take-in-javascript-soucemap

  13. 38 remaining items

  14. added
    NewFeature
    and removed
    Bug
    Improvement
    on Nov 8, 2022
  15. self-assigned this
    on Nov 9, 2022
  16. AndrewGable commented on Nov 10, 2022

    @AndrewGable
    Contributor

    Working on this now.

  17. AndrewGable commented on Nov 10, 2022

    @AndrewGable
    Contributor

    Made good progress on the API side of things, but running into issues when decoding. @kidroca or @roryabraham if you spot something, let me know...

    1. Using this source map from 1.2.24.0 found here: https://github.com/Expensify/App/actions/runs/3395575377
    2. I unzip it in App, get main.jsbundle.map
    3. I use the stack trace from this issue: [HOLD #9402] [$500] Investigate: 💥 Crash 💥 .getAttachmentName #10907 and same version
    4. I store it in encodedStackTrace.txt
    andrew ➜ (main) App cat encodedStackTrace.txt
    anonymous (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New Expensify.app/main.jsbundle:2527:489:2527)
    onPress (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New Expensify.app/main.jsbundle:2525:1587:2525)
    onPress (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New Expensify.app/main.jsbundle:2630:2354:2630)
    value (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New Expensify.app/main.jsbundle:2375:2034:2375)
    onPress (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New Expensify.app/main.jsbundle:1590:1947:1590)
    value (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New Expensify.app/main.jsbundle:197:8496:197)
    value (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New Expensify.app/main.jsbundle:197:7752:197)
    onResponderRelease (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New Expensify.app/main.jsbundle:197:5671:197)
    apply
    o (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New Expensify.app/main.jsbundle:51:151:51)
    apply
    h (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New Expensify.app/main.jsbundle:51:294:51)
    apply
    g (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New Expensify.app/main.jsbundle:51:348:51)
    S (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New Expensify.app/main.jsbundle:51:659:51)
    Ne (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New Expensify.app/main.jsbundle:51:14312:51)
    forEach
    Y (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New Expensify.app/main.jsbundle:51:5326:51)
    anonymous (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New Expensify.app/main.jsbundle:51:14660:51)
    Pe (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New Expensify.app/main.jsbundle:51:99214:51)
    Ce (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New Expensify.app/main.jsbundle:51:14122:51)
    Le (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New Expensify.app/main.jsbundle:51:14499:51)
    receiveTouches (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New Expensify.app/main.jsbundle:51:15298:51)
    apply
    value (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New Expensify.app/main.jsbundle:42:3798:42)
    anonymous (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New Expensify.app/main.jsbundle:42:674:42)
    value (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New Expensify.app/main.jsbundle:42:2504:42)
    value (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New Expensify.app/main.jsbundle:42:646:42)
    1. I get this as an output
    andrew ➜ (main) App npm run symbolicate:ios encodedStackTrace.txt
    
    > new.expensify@1.2.26-0 symbolicate:ios
    > npx metro-symbolicate main.jsbundle.map "encodedStackTrace.txt"
    
    null:null:null

    Any ideas? I think I remember we might need to do something to the stacktrace before running it through metro-symbolicate?

  18. JmillsExpensify commented on Nov 11, 2022

    @JmillsExpensify
    Contributor

    Adding this to WAQ based on recent discussion.

  19. AndrewGable commented on Nov 11, 2022

    @AndrewGable
    Contributor

    Ah OK I see from the PR:

    "stacktraces are expected to come from stdin"

    So seeing some better results with this command:

    npm run symbolicate:ios < encodedStackTrace.txt
    
    > new.expensify@1.2.24-3 symbolicate:ios
    > npx metro-symbolicate main.jsbundle.map
    
    anonymous (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New /Users/runner/work/App/App/node_modules/react-native-gesture-handler/src/PlatformConstants.ts:8:<global>)
    onPress (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New /Users/runner/work/App/App/src/styles/getModalStyles/getBaseModalStyles.js:205:default)
    onPress (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New /Users/runner/work/App/App/src/pages/EnablePayments/FailedKYC.js:32:<global>)
    value (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New /Users/runner/work/App/App/node_modules/react-native-render-html/node_modules/ramda/src/converge.js:66:<global>)
    onPress (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New /Users/runner/work/App/App/node_modules/react-native-render-html/node_modules/ramda/src/internal/_concat.js:33:_concat)
    value (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New null:null:null)
    value (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New null:null:null)
    onResponderRelease (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New null:null:null)
    apply
    o (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New /Users/runner/work/App/App/node_modules/react-native/Libraries/ReactNative/UIManagerProperties.js:29:<global>)
    apply
    h (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New null:null:null)
    apply
    g (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New /Users/runner/work/App/App/node_modules/react-native/Libraries/Utilities/logError.js:18:logError)
    S (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New /Users/runner/work/App/App/node_modules/es-abstract/2021/ToString.js:5:<global>)
    Ne (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New null:null:null)
    forEach
    Y (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New null:null:null)
    anonymous (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New null:null:null)
    Pe (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New null:null:null)
    Ce (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New null:null:null)
    Le (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New null:null:null)
    receiveTouches (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New null:null:null)
    apply
    value (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New null:null:null)
    anonymous (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New /Users/runner/work/App/App/node_modules/define-properties/index.js:4:<global>)
    value (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New null:null:null)
    value (/private/var/containers/Bundle/Application/0B131D53-17FA-4EAC-8C71-F9B65A5D0029/New /Users/runner/work/App/App/node_modules/es-abstract/2021/RequireObjectCoercible.js:3:<global>)
  20. AndrewGable commented on Nov 11, 2022

    @AndrewGable
    Contributor

    Discussing internally but sounds like we need to configure our API to run this command further than we initially expected. Working on it!

  21. AndrewGable commented on Nov 12, 2022

    @AndrewGable
    Contributor

    End of week update: We need to install NodeJS on the web servers, so this is turning into slightly a larger project. Working on doing so now and then will circle back to the specific API layer code once that's done. Otherwise this is working in local testing.

  22. AndrewGable commented on Nov 15, 2022

    @AndrewGable
    Contributor

    After discussion we wanted a different solution than the initial one proposed for NodeJS. Working on an alternative solution.

  23. AndrewGable commented on Nov 16, 2022

    @AndrewGable
    Contributor

    Closing per https://github.com/Expensify/Expensify/issues/243479, tl;dr we are turning off Firebase crashes for the time being.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

EngineeringNewFeatureWeekly

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions