Skip to content

Commit

Permalink
Use Sentry breadcrumbs instead of logging new events
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartinesp committed Jan 30, 2025
1 parent 22795af commit eced97d
Showing 1 changed file with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ import io.element.android.libraries.di.AppScope
import io.element.android.libraries.di.ApplicationContext
import io.element.android.services.analyticsproviders.api.AnalyticsProvider
import io.element.android.services.analyticsproviders.sentry.log.analyticsTag
import io.sentry.Breadcrumb
import io.sentry.Sentry
import io.sentry.SentryLevel
import io.sentry.SentryOptions
import io.sentry.android.core.SentryAndroid
import timber.log.Timber
import javax.inject.Inject
import kotlin.collections.component1
import kotlin.collections.component2
import kotlin.collections.iterator
import kotlin.collections.orEmpty

@ContributesMultibinding(AppScope::class)
class SentryAnalyticsProvider @Inject constructor(
Expand Down Expand Up @@ -59,11 +63,23 @@ class SentryAnalyticsProvider @Inject constructor(
}

override fun capture(event: VectorAnalyticsEvent) {
Sentry.captureMessage("Event: ${event.getName()}", SentryLevel.INFO)
val breadcrumb = Breadcrumb(event.getName()).apply {
category = "event"

Check warning on line 67 in services/analyticsproviders/sentry/src/main/kotlin/io/element/android/services/analyticsproviders/sentry/SentryAnalyticsProvider.kt

View check run for this annotation

Codecov / codecov/patch

services/analyticsproviders/sentry/src/main/kotlin/io/element/android/services/analyticsproviders/sentry/SentryAnalyticsProvider.kt#L66-L67

Added lines #L66 - L67 were not covered by tests
for ((key, value) in event.getProperties().orEmpty()) {
setData(key, value.toString())

Check warning on line 69 in services/analyticsproviders/sentry/src/main/kotlin/io/element/android/services/analyticsproviders/sentry/SentryAnalyticsProvider.kt

View check run for this annotation

Codecov / codecov/patch

services/analyticsproviders/sentry/src/main/kotlin/io/element/android/services/analyticsproviders/sentry/SentryAnalyticsProvider.kt#L69

Added line #L69 was not covered by tests
}
}
Sentry.addBreadcrumb(breadcrumb)

Check warning on line 72 in services/analyticsproviders/sentry/src/main/kotlin/io/element/android/services/analyticsproviders/sentry/SentryAnalyticsProvider.kt

View check run for this annotation

Codecov / codecov/patch

services/analyticsproviders/sentry/src/main/kotlin/io/element/android/services/analyticsproviders/sentry/SentryAnalyticsProvider.kt#L71-L72

Added lines #L71 - L72 were not covered by tests
}

override fun screen(screen: VectorAnalyticsScreen) {
Sentry.captureMessage("Screen: ${screen.getName()}", SentryLevel.INFO)
val breadcrumb = Breadcrumb(screen.getName()).apply {
category = "screen"

Check warning on line 77 in services/analyticsproviders/sentry/src/main/kotlin/io/element/android/services/analyticsproviders/sentry/SentryAnalyticsProvider.kt

View check run for this annotation

Codecov / codecov/patch

services/analyticsproviders/sentry/src/main/kotlin/io/element/android/services/analyticsproviders/sentry/SentryAnalyticsProvider.kt#L76-L77

Added lines #L76 - L77 were not covered by tests
for ((key, value) in screen.getProperties().orEmpty()) {
setData(key, value.toString())

Check warning on line 79 in services/analyticsproviders/sentry/src/main/kotlin/io/element/android/services/analyticsproviders/sentry/SentryAnalyticsProvider.kt

View check run for this annotation

Codecov / codecov/patch

services/analyticsproviders/sentry/src/main/kotlin/io/element/android/services/analyticsproviders/sentry/SentryAnalyticsProvider.kt#L79

Added line #L79 was not covered by tests
}
}
Sentry.addBreadcrumb(breadcrumb)

Check warning on line 82 in services/analyticsproviders/sentry/src/main/kotlin/io/element/android/services/analyticsproviders/sentry/SentryAnalyticsProvider.kt

View check run for this annotation

Codecov / codecov/patch

services/analyticsproviders/sentry/src/main/kotlin/io/element/android/services/analyticsproviders/sentry/SentryAnalyticsProvider.kt#L81-L82

Added lines #L81 - L82 were not covered by tests
}

override fun updateUserProperties(userProperties: UserProperties) {
Expand Down

0 comments on commit eced97d

Please sign in to comment.