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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for setting sentry-native handler_strategy #3671

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## 7.15.0-alpha.1

### Features

- Add support for setting sentry-native handler_strategy ([#3671](https://github.com/getsentry/sentry-java/pull/3671))
Copy link
Contributor

Choose a reason for hiding this comment

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

  • 🚫 The changelog entry seems to be part of an already released section ## 7.15.0.
    Consider moving the entry to the ## Unreleased section, please.


### Dependencies

- Bump `sentry-native` SDK to `d11359b` of [feat/inproc_handler_strategy](https://github.com/getsentry/sentry-native/pull/1027/)
- See the following issue for more details: https://github.com/getsentry/sentry-native/issues/1026

## 7.14.0

### Features
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ spotless {
target("**/*.java")
removeUnusedImports()
googleJavaFormat()
targetExclude("**/generated/**", "**/vendor/**")
targetExclude("**/generated/**", "**/vendor/**", "**/sentry-native/**")
}
kotlin {
target("**/*.kt")
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android.useAndroidX=true
android.defaults.buildfeatures.buildconfig=true

# Release information
versionName=7.14.0
versionName=7.15.0-alpha.1

# Override the SDK name on native crashes on Android
sentryAndroidSdkName=sentry.native.android
Expand Down
10 changes: 10 additions & 0 deletions sentry-android-core/api/sentry-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,14 @@ public final class io/sentry/android/core/LoadClass {
public fun loadClass (Ljava/lang/String;Lio/sentry/ILogger;)Ljava/lang/Class;
}

public final class io/sentry/android/core/NdkHandlerStrategy : java/lang/Enum {
public static final field SENTRY_HANDLER_STRATEGY_CHAIN_AT_START Lio/sentry/android/core/NdkHandlerStrategy;
public static final field SENTRY_HANDLER_STRATEGY_DEFAULT Lio/sentry/android/core/NdkHandlerStrategy;
public fun getValue ()I
public static fun valueOf (Ljava/lang/String;)Lio/sentry/android/core/NdkHandlerStrategy;
public static fun values ()[Lio/sentry/android/core/NdkHandlerStrategy;
}

public final class io/sentry/android/core/NdkIntegration : io/sentry/Integration, java/io/Closeable {
public static final field SENTRY_NDK_CLASS_NAME Ljava/lang/String;
public fun <init> (Ljava/lang/Class;)V
Expand Down Expand Up @@ -265,6 +273,7 @@ public final class io/sentry/android/core/SentryAndroidOptions : io/sentry/Sentr
public fun getDebugImagesLoader ()Lio/sentry/android/core/IDebugImagesLoader;
public fun getFrameMetricsCollector ()Lio/sentry/android/core/internal/util/SentryFrameMetricsCollector;
public fun getNativeSdkName ()Ljava/lang/String;
public fun getNdkHandlerStrategy ()I
public fun getProfilingTracesIntervalMillis ()I
public fun getStartupCrashDurationThresholdMillis ()J
public fun isAnrEnabled ()Z
Expand Down Expand Up @@ -309,6 +318,7 @@ public final class io/sentry/android/core/SentryAndroidOptions : io/sentry/Sentr
public fun setEnableScopeSync (Z)V
public fun setEnableSystemEventBreadcrumbs (Z)V
public fun setFrameMetricsCollector (Lio/sentry/android/core/internal/util/SentryFrameMetricsCollector;)V
public fun setNativeHandlerStrategy (Lio/sentry/android/core/NdkHandlerStrategy;)V
public fun setNativeSdkName (Ljava/lang/String;)V
public fun setProfilingTracesIntervalMillis (I)V
public fun setReportHistoricalAnrs (Z)V
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.sentry.android.core;

import org.jetbrains.annotations.ApiStatus;

@ApiStatus.Internal
public enum NdkHandlerStrategy {
SENTRY_HANDLER_STRATEGY_DEFAULT(0),
SENTRY_HANDLER_STRATEGY_CHAIN_AT_START(1);

private final int value;

NdkHandlerStrategy(final int value) {
this.value = value;
}

public int getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ public final class SentryAndroidOptions extends SentryOptions {
/** Turns NDK on or off. Default is enabled. */
private boolean enableNdk = true;

@NotNull
private NdkHandlerStrategy ndkHandlerStrategy =
NdkHandlerStrategy.SENTRY_HANDLER_STRATEGY_DEFAULT;
/**
* Enable the Java to NDK Scope sync. The default value for sentry-java is disabled and enabled
* for sentry-android.
Expand Down Expand Up @@ -472,6 +475,16 @@ public void setNativeSdkName(final @Nullable String nativeSdkName) {
this.nativeSdkName = nativeSdkName;
}

@ApiStatus.Internal
public void setNativeHandlerStrategy(final @NotNull NdkHandlerStrategy ndkHandlerStrategy) {
this.ndkHandlerStrategy = ndkHandlerStrategy;
}

@ApiStatus.Internal
public int getNdkHandlerStrategy() {
return ndkHandlerStrategy.getValue();
}

/**
* Returns the sdk name for the sentry native ndk module.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,19 @@ class SentryAndroidOptionsTest {
assertTrue(SentryAndroidOptions().isEnableScopeSync)
}

@Test
fun `ndk handler option defaults to default strategy`() {
val sentryOptions = SentryAndroidOptions()
assertEquals(NdkHandlerStrategy.SENTRY_HANDLER_STRATEGY_DEFAULT.value, sentryOptions.ndkHandlerStrategy)
}

@Test
fun `ndk handler strategy option can be changed`() {
val sentryOptions = SentryAndroidOptions()
sentryOptions.setNativeHandlerStrategy(NdkHandlerStrategy.SENTRY_HANDLER_STRATEGY_CHAIN_AT_START)
assertEquals(NdkHandlerStrategy.SENTRY_HANDLER_STRATEGY_CHAIN_AT_START.value, sentryOptions.ndkHandlerStrategy)
}

private class CustomDebugImagesLoader : IDebugImagesLoader {
override fun loadDebugImages(): List<DebugImage>? = null
override fun clearDebugImages() {}
Expand Down
2 changes: 1 addition & 1 deletion sentry-android-ndk/sentry-native
Submodule sentry-native updated 88 files
+12 −0 .craft.yml
+44 −21 .github/workflows/ci.yml
+1 −1 .github/workflows/release.yml
+7 −0 .gitignore
+118 −0 .mvn/wrapper/MavenWrapperDownloader.java
+ .mvn/wrapper/maven-wrapper.jar
+2 −0 .mvn/wrapper/maven-wrapper.properties
+70 −0 CHANGELOG.md
+9 −8 CMakeLists.txt
+1 −0 CONTRIBUTING.md
+10 −3 README.md
+17 −0 examples/example.c
+1 −1 external/crashpad
+39 −1 include/sentry.h
+75 −0 ndk/README.md
+207 −0 ndk/build.gradle.kts
+ ndk/debug.keystore
+53 −0 ndk/gradle.properties
+ ndk/gradle/wrapper/gradle-wrapper.jar
+7 −0 ndk/gradle/wrapper/gradle-wrapper.properties
+249 −0 ndk/gradlew
+92 −0 ndk/gradlew.bat
+17 −0 ndk/lib/CMakeLists.txt
+29 −0 ndk/lib/api/sentry-android-ndk.api
+132 −0 ndk/lib/build.gradle.kts
+22 −0 ndk/lib/proguard-rules.pro
+199 −0 ndk/lib/src/main/java/io/sentry/ndk/DebugImage.java
+18 −0 ndk/lib/src/main/java/io/sentry/ndk/INativeScope.java
+18 −0 ndk/lib/src/main/java/io/sentry/ndk/NativeModuleListLoader.java
+55 −0 ndk/lib/src/main/java/io/sentry/ndk/NativeScope.java
+64 −0 ndk/lib/src/main/java/io/sentry/ndk/NdkOptions.java
+42 −0 ndk/lib/src/main/java/io/sentry/ndk/SentryNdk.java
+489 −0 ndk/lib/src/main/jni/sentry.c
+4 −0 ndk/lib/src/main/res/values/public.xml
+18 −0 ndk/sample/CMakeLists.txt
+70 −0 ndk/sample/build.gradle.kts
+34 −0 ndk/sample/proguard-rules.pro
+18 −0 ndk/sample/src/main/AndroidManifest.xml
+25 −0 ndk/sample/src/main/cpp/ndk-sample.cpp
+54 −0 ndk/sample/src/main/java/io/sentry/ndk/sample/MainActivity.java
+11 −0 ndk/sample/src/main/java/io/sentry/ndk/sample/NdkSample.java
+36 −0 ndk/sample/src/main/res/layout/activity_main.xml
+19 −0 ndk/settings.gradle
+1 −0 scripts/bump-version.sh
+5 −5 scripts/install-llvm-mingw.ps1
+310 −0 scripts/mvnw
+182 −0 scripts/mvnw.cmd
+12 −0 scripts/settings.xml
+15 −2 scripts/start-android.sh
+21 −24 sentry-config.cmake.in
+7 −3 src/backends/sentry_backend_breakpad.cpp
+85 −46 src/backends/sentry_backend_crashpad.cpp
+62 −47 src/backends/sentry_backend_inproc.c
+64 −0 src/path/sentry_path_unix.c
+63 −0 src/path/sentry_path_windows.c
+9 −11 src/sentry_core.c
+5 −5 src/sentry_database.c
+37 −14 src/sentry_envelope.c
+148 −25 src/sentry_json.c
+17 −4 src/sentry_json.h
+3 −1 src/sentry_logger.c
+18 −0 src/sentry_options.c
+1 −0 src/sentry_options.h
+34 −1 src/sentry_os.c
+3 −0 src/sentry_os.h
+25 −0 src/sentry_path.h
+9 −8 src/sentry_session.c
+2 −2 src/sentry_session.h
+1 −1 src/sentry_slice.c
+9 −0 src/sentry_string.h
+37 −57 src/sentry_tracing.c
+13 −12 src/sentry_utils.c
+10 −10 src/sentry_utils.h
+14 −22 src/sentry_value.c
+40 −16 tests/assertions.py
+14 −0 tests/cmake.py
+7 −0 tests/leaks.txt
+42 −4 tests/test_integration_crashpad.py
+6 −2 tests/test_integration_http.py
+34 −2 tests/test_integration_stdout.py
+2 −2 tests/unit/fuzz.c
+2 −2 tests/unit/test_fuzzfailures.c
+4 −4 tests/unit/test_tracing.c
+11 −11 tests/unit/test_utils.c
+65 −1 tests/unit/test_value.c
+1 −0 tests/unit/tests.inc
+2 −0 vendor/mpack.c
+2 −3 vendor/mpack.h
5 changes: 5 additions & 0 deletions sentry-android-ndk/src/main/jni/sentry.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ Java_io_sentry_android_ndk_SentryNdk_initSentryNative(
jmethodID native_sdk_name_mid = (*env)->GetMethodID(env, options_cls, "getNativeSdkName",
"()Ljava/lang/String;");

jmethodID handler_strategy_mid = (*env)->GetMethodID(env, options_cls, "getNdkHandlerStrategy", "()I");

(*env)->DeleteLocalRef(env, options_cls);

char *outbox_path = NULL;
Expand Down Expand Up @@ -337,6 +339,9 @@ Java_io_sentry_android_ndk_SentryNdk_initSentryNative(
sentry_free(native_sdk_name_str);
}

jint handler_strategy = (jint) (*env)->CallIntMethod(env, sentry_sdk_options, handler_strategy_mid);
sentry_options_set_handler_strategy(options, handler_strategy);

sentry_init(options);
return;

Expand Down
Loading