Add extra code to make sure we can't upload a session/user id as an extra by mistake

This commit is contained in:
Jorge Martín
2025-12-16 16:52:48 +01:00
committed by Jorge Martin Espinosa
parent a4b908bc18
commit 20c0d0190e

View File

@@ -55,8 +55,13 @@ class SentryAnalyticsProvider(
SentryAndroid.init(context) { options ->
options.dsn = dsn
options.beforeSend = SentryOptions.BeforeSendCallback { event, _ -> event }
options.beforeSendTransaction = SentryOptions.BeforeSendTransactionCallback { transaction, _ ->
// Ensure we'll never upload any session ids
val possibleSessionIds = transaction.extras?.filter { (it.value as? String)?.startsWith("@") == true }.orEmpty()
for (invalidExtra in possibleSessionIds) {
transaction.extras?.remove(invalidExtra.key)
}
val sessionId = appNavigationStateService.appNavigationState.value.navigationState.currentSessionId()
if (sessionId != null) {
// This runs in a separate thread, so although using `runBlocking` is not great, at least it shouldn't freeze the app