getsentry / sentry-cli

A command line utility to work with Sentry.
https://docs.sentry.io/cli/
BSD 3-Clause "New" or "Revised" License
900 stars 221 forks source link

Typescript: "Source code was not found for app:///index.js" #375

Closed mrnagydavid closed 4 years ago

mrnagydavid commented 6 years ago

@HazAT, a little help, please. I noticed a lot of unanswered issues of a similar kind and a lot of issues where you didn't get a reply from OP. I won't disappear. Let's figure this out!

The problem is: the errors received in Sentry don't get mapped to the original .ts, but shown only in the transpiled .js. I was following the https://docs.sentry.io/clients/node/typescript/.

Our stack is Typescript using tsc and no webpack, no uglify etc. The folder structure is simple:

|
|-build/
|-deploy/
|-src/
|-package.json
|-tsconfig.json

tsconfig.json relevant settings:

"target": "es6",
"module": "commonjs",
"outDir": "./build",
"moduleResolution": "node",
"sourceMap": true,
"sourceRoot": "/",
"inlineSources": true

src/index.ts is the only file in the test repo:

import * as path from 'path'
import * as Raven from 'raven'

function a() {
    throw new Error("9");
}

const root = __dirname || process.cwd()
Raven.disableConsoleAlerts()
  Raven.config('https://fa995b4e59b7450f9335fe965ffeb9e7@sentry.io/1278659', {
    captureUnhandledRejections: true,
    environment: "test",
    dataCallback(data) {
      const stacktrace = data.exception && data.exception[0].stacktrace
      if (stacktrace && stacktrace.frames) {
        stacktrace.frames.forEach((frame: any) => {
          if (frame.filename.startsWith('/')) {
            frame.filename = 'app:///' + path.relative(root, frame.filename)
          }
        })
      }
      return data
    }
  }).install();

Raven.context(function () {
  a();
});

As per suggested by https://docs.sentry.io/clients/node/typescript/.

This produces the index.js and the index.js.map:

{
  "version":3,
  "file":"index.js",
  "sourceRoot":"/",
  "sources":["index.ts"],
  "names":[],
  "mappings":"..."
}

We use Codeship, so I use jet and getsentry/sentry-cli:latest attaching the project root to /work:

sentry-release:
  image: getsentry/sentry-cli:latest
  environment:
    SENTRY_AUTH_TOKEN: token
    SENTRY_ORG: myorg
    SENTRY_PROJECT: myproject
  volumes:
  - .:/work

codeship-steps.yml:

- name: '[testing] testing sentry'
  type: serial
  tag: sentry
  steps:
  - name: '[testing] release to sentry'
    service: sentry-release
    command: sh ./deploy/sentry-release.sh -e test

And finally the relevant commands in sentry-release.sh run inside the docker container:

sentry-cli --auth-token "$SENTRY_AUTH_TOKEN" releases -o "$SENTRY_ORG" -p "$SENTRY_PROJECT" new "$SENTRY_VERSION"
sentry-cli --auth-token "$SENTRY_AUTH_TOKEN" releases -o "$SENTRY_ORG" -p "$SENTRY_PROJECT" files "$SENTRY_VERSION" upload-sourcemaps --rewrite ./build
sentry-cli --auth-token "$SENTRY_AUTH_TOKEN" releases -o "$SENTRY_ORG" -p "$SENTRY_PROJECT" finalize "$SENTRY_VERSION"
sentry-cli --auth-token "$SENTRY_AUTH_TOKEN" releases -o "$SENTRY_ORG" -p "$SENTRY_PROJECT" deploys "$SENTRY_VERSION" new -e "$SENTRY_ENVIRONMENT"

With this setup running jet steps --tag sentry the sourcemaps get uploaded without a warning (both index.js and index.js.map), and the new release is registered on the dashboard.

When I run node build/index.js it throws an error that gets registered by Sentry. It is never assigned to the release I uploaded, but only appears on the main Issues page. And there:

Event
  There were 2 errors encountered while processing this event
      Source code was not found for app:///index.js  Collapse
        Url | app:///index.js
      Source code was not found for app:///../node_modules/raven/lib/client.js  Expand

Exception
 + app:///index.js in a at line 6:11

The only divergences from the sentry tutorial is that I use 'build' instead of 'dist' and I am not using a global root, because there is only one file, the entry file.

When I changed app:/// to just ~/, then the two errors disappeared from the Event block, but the Error stack trace is still displaying the .js file instead of the sourcemapped .ts.

How to move on?

Thanks, David

HazAT commented 6 years ago

Hey David,

First of all thanks for the detailed error description 👍 I think you are missing the release option in your config, that's why your crash is not associated to a release and therefore it could be that also the stack trace is not correctly mapped.

You have to do something like this

config('DSN', {
release: 'SENTRY_VERSION'
});
mrnagydavid commented 6 years ago

I came back to see if there was any follow up to my response just to see that my message is missing. I have no idea how. I even included a screenshot :(

So, I did as you told me and included the release version in the source code. That really did the trick and now the issues appear under the given release.

However, the stack trace still shows the javascript code. :(

Mokto commented 5 years ago

Any update on this ? Seems we can't get typescript + sourcemaps + sentry working.

I tried on @sentry/node and @sentry/browser 5.0.0. In my case the release is existing, match the code and contains the source file + source maps.

Source code was not found for app:///.next/server/static/ZYVS41NqhScfHuannaVZL/pages/_document.js even if ~/.next/server/static/ZYVS41NqhScfHuannaVZL/pages/_document.js.map and ~/.next/server/static/ZYVS41NqhScfHuannaVZL/pages/_document.js are existing.

Thanks !

heisian commented 5 years ago

I am confused by this output:

> Analyzing 14 sources
> Rewriting sources
> Adding source map references
> Uploading source maps for release 59c587b77

Source Map Upload Report
  Minified Scripts
    ~/0.59c587b77.chunk.js (sourcemap at 0.59c587b77.map)
      - warning: could not determine a source map reference (Could not auto-detect referenced sourcemap for ~/0.59c587b77.chunk.js.)                                                                                                                                  
    ~/1.59c587b77.chunk.js (sourcemap at 1.59c587b77.map)
      - warning: could not determine a source map reference (Could not auto-detect referenced sourcemap for ~/1.59c587b77.chunk.js.)                                                                                                                                  
    ~/2.59c587b77.chunk.js (sourcemap at 2.59c587b77.map)
      - warning: could not determine a source map reference (Could not auto-detect referenced sourcemap for ~/2.59c587b77.chunk.js.)                                                                                                                                  
    ~/attribution.bundle.js (sourcemap at attribution.59c587b77.map)
      - warning: could not determine a source map reference (Could not auto-detect referenced sourcemap for ~/attribution.bundle.js.)                                                                                                                                 
    ~/manifest.59c587b77.bundle.js (sourcemap at manifest.59c587b77.map)
      - warning: could not determine a source map reference (Could not auto-detect referenced sourcemap for ~/manifest.59c587b77.bundle.js.)                                                                                                                          
    ~/vendor.59c587b77.bundle.js (sourcemap at vendor.59c587b77.map)
      - warning: could not determine a source map reference (Could not auto-detect referenced sourcemap for ~/vendor.59c587b77.bundle.js.)                                                                                                                            
    ~/webApp.59c587b77.bundle.js (sourcemap at webApp.59c587b77.map)
      - warning: could not determine a source map reference (Could not auto-detect referenced sourcemap for ~/webApp.59c587b77.bundle.js.)                                                                                                                            
  Source Maps
    ~/0.59c587b77.map
    ~/1.59c587b77.map
    ~/2.59c587b77.map
    ~/attribution.59c587b77.map
    ~/manifest.59c587b77.map
    ~/vendor.59c587b77.map
    ~/webApp.59c587b77.map
 WPK | Webpack finished bundling.

From the output, the source map files are right next to the minified files, and yet it says a source map reference could not be found. What gives?

ModestinoAndre commented 5 years ago

I'm facing the Same problem described by @heisian

dccarmo commented 4 years ago

Any updates regarding this? We're facing the same issue (on React Native and Node SDKs) and can't figure out how to solve.

kamilogorek commented 4 years ago

Log displays list of files that has been referenced in all sourcemaps. It doesn't mean that they're available on a disk. And according to the log, it's not the case. Is someone able to provide a repro-case I could use to debug this?

kamilogorek commented 4 years ago

Closing the issue as there seems to be no viable reproduction of the issue. Please do not hesitate to ping me if it is still relevant, and I will happily reopen and work on it. Cheers!