Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Verified Commit a88b2670 authored by Yash Garg's avatar Yash Garg 💬
Browse files

chore: use sentry timber integration and add README

parent cb12a6ec
Loading
Loading
Loading
Loading
Loading

README.md

0 → 100644
+39 −0
Original line number Diff line number Diff line
# Telemetry

Wrapper for Sentry to use in /e/ OS default applications.

## Usage

- First, we need to add dependency repository to `settings.gradle`:

```groovy
maven("https://gitlab.e.foundation/api/v4/groups/1391/-/packages/maven")
```

- Then, we need to add dependency to `build.gradle`:

```groovy
implementation 'foundation.e.lib:telemetry:0.0.5-alpha'
```

- Get the Sentry DSN from the sentry dashboard and add the following to `build.gradle`:

```groovy
buildTypes {
    configureEach {
        buildConfigField("String", "SENTRY_DSN", "\"${System.getenv("SENTRY_DSN")}\"")
    }
}
```

- To use the library, we need to add the following code to the main `Application` class:

```kotlin
Telemetry.init(BuildConfig.SENTRY_DSN, this)
```

- To send an event, we need to add the following code:

```kotlin
Telemetry.reportMessage("sample message")
```
+9 −12
Original line number Diff line number Diff line
@@ -4,25 +4,23 @@ plugins {
    id 'maven-publish'
}


def versionMajor = 0
def versionMinor = 0
def versionPatch = 4
def versionPatch = 5
def releasePatch = "alpha"


android {
    namespace 'foundation.e.lib.telemetry'
    compileSdk 32
    compileSdk 33

    defaultConfig {
        minSdk 21
        targetSdk 32
        targetSdk 33
        versionCode versionMajor * 1000000 + versionMinor * 1000 + versionPatch
        versionName "${versionMajor}.${versionMinor}.${versionPatch}-${releasePatch}"
    }

    libraryVariants.all{ variant ->
    libraryVariants.configureEach { variant ->
        variant.outputs.each { output ->
            output.outputFileName = "telemetry-${defaultConfig.versionName}.aar"
        }
@@ -44,8 +42,6 @@ android {
    }
}



publishing {
    publications {
        maven(MavenPublication) {
@@ -86,5 +82,6 @@ publishing {
}

dependencies {
    api 'io.sentry:sentry-android:6.10.0'
    api 'io.sentry:sentry-android:6.16.0'
    api 'io.sentry:sentry-android-timber:6.16.0'
}
 No newline at end of file
+29 −1
Original line number Diff line number Diff line
@@ -4,7 +4,9 @@ import android.app.Application
import android.provider.Settings
import foundation.e.lib.telemetry.Constants.SETTINGS_TELEMETRY_FIELD
import io.sentry.Sentry
import io.sentry.SentryLevel
import io.sentry.android.core.SentryAndroid
import io.sentry.android.timber.SentryTimberIntegration

object Telemetry {

@@ -13,27 +15,53 @@ object Telemetry {
    /**
     * Call this function in `onCreate()` of custom Application class.
     * Telemetry will be enabled only if enabled from developer options.
     *
     * @param identifier: the DSN identifier of the Sentry project
     * @param application: the application context
     */
    @JvmStatic
    fun init(identifier: String, application: Application) {
        this.identifier = identifier
        if (isTelemetryEnabled(application)) {
            SentryAndroid.init(application) { options ->
                options.dsn = identifier
                options.addIntegration(
                    SentryTimberIntegration(
                        minEventLevel = SentryLevel.ERROR,
                        minBreadcrumbLevel = SentryLevel.WARNING
                    )
                )
            }

        }
    }

    /**
     * Send a simple string message.
     *
     * @param message: the message to send
     */
    @JvmStatic
    fun reportMessage(message: String) {
        Sentry.captureMessage(message)
    }

    /**
     * Send a simple string message.
     * Specify the level of the message.
     *
     * @param message: the message to send
     * @param level: the level of the message
     */
    @JvmStatic
    fun reportMessage(message: String, level: SentryLevel) {
        Sentry.captureMessage(message, level)
    }

    /**
     * Read from OS developer options.
     * Pass false by default.
     *
     * @param application: the application context
     */
    fun isTelemetryEnabled(application: Application): Boolean {
        return try {
+2 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ pluginManagement {
        mavenCentral()
    }
}

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
@@ -12,5 +13,6 @@ dependencyResolutionManagement {
        mavenCentral()
    }
}

rootProject.name = "e-telemetry"
include ':lib'