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
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ androidx-lifecycle-common-java8 = { module = "androidx.lifecycle:lifecycle-commo
androidx-lifecycle-process = { module = "androidx.lifecycle:lifecycle-process", version.ref = "androidxLifecycle" }
androidx-navigation-runtime = { module = "androidx.navigation:navigation-runtime", version.ref = "androidxNavigation" }
androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "androidxNavigation" }
androidx-navigation-fragment = { module = "androidx.navigation:navigation-fragment-ktx", version.ref = "androidxNavigation" }
androidx-room-compiler = { module = "androidx.room:room-compiler", version.ref = "room2" }
androidx-room-ktx = { module = "androidx.room:room-ktx", version.ref = "room2" }
androidx-room-runtime = { module = "androidx.room:room-runtime", version.ref = "room2" }
Expand Down
2 changes: 2 additions & 0 deletions sentry-samples/sentry-samples-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ dependencies {

implementation(projects.sentryAndroid)
implementation(projects.sentryAndroidFragment)
implementation(projects.sentryAndroidNavigation)
implementation(projects.sentryAndroidSqlite)
implementation(projects.sentryAndroidTimber)
implementation(projects.sentryCompose)
Expand All @@ -209,6 +210,7 @@ dependencies {
implementation(libs.androidx.compose.material.icons.core)
implementation(libs.androidx.compose.material.icons.extended)
implementation(libs.androidx.navigation.compose)
implementation(libs.androidx.navigation.fragment)
implementation(libs.androidx.recyclerview)
implementation(libs.androidx.browser)
implementation(libs.androidx.room3.runtime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@
android:name=".compose.ComposeActivity"
android:exported="false" />

<activity
android:name=".navigation.Nav2SetupActivity"
android:exported="false"
android:theme="@style/AppTheme.Main" />

<activity
android:name=".navigation.Nav2Activity"
android:exported="false"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.Main" />

<activity
android:name=".FrameDataForSpansActivity"
android:exported="false" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,20 @@ fun IntegrationsScreen() {
}
}
}
item {
SentryTraced("open_nav2_activity") {
OutlinedButton(
onClick = {
activity.startActivity(
Intent(activity, io.sentry.samples.android.navigation.Nav2SetupActivity::class.java)
)
},
modifier = Modifier,
) {
Text("Open Nav2Activity", maxLines = 2, overflow = TextOverflow.Ellipsis)
}
}
}
item {
SentryTraced("open_sample_fragment") {
OutlinedButton(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package io.sentry.samples.android

import io.sentry.SentryOptions
import io.sentry.protocol.SentryTransaction
import java.util.concurrent.CopyOnWriteArrayList

/**
* Owns the single global beforeSendTransaction hook used by sample screens that inspect finished
* transactions.
*
* Multiple sample activities can overlap briefly during configuration changes or relaunches. If
* each screen installs and restores its own callback, a later uninstall can resurrect a stale
* wrapper callback that still retains dead state and drops the original callback chain.
*
* Keep one stable callback installed and let sample screens register lightweight listeners against
* it instead.
*/
internal object SampleBeforeSendTransactionHook {

private val listeners = CopyOnWriteArrayList<(SentryTransaction, String?) -> Unit>()

@Volatile private var installedCallback: SentryOptions.BeforeSendTransactionCallback? = null
@Volatile private var previousCallback: SentryOptions.BeforeSendTransactionCallback? = null

fun installIfNeeded(options: SentryOptions) {
if (installedCallback != null) {
return
}

synchronized(this) {
if (installedCallback != null) {
return
}

previousCallback = options.beforeSendTransaction
val callback = SentryOptions.BeforeSendTransactionCallback { transaction, hint ->
val previous = previousCallback

val processedTransaction =
if (previous == null) {
transaction
} else {
previous.execute(transaction, hint)
}

processedTransaction?.let { processed ->
listeners.forEach { listener ->
try {
listener(processed, options.dsn)
} catch (e: RuntimeException) {
options.logger.log(
io.sentry.SentryLevel.ERROR,
"Sample transaction listener failed.",
e,
)
}
}
}

processedTransaction
}

installedCallback = callback
options.beforeSendTransaction = callback
}
}

fun addListener(listener: (SentryTransaction, String?) -> Unit) {
listeners.addIfAbsent(listener)
}

fun removeListener(listener: (SentryTransaction, String?) -> Unit) {
listeners.remove(listener)
}
}
Loading
Loading