sentry-capacitor icon indicating copy to clipboard operation
sentry-capacitor copied to clipboard

Source maps in production build pointing to .html file instead of .ts

Open EugeneDP89 opened this issue 1 year ago • 16 comments

Environment

Production

What version are you running? Etc.

"@angular/common": "^17.3.7" "@ionic/angular": "7.8.6" "@capacitor/ios": "5.7.5" "@sentry/angular-ivy": "^7.93.0" "@sentry/capacitor": "^0.17.0" "@sentry/cli": "^2.31.0"

Steps to Reproduce

  1. creating a build using command ionic capacitor build ios --configuration=prod --source-map
  2. uploading source maps using command sentry-cli sourcemaps inject --org gymcloud --project strongfirst-mobile ./www && sentry-cli sourcemaps upload --org gymcloud --project strongfirst-mobile ./www --release 1.6 --dist 14

Expected Result

With "optimization": true (enabled for production builds) error stack trace should point to .ts file and method that caused error

Actual Result

With "optimization": true (enabled for production builds) error stack trace points to .html file that contains button that triggers error method, but points to the code at the top of the file, not even the button itself

What actually happened.

The issue is with source maps. I have the next angular.json configuration

"app": {
  "architect": {
    "build": {
      "scripts": [],
      "vendorChunk": true,
      "extractLicenses": false,
      "buildOptimizer": false,
      "sourceMap": true,
      "optimization": false,
      "namedChunks": true
    },
    "configurations": {
      "prod": {
        "optimization": true,
        "outputHashing": "all",
        "sourceMap": {
          "scripts": true,
          "styles": false,
          "hidden": true,
          "vendor": false
        },
        "namedChunks": false,
        "extractLicenses": true,
        "vendorChunk": false,
        "buildOptimizer": true,
      }
    }
  }
}

When I'm using "optimization": true in configurations -> prod source maps are showing html file as a source of error, and position is wrong (button that triggers error is far below).

If I'm using "optimization": false then it shows correct typescript file (error location is little wrong, showing 3 lines higher then it is).

I've tried to choose both Angular and tsc options in sentry wizard, but result is the same. tsc option added this code to tsconfig.json file

"useDefineForClassFields": false,
"inlineSources": true,
// Set `sourceRoot` to  "/" to strip the build path prefix
// from generated source code references.
// This improves issue grouping in Sentry.
"sourceRoot": "/"

This is the result for "optimization": true optimisation_true link to event

this is for "optimization": false optimisation_false link to event

I don't think disabling optimization for production is good idea.

EugeneDP89 avatar May 08 '24 21:05 EugeneDP89

Hi Eugene and thank you for opening this issue with all the information for reproducing it! We will investigate what's going on and give you a feedback if anything needs to be changed on the script or on the SDK itself.

lucas-zimerman avatar May 11 '24 02:05 lucas-zimerman

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

github-actions[bot] avatar Jun 02 '24 00:06 github-actions[bot]

comment to not close

EugeneDP89 avatar Jun 02 '24 00:06 EugeneDP89

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

github-actions[bot] avatar Jun 24 '24 00:06 github-actions[bot]

comment to not close

EugeneDP89 avatar Jun 24 '24 00:06 EugeneDP89

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

github-actions[bot] avatar Jul 27 '24 00:07 github-actions[bot]

Hi Eugene and thank you for opening this issue with all the information for reproducing it! We will investigate what's going on and give you a feedback if anything needs to be changed on the script or on the SDK itself.

Any progress on this?

EugeneDP89 avatar Jul 27 '24 00:07 EugeneDP89

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

github-actions[bot] avatar Aug 19 '24 00:08 github-actions[bot]

comment to not close

EugeneDP89 avatar Aug 19 '24 00:08 EugeneDP89

I faced the same problem and the issue is because the copying of the web assets happens before the injection of the debug ids.

One way to fix this is to generate the web assets first, run the sentry cli sourcemap commands and then copy the web assets to Capacitor native platform(s). This would work even without providing the release and dist values and with optimization set to true

raygomez avatar Aug 22 '24 22:08 raygomez

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

github-actions[bot] avatar Sep 13 '24 00:09 github-actions[bot]

comment

EugeneDP89 avatar Sep 13 '24 00:09 EugeneDP89

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

github-actions[bot] avatar Oct 05 '24 00:10 github-actions[bot]

comment

EugeneDP89 avatar Oct 05 '24 00:10 EugeneDP89

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

github-actions[bot] avatar Oct 27 '24 00:10 github-actions[bot]

comment

EugeneDP89 avatar Oct 27 '24 12:10 EugeneDP89

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

github-actions[bot] avatar Nov 18 '24 00:11 github-actions[bot]

comment

EugeneDP89 avatar Nov 18 '24 18:11 EugeneDP89

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

github-actions[bot] avatar Dec 10 '24 00:12 github-actions[bot]

comment

EugeneDP89 avatar Dec 10 '24 01:12 EugeneDP89

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

github-actions[bot] avatar Jan 03 '25 00:01 github-actions[bot]

comment

EugeneDP89 avatar Jan 03 '25 19:01 EugeneDP89

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

github-actions[bot] avatar Jan 26 '25 00:01 github-actions[bot]

comment

EugeneDP89 avatar Jan 27 '25 14:01 EugeneDP89

Hi, sorry for the late response, I have checked the usage of the flag optimization and it is not altering the result from the stack-trace.

Could you also try with an easier example like capturing a message to see if the issue also happens to it?

import * as Sentry from '@sentry/capacitor';
...

Sentry.captureMessage('test');

lucas-zimerman avatar Jan 29 '25 19:01 lucas-zimerman

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

github-actions[bot] avatar Feb 20 '25 00:02 github-actions[bot]

Hi, sorry for the late response, I have checked the usage of the flag optimization and it is not altering the result from the stack-trace.

Could you also try with an easier example like capturing a message to see if the issue also happens to it?

import * as Sentry from '@sentry/capacitor'; ...

Sentry.captureMessage('test');

raygomez correctly described the issue in his comment and his workaround works perfect. Do you still want me to try capturing a message?

EugeneDP89 avatar Feb 24 '25 22:02 EugeneDP89

Ok thank you for your response, I will check with the folks who knows better about the CLI to see what could be done here

lucas-zimerman avatar Mar 14 '25 12:03 lucas-zimerman

At the moment, you can do the following:

Add two steps for injecting debug Ids

"build:android": "ionic capacitor build android --configuration=production --source-map && yarn sentry:sourcemaps:android && yarn clear:sourcemaps:android",
"build:ios": "ionic capacitor build ios --configuration=production --source-map && yarn sentry:sourcemaps:ios && yarn clear:sourcemaps:ios",
    
"sentry:sourcemaps:android": "sentry-cli sourcemaps inject --org YOUR_ORG --project YOUR_PROJECT ./android/app/src/main/assets/public && sentry-cli sourcemaps upload --org YOUR_ORG --project YOUR_PROJECT ./android/app/src/main/assets/public",
"sentry:sourcemaps:ios": "sentry-cli sourcemaps inject --org YOUR_ORG --project YOUR_PROJECT ./ios/App/App/public && sentry-cli sourcemaps upload --org YOUR_ORG --project YOUR_PROJECT ./ios/App/App/public",

// Suggested so you dont leave sourcemap files inside your app.
"clear:sourcemaps:android": "find ./android/app/src/main/assets/public -type f -name '*.map' -delete"
"clear:sourcemaps:ios": "find ./ios/App/App/public -type f -name '*.map' -delete"

The path to your public folder where Capacitor adds the JavaScript code may change slightly, but the scripts should work for your project.

lucas-zimerman avatar Jun 02 '25 14:06 lucas-zimerman