-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat: Add Room and SQLite integration page #4574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5041f02
Add Room and SQLite integration page
romtsn 41cd068
Rearrange existing content about Room
romtsn 1d47aff
Change image
romtsn 6e4f888
Align code indentation
romtsn b81daf4
Add imports to the sample
romtsn e9cf904
More imports
romtsn 2dc605a
Update src/platforms/android/configuration/integrations/room-and-sqli…
romtsn 1a88f3b
Update src/platforms/android/configuration/integrations/room-and-sqli…
romtsn f301a7d
Update src/platforms/android/configuration/integrations/room-and-sqli…
romtsn 5baeb72
Update src/platforms/android/configuration/integrations/room-and-sqli…
romtsn b91d19c
Update src/platforms/android/configuration/integrations/room-and-sqli…
romtsn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
155 changes: 155 additions & 0 deletions
155
src/platforms/android/configuration/integrations/room-and-sqlite.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
--- | ||
title: Room and SQLite | ||
caseStyle: camelCase | ||
supportLevel: production | ||
categories: | ||
- mobile | ||
--- | ||
|
||
<Note> | ||
|
||
Supported in Sentry's Android SDK version `4.0.0` and above. | ||
|
||
Supported in Sentry Android Gradle Plugin version `3.0.0` and above. | ||
|
||
</Note> | ||
|
||
The [Sentry Android Gradle Plugin](/platforms/android/gradle/) provides Room and AndroidX SQLite support through bytecode manipulation. The source can be found [on GitHub](https://github.com/getsentry/sentry-android-gradle-plugin/tree/main/plugin-build/src/main/kotlin/io/sentry/android/gradle/instrumentation). | ||
|
||
On this page, we get you up and running with Sentry's Room and SQLite Integration, so that it will automatically start a span out of the active transaction, bound to the scope for each sqlite/dao query. | ||
|
||
## Install | ||
|
||
To use the Room and AndroidX SQLite integration, add the Sentry Android Gradle plugin and the Sentry Android SDK (version `4.0.0` or above) in `build.gradle`: | ||
|
||
```groovy | ||
buildscript { | ||
repositories { | ||
mavenCentral() | ||
} | ||
} | ||
|
||
plugins { | ||
id "io.sentry.android.gradle" version "3.0.0-beta.3" | ||
} | ||
|
||
dependencies { | ||
implementation 'io.sentry:sentry-android:{{ packages.version('sentry.java.android', '5.0.0') }}' | ||
} | ||
``` | ||
|
||
```kotlin | ||
buildscript { | ||
repositories { | ||
mavenCentral() | ||
} | ||
} | ||
|
||
plugins { | ||
id("io.sentry.android.gradle") version "3.0.0-beta.3" | ||
} | ||
|
||
dependencies { | ||
implementation("io.sentry:sentry-android:{{ packages.version('sentry.java.android', '5.0.0') }}") | ||
} | ||
``` | ||
|
||
<Note> | ||
|
||
Make sure, that [performance monitoring](/platforms/android/performance/#configure-the-sample-rate) is enabled. | ||
|
||
</Note> | ||
|
||
## Configure | ||
|
||
In general, no further configuration is required as the auto-instrumentation is enabled by default. If you would like to disable the database instrumentation feature, we expose a configuration option for that: | ||
|
||
```groovy | ||
import io.sentry.android.gradle.InstrumentationFeature | ||
|
||
sentry { | ||
tracingInstrumentation { | ||
enabled = true | ||
features = EnumSet.allOf(InstrumentationFeature) - InstrumentationFeature.DATABASE | ||
} | ||
} | ||
``` | ||
|
||
```kotlin | ||
import java.util.EnumSet | ||
import io.sentry.android.gradle.InstrumentationFeature | ||
|
||
sentry { | ||
tracingInstrumentation { | ||
enabled.set(true) | ||
features.set(EnumSet.allOf(InstrumentationFeature::class.java) - InstrumentationFeature.DATABASE) | ||
} | ||
} | ||
``` | ||
|
||
## Verify | ||
|
||
Assuming you have the following (reduced) code snippet performing a database query on a Room Dao: | ||
|
||
```kotlin | ||
romtsn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import android.os.Bundle | ||
import android.widget.Button | ||
import androidx.activity.ComponentActivity | ||
import androidx.room.Database | ||
import androidx.room.Dao | ||
import androidx.room.Insert | ||
import androidx.room.OnConflictStrategy | ||
import androidx.room.RoomDatabase | ||
import io.sentry.Sentry | ||
import io.sentry.SpanStatus | ||
import kotlinx.coroutines.withContext | ||
|
||
@Dao | ||
abstract class TracksDao { | ||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
abstract suspend fun insert(track: Track): Long | ||
} | ||
|
||
@Database( | ||
entities = [Track::class], | ||
version = 1, | ||
exportSchema = false | ||
) | ||
abstract class TracksDatabase : RoomDatabase() { | ||
abstract fun tracksDao(): TracksDao | ||
} | ||
|
||
class EditActivity : ComponentActivity() { | ||
private lateinit var database: TracksDatabase | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
database = TODO("initialize database...") | ||
|
||
findViewById<Button>(R.id.editTrack).setOnClickListener { | ||
val transaction = Sentry.startTransaction( | ||
name = "Track Interaction", | ||
operation = "ui.action.edit", | ||
bindToScope = true | ||
) | ||
|
||
val newTrack = Track(/* fill in track values */) | ||
|
||
withContext(Dispatchers.IO) { | ||
database.tracksDao().insert(newTrack) | ||
transaction.finish(SpanStatus.OK) | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
To view the recorded transaction, log into [sentry.io](https://sentry.io) and open your project. Clicking on **Performance** will open a page with transactions, where you can select the just recorded transaction with the name `Track Interaction`. The event will look similar to this: | ||
|
||
 | ||
|
||
<Note> | ||
|
||
At the moment, we only support standard `androidx.room` usage. That is, the SDK will not report SQL queries for any `SupportSQLiteOpenHelper.Factory` other than [androidx.sqlite](https://github.com/androidx/androidx/tree/androidx-main/sqlite). However, if you are using a different `SupportSQLiteOpenHelper.Factory`, please report any [issues on Github](https://github.com/getsentry/sentry-android-gradle-plugin/issues), so we are aware and can possibly work on them. | ||
|
||
</Note> |
Binary file added
BIN
+34.4 KB
src/platforms/android/configuration/integrations/room-sqlite-instrumentation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.