Skip to content
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

🔊 Remove Sentry logging for FOSS build #251

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
🔊 Remove Sentry logging for FOSS build
  • Loading branch information
jheubuch committed Sep 4, 2023
commit a1e73772defd55215dfa8ad12f39b20ca323a98e
11 changes: 10 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ plugins {
id "kotlin-android"
id "kotlin-kapt"
id "androidx.navigation.safeargs.kotlin"
id "io.sentry.android.gradle" version "3.11.1"
id "io.sentry.android.gradle" version "3.12.0"
id "com.mikepenz.aboutlibraries.plugin"
id "com.google.gms.google-services"
}

sentry {
autoInstallation {
enabled = false
}
}

def sentryDsn = ""
def oauthClientId = ""
def oauthRedirectUrl = ""
Expand Down Expand Up @@ -178,6 +184,9 @@ dependencies {
// Feature flags
implementation "io.getunleash:unleash-android-proxy-sdk:0.5.5"

// Sentry
playImplementation "io.sentry:sentry-android:6.28.0"

// Unified Push
implementation 'com.github.UnifiedPush:android-connector:2.1.1'
playImplementation('com.github.UnifiedPush:android-embedded_fcm_distributor:2.2.0') {
Expand Down
33 changes: 33 additions & 0 deletions app/src/foss/kotlin/de/hbch/traewelling/logging/Logger.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package de.hbch.traewelling.logging

import android.util.Log

class Logger private constructor(): ILogger {

companion object {
@Volatile
private var instance: Logger? = null

private fun getInstance() = instance ?: synchronized(this) {
instance ?: Logger().also {
instance = it
}
}

fun captureException(t: Throwable) {
getInstance().captureException(t)
}

fun captureMessage(message: String, additionalInfo: Map<String, String>) {
getInstance().captureMessage(message, additionalInfo)
}
}

override fun captureException(t: Throwable) {
Log.e("Error", t.stackTraceToString())
}

override fun captureMessage(message: String, additionalInfo: Map<String, String>) {
Log.i("Info", message)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.hbch.traewelling.api.interceptors

import io.sentry.Sentry
import de.hbch.traewelling.logging.Logger
import okhttp3.Interceptor
import okhttp3.Response
import okio.Buffer
Expand All @@ -20,12 +20,14 @@ class LogInterceptor : Interceptor {
val requestBody = buffer.readUtf8()
buffer.close()

Sentry.captureMessage("[${response.code}] $path") { scope ->
scope.setExtra("path", path)
scope.setExtra("code", response.code.toString())
scope.setExtra("responseBody", response.body?.string() ?: "no body")
scope.setExtra("requestBody", requestBody)
}
val additionalInfo = mapOf(
Pair("path", path),
Pair("code", response.code.toString()),
Pair("responseBody", response.body?.string() ?: "no body"),
Pair("requestBody", requestBody)
)

Logger.captureMessage("[${response.code}] $path", additionalInfo)
}
return response
}
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/kotlin/de/hbch/traewelling/logging/ILogger.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package de.hbch.traewelling.logging

interface ILogger {
fun captureException(t: Throwable)
fun captureMessage(message: String, additionalInfo: Map<String, String>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import de.hbch.traewelling.api.models.status.StatusBusiness
import de.hbch.traewelling.api.models.status.StatusVisibility
import de.hbch.traewelling.api.models.status.UpdateStatusRequest
import de.hbch.traewelling.api.models.trip.ProductType
import de.hbch.traewelling.logging.Logger
import de.hbch.traewelling.ui.checkInResult.CheckInResult
import io.sentry.Sentry
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
Expand Down Expand Up @@ -112,7 +112,7 @@ class CheckInViewModel : ViewModel() {
onCheckedIn(checkInResult == CheckInResult.SUCCESSFUL)
}
override fun onFailure(call: Call<Data<CheckInResponse>>, t: Throwable) {
Sentry.captureException(t)
Logger.captureException(t)
checkInResult = CheckInResult.ERROR
onCheckedIn(false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.lifecycle.ViewModel
import de.hbch.traewelling.api.TraewellingApi
import de.hbch.traewelling.api.models.Data
import de.hbch.traewelling.api.models.event.Event
import io.sentry.Sentry
import de.hbch.traewelling.logging.Logger
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
Expand All @@ -31,7 +31,7 @@ class EventViewModel : ViewModel() {
}

override fun onFailure(call: Call<Data<List<Event>>>, t: Throwable) {
Sentry.captureException(t)
Logger.captureException(t)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import de.hbch.traewelling.api.models.status.StatusVisibility
import de.hbch.traewelling.api.models.user.User
import de.hbch.traewelling.ui.login.LoginActivity
import de.hbch.traewelling.util.removeDynamicShortcuts
import io.sentry.Sentry
import de.hbch.traewelling.logging.Logger
import org.unifiedpush.android.connector.UnifiedPush
import retrofit2.Call
import retrofit2.Callback
Expand Down Expand Up @@ -83,7 +83,7 @@ class LoggedInUserViewModel : ViewModel() {

override fun onFailure(call: Call<Unit>, t: Throwable) {
failureCallback()
Sentry.captureException(t)
Logger.captureException(t)
}
})
}
Expand Down Expand Up @@ -170,7 +170,7 @@ class LoggedInUserViewModel : ViewModel() {
}

override fun onFailure(call: Call<Data<List<Station>>>, t: Throwable) {
Sentry.captureException(t)
Logger.captureException(t)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import androidx.lifecycle.ViewModel
import de.hbch.traewelling.api.TraewellingApi
import de.hbch.traewelling.api.models.status.Status
import de.hbch.traewelling.api.models.status.StatusPage
import io.sentry.Sentry
import de.hbch.traewelling.logging.Logger
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
Expand Down Expand Up @@ -37,7 +37,7 @@ class ActiveCheckinsViewModel : ViewModel() {
}
override fun onFailure(call: Call<StatusPage>, t: Throwable) {
isRefreshing.postValue(false)
Sentry.captureException(t)
Logger.captureException(t)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import androidx.lifecycle.ViewModel
import de.hbch.traewelling.api.TraewellingApi
import de.hbch.traewelling.api.models.status.Status
import de.hbch.traewelling.api.models.status.StatusPage
import io.sentry.Sentry
import de.hbch.traewelling.logging.Logger
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
Expand Down Expand Up @@ -40,7 +40,7 @@ class DashboardFragmentViewModel : ViewModel() {
}
override fun onFailure(call: Call<StatusPage>, t: Throwable) {
isRefreshing.postValue(false)
Sentry.captureException(t)
Logger.captureException(t)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import de.hbch.traewelling.api.TraewellingApi
import de.hbch.traewelling.api.models.Data
import de.hbch.traewelling.api.models.station.Station
import de.hbch.traewelling.api.models.station.StationData
import io.sentry.Sentry
import de.hbch.traewelling.logging.Logger
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
Expand All @@ -30,7 +30,7 @@ class SearchStationCardViewModel: ViewModel() {
}
override fun onFailure(call: Call<Data<List<Station>>>, t: Throwable) {
failureCallback()
Sentry.captureException(t)
Logger.captureException(t)
}
})
}
Expand All @@ -56,7 +56,7 @@ class SearchStationCardViewModel: ViewModel() {

override fun onFailure(call: Call<StationData>, t: Throwable) {
failureCallback()
Sentry.captureException(t)
Logger.captureException(t)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package de.hbch.traewelling.ui.include.status

import androidx.lifecycle.ViewModel
import de.hbch.traewelling.api.TraewellingApi
import io.sentry.Sentry
import de.hbch.traewelling.logging.Logger
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
Expand All @@ -18,7 +18,7 @@ class CheckInCardViewModel : ViewModel() {
}
}
override fun onFailure(call: Call<Unit>, t: Throwable) {
Sentry.captureException(t)
Logger.captureException(t)
}
})
}
Expand All @@ -33,7 +33,7 @@ class CheckInCardViewModel : ViewModel() {
}
}
override fun onFailure(call: Call<Unit>, t: Throwable) {
Sentry.captureException(t)
Logger.captureException(t)
}
})
}
Expand All @@ -55,7 +55,7 @@ class CheckInCardViewModel : ViewModel() {

override fun onFailure(call: Call<Any>, t: Throwable) {
failureCallback()
Sentry.captureException(t)
Logger.captureException(t)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package de.hbch.traewelling.ui.login
import androidx.lifecycle.ViewModel
import de.hbch.traewelling.api.WebhookRelayApi
import de.hbch.traewelling.api.models.webhook.WebhookUserCreateRequest
import io.sentry.Sentry
import de.hbch.traewelling.logging.Logger
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
Expand All @@ -29,7 +29,7 @@ class LoginViewModel : ViewModel() {
}

override fun onFailure(call: Call<String>, t: Throwable) {
Sentry.captureException(t)
Logger.captureException(t)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import de.hbch.traewelling.api.TraewellingApi
import de.hbch.traewelling.api.models.Data
import de.hbch.traewelling.api.models.notifications.Notification
import de.hbch.traewelling.api.models.notifications.NotificationPage
import io.sentry.Sentry
import de.hbch.traewelling.logging.Logger
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
Expand All @@ -27,7 +27,7 @@ class NotificationsViewModel : ViewModel() {
}

override fun onFailure(call: Call<Data<Int>>, t: Throwable) {
Sentry.captureException(t)
Logger.captureException(t)
}
}
)
Expand All @@ -50,7 +50,7 @@ class NotificationsViewModel : ViewModel() {
}
}
override fun onFailure(call: Call<NotificationPage>, t: Throwable) {
Sentry.captureException(t)
Logger.captureException(t)
}
})
}
Expand All @@ -73,7 +73,7 @@ class NotificationsViewModel : ViewModel() {
}

override fun onFailure(call: Call<Data<Notification>>, t: Throwable) {
Sentry.captureException(t)
Logger.captureException(t)
}
})
}
Expand All @@ -96,7 +96,7 @@ class NotificationsViewModel : ViewModel() {
}

override fun onFailure(call: Call<Data<Notification>>, t: Throwable) {
Sentry.captureException(t)
Logger.captureException(t)
}
})
}
Expand All @@ -113,7 +113,7 @@ class NotificationsViewModel : ViewModel() {
}

override fun onFailure(call: Call<Unit>, t: Throwable) {
Sentry.captureException(t)
Logger.captureException(t)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import de.hbch.traewelling.api.models.Data
import de.hbch.traewelling.api.models.meta.Times
import de.hbch.traewelling.api.models.station.Station
import de.hbch.traewelling.api.models.trip.HafasTripPage
import io.sentry.Sentry
import de.hbch.traewelling.logging.Logger
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
Expand Down Expand Up @@ -48,7 +48,7 @@ class SearchConnectionViewModel: ViewModel() {
}
override fun onFailure(call: Call<HafasTripPage>, t: Throwable) {
failureCallback()
Sentry.captureException(t)
Logger.captureException(t)
}
})
}
Expand Down Expand Up @@ -76,7 +76,7 @@ class SearchConnectionViewModel: ViewModel() {

override fun onFailure(call: Call<Data<Station>>, t: Throwable) {
failureCallback()
Sentry.captureException(t)
Logger.captureException(t)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import de.hbch.traewelling.api.TraewellingApi
import de.hbch.traewelling.api.models.Data
import de.hbch.traewelling.api.dtos.Trip
import de.hbch.traewelling.api.models.trip.HafasTrainTrip
import io.sentry.Sentry
import de.hbch.traewelling.logging.Logger
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
Expand Down Expand Up @@ -35,7 +35,7 @@ class SelectDestinationViewModel : ViewModel() {
failureCallback()
}
override fun onFailure(call: Call<Data<HafasTrainTrip>>, t: Throwable) {
Sentry.captureException(t)
Logger.captureException(t)
}
})
}
Expand Down
Loading