sentry-dart
sentry-dart copied to clipboard
File sync run in the main isolate for a certain amount of time should report as a performance issue
Description
SImilar to how the native SDKs do it.
Needs investigation first if we can check if it's run in a background isolate
### Blocked by
- [ ] Flutter min version 3.7
Found ServicesBinding.rootIsolateToken, which should be able to tell us if we are in the root, or in a background isolate.
A token that represents the root isolate, used for coordinating with background isolates.
This property is primarily intended for use with BackgroundIsolateBinaryMessenger.ensureInitialized, which takes a RootIsolateToken as its argument. The value null is returned when executed from background isolates.
https://api.flutter.dev/flutter/services/ServicesBinding/rootIsolateToken.html
I think you can also check for the isolate name being 'main'. That way you don't need a dependency on Flutter.
The token is also a recent addition, which is not compatible with the lowest supported Flutter version
@ueman Do you mean with Isolate.current.debugName? Don't see it documented anywhere beeing set to main for the main isolate. Also it's not guaranteed to be unique.
This name does not uniquely identify an isolate. Multiple isolates in the same process may have the same debugName.
https://api.dart.dev/stable/3.2.2/dart-isolate/Isolate/debugName.html
I think the debugName falls back to method name it was launched with, not 100% sure though. So there's a good chance the main check actually works. But yeah, it's not guaranteed to always work.
@buenaflor Checked the cocoa SDK and could not find it at first glance. Can you point me to the right code snippet?
We will need to attach the relevant data:
asyncwe already do afaikthread: mainorisolate: mainsomething like that, depending on how the backend handles it currently for the native sdks - gotta check how relevant the current detector is for us: see here
Edit: this is blocked by min version Flutter 3.7.0, see here for more info
Important to know, Flutter Sentry can't be initialised from a background Isolate, as it has some references to APIs that are only available when on main.
Users need to init Dart Sentry separately in the background Isolate in order to use the File integration, as they otherwise do not have access to a valid Hub instance, as isolates don't share any state beyond data passed as arguments and return types.
This behaviour is reflected by the added integration tests in the example test.