Sentry-javascript: Cannot seem to get the Source Maps working with NodeJS + TypeScript.

Created on 21 Jan 2021  路  2Comments  路  Source: getsentry/sentry-javascript

Package + Version

  • [ ] @sentry/browser
  • [x] @sentry/node
  • [ ] raven-js
  • [ ] raven-node _(raven for node)_
  • [ ] other:

Version:

6.0.0

Description

I have followed this documentation to setup the source maps:

Looked at these previous issues for help:

Directory Setup:

- /dist
- /src
....

tsconfig.json:

{
    "compilerOptions": {
        "allowJs": false,
        "allowSyntheticDefaultImports": true,
        "alwaysStrict": true,
        "baseUrl": "./",
        "declaration": false,
        "esModuleInterop": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "forceConsistentCasingInFileNames": true,
        "inlineSources": true,
        "isolatedModules": false,
        "lib": ["ES2018"],
        "module": "commonjs",
        "moduleResolution": "node",
        "noEmit": false,
        "noFallthroughCasesInSwitch": true,
        "noImplicitAny": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "outDir": "./dist",
        "resolveJsonModule": true,
        "skipLibCheck": true,
        "sourceMap": true,
        "sourceRoot": "/",
        "strict": true,
        "strictNullChecks": true,
        "strictPropertyInitialization": true,
        "target": "ES2019",
        "types": ["node", "jest"],
        "typeRoots": ["./node_modules/@types", "./src/@types"]
    },
        "exclude": ["node_modules", "dist"]
}

Placed this at the top of /src/server.ts as outlined in the documentation:

declare global {
    namespace NodeJS {
        interface Global {
            __rootdir__: string
        }
    }
}
global.__rootdir__ = __dirname || process.cwd()

Initializing sentry like so:

import * as Sentry from '@sentry/node'

Sentry.init({
    dsn: process.env.SENTRY_DSN,
    environment: process.env.NODE_ENV,
    release: process.env.GITHUB_SHA,
    enabled: true,
    integrations: [
        new RewriteFrames({
            root: global.__rootdir__
        })
    ],
    debug: true
})

Uploading Source Maps in publish_sentry_source_maps.sh:

sentry-cli releases new "$GITHUB_SHA"
sentry-cli releases files "$GITHUB_SHA" upload-sourcemaps ./dist
sentry-cli releases finalize "$GITHUB_SHA"

JS and Source Maps are being published successfully and I can see them in my release. The exception is still showing up as pure JS instead of the expected TS. I haven't been able to find any other errors when debugging or through sentry processing.

An example of this issue can be seen here: https://sentry.io/organizations/mastery-logistics-systems/issues/2167890062/?project=5600691&query=is%3Aunresolved

@kamilogorek tagging you because it seems like you were pretty knowledgable on other similar issues. I would greatly appreciate any help, thanks!

Question

Most helpful comment

@rdelander change

sentry-cli releases files "$GITHUB_SHA" upload-sourcemaps ./dist

to

sentry-cli releases files "$GITHUB_SHA" upload-sourcemaps ./dist --url-prefix '~/dist'

Frame URL has to match the one from uploaded artifacts.

image
image

All 2 comments

@rdelander change

sentry-cli releases files "$GITHUB_SHA" upload-sourcemaps ./dist

to

sentry-cli releases files "$GITHUB_SHA" upload-sourcemaps ./dist --url-prefix '~/dist'

Frame URL has to match the one from uploaded artifacts.

image
image

@kamilogorek That fixed my issue. Thank you so much

Was this page helpful?
0 / 5 - 0 ratings

Related issues

grigored picture grigored  路  3Comments

adepue picture adepue  路  3Comments

jaylinski picture jaylinski  路  3Comments

dimmduh picture dimmduh  路  3Comments

franciscovelez picture franciscovelez  路  3Comments