diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cf56d17cee..8428f033b78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## Unreleased + +### Features + +- Add experimental `SentrySQLiteDriver` to `sentry-android-sqlite` for instrumenting `androidx.sqlite.SQLiteDriver` ([#5563](https://github.com/getsentry/sentry-java/pull/5563)) + - To use it, pass `SQLiteDriver` to `SentrySQLiteDriver.create(...)` + - Requires `androidx.sqlite:sqlite` (2.5.0+) on runtime classpath (typically provided by Room or SQLDelight) + ## 8.44.0 ### Features diff --git a/sentry-android-sqlite/api/sentry-android-sqlite.api b/sentry-android-sqlite/api/sentry-android-sqlite.api index c8780f1338d..7b9f633b46a 100644 --- a/sentry-android-sqlite/api/sentry-android-sqlite.api +++ b/sentry-android-sqlite/api/sentry-android-sqlite.api @@ -21,3 +21,15 @@ public final class io/sentry/android/sqlite/SentrySupportSQLiteOpenHelper$Compan public final fun create (Landroidx/sqlite/db/SupportSQLiteOpenHelper;)Landroidx/sqlite/db/SupportSQLiteOpenHelper; } +public final class io/sentry/sqlite/SentrySQLiteDriver : androidx/sqlite/SQLiteDriver { + public static final field Companion Lio/sentry/sqlite/SentrySQLiteDriver$Companion; + public synthetic fun (Landroidx/sqlite/SQLiteDriver;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public static final fun create (Landroidx/sqlite/SQLiteDriver;)Landroidx/sqlite/SQLiteDriver; + public fun hasConnectionPool ()Z + public fun open (Ljava/lang/String;)Landroidx/sqlite/SQLiteConnection; +} + +public final class io/sentry/sqlite/SentrySQLiteDriver$Companion { + public final fun create (Landroidx/sqlite/SQLiteDriver;)Landroidx/sqlite/SQLiteDriver; +} + diff --git a/sentry-android-sqlite/build.gradle.kts b/sentry-android-sqlite/build.gradle.kts index dd28252665e..6e0275b29b8 100644 --- a/sentry-android-sqlite/build.gradle.kts +++ b/sentry-android-sqlite/build.gradle.kts @@ -47,6 +47,10 @@ android { buildFeatures { buildConfig = true } + // Needed b/c Kotlin 1.4.x would otherwise pull in an older version without the annotations we + // want. + configurations.all { resolutionStrategy.force(libs.jetbrains.annotations.get()) } + androidComponents.beforeVariants { it.enable = !Config.Android.shouldSkipDebugVariant(it.buildType) } @@ -65,6 +69,7 @@ dependencies { api(projects.sentry) compileOnly(libs.androidx.sqlite) + compileOnly(libs.jetbrains.annotations) implementation(kotlin(Config.kotlinStdLib, Config.kotlinStdLibVersionAndroid)) diff --git a/sentry-android-sqlite/src/main/java/io/sentry/sqlite/SentrySQLiteDriver.kt b/sentry-android-sqlite/src/main/java/io/sentry/sqlite/SentrySQLiteDriver.kt index 9a619c418a5..e869778b811 100644 --- a/sentry-android-sqlite/src/main/java/io/sentry/sqlite/SentrySQLiteDriver.kt +++ b/sentry-android-sqlite/src/main/java/io/sentry/sqlite/SentrySQLiteDriver.kt @@ -5,6 +5,7 @@ import androidx.sqlite.SQLiteDriver import io.sentry.ScopesAdapter import io.sentry.SentryIntegrationPackageStorage import io.sentry.SentryLevel +import org.jetbrains.annotations.ApiStatus /** * Wraps a [SQLiteDriver] and automatically adds spans for each SQL statement it executes. @@ -28,13 +29,16 @@ import io.sentry.SentryLevel * * @param delegate The [SQLiteDriver] instance to delegate calls to. */ -internal class SentrySQLiteDriver private constructor(private val delegate: SQLiteDriver) : +@ApiStatus.Experimental +public class SentrySQLiteDriver private constructor(private val delegate: SQLiteDriver) : SQLiteDriver { init { SentryIntegrationPackageStorage.getInstance().addIntegration("SQLiteDriver") } + @Suppress("INAPPLICABLE_JVM_NAME") + @get:JvmName("hasConnectionPool") override val hasConnectionPool: Boolean get() = try { @@ -66,14 +70,14 @@ internal class SentrySQLiteDriver private constructor(private val delegate: SQLi } } - companion object { + public companion object { /** * Wraps the provided delegate in a [SentrySQLiteDriver]. Returns the delegate as-is if already * wrapped. */ @JvmStatic - fun create(delegate: SQLiteDriver): SQLiteDriver = + public fun create(delegate: SQLiteDriver): SQLiteDriver = delegate as? SentrySQLiteDriver ?: SentrySQLiteDriver(delegate) } }