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

Demo app ANR #634

Merged
merged 6 commits into from
Oct 17, 2024
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: 2 additions & 1 deletion demo-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ The OpenTelemetry Android Demo App currently supports the following features:
- Automatically detects and reports ANRs in the app.
- ANR events are captured as spans with detailed stack traces, providing insights into the exact operations that caused the ANR.
- The span includes key attributes such as `screen.name`, `session.id`, and network information to assist in diagnosing the issue.
- Note: The app currently does not have any features designed to intentionally trigger an ANR.
- In order to crash the demo app, try to add to cart exactly 9 National Park Foundation Explorascopes (first product on the product list) and click "Yes, I'm sure." on the alert pop-up.


* Slow Render Detection
- Automatically detects instances of slow rendering within the app.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable

@Composable
fun ConfirmCrashPopup(
fun ConfirmPopup(
text : String,
onConfirm: () -> Unit,
onDismiss: () -> Unit
) {
Expand All @@ -17,7 +18,7 @@ fun ConfirmCrashPopup(
Text(text = "Are you sure?")
},
text = {
Text(text = "This will crash the app.")
Text(text = text)
},
confirmButton = {
TextButton(onClick = { onConfirm() }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import androidx.compose.ui.zIndex
import io.opentelemetry.android.demo.shop.clients.ProductCatalogClient
import io.opentelemetry.android.demo.shop.clients.RecommendationService
import io.opentelemetry.android.demo.shop.ui.components.SlowCometAnimation
import io.opentelemetry.android.demo.shop.ui.components.ConfirmCrashPopup
import io.opentelemetry.android.demo.shop.ui.components.ConfirmPopup
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit

Expand Down Expand Up @@ -122,12 +122,14 @@ fun AddToCartButton(
quantity: Int,
onSlowRenderChange: (Boolean) -> Unit
) {
var showPopup by remember { mutableStateOf(false) }
var showCrashPopup by remember { mutableStateOf(false) }
var showANRPopup by remember { mutableStateOf(false) }

Button(
onClick = {
if (product.id == "OLJCESPC7Z" && quantity == 10) {
showPopup = true
if (product.id == "OLJCESPC7Z") {
if (quantity == 10) showCrashPopup = true
if (quantity == 9) showANRPopup = true
} else {
if (product.id == "HQTGWGPNH4") {
onSlowRenderChange(true)
Expand All @@ -142,13 +144,25 @@ fun AddToCartButton(
Text(text = "Add to Cart")
}

if (showPopup) {
ConfirmCrashPopup(
if (showCrashPopup) {
ConfirmPopup(
text = "This will crash the app",
onConfirm = {
multiThreadCrashing()
},
onDismiss = {
showPopup = false
showCrashPopup = false
}
)
}
if (showANRPopup) {
ConfirmPopup(
text = "This will freeze the app",
onConfirm = {
appFreezing()
},
onDismiss = {
showCrashPopup = false
}
)
}
Expand Down Expand Up @@ -179,3 +193,14 @@ fun multiThreadCrashing(numThreads : Int = 4) {
}
latch.countDown()
}

fun appFreezing(){
try {
for (i in 0 .. 20) {
Thread.sleep(1_000)
}
} catch (e: InterruptedException) {
e.printStackTrace()
}

}