getsentry / sentry-dart

Sentry SDK for Dart and Flutter
https://sentry.io/for/flutter/
MIT License
743 stars 227 forks source link

Dart stack trace format shown on the Sentry web UI is incompatible with the Dart tools #2040

Closed ekuleshov closed 1 month ago

ekuleshov commented 4 months ago

Platform

Dart

Obfuscation

Disabled

Debug Info

Disabled

Doctor

N/A

Version

8.1.0

Steps to Reproduce

Look at any issue reported from a Flutter/Dart app. Navigate to stack trace and turn on the "Raw stack trace" option.

The presented Dart stack trace look something like this:

  File "my_api.g.dart", line 975, in MyPeripheralManagerHostApi.startAdvertising
  File "<asynchronous suspension>"
  File "my_peripheral_manager.dart", line 138, in MyPeripheralManager.startAdvertising
  File "<asynchronous suspension>"
  File "sync_ble_controller.dart", line 148, in SyncBleController._initBlePeripheral

Expected Result

The raw/native stack trace format for Dart for the above trace should look something like this. Also note the package reference and the source path missing from the current Sentry's "raw stack trace" presentation, which is required in order to uniquely identify source of the issue.

#1  MyPeripheralManagerHostApi.startAdvertising (package:bluetooth_low_energy_darwin/lib/src/my_api.g.dart:975)
#2  <asynchronous suspension>
#3  MyPeripheralManager.startAdvertising (package:bluetooth_low_energy_darwin/lib/src/my_peripheral_manager.dart:138)
#4  <asynchronous suspension>
#5  SyncBleController._initBlePeripheral (package:xyz/lib/controllers/sync_ble_controller.dart:148)

Actual Result

The Dart stack trace presentation in the Sentry's web UI is not anywhere alike Dart's native/raw stack trace (e.g. if you catch and print stack trace in the Dart code).

Also if you copy it from the Sentry web UI, the stack trace format is not recognized by the Dart tools, e.g. "Code / Analyze Stack Trace or Thread Dump..." action in the IntelliJ Dart/Flutter plugins and as a result you can't easily navigate to the source code from the stack trace analysis view in the IDE.

Are you willing to submit a PR?

None

buenaflor commented 3 months ago

hey thanks for raising this issue.

This is indeed not the behaviour we want, currently we fallback to a python representation for dart stacktraces (didn't know this either) 😅

We'll take a look at that

ueman commented 3 months ago

For native stacktrace it already works correctly

https://github.com/getsentry/sentry-dart/blob/0f067d38500c0ab6b9e85d0b19690ba915d4fea1/dart/lib/src/sentry_stack_trace_factory.dart#L111-L113

For Dart stacktraces (in addition to the problem on the website) you need to set the platform for the frame to dart, which currently is not done

https://github.com/getsentry/sentry-dart/blob/0f067d38500c0ab6b9e85d0b19690ba915d4fea1/dart/lib/src/sentry_stack_trace_factory.dart#L126-L133

On the web platform, you may need to set platform to JS or something.

ekuleshov commented 1 month ago

Any update or what is holding this up? This is a critical essential issue for Dart/Flutter and there seem to be understanding what need to be fixed.

kahest commented 1 month ago

@ekuleshov thanks for checking in - I agree this is important and we're gonna revisit/bump priority

buenaflor commented 1 month ago

Improvements are in release 8.5.0, I'm closing this now but feel free to reopen if there are still issues

ekuleshov commented 1 month ago

Improvements are in release 8.5.0, I'm closing this now but feel free to reopen if there are still issues

@buenaflor the Sentry's web UI still shows non Dart's stack traces for existing issues (as per the title of this issue).

Some explanation how it supposed to work or what developers need to do would be good to see.

buenaflor commented 1 month ago

Sentry's web UI still shows non Dart's stack traces for existing issues (as per the title of this issue).

Stacktraces before 8.5.0 don't have platforms set in the event payload so by default our frontend will use the python stacktrace formatting. There's nothing much we can do here to make it work for existing issues.

The only thing that I can think of is to have some kind of dropdown menu to select which kind of formatting you want to see on-demand. That's a frontend issue though and should be brought up in the main sentry repo.

Some explanation how it supposed to work or what developers need to do would be good to see.

frames now have the platform field as of 8.5.0 which the frontend will format the stacktrace depending on the specified platform.

Anyway, I've added the dart raw stacktrace formatting to the frontend so my suggestion would be to request this over there, eg: some kind of dropdown menu to select which kind of formatting you want to see on-demand

buenaflor commented 1 month ago

Also in case you don't want to upgrade to your newest version you could also set the platform field to dart in the sentry frames within beforeSend, but this would still require another app release.

ekuleshov commented 1 month ago

Stacktraces before 8.5.0 don't have platforms set in the event payload so by default our frontend will use the python stacktrace formatting. There's nothing much we can do here to make it work for existing issues.

Hmm. Nothing can do? Are you carving received event data to the punch carts? Surely there is some way to update your event store and events themselves have information that they came from Dart...

And this issue was filled to the Sentry's web UI. I don't see it resolved there with this fix.

kahest commented 1 month ago

@ekuleshov Frame formatting is performed on the frontend based on the reported platform, we don't alter events in the event store afterwards to add the platform.

The changes to correctly format Dart frames for new events is now available in sentry-dart 8.5.0 and live on sentry.io.

ekuleshov commented 1 month ago

@kahest so, you don't find it feasible to update existing events in the Sentry's data store to correctly show Dart's stack traces for the past events?

Not sure what does "live on sentry.io" part means if only the Dart SDK was changed.

buenaflor commented 1 month ago

Ah, maybe you didn't see it, we did not only change the Dart SDK, we also made changes to the frontend: https://github.com/getsentry/sentry/pull/74715

we process the stacktrace formatting based on the specified platform, this is not dart specific but for all stacktraces that's the reason why existing issues are still in the python formatting.

but like I said above, maybe it makes sense to have some menu in the UI where you can toggle which kind of stacktrace formatting you'd like, choosing from javascript, java up to dart etc... that would work for all issues (even existing)