Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add urlPrefix to sentry configuration #222

Closed
wants to merge 2 commits into from
Closed

Conversation

JoydS
Copy link

@JoydS JoydS commented Apr 8, 2024

📜 Description

Add UrlPrefix for Source Map

💡 Motivation and Context

Required for subpath web app

💚 How did you test it?

Closes #204

📝 Checklist

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

🔮 Next steps

@buenaflor
Copy link
Contributor

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

@JoydS
Copy link
Author

JoydS commented Apr 10, 2024

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

@buenaflor
Copy link
Contributor

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

@buenaflor
Copy link
Contributor

I'd like to wait for #198 first before getting to this PR

@JoydS JoydS force-pushed the main branch 3 times, most recently from 1734f61 to 9fc266e Compare April 12, 2024 21:00
@buenaflor
Copy link
Contributor

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

@JoydS
Copy link
Author

JoydS commented Apr 15, 2024

@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 ?

@buenaflor
Copy link
Contributor

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

@JoydS
Copy link
Author

JoydS commented Apr 16, 2024

@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.

@buenaflor
Copy link
Contributor

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

@JoydS
Copy link
Author

JoydS commented Apr 18, 2024

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 JoydS force-pushed the main branch 3 times, most recently from d903f70 to b601e81 Compare April 18, 2024 14:38
@buenaflor
Copy link
Contributor

Can you follow this and see if it works?

getsentry/sentry-dart#897 (comment)

This text was written for the plugin version 1.7.1

@JoydS
Copy link
Author

JoydS commented Apr 24, 2024

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

@buenaflor
Copy link
Contributor

buenaflor commented Apr 24, 2024

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?

@JoydS
Copy link
Author

JoydS commented Apr 24, 2024

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" ?

@buenaflor
Copy link
Contributor

@denrase can you look into this? 🙏

@JoydS
Copy link
Author

JoydS commented May 15, 2024

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

@JoydS
Copy link
Author

JoydS commented May 21, 2024

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

@denrase
Copy link
Collaborator

denrase commented May 21, 2024

@JoydS Looking into this.

@denrase
Copy link
Collaborator

denrase commented May 21, 2024

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?

@JoydS
Copy link
Author

JoydS commented May 21, 2024

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
Copy link
Author

JoydS commented May 23, 2024

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 ?

@denrase
Copy link
Collaborator

denrase commented May 31, 2024

@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
Copy link
Collaborator

denrase commented May 31, 2024

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

@buenaflor
Copy link
Contributor

buenaflor commented Jun 19, 2024

@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

@denrase
Copy link
Collaborator

denrase commented Jun 24, 2024

Added to docs: getsentry/sentry-docs#10470

@JoydS
Copy link
Author

JoydS commented Jun 24, 2024

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

@buenaflor
Copy link
Contributor

@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
Copy link
Contributor

also let's add this to the sample when this is done @denrase

@denrase
Copy link
Collaborator

denrase commented Jul 16, 2024

@buenaflor

Build again with the approach from above, with the addition of rewriting the stack frame like in documentation. I now have a dart stacktrace, source context is pointing to the corerct address, it's also present in the json, but the frame without source context is pointing to a different url.

Source Map Frame
Bildschirmfoto 2024-07-16 um 15 33 15 Bildschirmfoto 2024-07-16 um 15 33 26

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

@denrase
Copy link
Collaborator

denrase commented Jul 16, 2024

@JoydS Here's the code that's missing. You just have to use your URL and correctly insert the prefix.

options.beforeSend = (event, hint) async {
  final exceptions = event.exceptions?.map((exception) {
    final stackTrace = exception.stackTrace;
    if (stackTrace != null) {
      final frames = stackTrace.frames.map((frame) {
        const baseUrl = 'https://example.com/';
        final modifiedAbsPath = frame.absPath?.replaceFirst(
          baseUrl,
          '${baseUrl}my_prefix/',
        );
        return frame.copyWith(absPath: modifiedAbsPath);
      }).toList();
      return exception.copyWith(
        stackTrace: SentryStackTrace(frames: frames),
      );
    }
    return exception;
  }).toList();
  return event.copyWith(exceptions: exceptions ?? []);
};

@JoydS
Copy link
Author

JoydS commented Jul 23, 2024

Hello @denrase

I added the script above, but I still have the issue :

Capture d’écran 2024-07-23 à 13 18 43

@denrase
Copy link
Collaborator

denrase commented Jul 30, 2024

@JoydS You could try to debug the script and check if the prefix is set correctly. Maybe we have missed something. Sorry this is taking so long, but it's really difficult to pinpoint where the issue is.

@buenaflor
Copy link
Contributor

@denrase let's test it again and then wrap it up in a forked branch

@denrase
Copy link
Collaborator

denrase commented Aug 6, 2024

For running on localhost i needed to slightly update the code snippet, but again, this did work for me:

options.beforeSend = (event, hint) async {
  final exceptions = event.exceptions?.map((exception) {
    final stackTrace = exception.stackTrace;
    if (stackTrace != null) {
      final frames = stackTrace.frames.map((frame) {
        final modifiedAbsPath = frame.absPath?.replaceFirstMapped(
            RegExp(r'(http://[^/]+)(/.*)'),
            (match) => '${match.group(1)}/foo${match.group(2)}',
        );
        return frame.copyWith(absPath: modifiedAbsPath ?? frame.absPath);
      }).toList();
      return exception.copyWith(
        stackTrace: SentryStackTrace(frames: frames),
      );
    }
    return exception;
  }).toList();
  return event.copyWith(exceptions: exceptions ?? []);
};
Bildschirmfoto 2024-08-06 um 14 15 42

Just need to make sure that the source maps also have the correct prefix. Either by setting url_prefix or by moving them in the correct folder structure before running the plugin.

Bildschirmfoto 2024-08-06 um 14 10 17

@denrase denrase mentioned this pull request Aug 6, 2024
5 tasks
@buenaflor
Copy link
Contributor

buenaflor commented Aug 6, 2024

Closing this in favour of this PR #253

@buenaflor buenaflor closed this Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add config param to set url prefix
3 participants