feat(plugin): Auto-instrument SQLiteDriver for Room users (GRADLE-107)#1285
Open
0xadam-brown wants to merge 2 commits into
Open
feat(plugin): Auto-instrument SQLiteDriver for Room users (GRADLE-107)#12850xadam-brown wants to merge 2 commits into
0xadam-brown wants to merge 2 commits into
Conversation
Contributor
|
0xadam-brown
commented
Jun 9, 2026
0xadam-brown
commented
Jun 9, 2026
| ### Features | ||
|
|
||
| - Auto-wrap SQLiteDriver with SentrySQLiteDriver for Room users ([#1281](https://github.com/getsentry/sentry-android-gradle-plugin/issues/1281)) | ||
| - Gated on `sentry-android-sqlite` >= 8.44.0 and the existing `tracingInstrumentation` `DATABASE` feature |
Member
Author
There was a problem hiding this comment.
TODO: Update version number once we ship the SentrySQLiteDriver in sentry-android.
0xadam-brown
commented
Jun 9, 2026
0xadam-brown
commented
Jun 9, 2026
0xadam-brown
commented
Jun 9, 2026
| internal val VERSION_LOGCAT = SemVer(6, 17, 0) | ||
| internal val VERSION_APP_START = SemVer(7, 1, 0) | ||
| internal val VERSION_SQLITE = SemVer(6, 21, 0) | ||
| internal val VERSION_SQLITE_DRIVER = SemVer(8, 44, 0) |
Member
Author
There was a problem hiding this comment.
TODO: Update version number once we ship the SentrySQLiteDriver in sentry-android.
f64ad3f to
1c821b7
Compare
0xadam-brown
commented
Jun 10, 2026
| } | ||
| } | ||
|
|
||
| @Ignore(SQLITE_DRIVER_IGNORE_REASON) |
Member
Author
There was a problem hiding this comment.
TODO: Remove @Ignore once we ship the SentrySQLiteDriver in sentry-android.
0xadam-brown
commented
Jun 10, 2026
| ) | ||
| } | ||
|
|
||
| @Ignore(SQLITE_DRIVER_IGNORE_REASON) |
Member
Author
There was a problem hiding this comment.
TODO: Remove @Ignore once we ship the SentrySQLiteDriver in sentry-android.
0xadam-brown
commented
Jun 10, 2026
| assertInstrumentableChain(build, "AndroidXSQLiteOpenHelper", "AndroidXRoomDao") | ||
| } | ||
|
|
||
| @Ignore(SQLITE_DRIVER_IGNORE_REASON) |
Member
Author
There was a problem hiding this comment.
TODO: Remove @Ignore once we ship the SentrySQLiteDriver in sentry-android.
0xadam-brown
commented
Jun 10, 2026
| ) | ||
| } | ||
|
|
||
| @Ignore(SQLITE_DRIVER_IGNORE_REASON) |
Member
Author
There was a problem hiding this comment.
TODO: Remove @Ignore once we ship the SentrySQLiteDriver in sentry-android.
… users (GRADLE-107)
Adds a new ASM bytecode method visitor that lets us auto-wrap all occurrences of SQLiteDriver with SentrySQLiteDriver whenever the driver is passed to Room.DatabaseBuilder.setDriver(...).
For instance:
val database = Room.databaseBuilder(context, MyDatabase::class.java, "dbName")
.setDriver(AndroidSQLiteDriver())
.build()
becomes:
val database = Room.databaseBuilder(context, MyDatabase::class.java, "dbName")
.setDriver(SentrySQLiteDriver.create(AndroidSQLiteDriver()))
.build()
The wrapping policy is naive in that every SQLiteDriver passed to setDriver() is wrapped. That's deliberate because SentrySQLiteDriver protects against double-wrapping internally, which lets us keep our visitor implementation simple.
Preconditions:
1. InstrumentationFeature.DATABASE is enabled
2. The owning app is using a version of sentry-android-sqlite that includes SentrySQLiteDriver
Coverage:
- Auto-wraps SQLiteDriver for all Room users (sole Room access point is via its Room.DatabaseBuilder.setDriver() method).
- SQLDelight users don't need driver auto-wrapping (they still use SupportSQLiteOpenHelper, which we already auto-wrap).
- The few developers who use SQLiteDriver directly will need to wrap it manually.
1c821b7 to
1548c9c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📜 Description
Adds a new bytecode method visitor that lets us auto-wrap all occurrences of
SQLiteDriverwithSentrySQLiteDriverwhenever the driver is passed toRoom.DatabaseBuilder.setDriver(SQLiteDriver)(Room's sole driver access point – see the "Coverage" section from #1281 for why we don't need to worry about anything else).In other words, this:
becomes:
The wrapping policy is naive in that every SQLiteDriver passed to Room.DatabaseBuilder.setDriver() is wrapped. That's deliberate because SentrySQLiteDriver protects against double-wrapping internally, which lets us keep our visitor implementation simple.
💡 Motivation and Context
Room 2.7 introduced
RoomDatabase.Builder.setDriver(SQLiteDriver)as the new way to configure an underlying SQLite implementation (link), with the intention of eventually replacingSupportSQLiteOpenHelper. (Room 3.0+ does just that.)The Sentry Android Gradle Plugin currently auto-instruments only the open helper path. Apps that adopt the driver-based API will lose automatic SQL performance instrumentation unless they manually wrap their driver with
SentrySQLiteDriver.create(...)at everysetDriver(...)call site.This PR provides auto-wrapping for the driver path too.
Addresses GRADLE-107 / #1281
Preconditions
Coverage
Impact on build times
Near zero. The new instrumentation gates on a two-entry allowlist (androidx.room.RoomDatabase$Builder / androidx.room3.RoomDatabase$Builder), which means 0-1 classes will be visited per build in virtually all scenarios. The rest of the per-class cost is a single Set.contains check.
Interactions with other db instrumentation
SupportSQLiteOpenHelper
Driver instrumentation operates alongside our existing instrumentation of SupportSQLiteOpenHelper. (It's fine to use both drivers and open helpers in the same project, so long as a given db file is associated with exactly one of them. Room's APIs help enforce that restriction.)
The Sentry Android SDK – and not the SAGP – is responsible for protecting against double-wrapping and duplicate spans. In general that's easy (just check the type being passed to the wrapper). In the case of the SupportSQLiteDriver used with Room [2.7, 3.0) things get a bit trickier, as it's both a driver and consumes an open helper. But the SDK has that covered as well (see #5514).
Room DAO methods
Driver instrumentation also operates in tandem with our existing Room DAO spans – in theory, at least. Unfortunately DAO instrumentation broke under API changes in Room 2.7, which is the same version that introduced SQLiteDriver. So for now the two are never active at the same time. Fixing that is a task for another day...
💚 How did you test it?
[1] Added unit tests + integration tests in this PR
[2] Verified that all the (for now)
@Ignoredintegration tests pass against a local sentry-java SDK artifact containing SentrySQLiteDriver.[3] Built out a local version of the Sentry Android sample app that let me manually test SAGP + sentry-java compatibility end-to-end. Verified that auto-instrumentation of
SQLiteDriverworks as expected.📝 Checklist
🔮 Next steps
VERSION_SQLITE_DRIVERto match the sentry-android version that introducesSentrySQLiteDriver(PR here) + address other inline TODOs.