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

Source Context support if not using `split-debug-info`

Open marandaneto opened this issue 2 years ago • 6 comments

Description

Sentry already offers Source context support but only when using split-debug-info as well. https://docs.sentry.io/platforms/flutter/troubleshooting/#source-context

This issue is to make it possible without the split-debug-info as well. This would need changes in the SDK related to SentryStackFrame#fileName and/or SentryStackFrame#absPath cus we strip the path to the last segment due to PII.

It might need changes on https://github.com/getsentry/symbolicator as well.

For context: what is source context.


TLDR on making this work:

  • we need a "debug id" that would be stored during app build in dart code and sent over when reporting frames - achievable e.g. by --dart-define - this could be called by starting flutter build through the sentry_dart_plugin.
  • sentry-cli needs to be updated to support creating source-bundles with custom debug IDs.
  • The plugin would use the same debug id when creating a source bundle and uploading to Sentry.
  • symbolicator may need an update to resolve these paths

However I'm not positive that we can make this work entirely by running only flutter run

marandaneto avatar Mar 07 '23 08:03 marandaneto

SentryStackFrame#absPath cus we strip the path to the last segment due to PII.

Just wanted to say paths to source files/debug files aren't considered PII in other SDKs, AFAICT. Nor are they stripped from the debug-files during upload of course because that would render them useless.

vaind avatar Mar 19 '23 12:03 vaind

SentryStackFrame#absPath cus we strip the path to the last segment due to PII.

Just wanted to say paths to source files/debug files aren't considered PII in other SDKs, AFAICT. Nor are they stripped from the debug-files during upload of course because that would render them useless.

I recall asking this back then and it was considered PII, I will double-check this.

marandaneto avatar Mar 20 '23 09:03 marandaneto

Ps: Right now the absPath is the very same as fileName which is just the last segment of the Frame.uri, for example: dart:ui/hooks.dart becomes hooks.dart, I've changed to the full Uri to test it out.

For Flutter, the absPath will have then the format below:

dart:ui/hooks.dart (from the Dart SDK itself) package:flutter/src/gestures/binding.dart (from the Flutter SDK itself) package:sentry_flutter_example/main.dart (from the App itself)

Right now we don't send the debug image list if the app isn't compiled with split-debug-info. I've changed that to test it and it results in all the debug images Unreferenced since the frames don't contain the instructionAddr, so they are not processed at all.

instructionAddr is only available if the Frame is of the type UnparsedFrame which means the app was compiled with split-debug-info.

The debug files if no split-debug-info is passed don't have sources:

Debug Info File Check Type: elf library Contained debug identifiers: > Debug ID: bf4aa6bc-f74c-57b6-3475-8117432454de Code ID: bca64abf4cf7b65734758117432454de Arch: arm64 Contained debug information: > symtab, unwind Usable: yes

When using split-debug-info:

Debug Info File Check Type: elf debug companion Contained debug identifiers: > Debug ID: bf4aa6bc-1cde-fefb-31bb-8f1cd6036d60 Code ID: bca64abfde1cfbfe31bb8f1cd6036d60 Arch: arm64 Contained debug information: > symtab, debug Usable: yes

When using split-debug-info AND obfuscate:

Debug Info File Check Type: elf debug companion Contained debug identifiers: > Debug ID: bf4aa6bc-7bfc-1709-31bb-8f1c3e639eb9 Code ID: bca64abffc7b091731bb8f1c3e639eb9 Arch: arm64 Contained debug information: > symtab, debug Usable: yes

So only when using split-debug-info either alone or with obfuscate has the debug information.

When compiling the Flutter app without split-debug-info but with debug, the debug file has the debug info instead of only symtab and unwind, but that is irrelevant because each build has its own debug Ids and codeIds.

marandaneto avatar Apr 24 '23 12:04 marandaneto

Seems like supporting Source code context for apps not using split-debug-info would require quite a bit of work, probably making our own version of source bundle or loading source code context directly from GH using heuristics to determine the file path of each file, based on the given absPath.

Flutter is pushing to make the adoption of split-debug-info more and more due to better optimizations and smaller bundle sizes, not sure if it's worth the effort. https://docs.flutter.dev/deployment/obfuscate#obfuscating-your-app https://docs.flutter.dev/perf/app-size#reducing-app-size

marandaneto avatar Apr 24 '23 13:04 marandaneto

For completeness, copy-pasting our conversation from Discord image

TLDR;

  • we need a "debug id" that would be stored during app build in dart code and sent over when reporting frames - achievable e.g. by --dart-define - this could be called by starting flutter build through the sentry_dart_plugin. The plugin would use the same debug id when creating a source bundle and uploading to Sentry.
  • sentry-cli needs to be updated to support creating source-bundles with custom debug IDs.
  • symbolicator may need an update to resolve these paths

vaind avatar Apr 24 '23 13:04 vaind

FE already does something similar with the absPath -> package heuristics https://github.com/getsentry/sentry/blob/0260a8769124adad82ada598ed960b36468bf233/src/sentry/utils/event_frames.py#L59-L79 This is for Stack Trace Linking IIRC.

marandaneto avatar Apr 24 '23 14:04 marandaneto