14

I would like to have better stacktrace information when I get some error information over sentry. At the moment, flutter sentry only gives you a stacktrace where it appears as "Compiled" code and it makes debugging more difficult.

Is there a way to upload the source maps or the source code to have a more accurate idea when an error comes ?

thank you!

Here an example (It is not really useful) :

Here an example from sentry

  • Were you able to get this working? I don't think flutter web even exports source maps, so how would you upload them? – Jan Dec 11 '20 at 20:40

1 Answers1

10

there is a new flag you can set when building https://github.com/flutter/flutter/issues/72150

 --source-maps

the following script might help you

export SENTRY_RELEASE=$(date +%Y-%m-%d_%H-%M-%S)
export OUTPUT_FOLDER_WEB=./build/web/

flutter build web --dart-define=SENTRY_RELEASE=$SENTRY_RELEASE --source-maps

echo -e "[\033[92mrun\033[0m] Uploading sourcemaps for $SENTRY_RELEASE"
sentry-cli releases new $SENTRY_RELEASE
sentry-cli releases files $SENTRY_RELEASE upload-sourcemaps . \
    --ext dart \
    --rewrite
sentry-cli releases files $SENTRY_RELEASE upload-sourcemaps ${OUTPUT_FOLDER_WEB}main.dart.js.map
sentry-cli releases finalize $SENTRY_RELEASE

Sentry also provides an example without the --source-maps https://github.com/getsentry/sentry-flutter/blob/d22e8376648dd9746304646036dbd24bb885e177/example/run.sh#L24-L29

m1416
  • 1,049
  • 12
  • 22
  • Just an important note, that flutter's build methods generate the source maps even without the `--source-maps` flag. However, this flag is required to link the minified code to the source map with the `//# sourceMappingURL=` comment at the bottom. Without the build flag, that line will be omitted and the map won't be utilized by chrome devtools or sentry. – Matthew Rideout Dec 27 '21 at 21:16
  • 2
    Is this still a valid solution? Doesn't seem to work for me - stacktrace remains not readable – Nazarii Kahaniak Apr 14 '23 at 13:27
  • @NazariiKahaniak Mine works with `curl -sL https://sentry.io/get-cli/ | sh` to download the CLI tool, then `dart run sentry_dart_plugin`. Also works in Codemagic CI/CD. I think it will use settings from the `sentry:` section of your "pubspec.yaml", so it might not work well with multiple environments with different settings, in which case you may need to somehow get the script in this answer working. Also be careful to check in Sentry if there are ANY dart files in the stack trace, because it minifies my package files and not my source files and i thought it minified everything at first. – BeniaminoBaggins Aug 05 '23 at 05:33