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 c9b904e606
commit c864fbac8c

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