sentry-dart-plugin icon indicating copy to clipboard operation
sentry-dart-plugin copied to clipboard

feat: Add urlPrefix to sentry configuration

Open JoydS opened this issue 1 year ago • 23 comments

:scroll: Description

Add UrlPrefix for Source Map

:bulb: Motivation and Context

Required for subpath web app

:green_heart: How did you test it?

Closes https://github.com/getsentry/sentry-dart-plugin/issues/204

:pencil: Checklist

  • [x] I reviewed submitted code
  • [x] I added tests to verify changes
  • [x] I updated the docs if needed
  • [x] All tests passing
  • [x] No breaking changes

:crystal_ball: Next steps

JoydS avatar Apr 08 '24 09:04 JoydS

Hey! thx for the contrib, really appreciate that :)

buenaflor avatar Apr 09 '24 10:04 buenaflor

@buenaflor I don't understand why the CI is not working here ?

JoydS avatar Apr 10 '24 07:04 JoydS

Changelog entry was missing a link to the PR, fixed it now

buenaflor avatar Apr 10 '24 08:04 buenaflor

I'd like to wait for https://github.com/getsentry/sentry-dart-plugin/pull/198 first before getting to this PR

buenaflor avatar Apr 10 '24 08:04 buenaflor

@JoydS we merged the other pr and can continue here, there should be some changes to the code that you also need to adjust

buenaflor avatar Apr 15 '24 11:04 buenaflor

@JoydS we merged the other pr and can continue here, there should be some changes to the code that you also need to adjust

Can you give me more details ?

JoydS avatar Apr 15 '24 12:04 JoydS

@JoydS I think resolving the merge conflics is all you need to do here

buenaflor avatar Apr 15 '24 12:04 buenaflor

@buenaflor to be honnest for now I can't make it work.

Do you have an idea where could be the issue ?

Capture d’écran 2024-04-16 à 18 17 28

I checked my source maps that seems good

Capture d’écran 2024-04-16 à 18 21 43

But I still don't have the trace.

JoydS avatar Apr 16 '24 16:04 JoydS

Does it not work even when not using the url prefix?

buenaflor avatar Apr 17 '24 08:04 buenaflor

When I do not use url prefix, my sources maps are wrong. But when I use it, sentry find my sources maps but can't unminify (I have no error but I don't have really more informations).

JoydS avatar Apr 18 '24 14:04 JoydS

Can you follow this and see if it works?

https://github.com/getsentry/sentry-dart/issues/897#issuecomment-2059250182

This text was written for the plugin version 1.7.1

buenaflor avatar Apr 22 '24 08:04 buenaflor

Hello @buenaflor

I just did, and it's not working.

Here is my config :

sentry:
  dsn: "https://[email protected]/YYY"
  upload_source_maps: true
  project: flutter
  org: yumi-q2
  auth_token: XXXXXX
  ignore_missing: true
  upload_sources: true
  upload_debug_symbols: true
  url_prefix: "~/app/"

Here is my error :

Capture d’écran 2024-04-24 à 15 45 43

I do have this message, is it a requirement to have my github repository set-up on sentry ?

Capture d’écran 2024-04-24 à 15 46 28

JoydS avatar Apr 24 '24 13:04 JoydS

I've received some information that uploading debug symbols might not work with sentry-cli versions below 2.31.0 due to some issues.

our newest dart plugin 2.0.0 does have 2.31.0 which should have this fixed, maybe that would work?

buenaflor avatar Apr 24 '24 14:04 buenaflor

Im already in 2.0.0.

Here is my logs :

[❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚] 0% reading config values..        
#21 2.402 retrieving config from pubspec.yaml
#21 2.444 
#21 2.444 Downloading Sentry CLI 2.31.0 from https://downloads.sentry-cdn.com/sentry-cli/2.31.0/sentry-cli-Linux-x86_64 to .dart_tool/pub/bin/sentry_dart_plugin/sentry-cli
#21 3.038 
#21 3.038 Sentry CLI binary checksum verification passed successfully (hash: baeb5b4ca0a5e500d667087f0b7fbb2865d3b8f01896cfba5144433dbe59bebd).
#21 3.038 
#21 3.038 Sentry CLI downloaded successfully.
#21 3.054 
☑ reading config values                                                             
#21 3.055 
[❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚] 9% validating config values..                             
☑ validating config values                                                             
#21 3.063 
[❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚] 18% uploading debug symbols..                                
#21 3.754 > Found 1 debug information file
#21 3.754 
#21 3.754 > Resolved source code for 0 debug information files
#21 3.894 
#21 3.894 > Prepared debug information file for upload
#21 4.023 
#21 4.023 > Nothing to upload, all files are on the server
#21 4.133 
☑ uploading debug symbols                                                             
#21 4.413 
#21 4.414 Created release [email protected]+56
#21 4.417 
[❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚] 27% uploading source maps..                               
#21 4.543 > Found 10 files
#21 4.547 
#21 4.547 > Analyzing 10 sources
#21 4.568 
#21 4.569 > Rewriting sources
#21 4.950 
#21 4.950 > Adding source map references
#21 7.597 
#21 7.597 > Bundled 10 files for upload
#21 7.597 > Bundle ID: e1ba8f62-bada-58ce-bd51-2929e17b1578
#21 8.[746](https://github.com/xxx/xxx/actions/runs/8803629375/job/24162261507#step:4:751) 
#21 8.746 > Uploaded files to Sentry
#21 10.01 
#21 10.01 > File processing complete
#21 10.01 > Organization: yumi-q2
#21 10.01 > Project: flutter
#21 10.01 > Release: [email protected]+56
#21 10.01 > Dist: 56
#21 10.01 > Upload type: artifact bundle
#21 10.01 
#21 10.01 Source Map Upload Report
#21 10.01   Scripts
#21 10.01     ~/app/assets/packages/wakelock_plus/assets/no_sleep.js (sourcemap at ../../../../main.dart.js.map)
#21 10.01     ~/app/canvaskit/canvaskit.js (sourcemap at ../main.dart.js.map)
#21 10.01     ~/app/canvaskit/chromium/canvaskit.js (sourcemap at ../../main.dart.js.map)
#21 10.01     ~/app/canvaskit/skwasm.js (sourcemap at ../main.dart.js.map)
#21 10.01     ~/app/canvaskit/skwasm.worker.js (sourcemap at ../main.dart.js.map)
#21 10.01     ~/app/firebase-messaging-sw.js (sourcemap at main.dart.js.map)
#21 10.01     ~/app/flutter.js (sourcemap at flutter.js.map)
#21 10.01 
#21 10.01 ~/app/flutter_service_worker.js (sourcemap at main.dart.js.map)
#21 10.01     ~/app/main.dart.js (sourcemap at main.dart.js.map)
#21 10.01   Source Maps
#21 10.01     ~/app/main.dart.js.map
#21 10.17 
#21 10.17 > Found 89 files
#21 10.17 
#21 10.17 > Analyzing 89 sources
#21 10.17 
#21 10.17 > Rewriting sources
#21 10.17 
#21 10.17 > Adding source map references
#21 10.66 
#21 10.66 > Bundled 89 files for upload
#21 10.66 > Bundle ID: e8c3b912-bb78-5ce9-8130-670d3817aec4
#21 10.78 
#21 10.78 > Nothing to upload, all files are on the server
#21 11.97 
#21 11.97 > File processing complete
#21 11.97 > Organization: yumi-q2
#21 11.97 > Project: flutter
#21 11.97 > Release: [email protected]+56
#21 11.97 > Dist: 56
#21 11.97 > Upload type: artifact bundle
#21 11.97 
#21 11.97 Source Map Upload Report
#21 11.97   Scripts
#21 11.97     ~/lib/event_bus.dart (no sourcemap ref)
#21 11.97       - warning: could not determine a source map reference (Could not auto-detect referenced sourcemap for ~/lib/event_bus.dart)
#21 11.97     ~/lib/firebase_options.dart (no sourcemap ref)
#21 11.97       - warning: could not determine a source map reference (Could not auto-detect referenced sourcemap for ~/lib/firebase_options.dart)
#21 11.97     ~/lib/main.dart (no sourcemap ref)
#21 11.97       - warning: could not determine a source map reference (Could not auto-detect referenced sourcemap for ~/lib/main.dart)
....
....
....
#21 11.98 
☑ uploading source maps                                                             
#21 11.98 
#21 11.98 Commit integration is disabled.
#21 12.49 
#21 12.49 Finalized release [email protected]+56
#21 DONE 12.6s

Maybe the issue is from "warning: could not determine a source map reference" ?

JoydS avatar Apr 24 '24 14:04 JoydS

@denrase can you look into this? :pray:

buenaflor avatar May 07 '24 10:05 buenaflor

Hello, Im still stuck on this subject, and it's really embarrassing... Thanks

JoydS avatar May 13 '24 16:05 JoydS

@JoydS It seems the issue with sourcemaps is also there with sentry-cli 2.32.0. Could you check with version 2.27.0 to see if this resolves your issues?

denrase avatar May 14 '24 13:05 denrase

Let us know if you have any updates here

buenaflor avatar May 14 '24 17:05 buenaflor

Hello @denrase @buenaflor It still doesn't work with version 2.27.0 :/

JoydS avatar May 15 '24 07:05 JoydS

Hello guys, It's been a while Im working on this subject, and I still have minified alerts. I really need to fix this, I can't stay like that. Thanks

JoydS avatar May 21 '24 08:05 JoydS

@JoydS Looking into this.

denrase avatar May 21 '24 09:05 denrase

I have used the plugin from your PR in the sentry flutter example app.

In the override I configured the path to your fork, which I checked out locally

  sentry_dart_plugin:
    path: ../../../forks/joyds/sentry-dart-plugin

and added the prefix to the config.

 url_prefix: ~/app/

I build the web version with:

flutter build web --source-maps

and ran the plugin

flutter pub run sentry_dart_plugin

Changed to the correct directory

cd build/web

and started a local web server

python3 -m http.server

Then I triggered a couple of issues and could see them on sentry.io

Issue
Bildschirmfoto 2024-05-21 um 12 17 02

https://sentry-sdks.sentry.io/issues/5384272416/?project=5428562&query=is%3Aunresolved+issue.priority%3A%5Bhigh%2C+medium%5D&referrer=issue-stream&statsPeriod=1h&stream_index=0

Also, the prefix seems to be there in the uploaded source maps

Source Maps
Bildschirmfoto 2024-05-21 um 12 15 57

I'm not sure if there is anything, like uploads of previous releases/files, that would interfere and give us false positives here. Could you provide a minimal setup in a public GitHub repo so we can try to reproduce this issue?

denrase avatar May 21 '24 10:05 denrase

Hello @denrase

Im going to try to give you the more information that I can.

dependency_overrides:
  sentry_dart_plugin:
    git:
      url: https://github.com/JoydS/sentry-dart-plugin.git
  url_prefix: "~/app/"

Dans ma config Dockerfile :

RUN flutter clean
RUN flutter pub get
RUN flutter build web \
	--dart-define=STAGE=${BUILD_ENV} \
	--base-href=/app/ \
	--verbose \
	--source-maps \
	--web-renderer canvaskit

# Upload source maps to sentry only on main branch
# see https://docs.sentry.io/platforms/flutter/upload-debug/#uploading-source-maps-for-flutter-web
RUN flutter packages pub run sentry_dart_plugin

# use nginx to deploy
FROM nginx:alpine

ENV PORT=8080
EXPOSE $PORT

# copy the info of the builded web app to nginx
COPY --from=build-env /app/client/app/build/web /usr/share/nginx/html/app

# copy nginx config file
COPY docker/client/webapp/nginx.conf /etc/nginx/conf.d/default.conf.template

# replace the port in the nginx config file
RUN envsubst '\$PORT' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf

CMD ["nginx", "-g", "daemon off;"]

Here is my uploaded source maps :

Capture d’écran 2024-05-21 à 15 42 58 Capture d’écran 2024-05-21 à 15 43 12 Capture d’écran 2024-05-21 à 15 43 25

My app is here : https://preprod.yumi.club/app/

Could you give me more informations about how it suppose to work ? Because I have the sources maps uploaded (and the path seems good), but here is one error :

Capture d’écran 2024-05-21 à 15 47 40

Im sorry but I can't create a project with the same config from scratch, I have no time for that and the config that we have is kinda complex (behind load balancer and so on).

Thanks for your help

JoydS avatar May 21 '24 13:05 JoydS

What I don't understand is that this URL still wrong :

Capture d’écran 2024-05-23 à 17 32 36

Is this could be the issue ?

JoydS avatar May 23 '24 15:05 JoydS

@buenaflor @JoydS I could reproduce the issue now. Before I was still executing in the url root without prefix. I created a release with flutter build web --base-href=/foo/ --source-maps now and when starting the local web server I moved the build files into the foo folder.

Issue

Bildschirmfoto 2024-05-31 um 11 14 56

Source Maps

Bildschirmfoto 2024-05-31 um 11 14 31

The prefix is missing in the url which is shown in the ST. The symbol maps were uploaded and showing as expected.

denrase avatar May 31 '24 09:05 denrase

@JoydS We have created an issue, let's see if we get some feedback.

denrase avatar May 31 '24 12:05 denrase

@JoydS Okay sorry for the delay. The missing piece is that in the flutter sdk we have to modify the absolute path of the stackframe and add the url prefix. see my comment here

basically the absolute path of each stack frame doesn't have the url prefix which messes up symbolication with the source maps

if you have time please try it out and if everything is fine then we're good to go here

buenaflor avatar Jun 19 '24 12:06 buenaflor

Added to docs: https://github.com/getsentry/sentry-docs/pull/10470

denrase avatar Jun 24 '24 12:06 denrase

Hello @buenaflor & @denrase What Im suppose to do here, Im sorry but it's not really clear for me :) Thx

JoydS avatar Jun 24 '24 14:06 JoydS

@JoydS you need to apply the beforeSend code snippet I wrote into your SentryFlutter.init options (and change the baseUrl to your url) and then try out the url prefix from this PR.

@denrase could you also try out if it works with this

buenaflor avatar Jun 25 '24 14:06 buenaflor