Skip to content

Instantly share code, notes, and snippets.

@danharper
Forked from dcramer/normalize-filenames.js
Last active August 17, 2018 19:32
Show Gist options
  • Save danharper/a89685cc1028759345b8 to your computer and use it in GitHub Desktop.
Save danharper/a89685cc1028759345b8 to your computer and use it in GitHub Desktop.
use Sentry (Raven) on PhoneGap
Raven.config(dsn, {
dataCallback(data) {
const normalize = filename => filename.split('/www/', 2)[1]
data.exception.values[0].stacktrace.frames.forEach(frame => {
frame.filename = normalize(frame.filename)
})
data.culprit = data.exception.values[0].stacktrace.frames[0].filename
return data
}
})
@nicolaidahl
Copy link

Thanks.. This was very helpful!

@charliermarsh
Copy link

Super helpful -- thank you!

One thing to note for onlookers is that if you do have any dynamically-loaded JS (e.g., off the local filesystem), this script will error, since filename.split('/www/', 2)[1] will return undefined. You can add a guard to check for /www/ before splitting to work around it.

@slorber
Copy link

slorber commented Feb 1, 2017

Thanks!

Hey for those interested the authentication part has changed:

curl 'https://app.getsentry.com/api/0/projects/MY_ORG/MY_PROJECT/releases/' -H 'Authorization: Bearer API_TOKEN' -X POST -d '{ "version": "TEST_RELEASE" }' -H 'Content-Type: application/json'

@filipsuk
Copy link

I trying to get this working with Ionic 2. However I'm getting this error when displaying the issue on sentry:
Source code was not found for /Users/filipsuk/IonicProjects/faviApp/www/build/main.js
This probably comes from the sources part of .map file where I have this path.
Do you modify the source map before uploading? Or when exactly do you upload the source map? I upload it right after production build of the app.

@yuichiro-yoshida
Copy link

Very helpful! Thanks!

@ronaldozanoni
Copy link

ronaldozanoni commented Apr 10, 2018

Thanks, @danharper.

I have forked and made a little change because sometimes the filename is [native code] and does not have the www path, so it was appearing as undefined in the Sentry.

image

You can see the changes here https://gist.github.com/ronaldozanoni/ff1c3d714c2c18219a9587b4d7cc7af8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment