Skip to content

Commit

Permalink
Merge ae287d1 into f1e4d4c
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanosiano authored May 29, 2023
2 parents f1e4d4c + ae287d1 commit 69fdf80
Show file tree
Hide file tree
Showing 17 changed files with 990 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Features

- Refactor android sqlite instrumentation (SDK side) ([#2722](https://github.com/getsentry/sentry-java/pull/2722))
- Add SentryWrapper for Callable and Supplier Interface ([#2720](https://github.com/getsentry/sentry-java/pull/2720))

## 6.20.0
Expand Down
1 change: 1 addition & 0 deletions buildSrc/src/main/java/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ object Config {
val lifecycleProcess = "androidx.lifecycle:lifecycle-process:$lifecycleVersion"
val lifecycleCommonJava8 = "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion"
val androidxCore = "androidx.core:core:1.3.2"
val androidxSqlite = "androidx.sqlite:sqlite:2.3.1"
val androidxRecylerView = "androidx.recyclerview:recyclerview:1.2.1"

val slf4jApi = "org.slf4j:slf4j-api:1.7.30"
Expand Down
21 changes: 21 additions & 0 deletions sentry-android-sqlite/api/sentry-android-okhttp.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
public final class io/sentry/android/okhttp/BuildConfig {
public static final field BUILD_TYPE Ljava/lang/String;
public static final field DEBUG Z
public static final field LIBRARY_PACKAGE_NAME Ljava/lang/String;
public static final field VERSION_NAME Ljava/lang/String;
public fun <init> ()V
}

public final class io/sentry/android/okhttp/SentryOkHttpInterceptor : io/sentry/IntegrationName, okhttp3/Interceptor {
public fun <init> ()V
public fun <init> (Lio/sentry/IHub;)V
public fun <init> (Lio/sentry/IHub;Lio/sentry/android/okhttp/SentryOkHttpInterceptor$BeforeSpanCallback;ZLjava/util/List;Ljava/util/List;)V
public synthetic fun <init> (Lio/sentry/IHub;Lio/sentry/android/okhttp/SentryOkHttpInterceptor$BeforeSpanCallback;ZLjava/util/List;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Lio/sentry/android/okhttp/SentryOkHttpInterceptor$BeforeSpanCallback;)V
public fun intercept (Lokhttp3/Interceptor$Chain;)Lokhttp3/Response;
}

public abstract interface class io/sentry/android/okhttp/SentryOkHttpInterceptor$BeforeSpanCallback {
public abstract fun execute (Lio/sentry/ISpan;Lokhttp3/Request;Lokhttp3/Response;)Lio/sentry/ISpan;
}

90 changes: 90 additions & 0 deletions sentry-android-sqlite/api/sentry-android-sqlite.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
public final class io/sentry/android/sqlite/BuildConfig {
public static final field BUILD_TYPE Ljava/lang/String;
public static final field DEBUG Z
public static final field LIBRARY_PACKAGE_NAME Ljava/lang/String;
public static final field VERSION_NAME Ljava/lang/String;
public fun <init> ()V
}

public final class io/sentry/android/sqlite/SQLiteSpanManager {
public fun <init> ()V
public fun <init> (Lio/sentry/IHub;)V
public synthetic fun <init> (Lio/sentry/IHub;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun performSql (Ljava/lang/String;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object;
}

public final class io/sentry/android/sqlite/SentrySupportSQLiteDatabase : androidx/sqlite/db/SupportSQLiteDatabase {
public fun <init> (Landroidx/sqlite/db/SupportSQLiteDatabase;Lio/sentry/android/sqlite/SQLiteSpanManager;)V
public fun beginTransaction ()V
public fun beginTransactionNonExclusive ()V
public fun beginTransactionWithListener (Landroid/database/sqlite/SQLiteTransactionListener;)V
public fun beginTransactionWithListenerNonExclusive (Landroid/database/sqlite/SQLiteTransactionListener;)V
public fun close ()V
public fun compileStatement (Ljava/lang/String;)Landroidx/sqlite/db/SupportSQLiteStatement;
public fun delete (Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)I
public fun disableWriteAheadLogging ()V
public fun enableWriteAheadLogging ()Z
public fun endTransaction ()V
public fun execPerConnectionSQL (Ljava/lang/String;[Ljava/lang/Object;)V
public fun execSQL (Ljava/lang/String;)V
public fun execSQL (Ljava/lang/String;[Ljava/lang/Object;)V
public fun getAttachedDbs ()Ljava/util/List;
public fun getMaximumSize ()J
public fun getPageSize ()J
public fun getPath ()Ljava/lang/String;
public fun getVersion ()I
public fun inTransaction ()Z
public fun insert (Ljava/lang/String;ILandroid/content/ContentValues;)J
public fun isDatabaseIntegrityOk ()Z
public fun isDbLockedByCurrentThread ()Z
public fun isExecPerConnectionSQLSupported ()Z
public fun isOpen ()Z
public fun isReadOnly ()Z
public fun isWriteAheadLoggingEnabled ()Z
public fun needUpgrade (I)Z
public fun query (Landroidx/sqlite/db/SupportSQLiteQuery;)Landroid/database/Cursor;
public fun query (Landroidx/sqlite/db/SupportSQLiteQuery;Landroid/os/CancellationSignal;)Landroid/database/Cursor;
public fun query (Ljava/lang/String;)Landroid/database/Cursor;
public fun query (Ljava/lang/String;[Ljava/lang/Object;)Landroid/database/Cursor;
public fun setForeignKeyConstraintsEnabled (Z)V
public fun setLocale (Ljava/util/Locale;)V
public fun setMaxSqlCacheSize (I)V
public fun setMaximumSize (J)J
public fun setPageSize (J)V
public fun setTransactionSuccessful ()V
public fun setVersion (I)V
public fun update (Ljava/lang/String;ILandroid/content/ContentValues;Ljava/lang/String;[Ljava/lang/Object;)I
public fun yieldIfContendedSafely ()Z
public fun yieldIfContendedSafely (J)Z
}

public final class io/sentry/android/sqlite/SentrySupportSQLiteOpenHelper : androidx/sqlite/db/SupportSQLiteOpenHelper {
public static final field Companion Lio/sentry/android/sqlite/SentrySupportSQLiteOpenHelper$Companion;
public fun <init> (Landroidx/sqlite/db/SupportSQLiteOpenHelper;)V
public fun close ()V
public fun getDatabaseName ()Ljava/lang/String;
public fun getReadableDatabase ()Landroidx/sqlite/db/SupportSQLiteDatabase;
public fun getWritableDatabase ()Landroidx/sqlite/db/SupportSQLiteDatabase;
public fun setWriteAheadLoggingEnabled (Z)V
}

public final class io/sentry/android/sqlite/SentrySupportSQLiteOpenHelper$Companion {
public final fun create (Landroidx/sqlite/db/SupportSQLiteOpenHelper;)Landroidx/sqlite/db/SupportSQLiteOpenHelper;
}

public final class io/sentry/android/sqlite/SentrySupportSQLiteStatement : androidx/sqlite/db/SupportSQLiteStatement {
public fun <init> (Landroidx/sqlite/db/SupportSQLiteStatement;Lio/sentry/android/sqlite/SQLiteSpanManager;Ljava/lang/String;)V
public fun bindBlob (I[B)V
public fun bindDouble (ID)V
public fun bindLong (IJ)V
public fun bindNull (I)V
public fun bindString (ILjava/lang/String;)V
public fun clearBindings ()V
public fun close ()V
public fun execute ()V
public fun executeInsert ()J
public fun executeUpdateDelete ()I
public fun simpleQueryForLong ()J
public fun simpleQueryForString ()Ljava/lang/String;
}

87 changes: 87 additions & 0 deletions sentry-android-sqlite/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import io.gitlab.arturbosch.detekt.Detekt
import org.jetbrains.kotlin.config.KotlinCompilerVersion

plugins {
id("com.android.library")
kotlin("android")
jacoco
id(Config.QualityPlugins.gradleVersions)
id(Config.QualityPlugins.detektPlugin)
}

android {
compileSdk = Config.Android.compileSdkVersion
namespace = "io.sentry.android.sqlite"

defaultConfig {
targetSdk = Config.Android.targetSdkVersion
minSdk = Config.Android.minSdkVersion

// for AGP 4.1
buildConfigField("String", "VERSION_NAME", "\"${project.version}\"")
}

buildTypes {
getByName("debug")
getByName("release") {
consumerProguardFiles("proguard-rules.pro")
}
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
kotlinOptions.languageVersion = Config.kotlinCompatibleLanguageVersion
}

testOptions {
animationsDisabled = true
unitTests.apply {
isReturnDefaultValues = true
isIncludeAndroidResources = true
}
}

lint {
warningsAsErrors = true
checkDependencies = true

// We run a full lint analysis as build part in CI, so skip vital checks for assemble tasks.
checkReleaseBuilds = false
}

variantFilter {
if (Config.Android.shouldSkipDebugVariant(buildType.name)) {
ignore = true
}
}
}

tasks.withType<Test> {
configure<JacocoTaskExtension> {
isIncludeNoLocationClasses = false
}
}

kotlin {
explicitApi()
}

dependencies {
api(projects.sentry)

compileOnly(Config.Libs.androidxSqlite)

implementation(kotlin(Config.kotlinStdLib, KotlinCompilerVersion.VERSION))

// tests
testImplementation(Config.Libs.androidxSqlite)
testImplementation(Config.TestLibs.kotlinTestJunit)
testImplementation(Config.TestLibs.androidxJunit)
testImplementation(Config.TestLibs.mockitoKotlin)
testImplementation(Config.TestLibs.mockitoInline)
}

tasks.withType<Detekt> {
// Target version of the generated JVM bytecode. It is used for type resolution.
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
13 changes: 13 additions & 0 deletions sentry-android-sqlite/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
##---------------Begin: proguard configuration for OkHttp ----------

# To ensure that stack traces is unambiguous
# https://developer.android.com/studio/build/shrink-code#decode-stack-trace
-keepattributes LineNumberTable,SourceFile

# https://square.github.io/okhttp/features/r8_proguard/
# If you use OkHttp as a dependency in an Android project which uses R8 as a default compiler you
# don’t have to do anything. The specific rules are already bundled into the JAR which can
# be interpreted by R8 automatically.
# https://raw.githubusercontent.com/square/okhttp/master/okhttp/src/jvmMain/resources/META-INF/proguard/okhttp3.pro

##---------------End: proguard configuration for OkHttp ----------
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.sentry.android.sqlite

import android.database.SQLException
import io.sentry.HubAdapter
import io.sentry.IHub
import io.sentry.SentryIntegrationPackageStorage
import io.sentry.SpanStatus

class SQLiteSpanManager(
private val hub: IHub = HubAdapter.getInstance()
) {

init {
SentryIntegrationPackageStorage.getInstance().addIntegration("SQLite")
}

/**
* Performs a sql operation, creates a span and handles exceptions in case of occurrence.
*
* @param sql The sql query
* @param operation The sql operation to execute.
* In case of an error the surrounding span will have its status set to INTERNAL_ERROR
*/
@Throws(SQLException::class)
fun <T> performSql(sql: String, operation: () -> T): T {
val span = hub.span?.startChild("db.sql.query", sql)
return try {
val result = operation()
span?.status = SpanStatus.OK
result
} catch (e: SQLException) {
span?.status = SpanStatus.INTERNAL_ERROR
span?.throwable = e
throw e
} catch (e: UnsupportedOperationException) {
span?.status = SpanStatus.INTERNAL_ERROR
span?.throwable = e
throw e
} finally {
span?.finish()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package io.sentry.android.sqlite

import android.annotation.SuppressLint
import android.database.Cursor
import android.database.SQLException
import android.os.Build
import android.os.CancellationSignal
import androidx.annotation.RequiresApi
import androidx.sqlite.db.SupportSQLiteDatabase
import androidx.sqlite.db.SupportSQLiteQuery
import androidx.sqlite.db.SupportSQLiteStatement

class SentrySupportSQLiteDatabase(
private val delegate: SupportSQLiteDatabase,
private val sqLiteSpanManager: SQLiteSpanManager
) : SupportSQLiteDatabase by delegate {

/**
* Compiles the given SQL statement. It will return Sentry's wrapper around SupportSQLiteStatement.
*
* @param sql The sql query.
* @return Compiled statement.
*/
override fun compileStatement(sql: String): SupportSQLiteStatement {
return SentrySupportSQLiteStatement(delegate.compileStatement(sql), sqLiteSpanManager, sql)
}

/** Execute the given SQL statement on all connections to this database. */
@Suppress("AcronymName") // To keep consistency with framework method name.
override fun execPerConnectionSQL(
sql: String,
@SuppressLint("ArrayReturn") bindArgs: Array<out Any?>?
) {
sqLiteSpanManager.performSql(sql) {
delegate.execPerConnectionSQL(sql, bindArgs)
}
}

override fun query(query: String): Cursor {
return sqLiteSpanManager.performSql(query) {
delegate.query(query)
}
}

override fun query(query: String, bindArgs: Array<out Any?>): Cursor {
return sqLiteSpanManager.performSql(query) {
delegate.query(query, bindArgs)
}
}

override fun query(query: SupportSQLiteQuery): Cursor {
return sqLiteSpanManager.performSql(query.sql) {
delegate.query(query)
}
}

@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
override fun query(
query: SupportSQLiteQuery,
cancellationSignal: CancellationSignal?
): Cursor {
return sqLiteSpanManager.performSql(query.sql) {
delegate.query(query, cancellationSignal)
}
}

@Throws(SQLException::class)
override fun execSQL(sql: String) {
sqLiteSpanManager.performSql(sql) {
delegate.execSQL(sql)
}
}

@Throws(SQLException::class)
override fun execSQL(sql: String, bindArgs: Array<out Any?>) {
sqLiteSpanManager.performSql(sql) {
delegate.execSQL(sql, bindArgs)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.sentry.android.sqlite

import androidx.sqlite.db.SupportSQLiteDatabase
import androidx.sqlite.db.SupportSQLiteOpenHelper

class SentrySupportSQLiteOpenHelper(
private val delegate: SupportSQLiteOpenHelper
) : SupportSQLiteOpenHelper by delegate {

private val sqLiteSpanManager = SQLiteSpanManager()

private val sentryDatabase: SupportSQLiteDatabase by lazy {
SentrySupportSQLiteDatabase(delegate.writableDatabase, sqLiteSpanManager)
}

override val writableDatabase: SupportSQLiteDatabase
get() = sentryDatabase

companion object {

fun create(delegate: SupportSQLiteOpenHelper): SupportSQLiteOpenHelper {
return if (delegate is SentrySupportSQLiteOpenHelper) {
delegate
} else {
SentrySupportSQLiteOpenHelper(delegate)
}
}
}
}
Loading

0 comments on commit 69fdf80

Please sign in to comment.