sentry-java: Sentry.init takes too much time and blocks ui thread
On some android devices Sentry initialization may take up to 1-2 seconds
what could be critical for a lot of apps.

The root of the problem is static initialization block in Lookup class which tries to find sentry.properties files in classpath. Sentry uses this Lookup class during initialization stage for getting initialization params from dsn. Even if all needed information is presented in dsn Sentry tries to load properties file because of static block that may take a lot of time.
@mcomella have already mentioned this problem in similar issue.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 7
- Comments: 17 (4 by maintainers)
This article explains why Android’s resources are so slow.
I’m working around this problem by overriding all the methods of
AndroidSentryClientFactorythat useLookup.lookupto instead just look in an instance ofPropertieswhich I store in my client factory class.A proper solution to this could be to add a
lookupmethod toSentryClientFactorywhichAndroidSentryClientFactorycould override to not try to find asentry.propertiesfile in resources, and instead access the properties through the assets mechanism. This is what the java.time backport for Android does to avoid the slow resources mechanism when loading its timezone database, so the properties would instead be accessed likecontext.getAssets().open("sentry.properties").For backwards compatibility, it could still look for the config in the resources folder if it doesn’t find the config as an asset, and we print a warning about this happening to say they can get better startup performance if they put the properties file in the assets folder
You can set a ResourceLoader via
Sentry.initnow through options:Feel free to reopen if there’s any issue.