Help getting Angular private source maps working

Hi, I have successfully configured our Angular project to create source maps and upload them to Sentry as private source maps. Although Sentry now captures events and logs them, when I view them on sentry.io it’s only showing the transpiled, minified JavaScript in the backtrace. From studying the docs and troubleshooting it, it looks like at least one issue is that my new events are not associated with any release – the events say, “Release: n/a”, and the docs say that Sentry uses the release to associate an event to an uploaded source map. However, I have double-checked that my Angular TypeScript code is specifying the same release name as the release I’m creating in the build script that uploads the source maps, so I’m trying to figure out why my events are not associated with any release – and, therefore (I assume), why the events are not using my uploaded source maps.

Here is the code I use to initialize Sentry:

const releaseName = environment.sentryReleaseName;
console.log(`Initializing Sentry for release '${releaseName}' ...`);
Sentry.init({ 
  dsn: environment.sentryDSN,  
  release: releaseName
});

Here are the relevant settings in my tsconfig.json:

"sourceMap": true,
"inlineSources": true,
"sourceRoot": "/",

Here are the relevant settings in my angular.json:

"configurations": {
            "webise": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.webise.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": {
                "hidden": true,
                "scripts": true,
                "styles": true
              },
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true
            },

…and here is the code my build script uses to create and the upload source maps to Sentry:

echo "Uploading source maps to Sentry [ org=${ORG_SLUG}, project=${PROJECT_SLUG} ] ..."
$SENTRY_CLI releases --org "$ORG_SLUG" new --project "$PROJECT_SLUG" "$RELEASE_NAME"

$SENTRY_CLI releases --org "$ORG_SLUG" --project "$PROJECT_SLUG" files "$RELEASE_NAME" upload-sourcemaps ./dist/ise-frontend/ --rewrite --strip-common-prefix

I have also tried finalizing the release via the Sentry CLI, but that seems to make no difference – the backtraces in the Sentry events still show minified JS code, and the release on each event shows “n/a”.

I have verified that the build artifacts are present in our project’s page in Sentry – both the *.js and *.js.map files are present. I have also verified that the uploaded *.js files do not contain a trailing //# sourceMappingURL=foo.js.map comment (due to the fact I set sourceMap -> hidden: true in angular.json).

I’ve been chasing this most of the day, and I think the root issue is the events are not being associated with any project. I’ve triple-checked that the release name set in my Sentry.init TypeScript code matches the release I’m using the build script that uploads the source maps to Sentry, so I’m stuck on what to check next.

One other question – does the string passed to release in the Sentry.init call need to have a special format? Or is it just an arbitrary string that must be unique within the organization? Right now I’m just passing a fixed string for that.

EDIT: one thing I forgot to mention: I don’t have our source control (git) associated with Sentry for this project – I’m just uploading uploading inline source maps (i.e., maps that include the source code in the map) to Sentry. The ‘Releases’ page in Sentry says Releases aren't 100% set up because I don’t have repository integration. Is that mandatory in order for source maps to work?? From reading the docs, it appears that is optional, but I wanted to make sure.

1 Like

Got it working today. Long-story-short, the issue was that Sentry was being initialized twice because one file still had very early code in it, and the second Sentry.init call did not specify a release. The second Sentry.init call (correctly) overwrite the configuration from the first call, so that’s why no release was specified in the code, and that was why Sentry could not associate the events with the source maps for that matching release.