Repository navigation
Support for androidx.sqlite's SQLiteDriver #5001
Copy link
Copy link
Closed
Labels
Description
Problem Statement
androidx.sqlite 2.5.0 added SQLiteDriver, a new alternative to SupportSQLiteOpenHelper. The new SQLiteDriver API benefits from being Kotlin multi-platform, having a much simpler API, and supporting a bundle of the latest SQLite into your app (rather than getting whatever the Android framework has at runtime). We've switched to this API in our app, but now cannot get SQL query breadcrumbs in Sentry afaict, because we can't use the old SupportSQLiteOpenHelper anymore.
Solution Brainstorm
I sketched a basic MVP of how I think the integration would work:
SentrySQLiteDriver.kt:
import androidx.sqlite.SQLiteConnection
import androidx.sqlite.SQLiteDriver
import androidx.sqlite.SQLiteStatement
import io.sentry.android.sqlite.SQLiteSpanManager
public class SentrySQLiteDriver(
private val delegate: SQLiteDriver,
) : SQLiteDriver {
override fun open(fileName: String): SQLiteConnection {
val sqliteSpanManager = SQLiteSpanManager(
// SQLiteDriver.open docs say:
// >> To open an in-memory database use the special name :memory: as the fileName.
// SQLiteSpanManager expects null for an in-memory databaseName, so replace ":memory:" with null.
databaseName = fileName.takeIf { it != ":memory:" }
)
val connection = delegate.open(fileName)
return SentrySQLiteConnection(connection, sqliteSpanManager)
}
}
internal class SentrySQLiteConnection(
private val delegate: SQLiteConnection,
private val sqliteSpanManager: SQLiteSpanManager,
) : SQLiteConnection by delegate {
override fun prepare(sql: String): SQLiteStatement {
val statement = delegate.prepare(sql)
return SentrySQLiteStatement(statement, sqliteSpanManager, sql)
}
}
internal class SentrySQLiteStatement(
private val delegate: SQLiteStatement,
private val sqliteSpanManager: SQLiteSpanManager,
private val sql: String,
) : SQLiteStatement by delegate {
// We have to start the span only the first time, regardless of how many times its methods get
// called.
private var isSpanStarted = false
override fun step(): Boolean {
if (isSpanStarted) {
return delegate.step()
} else {
isSpanStarted = true
return sqliteSpanManager.performSql(sql) { delegate.step() }
}
}
override fun reset() {
isSpanStarted = false
delegate.reset()
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsNo status
Activity
linear commentedon Jan 5, 2026
JAVA-275
romtsn commentedon Jan 5, 2026
hi @angusholder thanks for proposing the feature, we'll look into prioritizing it soon-ish! Or feel free to open up a PR with your proposed solution.
angusholder commentedon Jan 6, 2026
I've opened PR #5002 for this, please take a look if you have a chance
romtsn commentedon Jan 7, 2026
Thanks so much! We'll take a look this or early next week.
5 remaining items
angusholder commentedon Mar 17, 2026
The new Room 3.0 uses only the SQLiteDriver API out of the box, so this will become more important.
(note there's still a compat library for converting the older SupportSQLiteOpenHelper to a SQLiteDriver)angusholder commentedon Apr 29, 2026
@romtsn Any update on this? After my last comment, I realised that Room 3.0 doesn't have SupportSQLiteOpenHelper.Factory anymore, so I don't think there's any way to use SentrySupportSQLiteOpenHelper with Room 3.0
0xadam-brown commentedon May 6, 2026
Hey @angusholder – turns out we've been...busy 😅. It's in our queue to review in the next few weeks. We'll look into Room 3.0 compatibility as well. Thanks again for the patience.