feat(android-sqlite): Add SentrySQLiteDriver (JAVA-275)#5466
Draft
0xadam-brown wants to merge 2 commits into
Draft
feat(android-sqlite): Add SentrySQLiteDriver (JAVA-275)#54660xadam-brown wants to merge 2 commits into
0xadam-brown wants to merge 2 commits into
Conversation
Introduces support for AndroidX's SQLiteDriver via a new SentrySQLiteDriver wrapper. SentrySQLiteDriver automatically creates Sentry spans for each SQL statement. It's the Driver API / KMP-compatible equivalent of SentrySupportSQLiteOpenHelper. --- Co-authored-by: Angus Holder <7407345+angusholder@users.noreply.github.com>
Contributor
|
📲 Install BuildsAndroid
|
Contributor
Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 91bb874 | 310.68 ms | 359.24 ms | 48.56 ms |
| ad8da22 | 314.38 ms | 352.29 ms | 37.91 ms |
| 27d7cf8 | 306.76 ms | 366.66 ms | 59.90 ms |
| 092f017 | 353.13 ms | 433.84 ms | 80.71 ms |
| b750b96 | 421.25 ms | 444.09 ms | 22.84 ms |
| a1eadfa | 345.67 ms | 411.26 ms | 65.59 ms |
| 5f14e5d | 325.76 ms | 368.32 ms | 42.56 ms |
| 22f4345 | 325.23 ms | 454.66 ms | 129.43 ms |
| 9054d65 | 330.94 ms | 403.24 ms | 72.30 ms |
| cf708bd | 408.35 ms | 458.98 ms | 50.63 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 91bb874 | 1.58 MiB | 2.13 MiB | 559.07 KiB |
| ad8da22 | 1.58 MiB | 2.29 MiB | 719.83 KiB |
| 27d7cf8 | 1.58 MiB | 2.12 MiB | 549.42 KiB |
| 092f017 | 0 B | 0 B | 0 B |
| b750b96 | 1.58 MiB | 2.10 MiB | 533.20 KiB |
| a1eadfa | 0 B | 0 B | 0 B |
| 5f14e5d | 1.58 MiB | 2.19 MiB | 620.00 KiB |
| 22f4345 | 1.58 MiB | 2.29 MiB | 719.83 KiB |
| 9054d65 | 1.58 MiB | 2.29 MiB | 723.38 KiB |
| cf708bd | 1.58 MiB | 2.11 MiB | 539.71 KiB |
8 tasks
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
Introduces
SentrySQLiteDriverfor wrapping and instrumentingandroidx.sqlite.SQLiteDriver. Like our existingSentrySupportSQLiteOpenHelper, the new wrapper produces a span per executed SQL statement.Example use:
The wrapper protects against duplicate span creation, but users migrating from
SentrySupportSQLiteOpenHelpertoSentrySQLiteDrivershould be careful not to wrap both the helper and driver when using Room's bridge adapter (see the README for more details).💡 Motivation and Context
Room 2.7 introduced the
SQLiteDriverAPI as a replacement forSupportSQLiteOpenHelper; Room 3.0+ makes use ofSQLiteDrivermandatory.A key motivation behind the introduction of
SQLiteDriverwas Kotlin Multiplatform compatibility. This PR makesSentrySQLiteDriveravailable on Android only, but the wrapper has been packaged so that we can lift it into our KMP module in the future without having to break clients.Background: Click to expand
Background
Android has three separate APIs for accessing on-device SQLite dbs:
[1]
SQLiteOpenHelper→ Original framework API, available since Android 1.0.[2]
SupportSQLiteOpenHelper→ An AndroidX abstraction layer that mirrors theSQLiteOpenHelperAPI. Introduced so that SQL mapping libraries like Room and SQLDelight could swap out the ORM-provided SQLite library for alternatives like SQLCipher. Delegates toSQLiteOpenHelperand ORM SQLite by default. On the deprecation runway.[3]
SQLiteDriver→ Kotlin Multiplatform-compatible API introduced with Room 2.7+. Uses the ORM SQLite library by default. The Google-recommended API, and required by Room 3.0+. Scrubs all Android-specific dependencies, and has a relatively narrow API in comparison with(Support)SQLiteOpenHelper.Sentry already supports [2]; this PR is about extending support to [3].
Addresses JAVA-275.
[1] Unlike
SentrySupportSQLiteOpenHelper, theSentrySQLiteDriveris not automatically wrapped via the sentry-android-gradle-plugin. (Can add byte code support later if we want.)[2] Behavior differences
Click to expand
Behavior differences
SentrySupportSQLiteOpenHelper(old)SentrySQLiteDriver(new)performSqlcall (incl. app time during cursor materialization)step()db time only – app time between steps excludedgetCount/onMove/fillWindowtimed; later rows untimedstep()contributes to cumulative span timestep()of the cycledb.namederivationdatabaseName(for Room, the builder name, e.g.,"tracks"fromdatabaseBuilder(ctx, MyDb, "tracks")).File(fileName).name— the on-disk filename of the path Room passes todriver.open()(e.g.,"tracks.db").db.namevalues during migration. Both paths report data correctly, but will attribute it to different sources.execSQL("CREATE TABLE …; INSERT …; INSERT …;")produces one span whose description is the full script.prepare(...), so multi-statement scripts must be split by Room (or the caller) into separate prepare/step cycles → one span per statement.💚 How did you test it?
Unit tests cover:
SentrySQLiteDriverdelegation and wrappingSentrySQLiteConnectiondelegation and wrappingSentrySQLiteStatementspan creation, cancellation, and success/error taggingSQLiteSpanRecorderspan lifecycle (start/finish/cancel)LegacyInstrumentedSQLiteStatementno-op passthrough📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
If there's sufficient demand, support auto-wrapping
SQLiteDrivervia the sentry-android-gradle-plugin.