Skip to content
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
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@

### Dependencies

- Bump Native SDK from v0.8.1 to v0.8.2 ([#4267](https://github.com/getsentry/sentry-java/pull/4267))
- [changelog](https://github.com/getsentry/sentry-native/blob/master/CHANGELOG.md#082)
- [diff](https://github.com/getsentry/sentry-native/compare/0.8.1...0.8.2)
- Bump Native SDK from v0.8.1 to v0.8.3 ([#4267](https://github.com/getsentry/sentry-java/pull/4267), [#4298](https://github.com/getsentry/sentry-java/pull/4298))
- [changelog](https://github.com/getsentry/sentry-native/blob/master/CHANGELOG.md#083)
- [diff](https://github.com/getsentry/sentry-native/compare/0.8.1...0.8.3)
- Bump Spring Boot from 2.7.5 to 2.7.18 ([#3496](https://github.com/getsentry/sentry-java/pull/3496))

## 8.5.0
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ object Config {
val apolloKotlin = "com.apollographql.apollo3:apollo-runtime:3.8.2"
val apolloKotlin4 = "com.apollographql.apollo:apollo-runtime:4.1.1"

val sentryNativeNdk = "io.sentry:sentry-native-ndk:0.8.2"
val sentryNativeNdk = "io.sentry:sentry-native-ndk:0.8.3"

object OpenTelemetry {
val otelVersion = "1.44.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.concurrent.TimeUnit;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@ApiStatus.Internal
public final class SentryNdk {
Expand Down Expand Up @@ -65,6 +66,13 @@ public static void init(@NotNull final SentryAndroidOptions options) {
io.sentry.ndk.NdkHandlerStrategy.SENTRY_HANDLER_STRATEGY_CHAIN_AT_START);
}

final @Nullable Double tracesSampleRate = options.getTracesSampleRate();
if (tracesSampleRate == null) {
ndkOptions.setTracesSampleRate(0.0f);
} else {
ndkOptions.setTracesSampleRate(tracesSampleRate.floatValue());
}

//noinspection UnstableApiUsage
io.sentry.ndk.SentryNdk.init(ndkOptions);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package io.sentry.android.ndk

import io.sentry.android.core.SentryAndroidOptions
import io.sentry.ndk.NdkOptions
import org.junit.Test
import org.mockito.Mockito
import org.mockito.kotlin.any
import org.mockito.kotlin.doAnswer
import kotlin.test.assertEquals
import kotlin.test.assertNotNull

@Suppress("UnstableApiUsage")
class SentryNdkTest {

class Fixture {

var capturedOptions: NdkOptions? = null

fun getSut(
options: SentryAndroidOptions = SentryAndroidOptions().apply {
dsn = "https://key@sentry.io/proj"
cacheDirPath = "/cache"
},
closure: () -> Unit
) {
Mockito.mockStatic(io.sentry.ndk.SentryNdk::class.java).use { utils ->
utils.`when`<Any> { io.sentry.ndk.SentryNdk.init(any<NdkOptions>()) }.doAnswer {
capturedOptions = it.arguments[0] as NdkOptions
}
SentryNdk.init(options)
closure.invoke()
}
}
}

val fixture = Fixture()

@Test
fun `SentryNdk calls NDK init`() {
fixture.getSut() {
assertNotNull(fixture.capturedOptions)
}
}

@Test
fun `SentryNdk propagates null tracesSampleRate`() {
fixture.getSut(
options = SentryAndroidOptions().apply {
dsn = "https://key@sentry.io/proj"
cacheDirPath = "/cache"
tracesSampleRate = null
}
) {
assertNotNull(fixture.capturedOptions)
assertEquals(0.0f, fixture.capturedOptions!!.tracesSampleRate, 0.0001f)
}
}

@Test
fun `SentryNdk propagates non-null tracesSampleRate`() {
fixture.getSut(
options = SentryAndroidOptions().apply {
dsn = "https://key@sentry.io/proj"
cacheDirPath = "/cache"
tracesSampleRate = 0.75
}
) {
assertNotNull(fixture.capturedOptions)
assertEquals(0.75f, fixture.capturedOptions!!.tracesSampleRate, 0.0001f)
}
}
}
Loading