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 API to set custom sentry-native sdk name #2704

Merged
merged 3 commits into from
May 15, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
- Bump Gradle from v8.1.0 to v8.1.1 ([#2666](https://github.com/getsentry/sentry-java/pull/2666))
- [changelog](https://github.com/gradle/gradle/blob/master release-test/CHANGELOG.md#v811)
- [diff](https://github.com/gradle/gradle/compare/v8.1.0...v8.1.1)
- Bump Native SDK from v0.6.1 to v0.6.2 ([#2689](https://github.com/getsentry/sentry-java/pull/2689))
- [changelog](https://github.com/getsentry/sentry-native/blob/master/CHANGELOG.md#062)
- [diff](https://github.com/getsentry/sentry-native/compare/0.6.1...0.6.2)

## 6.18.1

Expand Down
2 changes: 2 additions & 0 deletions sentry-android-core/api/sentry-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ public final class io/sentry/android/core/SentryAndroidOptions : io/sentry/Sentr
public fun enableAllAutoBreadcrumbs (Z)V
public fun getAnrTimeoutIntervalMillis ()J
public fun getDebugImagesLoader ()Lio/sentry/android/core/IDebugImagesLoader;
public fun getNativeSdkName ()Ljava/lang/String;
public fun getProfilingTracesHz ()I
public fun getProfilingTracesIntervalMillis ()I
public fun getStartupCrashDurationThresholdMillis ()J
Expand Down Expand Up @@ -239,6 +240,7 @@ public final class io/sentry/android/core/SentryAndroidOptions : io/sentry/Sentr
public fun setEnableFramesTracking (Z)V
public fun setEnableNetworkEventBreadcrumbs (Z)V
public fun setEnableSystemEventBreadcrumbs (Z)V
public fun setNativeSdkName (Ljava/lang/String;)V
public fun setProfilingTracesHz (I)V
public fun setProfilingTracesIntervalMillis (I)V
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.sentry.protocol.SdkVersion;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;

/** Sentry SDK options for Android */
Expand Down Expand Up @@ -133,6 +134,8 @@ public final class SentryAndroidOptions extends SentryOptions {

private boolean enableFramesTracking = true;

private @Nullable String nativeSdkName = null;

public SentryAndroidOptions() {
setSentryClientName(BuildConfig.SENTRY_ANDROID_SDK_NAME + "/" + BuildConfig.VERSION_NAME);
setSdkVersion(createSdkVersion());
Expand Down Expand Up @@ -402,4 +405,25 @@ void setStartupCrashFlushTimeoutMillis(long startupCrashFlushTimeoutMillis) {
public long getStartupCrashDurationThresholdMillis() {
return startupCrashDurationThresholdMillis;
}

/**
* Sets the sdk name for the sentry-native ndk module. The value is used for the event->sdk
* attribute and the sentry_client auth header.
*
* @param nativeSdkName the native sdk name
*/
@ApiStatus.Internal
public void setNativeSdkName(final @Nullable String nativeSdkName) {
this.nativeSdkName = nativeSdkName;
}

/**
* Returns the sdk name for the sentry native ndk module.
*
* @return the custom SDK name if set, otherwise null
*/
@ApiStatus.Internal
public @Nullable String getNativeSdkName() {
return nativeSdkName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNotNull
import kotlin.test.assertNull
import kotlin.test.assertTrue

class SentryAndroidOptionsTest {
Expand Down Expand Up @@ -111,6 +112,27 @@ class SentryAndroidOptionsTest {
assertFalse(sentryOptions.isAttachViewHierarchy)
}

@Test
fun `native sdk name is null by default`() {
val sentryOptions = SentryAndroidOptions()
assertNull(sentryOptions.nativeSdkName)
}

@Test
fun `native sdk name can be properly set`() {
val sentryOptions = SentryAndroidOptions()
sentryOptions.nativeSdkName = "test_ndk_name"
assertEquals("test_ndk_name", sentryOptions.nativeSdkName)
}

@Test
fun `native sdk name can be properly set to null`() {
val sentryOptions = SentryAndroidOptions()
sentryOptions.nativeSdkName = "test_ndk_name"
sentryOptions.nativeSdkName = null
assertNull(sentryOptions.nativeSdkName)
}

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
9 changes: 9 additions & 0 deletions sentry-android-ndk/src/main/jni/sentry.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ Java_io_sentry_android_ndk_SentryNdk_initSentryNative(
"()Ljava/lang/String;");
jmethodID dist_mid = (*env)->GetMethodID(env, options_cls, "getDist", "()Ljava/lang/String;");
jmethodID max_crumbs_mid = (*env)->GetMethodID(env, options_cls, "getMaxBreadcrumbs", "()I");
jmethodID native_sdk_name_mid = (*env)->GetMethodID(env, options_cls, "getNativeSdkName",
"()Ljava/lang/String;");

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

Expand All @@ -264,6 +266,7 @@ Java_io_sentry_android_ndk_SentryNdk_initSentryNative(
char *release_str = NULL;
char *environment_str = NULL;
char *dist_str = NULL;
char *native_sdk_name_str = NULL;

options = sentry_options_new();
ENSURE_OR_FAIL(options);
Expand Down Expand Up @@ -328,6 +331,12 @@ Java_io_sentry_android_ndk_SentryNdk_initSentryNative(
sentry_free(dist_str);
}

native_sdk_name_str = call_get_string(env, sentry_sdk_options, native_sdk_name_mid);
if (native_sdk_name_str) {
sentry_options_set_sdk_name(options, native_sdk_name_str);
sentry_free(native_sdk_name_str);
}

sentry_init(options);
return;

Expand Down
Loading