Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Enable enableScopeSync by default for Android #1928

Merged
merged 5 commits into from Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,8 @@

## Unreleased

* Feat: Enable enableScopeSync by default for Android (#1928)

## 5.6.2-beta.2

* Fix: NPE while adding "response_body_size" breadcrumb, when response body length is unknown (#1908)
Expand Down
Expand Up @@ -42,7 +42,7 @@ public final void register(final @NotNull IHub hub, final @NotNull SentryOptions
final String cachedDir = this.options.getCacheDirPath();
if (cachedDir == null || cachedDir.isEmpty()) {
this.options.getLogger().log(SentryLevel.ERROR, "No cache dir path is defined in options.");
this.options.setEnableNdk(false);
disableNdkIntegration(this.options);
return;
}

Expand All @@ -54,19 +54,24 @@ public final void register(final @NotNull IHub hub, final @NotNull SentryOptions

this.options.getLogger().log(SentryLevel.DEBUG, "NdkIntegration installed.");
} catch (NoSuchMethodException e) {
this.options.setEnableNdk(false);
disableNdkIntegration(this.options);
this.options
.getLogger()
.log(SentryLevel.ERROR, "Failed to invoke the SentryNdk.init method.", e);
} catch (Throwable e) {
this.options.setEnableNdk(false);
disableNdkIntegration(this.options);
this.options.getLogger().log(SentryLevel.ERROR, "Failed to initialize SentryNdk.", e);
}
} else {
this.options.setEnableNdk(false);
disableNdkIntegration(this.options);
}
}

private void disableNdkIntegration(final @NotNull SentryOptions options) {
options.setEnableNdk(false);
options.setEnableScopeSync(false);
}

@TestOnly
@Nullable
Class<?> getSentryNdkClass() {
Expand All @@ -88,7 +93,7 @@ public void close() throws IOException {
} catch (Throwable e) {
options.getLogger().log(SentryLevel.ERROR, "Failed to close SentryNdk.", e);
} finally {
this.options.setEnableNdk(false);
disableNdkIntegration(this.options);
}
}
}
Expand Down
Expand Up @@ -91,6 +91,9 @@ public SentryAndroidOptions() {
setSentryClientName(BuildConfig.SENTRY_ANDROID_SDK_NAME + "/" + BuildConfig.VERSION_NAME);
setSdkVersion(createSdkVersion());
setAttachServerName(false);

// enable scope sync for Android by default
setEnableScopeSync(true);
}

private @NotNull SdkVersion createSdkVersion() {
Expand Down
Expand Up @@ -551,14 +551,14 @@ class ManifestMetadataReaderTest {
@Test
fun `applyMetadata reads enableScopeSync to options`() {
// Arrange
val bundle = bundleOf(ManifestMetadataReader.NDK_SCOPE_SYNC_ENABLE to true)
val bundle = bundleOf(ManifestMetadataReader.NDK_SCOPE_SYNC_ENABLE to false)
val context = fixture.getContext(metaData = bundle)

// Act
ManifestMetadataReader.applyMetadata(context, fixture.options)

// Assert
assertTrue(fixture.options.isEnableScopeSync)
assertFalse(fixture.options.isEnableScopeSync)
}

@Test
Expand All @@ -570,7 +570,7 @@ class ManifestMetadataReaderTest {
ManifestMetadataReader.applyMetadata(context, fixture.options)

// Assert
assertFalse(fixture.options.isEnableScopeSync)
assertTrue(fixture.options.isEnableScopeSync)
}

@Test
Expand Down
Expand Up @@ -35,6 +35,7 @@ class NdkIntegrationTest {

verify(fixture.logger, never()).log(eq(SentryLevel.ERROR), any<String>(), any())
assertTrue(options.isEnableNdk)
assertTrue(options.isEnableScopeSync)
}

@Test
Expand All @@ -46,11 +47,13 @@ class NdkIntegrationTest {
integration.register(fixture.hub, options)

assertTrue(options.isEnableNdk)
assertTrue(options.isEnableScopeSync)

integration.close()

verify(fixture.logger, never()).log(eq(SentryLevel.ERROR), any<String>(), any())
assertFalse(options.isEnableNdk)
assertFalse(options.isEnableScopeSync)
}

@Test
Expand All @@ -64,6 +67,7 @@ class NdkIntegrationTest {
verify(fixture.logger, never()).log(eq(SentryLevel.ERROR), any<String>(), any())

assertFalse(options.isEnableNdk)
assertFalse(options.isEnableScopeSync)
}

@Test
Expand All @@ -77,6 +81,7 @@ class NdkIntegrationTest {
verify(fixture.logger, never()).log(eq(SentryLevel.ERROR), any<String>(), any())

assertFalse(options.isEnableNdk)
assertFalse(options.isEnableScopeSync)
}

@Test
Expand All @@ -90,6 +95,7 @@ class NdkIntegrationTest {
verify(fixture.logger).log(eq(SentryLevel.ERROR), any<String>(), any())

assertFalse(options.isEnableNdk)
assertFalse(options.isEnableScopeSync)
}

@Test
Expand All @@ -101,11 +107,13 @@ class NdkIntegrationTest {
integration.register(fixture.hub, options)

assertTrue(options.isEnableNdk)
assertTrue(options.isEnableScopeSync)

integration.close()

verify(fixture.logger).log(eq(SentryLevel.ERROR), any<String>(), any())
assertFalse(options.isEnableNdk)
assertFalse(options.isEnableScopeSync)
}

@Test
Expand All @@ -119,6 +127,7 @@ class NdkIntegrationTest {
verify(fixture.logger).log(eq(SentryLevel.ERROR), any<String>(), any())

assertFalse(options.isEnableNdk)
assertFalse(options.isEnableScopeSync)
}

@Test
Expand All @@ -132,6 +141,7 @@ class NdkIntegrationTest {
verify(fixture.logger).log(eq(SentryLevel.ERROR), any())

assertFalse(options.isEnableNdk)
assertFalse(options.isEnableScopeSync)
}

@Test
Expand All @@ -145,12 +155,13 @@ class NdkIntegrationTest {
verify(fixture.logger).log(eq(SentryLevel.ERROR), any())

assertFalse(options.isEnableNdk)
assertFalse(options.isEnableScopeSync)
}

private fun getOptions(enableNdk: Boolean = true, cacheDir: String? = "abc"): SentryAndroidOptions {
return SentryAndroidOptions().apply {
setLogger(fixture.logger)
setDebug(true)
isDebug = true
isEnableNdk = enableNdk
cacheDirPath = cacheDir
}
Expand Down
Expand Up @@ -55,6 +55,13 @@ class SentryAndroidOptionsTest {
assertNotNull(sentryOptions.debugImagesLoader)
}

@Test
fun `enable scope sync by default for Android`() {
val sentryOptions = SentryAndroidOptions()

assertTrue(sentryOptions.isEnableScopeSync)
}

private class CustomDebugImagesLoader : IDebugImagesLoader {
override fun loadDebugImages(): List<DebugImage>? = null
override fun clearDebugImages() {}
Expand Down
Expand Up @@ -32,7 +32,11 @@ private SentryNdk() {}
public static void init(@NotNull final SentryAndroidOptions options) {
SentryNdkUtil.addPackage(options.getSdkVersion());
initSentryNative(options);
options.addScopeObserver(new NdkScopeObserver(options));

// only add scope sync observer if the scope sync is enabled.
if (options.isEnableScopeSync()) {
options.addScopeObserver(new NdkScopeObserver(options));
}

options.setDebugImagesLoader(new DebugImagesLoader(options, new NativeModuleListLoader()));
}
Expand Down
5 changes: 4 additions & 1 deletion sentry/src/main/java/io/sentry/SentryOptions.java
Expand Up @@ -249,7 +249,10 @@ public class SentryOptions {
/** list of scope observers */
private final @NotNull List<IScopeObserver> observers = new ArrayList<>();

/** Enable the Java to NDK Scope sync */
/**
* Enable the Java to NDK Scope sync. The default value for sentry-java is disabled and enabled
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Enable the Java to NDK Scope sync. The default value for sentry-java is disabled and enabled
* Enable the Java to Native Scope sync. The default value for sentry-java is disabled and enabled

I think NDK is something Android-specific and these are general Java options?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now we only support NDK anyway, Its fine IMO.

* for sentry-android.
*/
private boolean enableScopeSync;

/**
Expand Down