getsentry / sentry-react-native

Official Sentry SDK for React Native
https://sentry.io
MIT License
1.57k stars 337 forks source link

Stack trace is not deobfuscated when doing codepush releases #3593

Closed DaniyarJakupov closed 8 months ago

DaniyarJakupov commented 8 months ago

OS:

Platform:

SDK:

SDK version: 5.7.1

react-native version: 0.72.3

Are you using Expo?

Are you using sentry.io or on-premise?

If you are using sentry.io, please post a link to your issue so we can take a look:

Link to issue

Configuration:

(@sentry/react-native)

Sentry.init({
  dsn: 'https://...@sentry.io/...'
   enableAutoSessionTracking: true,
      enableOutOfMemoryTracking: false,
      environment: config.env,
      release,
      dist
});

For the codepush releases, stack traces are not deobfuscated. Source map are generated via appcenter codepush release-react command and then uploaded to Sentry. On sentry we can see a source map associated with the release. Here are the logs from bitrise:

Running "react-native bundle" command:
node node_modules/.bin/react-native bundle --assets-dest .tmp/CodePush --bundle-output .tmp/CodePush/index.android.bundle --dev false --entry-file ./packages/mobile/index.android.js --platform android --config ./packages/mobile/metro.config.js --sourcemap-output ./.tmp/CodePush/index.android.bundle.map

info Writing bundle output to:, .tmp/CodePush/index.android.bundle
info Writing sourcemap output to:, ./.tmp/CodePush/index.android.bundle.map
info Done writing bundle output
info Done writing sourcemap output
info Copying 231 asset files
info Done copying assets

Uploading source maps for android: {
  appVersion: '3.2.16',
  targetBinaryVersion: '>=3.0.0',
  cmd: "export SENTRY_PROPERTIES=./packages/mobile/android/sentry.properties && ./node_modules/@sentry/cli/sentry-cli releases files 'codepush:3.2.16-b6456_branch-fix_HART-276-sentry-mobile-doe' upload-sourcemaps ./.tmp/CodePush/index.android.bundle.map  --dist 'android-3.2.16-b6456_branch-fix_HART-276-sentry-mobile-doe' --strip-common-prefix --rewrite --log-level=debug"
}
> Found 1 file
> Analyzing 1 sources
> Rewriting sources
> Adding source map references
> Bundled 1 file for upload
> Bundle ID: e3e57d71-635f-52b2-9999-7916414153a9
> Uploaded files to Sentry
> File upload complete (processing pending on server)
> Organization: REDACTED
> Project: [REDACTED]-mobile
> Release: codepush:3.2.16-b6456_branch-fix_HART-276-sentry-mobile-doe
> Dist: android-3.2.16-b6456_branch-fix_HART-276-sentry-mobile-doe
> Upload type: artifact bundle
Source Map Upload Report
  Source Maps
    ~/index.android.bundle.map
Screenshot 2024-02-13 at 10 09 13

Actual result:

Screenshot 2024-02-13 at 09 59 07

Expected result:

Screenshot 2024-02-13 at 09 59 26

Thank you for the help!

krystofwoldrich commented 8 months ago

Hi @DaniyarJakupov, thank you for the message,

for the source maps to work, you must upload both the bundle and the source map.

Adjusted command:

export SENTRY_PROPERTIES=./packages/mobile/android/sentry.properties && ./node_modules/@sentry/cli/sentry-cli releases files 'codepush:3.2.16-b6456_branch-fix_HART-276-sentry-mobile-doe' upload-sourcemaps ./.tmp/CodePush/index.android.bundle.map ./.tmp/CodePush/index.android.bundle  --dist 'android-3.2.16-b6456_branch-fix_HART-276-sentry-mobile-doe' --strip-common-prefix --rewrite --log-level=debug

Let us know if this solved the issue.

DaniyarJakupov commented 8 months ago

Hello @krystofwoldrich , thank you for the answer! Actually we already upload the bundle before uploading source maps in a separate Uploading bundle for android step. I missed to include it in the logs, sorry. Full log looks like that:

Running "react-native bundle" command:
node node_modules/.bin/react-native bundle --assets-dest .tmp/CodePush --bundle-output .tmp/CodePush/index.android.bundle --dev false --entry-file ./packages/mobile/index.android.js --platform android --config ./packages/mobile/metro.config.js --sourcemap-output ./.tmp/CodePush/index.android.bundle.map

info Writing bundle output to:, .tmp/CodePush/index.android.bundle
info Writing sourcemap output to:, ./.tmp/CodePush/index.android.bundle.map
info Done writing bundle output
info Done writing sourcemap output
info Copying 231 asset files
info Done copying assets

Uploading bundle for android: {
  appVersion: '3.2.16',
  targetBinaryVersion: '>=3.0.0',
  cmd: "export SENTRY_PROPERTIES=./packages/mobile/android/sentry.properties && ./node_modules/@sentry/cli/sentry-cli releases new 'codepush:3.2.16-b6456_branch-fix_HART-276-sentry-mobile-doe' && ./node_modules/@sentry/cli/sentry-cli releases files 'codepush:3.2.16-b6456_branch-fix_HART-276-sentry-mobile-doe' upload ./.tmp/CodePush/index.android.bundle '~/index.android.bundle' --dist 'android-3.2.16-b6456_branch-fix_HART-276-sentry-mobile-doe' --log-level=debug"
}

Uploading source maps for android: {
  appVersion: '3.2.16',
  targetBinaryVersion: '>=3.0.0',
  cmd: "export SENTRY_PROPERTIES=./packages/mobile/android/sentry.properties && ./node_modules/@sentry/cli/sentry-cli releases files 'codepush:3.2.16-b6456_branch-fix_HART-276-sentry-mobile-doe' upload-sourcemaps ./.tmp/CodePush/index.android.bundle.map  --dist 'android-3.2.16-b6456_branch-fix_HART-276-sentry-mobile-doe' --strip-common-prefix --rewrite --log-level=debug"
}
> Found 1 file
> Analyzing 1 sources
> Rewriting sources
> Adding source map references
> Bundled 1 file for upload
> Bundle ID: e3e57d71-635f-52b2-9999-7916414153a9
> Uploaded files to Sentry
> File upload complete (processing pending on server)
> Organization: REDACTED
> Project: [REDACTED]-mobile
> Release: codepush:3.2.16-b6456_branch-fix_HART-276-sentry-mobile-doe
> Dist: android-3.2.16-b6456_branch-fix_HART-276-sentry-mobile-doe
> Upload type: artifact bundle
Source Map Upload Report
  Source Maps
    ~/index.android.bundle.map

Now just in case I've added ./.tmp/CodePush/index.android.bundle again like you suggested:

info Writing bundle output to:, .tmp/CodePush/index.android.bundle
info Writing sourcemap output to:, ./.tmp/CodePush/index.android.bundle.map
info Done writing bundle output
info Done writing sourcemap output
info Copying 231 asset files
info Done copying assets

Uploading bundle for android: {
  appVersion: '3.3.1',
  targetBinaryVersion: '>=3.0.0',
  cmd: "export SENTRY_PROPERTIES=./packages/mobile/android/sentry.properties && ./node_modules/@sentry/cli/sentry-cli releases new 'codepush:3.3.1-b6476_branch-fix_HART-276-sentry-mobile-does' && ./node_modules/@sentry/cli/sentry-cli releases files 'codepush:3.3.1-b6476_branch-fix_HART-276-sentry-mobile-does' upload ./.tmp/CodePush/index.android.bundle '~/index.android.bundle' --dist 'android-3.3.1-b6476_branch-fix_HART-276-sentry-mobile-does' --log-level=debug"
}

Uploading source maps for android: {
  appVersion: '3.3.1',
  targetBinaryVersion: '>=3.0.0',
  cmd: "export SENTRY_PROPERTIES=./packages/mobile/android/sentry.properties && ./node_modules/@sentry/cli/sentry-cli releases files 'codepush:3.3.1-b6476_branch-fix_HART-276-sentry-mobile-does' upload-sourcemaps ./.tmp/CodePush/index.android.bundle.map ./.tmp/CodePush/index.android.bundle --dist 'android-3.3.1-b6476_branch-fix_HART-276-sentry-mobile-does' --strip-common-prefix --rewrite --log-level=debug"
}
> Found 1 file
> Found 1 file
> Analyzing 2 sources
> Rewriting sources
> Adding source map references
> Bundled 1 file for upload
> Bundle ID: e053b4d1-49ed-5a35-baed-28d84b66644d
> Uploaded files to Sentry
> File upload complete (processing pending on server)
> Organization: REDACTED
> Project: [REDACTED]-mobile
> Release: codepush:3.3.1-b6476_branch-fix_HART-276-sentry-mobile-does
> Dist: android-3.3.1-b6476_branch-fix_HART-276-sentry-mobile-does
> Upload type: artifact bundle
Source Map Upload Report
  Minified Scripts
    ~/index.android.bundle (skipped; already uploaded)
  Source Maps
    ~/index.android.bundle.map

As you can see, we get ~/index.android.bundle (skipped; already uploaded), but it still not showing up as an artifact, only ~/index.android.bundle.map is there. And as a result, stack trace again not deobfuscated. Any ideas?

Screenshot 2024-02-14 at 14 27 43 Screenshot 2024-02-14 at 14 32 47
DaniyarJakupov commented 8 months ago

So what worked is to remove our bundle upload command: const sentryUploadBundleCmd = `export SENTRY_PROPERTIES=./packages/mobile/${platform}/sentry.properties && ${SENTRY_CLI_PATH} releases new 'codepush:${releaseDescription}' && ${SENTRY_CLI_PATH} releases files 'codepush:${releaseDescription}' upload ${platforms[platform].bundleOutput} '~/${platforms[platform].bundleName}' --dist '${platform}-${releaseDescription}' --log-level=debug

and just have sourcemap and bundle upload together: const sentryUploadSourceMap = `export SENTRY_PROPERTIES=./packages/mobile/${platform}/sentry.properties && ${SENTRY_CLI_PATH} releases files 'codepush:${releaseDescription}' upload-sourcemaps ${platforms[platform].sourcemapOutput} ${platforms[platform].bundleOutput} --dist '${platform}-${releaseDescription}' --strip-common-prefix --rewrite --log-level=debug

But don't get why sentryUploadBundleCmd stopped working at some point. Any insights @krystofwoldrich ? And thank you for the help!

krystofwoldrich commented 8 months ago

@DaniyarJakupov Thank you for the details and I'm happy that it works now.

krystofwoldrich commented 8 months ago

@DaniyarJakupov The separate bundle and source map upload doesn't work because of the change to Artifact Bundles.

This looks like sentry-cli bug as it reports that the bundle will include both bundle and source maps but only the source map is registered to the bundle.

> Found 1 file
> Found 1 file
> Analyzing 2 sources
> Rewriting sources
> Adding source map references
> Bundled 1 file for upload
> Bundle ID: e053b4d1-49ed-5a35-baed-28d84b66644d
> Uploaded files to Sentry
> File upload complete (processing pending on server)
> Organization: REDACTED
> Project: [REDACTED]-mobile
> Release: codepush:3.3.1-b6476_branch-fix_HART-276-sentry-mobile-does
> Dist: android-3.3.1-b6476_branch-fix_HART-276-sentry-mobile-does
> Upload type: artifact bundle
Source Map Upload Report
  Minified Scripts
    ~/index.android.bundle (skipped; already uploaded)
  Source Maps
    ~/index.android.bundle.map
krystofwoldrich commented 8 months ago

I'll close this as the RN issue was resolved by performing a single upload.