Skip to content

Commit 10a0bc2

Browse files
authored
feat(android-sqlite): Make SentrySQLiteDriver experimental (JAVA-275) (#5563)
Makes SentrySQLiteDriver public + experimental during development. In particular, lets us access the driver via the Sentry Android sample app.
1 parent dcb1587 commit 10a0bc2

4 files changed

Lines changed: 32 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Features
6+
7+
- Add experimental `SentrySQLiteDriver` to `sentry-android-sqlite` for instrumenting `androidx.sqlite.SQLiteDriver` ([#5563](https://github.com/getsentry/sentry-java/pull/5563))
8+
- To use it, pass `SQLiteDriver` to `SentrySQLiteDriver.create(...)`
9+
- Requires `androidx.sqlite:sqlite` (2.5.0+) on runtime classpath (typically provided by Room or SQLDelight)
10+
311
## 8.44.0
412

513
### Features

sentry-android-sqlite/api/sentry-android-sqlite.api

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,15 @@ public final class io/sentry/android/sqlite/SentrySupportSQLiteOpenHelper$Compan
2121
public final fun create (Landroidx/sqlite/db/SupportSQLiteOpenHelper;)Landroidx/sqlite/db/SupportSQLiteOpenHelper;
2222
}
2323

24+
public final class io/sentry/sqlite/SentrySQLiteDriver : androidx/sqlite/SQLiteDriver {
25+
public static final field Companion Lio/sentry/sqlite/SentrySQLiteDriver$Companion;
26+
public synthetic fun <init> (Landroidx/sqlite/SQLiteDriver;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
27+
public static final fun create (Landroidx/sqlite/SQLiteDriver;)Landroidx/sqlite/SQLiteDriver;
28+
public fun hasConnectionPool ()Z
29+
public fun open (Ljava/lang/String;)Landroidx/sqlite/SQLiteConnection;
30+
}
31+
32+
public final class io/sentry/sqlite/SentrySQLiteDriver$Companion {
33+
public final fun create (Landroidx/sqlite/SQLiteDriver;)Landroidx/sqlite/SQLiteDriver;
34+
}
35+

sentry-android-sqlite/build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ android {
4747

4848
buildFeatures { buildConfig = true }
4949

50+
// Needed b/c Kotlin 1.4.x would otherwise pull in an older version without the annotations we
51+
// want.
52+
configurations.all { resolutionStrategy.force(libs.jetbrains.annotations.get()) }
53+
5054
androidComponents.beforeVariants {
5155
it.enable = !Config.Android.shouldSkipDebugVariant(it.buildType)
5256
}
@@ -65,6 +69,7 @@ dependencies {
6569
api(projects.sentry)
6670

6771
compileOnly(libs.androidx.sqlite)
72+
compileOnly(libs.jetbrains.annotations)
6873

6974
implementation(kotlin(Config.kotlinStdLib, Config.kotlinStdLibVersionAndroid))
7075

sentry-android-sqlite/src/main/java/io/sentry/sqlite/SentrySQLiteDriver.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import androidx.sqlite.SQLiteDriver
55
import io.sentry.ScopesAdapter
66
import io.sentry.SentryIntegrationPackageStorage
77
import io.sentry.SentryLevel
8+
import org.jetbrains.annotations.ApiStatus
89

910
/**
1011
* Wraps a [SQLiteDriver] and automatically adds spans for each SQL statement it executes.
@@ -28,13 +29,16 @@ import io.sentry.SentryLevel
2829
*
2930
* @param delegate The [SQLiteDriver] instance to delegate calls to.
3031
*/
31-
internal class SentrySQLiteDriver private constructor(private val delegate: SQLiteDriver) :
32+
@ApiStatus.Experimental
33+
public class SentrySQLiteDriver private constructor(private val delegate: SQLiteDriver) :
3234
SQLiteDriver {
3335

3436
init {
3537
SentryIntegrationPackageStorage.getInstance().addIntegration("SQLiteDriver")
3638
}
3739

40+
@Suppress("INAPPLICABLE_JVM_NAME")
41+
@get:JvmName("hasConnectionPool")
3842
override val hasConnectionPool: Boolean
3943
get() =
4044
try {
@@ -66,14 +70,14 @@ internal class SentrySQLiteDriver private constructor(private val delegate: SQLi
6670
}
6771
}
6872

69-
companion object {
73+
public companion object {
7074

7175
/**
7276
* Wraps the provided delegate in a [SentrySQLiteDriver]. Returns the delegate as-is if already
7377
* wrapped.
7478
*/
7579
@JvmStatic
76-
fun create(delegate: SQLiteDriver): SQLiteDriver =
80+
public fun create(delegate: SQLiteDriver): SQLiteDriver =
7781
delegate as? SentrySQLiteDriver ?: SentrySQLiteDriver(delegate)
7882
}
7983
}

0 commit comments

Comments
 (0)