Skip to content

Support for androidx.sqlite's SQLiteDriver #5001

Closed

Description

@angusholder

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()
  }
}

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Jan 5, 2026
  2. linear commented on Jan 5, 2026

    @linear
  3. romtsn commented on Jan 5, 2026

    @romtsn
    Contributor

    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.

  4. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jan 5, 2026
  5. angusholder commented on Jan 6, 2026

    @angusholder
    ContributorAuthor

    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.

    I've opened PR #5002 for this, please take a look if you have a chance

  6. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Jan 6, 2026
  7. romtsn commented on Jan 7, 2026

    @romtsn
    Contributor

    Thanks so much! We'll take a look this or early next week.

  8. 5 remaining items

  9. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jan 30, 2026
  10. angusholder commented on Mar 17, 2026

    @angusholder
    ContributorAuthor

    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)

  11. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Mar 17, 2026
  12. angusholder commented on Apr 29, 2026

    @angusholder
    ContributorAuthor

    @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

  13. 0xadam-brown commented on May 6, 2026

    @0xadam-brown
    Member

    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.

  14. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions