-
-
Notifications
You must be signed in to change notification settings - Fork 472
Expand file tree
/
Copy pathSentrySupportSQLiteOpenHelper.kt
More file actions
62 lines (55 loc) · 2.2 KB
/
Copy pathSentrySupportSQLiteOpenHelper.kt
File metadata and controls
62 lines (55 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package io.sentry.android.sqlite
import androidx.sqlite.db.SupportSQLiteDatabase
import androidx.sqlite.db.SupportSQLiteOpenHelper
/**
* The Sentry's [SentrySupportSQLiteOpenHelper], it will automatically add a span out of the active
* span bound to the scope for each database query. It's a wrapper around an instance of
* [SupportSQLiteOpenHelper].
*
* You can wrap your custom [SupportSQLiteOpenHelper] instance with
* `SentrySupportSQLiteOpenHelper(myHelper)`. If you're using the Sentry Android Gradle plugin, this
* will be applied automatically.
*
* Usage - wrap your custom [SupportSQLiteOpenHelper] instance in [SentrySupportSQLiteOpenHelper]
*
* ```
* val openHelper = SentrySupportSQLiteOpenHelper.create(myOpenHelper)
* ```
*
* If you use Room you can wrap the default [FrameworkSQLiteOpenHelperFactory]:
* ```
* val database = Room.databaseBuilder(context, MyDatabase::class.java, "dbName")
* .openHelperFactory { configuration ->
* SentrySupportSQLiteOpenHelper.create(FrameworkSQLiteOpenHelperFactory().create(configuration))
* }
* ...
* .build()
* ```
*
* @param delegate The [SupportSQLiteOpenHelper] instance to delegate calls to.
*/
public class SentrySupportSQLiteOpenHelper
private constructor(private val delegate: SupportSQLiteOpenHelper) :
SupportSQLiteOpenHelper by delegate {
private val spans = OpenHelperSpans(databaseName = delegate.databaseName)
private val sentryWritableDatabase: SupportSQLiteDatabase by lazy {
SentrySupportSQLiteDatabase(delegate.writableDatabase, spans)
}
private val sentryReadableDatabase: SupportSQLiteDatabase by lazy {
SentrySupportSQLiteDatabase(delegate.readableDatabase, spans)
}
override val writableDatabase: SupportSQLiteDatabase
get() = sentryWritableDatabase
override val readableDatabase: SupportSQLiteDatabase
get() = sentryReadableDatabase
public companion object {
// @JvmStatic is needed to let this method be accessed by our gradle plugin
@JvmStatic
public fun create(delegate: SupportSQLiteOpenHelper): SupportSQLiteOpenHelper =
if (delegate is SentrySupportSQLiteOpenHelper) {
delegate
} else {
SentrySupportSQLiteOpenHelper(delegate)
}
}
}