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

File sync run in the main isolate for a certain amount of time should report as a performance issue

Open buenaflor opened this issue 2 years ago • 7 comments
trafficstars

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

buenaflor avatar Nov 14 '23 15:11 buenaflor

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

denrase avatar Dec 04 '23 13:12 denrase

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 avatar Dec 04 '23 13:12 ueman

@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

denrase avatar Dec 05 '23 12:12 denrase

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.

ueman avatar Dec 05 '23 13:12 ueman

@buenaflor Checked the cocoa SDK and could not find it at first glance. Can you point me to the right code snippet?

denrase avatar Dec 05 '23 13:12 denrase

We will need to attach the relevant data:

  • async we already do afaik
  • thread: main or isolate: main something 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

buenaflor avatar Dec 19 '23 15:12 buenaflor

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.

denrase avatar Jan 30 '24 12:01 denrase