File tree Expand file tree Collapse file tree
main/java/com/automattic/android/tracks/crashlogging
test/java/com/automattic/android/tracks
sampletracksapp/src/main/java/com/example/sampletracksapp Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ interface CrashLoggingDataProvider {
1717 /* *
1818 * Provides [CrashLogging] with the name of this release.
1919 */
20- val releaseName: String
20+ val releaseName: ReleaseName
2121
2222 /* *
2323 * Provides the [CrashLogging] with information about the user's current locale
@@ -80,6 +80,20 @@ interface CrashLoggingDataProvider {
8080
8181typealias ExtraKnownKey = String
8282
83+ sealed class ReleaseName {
84+ /* *
85+ * Sets release name attached for every event sent to Sentry. It's indented to use in debug.
86+ */
87+ class SetByApplication (val name : String ) : ReleaseName()
88+
89+ /* *
90+ * Delegates setting the release name to the Tracks library. It's indented to use in release
91+ * builds. The crash logging framework will single-handledly set the release name based on the
92+ * build configuration.
93+ */
94+ object SetByTracksLibrary : ReleaseName()
95+ }
96+
8397sealed class PerformanceMonitoringConfig {
8498 object Disabled : PerformanceMonitoringConfig()
8599
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import com.automattic.android.tracks.crashlogging.JsException
99import com.automattic.android.tracks.crashlogging.JsExceptionCallback
1010import com.automattic.android.tracks.crashlogging.PerformanceMonitoringConfig.Disabled
1111import com.automattic.android.tracks.crashlogging.PerformanceMonitoringConfig.Enabled
12+ import com.automattic.android.tracks.crashlogging.ReleaseName
1213import com.automattic.android.tracks.crashlogging.eventLevel
1314import io.sentry.Breadcrumb
1415import io.sentry.Sentry
@@ -44,7 +45,10 @@ internal class SentryCrashLogging constructor(
4445 options.apply {
4546 dsn = dataProvider.sentryDSN
4647 environment = dataProvider.buildType
47- release = dataProvider.releaseName
48+ release = when (val releaseName = dataProvider.releaseName) {
49+ is ReleaseName .SetByApplication -> releaseName.name
50+ ReleaseName .SetByTracksLibrary -> null
51+ }
4852 this .tracesSampleRate = tracesSampleRate
4953 this .profilesSampleRate = profilesSampleRate
5054 isDebug = dataProvider.enableCrashLoggingLogs
Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ class SentryCrashLoggingTest {
8080 SoftAssertions ().apply {
8181 assertThat(options.dsn).isEqualTo(dataProvider.sentryDSN)
8282 assertThat(options.environment).isEqualTo(dataProvider.buildType)
83- assertThat(options.release).isEqualTo(dataProvider.releaseName)
83+ assertThat(options.release).isEqualTo(( dataProvider.releaseName as ReleaseName . SetByApplication ).name )
8484 }.assertAll()
8585 }
8686 }
Original file line number Diff line number Diff line change @@ -6,14 +6,15 @@ import com.automattic.android.tracks.crashlogging.CrashLoggingUser
66import com.automattic.android.tracks.crashlogging.EventLevel
77import com.automattic.android.tracks.crashlogging.ExtraKnownKey
88import com.automattic.android.tracks.crashlogging.PerformanceMonitoringConfig
9+ import com.automattic.android.tracks.crashlogging.ReleaseName
910import kotlinx.coroutines.flow.Flow
1011import kotlinx.coroutines.flow.MutableStateFlow
1112import java.util.Locale
1213
1314class FakeDataProvider (
1415 override val sentryDSN : String = BuildConfig .SENTRY_TEST_PROJECT_DSN ,
1516 override val buildType : String = " testBuildType" ,
16- override val releaseName : String = " testReleaseName" ,
17+ override val releaseName : ReleaseName = ReleaseName . SetByApplication ( "testReleaseName") ,
1718 override val locale : Locale ? = Locale .US ,
1819 override val enableCrashLoggingLogs : Boolean = true ,
1920 var crashLoggingEnabled : Boolean = true ,
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import com.automattic.android.tracks.crashlogging.JsException
1313import com.automattic.android.tracks.crashlogging.JsExceptionCallback
1414import com.automattic.android.tracks.crashlogging.JsExceptionStackTraceElement
1515import com.automattic.android.tracks.crashlogging.PerformanceMonitoringConfig
16+ import com.automattic.android.tracks.crashlogging.ReleaseName
1617import com.automattic.android.tracks.crashlogging.RequestFormatter
1718import com.automattic.android.tracks.crashlogging.performance.PerformanceMonitoringRepositoryProvider
1819import com.automattic.android.tracks.crashlogging.performance.PerformanceTransactionRepository
@@ -41,7 +42,7 @@ class MainActivity : AppCompatActivity() {
4142 object : CrashLoggingDataProvider {
4243 override val sentryDSN = BuildConfig .SENTRY_TEST_PROJECT_DSN
4344 override val buildType = BuildConfig .BUILD_TYPE
44- override val releaseName = " test"
45+ override val releaseName = ReleaseName . SetByApplication ( " test" )
4546 override val locale = Locale .US
4647 override val enableCrashLoggingLogs = true
4748 override val performanceMonitoringConfig = PerformanceMonitoringConfig .Enabled (sampleRate = 1.0 , profilesSampleRate = 1.0 )
You can’t perform that action at this time.
0 commit comments