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

Merged
merged 11 commits into from
Dec 6, 2024
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## Unreleased

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

### Dependencies

- Bump Native SDK from v0.7.8 to v0.7.16 ([#3671](https://github.com/getsentry/sentry-java/pull/3671))
- [changelog](https://github.com/getsentry/sentry-native/blob/master/CHANGELOG.md#0716)
- [diff](https://github.com/getsentry/sentry-native/compare/0.7.2...0.7.16)
markushi marked this conversation as resolved.
Show resolved Hide resolved

## 7.18.1

### Fixes
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 @@ -220,6 +220,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 @@ -266,6 +274,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 @@ -310,6 +319,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 79 files
+1 −1 .github/ISSUE_TEMPLATE/bug_report.md
+38 −37 .github/workflows/ci.yml
+67 −0 .github/workflows/codeql.yml
+74 −1 CHANGELOG.md
+18 −0 CMakeLists.txt
+5 −3 CONTRIBUTING.md
+4 −8 Makefile
+42 −34 README.md
+21 −0 cmake/utils.cmake
+13 −1 examples/example.c
+1 −0 external/CMakeLists.txt
+1 −1 external/breakpad
+1 −1 external/crashpad
+1 −1 external/libunwindstack-ndk
+134 −4 include/sentry.h
+21 −0 ndk/Makefile
+33 −33 ndk/README.md
+37 −23 ndk/build.gradle.kts
+3 −1 ndk/gradle.properties
+0 −29 ndk/lib/api/sentry-android-ndk.api
+84 −0 ndk/lib/api/sentry-native-ndk.api
+196 −192 ndk/lib/src/main/java/io/sentry/ndk/DebugImage.java
+8 −8 ndk/lib/src/main/java/io/sentry/ndk/INativeScope.java
+8 −8 ndk/lib/src/main/java/io/sentry/ndk/NativeModuleListLoader.java
+38 −38 ndk/lib/src/main/java/io/sentry/ndk/NativeScope.java
+56 −48 ndk/lib/src/main/java/io/sentry/ndk/NdkOptions.java
+40 −32 ndk/lib/src/main/java/io/sentry/ndk/SentryNdk.java
+5 −3 ndk/sample/build.gradle.kts
+39 −41 ndk/sample/src/main/java/io/sentry/ndk/sample/MainActivity.java
+5 −5 ndk/sample/src/main/java/io/sentry/ndk/sample/NdkSample.java
+1 −0 scripts/bump-version.sh
+3 −3 scripts/git-precommit-hook.sh
+45 −0 scripts/run_tests.ps1
+20 −2 scripts/start-android.sh
+7 −0 scripts/update_test_discovery.ps1
+22 −0 sentry.rc.in
+37 −25 src/backends/sentry_backend_breakpad.cpp
+7 −13 src/backends/sentry_backend_crashpad.cpp
+41 −37 src/backends/sentry_backend_inproc.c
+2 −2 src/modulefinder/sentry_modulefinder_apple.c
+14 −10 src/modulefinder/sentry_modulefinder_linux.c
+14 −7 src/path/sentry_path_windows.c
+138 −15 src/sentry_core.c
+1 −1 src/sentry_core.h
+3 −0 src/sentry_envelope.c
+43 −6 src/sentry_options.c
+2 −1 src/sentry_options.h
+28 −0 src/sentry_os.c
+2 −0 src/sentry_os.h
+14 −3 src/sentry_scope.c
+3 −3 src/sentry_scope.h
+1 −1 src/sentry_string.h
+2 −11 src/sentry_sync.h
+63 −5 src/sentry_tracing.c
+2 −2 src/sentry_tracing.h
+2 −4 src/sentry_utils.h
+56 −22 src/sentry_value.c
+12 −3 src/sentry_value.h
+6 −6 src/transports/sentry_transport_curl.c
+2 −3 src/transports/sentry_transport_winhttp.c
+9 −0 tests/__init__.py
+5 −4 tests/assertions.py
+10 −0 tests/cmake.py
+64 −0 tests/fixtures/dotnet_signal/Program.cs
+19 −0 tests/fixtures/dotnet_signal/crash.c
+8 −0 tests/fixtures/dotnet_signal/test_dotnet.csproj
+ tests/fixtures/minidump.dmp
+4 −1 tests/requirements.txt
+119 −0 tests/test_dotnet_signals.py
+74 −1 tests/test_integration_crashpad.py
+102 −3 tests/test_integration_http.py
+2 −0 tests/unit/CMakeLists.txt
+16 −0 tests/unit/test_envelopes.c
+1 −1 tests/unit/test_sync.c
+220 −28 tests/unit/test_tracing.c
+1 −1 tests/unit/test_uninit.c
+54 −60 tests/unit/test_value.c
+6 −1 tests/unit/tests.inc
+19 −0 tests/win_utils.py
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