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

Source context not applied to .dart stack traces #299

Open
rodolfoBee opened this issue Feb 6, 2025 · 19 comments · May be fixed by #306
Open

Source context not applied to .dart stack traces #299

rodolfoBee opened this issue Feb 6, 2025 · 19 comments · May be fixed by #306
Assignees

Comments

@rodolfoBee
Copy link
Member

Environment

SaaS (https://sentry.io/)

Steps to Reproduce

  1. Install the Flutter SDK in a Flutter app
  2. Upload the .dart source code to Sentry
  3. Send a test event to Sentry

Expected Result

The stack trace has source code context added based on the upload files.

Actual Result

Source context is not applied to the event.

The code is not minified and build using ShoreBird.
The stack trace abs_paths is: app:///http/skydart_roster_update.dart:109:7

The uploaded file to the event's release is: ~/http/skydart_roster_update.dart

Files are uploaded using sentry dart plugin:

sentry_dart_plugin: ^2.4.0
sentry:
  project: [redacted]
  org: [redacted]
  auth_token: [redacted]
  upload_source_maps: true
  upload_sources: true

This issue seems to be limited to .dart stack traces. The same process was done with a .js stack trace as test and the uploaded source context was applied to the event.

The issue was originally reported on this internal ticket.

Product Area

Issues - Source Maps

Link

No response

DSN

No response

Version

No response

@getsantry
Copy link

getsantry bot commented Feb 6, 2025

Auto-routing to @getsentry/product-owners-issues for triage ⏲️

@buenaflor
Copy link
Contributor

thanks, will have a look 👍

@buenaflor
Copy link
Contributor

@denrase we should check if source context works in Flutter web on non-minified builds

@talas9
Copy link

talas9 commented Feb 7, 2025

Hi,

I tried changing the event absPath and package:

absPath was changed to all possible values (Flutter package name, iOS package name, Android package name, app://, app:/, ~, "")

nothing worked, then I tried changing package to match the uploaded artifacts, still nothing works!

is there a way I can view the uploaded sources so I can modify the event sent to match the ones in Sentry so the system can match them properly until you fix the issue in the SDK?

Here is my final code:

// Add a prefix to the stack trace
      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?.replaceFirst(
                "package:sky_crews",
                Platform.isIOS
                    ? "[redacted]"
                    : "[redacted]",
              );
              final modifiedPackage = frame.package?.replaceFirst(
                "sky_crew",
                Platform.isIOS
                    ? "[redacted]"
                    : "[redacted]",
              );

              return frame.copyWith(
                absPath: modifiedAbsPath,
                package: modifiedPackage,
              );
            }).toList();
            // Remove frames that has function as "exceptionLog" && fileName as "logger.dart"
            // as this is the logger function and we don't need it in the stack trace
            frames.removeWhere((frame) =>
                frame.function == "exceptionLog" &&
                frame.fileName == "logger.dart");
            return exception.copyWith(
              stackTrace: SentryStackTrace(frames: frames),
            );
          }
          return exception;
        }).toList();
        return event.copyWith(exceptions: exceptions ?? []);
      };

Thanks.

@rodolfoBee
Copy link
Member Author

@buenaflor
I created a simple flutter web project and trigger some errors to my project.

I got a stack trace similar to the one from the affected user:

"abs_path": "http://localhost:49275/main.dart",

After that, I uploaded the file to my project/release: https://dev-curumas.sentry.io/settings/projects/flutter/source-maps/sentrytest%401.0.0%2B1/

New test events do not contain the source context: https://dev-curumas.sentry.io/issues/6285810522/events/95e91fafb6ec46b18da4ec3b1a23d86a/

I did not minify my code. From the quick internal chat it might be a result of the app not using split-debug-info, were you able to confirm this is the root cause?
Reference: getsentry/sentry-dart#1314

@talas9
Copy link

talas9 commented Feb 10, 2025

@rodolfoBee just to be clear, I tried building with split-debug-info as well.. It didn't help!

@buenaflor
Copy link
Contributor

buenaflor commented Feb 10, 2025

Would you mind trying out the sentry-dart-plugin 2.1.0? We've done some changes to uploading dart file, not sure if that's related

@talas9
Copy link

talas9 commented Feb 10, 2025

@buenaflor, Just to confirm.. you want me to downgrade to 2.1.0? currently I'm using sentry_dart_plugin: ^2.4.0

@buenaflor
Copy link
Contributor

yes, just wanna validate that this issue existed before some of our changes

@talas9
Copy link

talas9 commented Feb 11, 2025

Hi @buenaflor ,

Bellow is my test result with both versions..\

Image

TypeError: type 'Null' is not a subtype of type 'String' in type cast
  #0      _$FCMDataFromJson (package:sky_crew/models/fcm_data.g.dart:19)
  #1      new FCMData.fromJson (package:sky_crew/models/fcm_data.dart:44)
  #2      MyFirebaseMessaging.handleMessage (package:sky_crew/firebase_messaging.dart:61)
  #3      _RootZone.runUnaryGuarded (dart:async/zone.dart:1609)
  #4      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:366)
  #5      _DelayedData.perform (dart:async/stream_impl.dart:542)
  #6      _PendingEvents.handleNext (dart:async/stream_impl.dart:647)
  #7      _PendingEvents.schedule.<fn> (dart:async/stream_impl.dart:618)
  #8      _microtaskLoop (dart:async/schedule_microtask.dart:40)
  #9      _startMicrotaskLoop (dart:async/schedule_microtask.dart:49)

for this stack I'm using the command:
flutter packages pub run sentry_dart_plugin [email protected]+9274 --upload-sources

and the output for 2.4.0 is:

PS E:\skyflutter> flutter packages pub run sentry_dart_plugin [email protected]+9274 --upload-sources
Deprecated. Use `dart run` instead.
[❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚] 0% reading config values..        
Searching for pubspec.yaml or sentry.properties config...

Found config from sentry.properties

Sentry CLI binary checksum verification passed successfully (hash: 34878a7f30c3da8861455a2e8a8cfbd5a861649e11fe88432e9b610c83650896).
☑ reading config values
☑ validating config values
[❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚] 18% uploading debug symbols..
> Found 0 debug information files
> No debug information files found

> Found 65 debug information files

> Resolved source code for 0 debug information files

> Prepared debug information files for upload

> Nothing to upload, all files are on the server
☑ uploading debug symbols

Created release [email protected]+9274

uploadSourceMaps is disabled.

+-----------------------+--------------+

| Repository            | Revision     |
+-----------------------+--------------+
| skycrewapp/skyflutter | 8d8fbac9483d |
+-----------------------+--------------+

Finalized release [email protected]+9274

Output for 2.1.0 is:

PS E:\skyflutter> flutter packages pub run sentry_dart_plugin [email protected]+9274 --upload-sources
Deprecated. Use `dart run` instead.
[❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚] 0% reading config values..        
Searching for pubspec.yaml or sentry.properties config...

Found config from sentry.properties

Sentry CLI binary checksum verification passed successfully (hash: 34878a7f30c3da8861455a2e8a8cfbd5a861649e11fe88432e9b610c83650896).
☑ reading config values
☑ validating config values
[❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚❚] 18% uploading debug symbols..
> Found 0 debug information files
> No debug information files found

> Found 65 debug information files

> Resolved source code for 0 debug information files

> Prepared debug information files for upload

> Nothing to upload, all files are on the server
☑ uploading debug symbols

Created release [email protected]+9274

uploadSourceMaps is disabled.

+-----------------------+--------------+

| Repository            | Revision     |
+-----------------------+--------------+
| skycrewapp/skyflutter | 8d8fbac9483d |
+-----------------------+--------------+

Finalized release [email protected]+9274

I don't see any change in output, and context is still not showing in Sentry.

Could you please confirm I'm providing correct release name based on raw stack details provided above?
I tried every combination, but I can't get my hands on how this stack <-> source (context) matching works.

As you can see in the ticket @rodolfoBee was trying to help me and suggested altering the event before sending it to sentry, that didn't work so now I'm trying to change the release name when uploading source to try and match it with the previous stacks.

@rodolfoBee
Copy link
Member Author

Today I realised I made a mistake in my tests: I forgot the "dist" value is automatically added by the SDK. After adding it to my uploaded file, the source code is shown. Here are screenshots (stack trace is the same as before):

Image
Image

You can notice one thing in the uploaded file: it is not marked as "minified". I am using the CLI v2.39.1 to upload a specific file instead of the plugin:

 sentry-cli files upload -p flutter --release "[email protected]+1" --dist 1 lib/main.dart "~/main.dart"   

I remember seeing in one of @talas9 events the same frame format (using http://...). Maybe this helps @buenaflor understand the root cause?

@talas9
Copy link

talas9 commented Feb 11, 2025

Hi @rodolfoBee,

I tried your solution, it didn't work for me, do I still need to do the beforeSend alteration?

sentry-cli files upload --release "[email protected]+9274" --dist 9274 lib/main.dart "~/main.dart"

Image

I'm checking an existing issue after uploading the sources using previous command on the following stack:

_Exception: Exception: Image upload failed due to loss of GPU access.
  File "<asynchronous suspension>"
  File "<asynchronous suspension>"
  #2      main.<fn>.<fn> (package:sky_crew/main.dart:159)

@buenaflor
Copy link
Contributor

which platforms does this affect? ios, android and web?

@buenaflor buenaflor moved this from Needs Discussion to Needs Investigation in Mobile & Cross Platform SDK Feb 11, 2025
@rodolfoBee
Copy link
Member Author

My test is only on web. Talas' event is from iOS from what it seems.

You can try the formats app:///main.dart replacing package:sky_crew with app://

@talas9
Copy link

talas9 commented Feb 13, 2025

@buenaflor I'm only using iOS and Android for my project.

With the new commands I added seems like it works when I build on CodeMagic, but not for local dev reported events!

I've added a lot of commands so I'm not even sure which one is the one that did the trick, but I will list them:

1- Added --split-debug-info=build/app/outputs/debug-info to Shorebird/Flutter build command
2- I'm uploading sources in CodeMagic under 4 release names (sky_crew, package:sky_crew, co.ucentric.Sky-Crew, co.ucentric.Sky_Crew)
3- I have implement beforeSend option which originally was provided by @rodolfoBee , with some modifications I did on it:
Image

So this is one of the stacktraces that are showing with context now:

Image

Notice how in the previous stack it is showing the path of the file on CodeMagic MacOS, while in my dev env which is windows, this is not working, not sure if this has anything to do with OS but wanted to bring that to your attention as well

Image

I'll be happy to share log files from CodeMagic and commands output with you if you require that.

Thanks.

@denrase
Copy link
Collaborator

denrase commented Feb 18, 2025

@buenaflor I tried many combinations (downgrading sentry-cli, downgrading the plugin, setting root as build dir, release or profile build, throwing or capturing with sentry), but I just can't get a valid stack trace with source context on sentry web.

The only case where a valid stack trace was produced when running with flutter run -d chrome. In that case it looks like this.

Image

In all other combinations, source contexts can't be found, even though they are available on Sentry.io as far as i can tell.

Image Image Image

@denrase
Copy link
Collaborator

denrase commented Feb 19, 2025

Test

Created a fresh app and setup with sentry. Wrote a script to build, upload and run the sample app. Always a random exception, so it can be identified when it is grouped.

#!/bin/bash

# Generate a random string of 8 characters using OpenSSL
random_string=$(openssl rand -base64 6 | tr -dc 'a-zA-Z0-9' | head -c 8)

# Use sed to replace the text after 'seed ' with the random string
sed -i '' "s/throw Exception('seed [^']*')/throw Exception('seed $random_string')/" lib/main.dart
sed -i '' "s/const Text('seed [^']*')/const Text('seed $random_string')/" lib/main.dart

# Build and serve
rm -rf build
flutter build web --release --source-maps
dart run sentry_dart_plugin

echo "seed: $random_string"

cd build/web
python3 -m http.server & open -na "Google Chrome" --args --incognito "http://localhost:8000"

Results

  • sentry_dart_plugin 2.1.0

    • sentry-cli 2.27.0
    • ✅ this version worked
  • sentry_dart_plugin 2.1.0

    • sentry-cli 2.42.1
    • ✅ bumping sentry-cli makes no difference, so we can rule that out as the reason
  • sentry_dart_plugin 2.2.0

    • sentry-cli 2.38.1
    • ❌ source map not uploaded, no source shown in issue
  • sentry_dart_plugin 2.2.1

    • sentry-cli 2.38.1
    • ❌ source map uploaded, but on sentry.io it shows JS instead of dart... this verison has 'lib' for the sources, build for the build path, and build/web for the web build path.
  • sentry_dart_plugin 2.2.1

    • sentry-cli 2.38.1
    • set build path to . and web build path to build/web
    • ❌ dart stack trace, no source context
  • sentry_dart_plugin 2.2.1

    • sentry-cli 2.38.1
    • add ~/lib/ url_prefix in pubspec
    • ❌ only js stack trace again
  • sentry_dart_plugin 2.2.1

    • sentry-cli 2.38.1
    • add ~/lib/ url_prefix in pubspec and update stack traces in beforeSend
    • ❌ dart stack trace, no source context

Conclusion

The issue seems to be that the sources do not have the lib prefix, which is expected from the source maps, as it is always referncing it from the root. It seems by setting the source upload folder to build (2.2.0) or lib (2.2.1), the source can't be found.

Now i'm looking into how to fix this.

✅ Correct: Source has lib prefix.

Image Image

❌ Incorrect: Source has no prefix.

Image

@denrase
Copy link
Collaborator

denrase commented Feb 19, 2025

Adding the subfolder name as --url-prefix of the sources folder (lib) seems to resolve the issue. I'll prepare a PR.

Image Image

@denrase denrase linked a pull request Feb 19, 2025 that will close this issue
5 tasks
@denrase
Copy link
Collaborator

denrase commented Feb 19, 2025

Would you be so kind to test the fix from #306 before we merge? This fix is in relation to missing web source contexts.

You can verify or use the fix in the meantime by adding a dependency override:

  sentry_dart_plugin:
    git:
      url: https://github.com/getsentry/sentry-dart-plugin.git
      ref: fc658591361354a3f93cf174098dd4d8df4b4375

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Status: Needs Investigation
Development

Successfully merging a pull request may close this issue.

5 participants